Pose library: fix asset creation operator poll when no object active
[blender-addons.git] / space_view3d_pie_menus / pie_shading_menu.py
blob9ab8d617598ae780c0e0f38d0a450b218eef11a8
1 # SPDX-License-Identifier: GPL-2.0-or-later
3 bl_info = {
4 "name": "Hotkey: 'Z'",
5 "description": "Viewport Shading Menus",
6 "author": "pitiwazou, meta-androcto",
7 "version": (0, 1, 1),
8 "blender": (2, 80, 0),
9 "location": "3D View",
10 "warning": "",
11 "doc_url": "",
12 "category": "Shading Pie"
15 import bpy
16 from bpy.types import Menu
19 # Pie Shading - Z
20 class PIE_MT_ShadingView(Menu):
21 bl_idname = "PIE_MT_shadingview"
22 bl_label = "Pie Shading"
24 def draw(self, context):
25 layout = self.layout
27 pie = layout.menu_pie()
28 pie.prop(context.space_data.shading, "type", expand=True)
30 if context.active_object:
31 if context.mode == 'EDIT_MESH':
32 pie.operator("MESH_OT_faces_shade_smooth")
33 pie.operator("MESH_OT_faces_shade_flat")
34 else:
35 pie.operator("OBJECT_OT_shade_smooth")
36 pie.operator("OBJECT_OT_shade_flat")
39 classes = (
40 PIE_MT_ShadingView,
43 addon_keymaps = []
46 def register():
47 for cls in classes:
48 bpy.utils.register_class(cls)
50 wm = bpy.context.window_manager
51 if wm.keyconfigs.addon:
52 # Shading
53 km = wm.keyconfigs.addon.keymaps.new(name='3D View Generic', space_type='VIEW_3D')
54 kmi = km.keymap_items.new('wm.call_menu_pie', 'Z', 'PRESS')
55 kmi.properties.name = "PIE_MT_shadingview"
56 addon_keymaps.append((km, kmi))
59 def unregister():
60 for cls in classes:
61 bpy.utils.unregister_class(cls)
63 wm = bpy.context.window_manager
64 kc = wm.keyconfigs.addon
65 if kc:
66 for km, kmi in addon_keymaps:
67 km.keymap_items.remove(kmi)
68 addon_keymaps.clear()
71 if __name__ == "__main__":
72 register()