1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
#====================== BEGIN GPL LICENSE BLOCK ======================
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
#======================= END GPL LICENSE BLOCK ========================
bl_info = {
"name": "Math Vis (Console)",
"author": "Campbell Barton",
"version": (0, 1),
"blender": (2, 5, 6),
"api": 33110,
"location": "View3D > Tool Shelf or Console",
"description": "Display console defined mathutils variables in the 3D view",
"wiki_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/"\
"Scripts/3D_interaction/Math_Viz",
"tracker_url": "http://projects.blender.org/tracker/index.php?"\
"func=detail&aid=25545",
"support": "OFFICIAL",
"category": "3D View"}
if "bpy" in locals():
import imp
imp.reload(utils)
imp.reload(draw)
else:
from . import utils, draw
import bpy
class VIEW3D_PT_math_vis(bpy.types.Panel):
bl_space_type = "VIEW_3D"
bl_region_type = "TOOLS"
bl_label = "Math View"
def draw(self, context):
layout = self.layout
view = context.space_data
col = layout.column(align=True)
callbacks = draw.callbacks
ok = False
for region in context.area.regions:
if callbacks.get(hash(region)):
ok = True
break
col.operator("view3d.math_vis_toggle", emboss=False, icon='CHECKBOX_HLT' if ok else 'CHECKBOX_DEHLT')
class SetupMathView(bpy.types.Operator):
'''Draw a line with the mouse'''
bl_idname = "view3d.math_vis_toggle"
bl_label = "Use Math Vis"
def execute(self, context):
callbacks = draw.callbacks
region = context.region
region_id = hash(region)
cb_data = callbacks.get(region_id)
if cb_data is None:
handle_pixel = region.callback_add(draw.draw_callback_px, (self, context), 'POST_PIXEL')
handle_view = region.callback_add(draw.draw_callback_view, (self, context), 'POST_VIEW')
callbacks[region_id] = region, handle_pixel, handle_view
else:
region.callback_remove(cb_data[1])
region.callback_remove(cb_data[2])
del callbacks[region_id]
context.area.tag_redraw()
return {'FINISHED'}
def console_hook():
for region, handle_pixel, handle_view in draw.callbacks.values():
region.tag_redraw()
def register():
bpy.utils.register_module(__name__)
import console_python
console_python.execute.hooks.append((console_hook, ()))
def unregister():
bpy.utils.unregister_module(__name__)
import console_python
console_python.execute.hooks.remove((console_hook, ()))
draw.callbacks_clear()
|