1
#====================== BEGIN GPL LICENSE BLOCK ======================
3
# This program is free software; you can redistribute it and/or
4
# modify it under the terms of the GNU General Public License
5
# as published by the Free Software Foundation; either version 2
6
# of the License, or (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software Foundation,
15
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
#======================= END GPL LICENSE BLOCK ========================
20
"name": "Math Vis (Console)",
21
"author": "Campbell Barton",
25
"location": "3D View Toolbar, Python Console",
26
"description": "Display console defined mathutils variables in the 3D view",
29
"category": "3D View"}
36
from . import utils, draw
41
class VIEW3D_PT_math_vis(bpy.types.Panel):
42
bl_space_type = "VIEW_3D"
43
bl_region_type = "TOOLS"
44
bl_label = "Math View"
46
def draw(self, context):
48
view = context.space_data
50
col = layout.column(align=True)
52
callbacks = draw.callbacks
54
for region in context.area.regions:
55
if callbacks.get(hash(region)):
59
col.operator("view3d.math_vis_toggle", emboss=False, icon='CHECKBOX_HLT' if ok else 'CHECKBOX_DEHLT')
63
class SetupMathView(bpy.types.Operator):
64
'''Draw a line with the mouse'''
65
bl_idname = "view3d.math_vis_toggle"
66
bl_label = "Use Math Vis"
68
def execute(self, context):
69
callbacks = draw.callbacks
70
region = context.region
71
region_id = hash(region)
72
cb_data = callbacks.get(region_id)
74
handle_pixel = region.callback_add(draw.draw_callback_px, (self, context), 'POST_PIXEL')
75
handle_view = region.callback_add(draw.draw_callback_view, (self, context), 'POST_VIEW')
76
callbacks[region_id] = region, handle_pixel, handle_view
78
region.callback_remove(cb_data[1])
79
region.callback_remove(cb_data[2])
80
del callbacks[region_id]
82
context.area.tag_redraw()
87
for region, handle_pixel, handle_view in draw.callbacks.values():
93
console_python.execute.hooks.append((console_hook, ()))
97
console_python.execute.hooks.remove((console_hook, ()))
99
draw.callbacks_clear()