Cleanup: quiet warnings with descriptions ending with a '.'
[blender-addons.git] / space_view3d_math_vis / __init__.py
blobac05ffc602890ffa451c1866292590d854b8d826
1 # SPDX-License-Identifier: GPL-2.0-or-later
3 bl_info = {
4 "name": "Math Vis (Console)",
5 "author": "Campbell Barton",
6 "version": (0, 2, 2),
7 "blender": (3, 0, 0),
8 "location": "Properties: Scene > Math Vis Console and Python Console: Menu",
9 "description": "Display console defined mathutils variables in the 3D view",
10 "doc_url": "{BLENDER_MANUAL_URL}/addons/3d_view/math_vis_console.html",
11 "support": "OFFICIAL",
12 "category": "3D View",
16 if "bpy" in locals():
17 import importlib
18 importlib.reload(utils)
19 importlib.reload(draw)
20 else:
21 from . import utils
22 from . import draw
24 import bpy
25 from bpy.types import (
26 Operator,
27 Panel,
28 PropertyGroup,
29 UIList,
31 from bpy.props import (
32 StringProperty,
33 BoolProperty,
34 BoolVectorProperty,
35 FloatProperty,
36 IntProperty,
37 PointerProperty,
38 CollectionProperty,
42 class PanelConsoleVars(Panel):
43 bl_space_type = 'PROPERTIES'
44 bl_region_type = 'WINDOW'
45 bl_context = 'scene'
46 bl_label = "Math Vis Console"
47 bl_idname = "MATHVIS_PT_panel_console_vars"
48 bl_category = "Math Vis"
49 bl_options = {'DEFAULT_CLOSED'}
51 def draw(self, context):
52 layout = self.layout
53 wm = context.window_manager
54 state_props = wm.MathVisStatePropList
56 if len(state_props) == 0:
57 box = layout.box()
58 col = box.column(align=True)
59 col.label(text="No vars to display")
60 else:
61 layout.template_list(
62 MathVisVarList.bl_idname,
63 'MathVisStatePropList',
64 bpy.context.window_manager,
65 'MathVisStatePropList',
66 bpy.context.window_manager.MathVisProp,
67 'index',
68 rows=10
70 col = layout.column()
71 mvp = wm.MathVisProp
72 col.prop(mvp, "name_hide")
73 col.prop(mvp, "bbox_hide")
74 col.prop(mvp, "in_front")
75 col.prop(mvp, "bbox_scale")
76 col.operator("mathvis.cleanup_console")
79 class DeleteVar(Operator):
80 bl_idname = "mathvis.delete_var"
81 bl_label = "Delete Var"
82 bl_description = "Remove the variable from the Console"
83 bl_options = {'REGISTER'}
85 key: StringProperty(name="Key")
87 def execute(self, context):
88 locals = utils.console_namespace()
89 utils.VarStates.delete(self.key)
90 del locals[self.key]
91 draw.tag_redraw_areas()
92 return {'FINISHED'}
95 class ToggleDisplay(Operator):
96 bl_idname = "mathvis.toggle_display"
97 bl_label = "Hide/Unhide"
98 bl_description = "Change the display state of the var"
99 bl_options = {'REGISTER'}
101 key: StringProperty(name="Key")
103 def execute(self, context):
104 utils.VarStates.toggle_display_state(self.key)
105 draw.tag_redraw_areas()
106 return {'FINISHED'}
109 class ToggleLock(Operator):
110 bl_idname = "mathvis.toggle_lock"
111 bl_label = "Lock/Unlock"
112 bl_description = "Lock the var from being deleted"
113 bl_options = {'REGISTER'}
115 key: StringProperty(name="Key")
117 def execute(self, context):
118 utils.VarStates.toggle_lock_state(self.key)
119 draw.tag_redraw_areas()
120 return {'FINISHED'}
123 class ToggleMatrixBBoxDisplay(Operator):
124 bl_idname = "mathvis.show_bbox"
125 bl_label = "Show BBox"
126 bl_description = "Show/Hide the BBox of Matrix items"
127 bl_options = {'REGISTER'}
129 def execute(self, context):
130 utils.VarStates.toggle_show_bbox()
131 draw.tag_redraw_areas()
132 return {'FINISHED'}
135 class CleanupConsole(Operator):
136 bl_idname = "mathvis.cleanup_console"
137 bl_label = "Cleanup Math Vis Console"
138 bl_description = "Remove all visualized variables from the Console"
139 bl_options = {'REGISTER'}
141 def execute(self, context):
142 utils.cleanup_math_data()
143 draw.tag_redraw_areas()
144 return {'FINISHED'}
147 def menu_func_cleanup(self, context):
148 self.layout.operator("mathvis.cleanup_console", text="Clear Math Vis")
151 def console_hook():
152 utils.VarStates.store_states()
153 draw.tag_redraw_areas()
154 context = bpy.context
155 for window in context.window_manager.windows:
156 window.screen.areas.update()
159 def call_console_hook(self, context):
160 console_hook()
163 class MathVisStateProp(PropertyGroup):
164 ktype: StringProperty()
165 state: BoolVectorProperty(default=(False, False), size=2)
168 class MathVisVarList(UIList):
169 bl_idname = "MATHVIS_UL_MathVisVarList"
171 def draw_item(self,
172 context,
173 layout,
174 data,
175 item,
176 icon,
177 active_data,
178 active_propname
181 col = layout.column()
182 key = item.name
183 ktype = item.ktype
184 is_visible = item.state[0]
185 is_locked = item.state[1]
187 row = col.row(align=True)
188 row.label(text='%s - %s' % (key, ktype))
190 icon = 'RESTRICT_VIEW_OFF' if is_visible else 'RESTRICT_VIEW_ON'
191 prop = row.operator("mathvis.toggle_display", text='', icon=icon, emboss=False)
192 prop.key = key
194 icon = 'LOCKED' if is_locked else 'UNLOCKED'
195 prop = row.operator("mathvis.toggle_lock", text='', icon=icon, emboss=False)
196 prop.key = key
198 if is_locked:
199 row.label(text='', icon='BLANK1')
200 else:
201 prop = row.operator("mathvis.delete_var", text='', icon='X', emboss=False)
202 prop.key = key
205 class MathVis(PropertyGroup):
207 index: IntProperty(
208 name="index"
210 bbox_hide: BoolProperty(
211 name="Hide BBoxes",
212 default=False,
213 description="Hide the bounding boxes rendered for Matrix like items",
214 update=call_console_hook
216 name_hide: BoolProperty(
217 name="Hide Names",
218 default=False,
219 description="Hide the names of the rendered items",
220 update=call_console_hook
222 bbox_scale: FloatProperty(
223 name="Scale factor",
224 min=0, default=1,
225 description="Resize the Bounding Box and the coordinate "
226 "lines for the display of Matrix items"
229 in_front: BoolProperty(
230 name="Always In Front",
231 default=True,
232 description="Draw Points and lines always in front",
233 update=call_console_hook
237 classes = (
238 PanelConsoleVars,
239 DeleteVar,
240 ToggleDisplay,
241 ToggleLock,
242 ToggleMatrixBBoxDisplay,
243 CleanupConsole,
244 MathVisStateProp,
245 MathVisVarList,
246 MathVis,
250 def register():
251 from bpy.utils import register_class
253 draw.callback_enable()
255 import console_python
256 console_python.execute.hooks.append((console_hook, ()))
257 for cls in classes:
258 bpy.utils.register_class(cls)
259 bpy.types.WindowManager.MathVisProp = PointerProperty(type=MathVis)
260 bpy.types.WindowManager.MathVisStatePropList = CollectionProperty(type=MathVisStateProp)
261 bpy.types.CONSOLE_MT_console.prepend(menu_func_cleanup)
264 def unregister():
265 from bpy.utils import unregister_class
267 draw.callback_disable()
269 import console_python
270 console_python.execute.hooks.remove((console_hook, ()))
271 bpy.types.CONSOLE_MT_console.remove(menu_func_cleanup)
272 del bpy.types.WindowManager.MathVisProp
273 del bpy.types.WindowManager.MathVisStatePropList
275 for cls in classes:
276 unregister_class(cls)