[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [4083] trunk/py/scripts/addons/ space_view3d_math_vis: update for changes to the rna api
Campbell Barton
ideasman42 at gmail.com
Thu Dec 20 14:32:15 CET 2012
Revision: 4083
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=4083
Author: campbellbarton
Date: 2012-12-20 13:32:14 +0000 (Thu, 20 Dec 2012)
Log Message:
-----------
update for changes to the rna api
Modified Paths:
--------------
trunk/py/scripts/addons/space_view3d_math_vis/__init__.py
trunk/py/scripts/addons/space_view3d_math_vis/draw.py
trunk/py/scripts/addons/space_view3d_math_vis/utils.py
Modified: trunk/py/scripts/addons/space_view3d_math_vis/__init__.py
===================================================================
--- trunk/py/scripts/addons/space_view3d_math_vis/__init__.py 2012-12-20 09:41:07 UTC (rev 4082)
+++ trunk/py/scripts/addons/space_view3d_math_vis/__init__.py 2012-12-20 13:32:14 UTC (rev 4083)
@@ -42,62 +42,18 @@
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):
- callbacks = draw.callbacks
- ok = False
- for region in context.area.regions:
- if callbacks.get(hash(region)):
- ok = True
- break
-
- self.layout.operator("view3d.math_vis_toggle", emboss=False, icon='CHECKBOX_HLT' if ok else 'CHECKBOX_DEHLT')
-
-
-class SetupMathView(bpy.types.Operator):
- """Visualize mathutils type python variables from the """ \
- """interactive console, see addon docs"""
- 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()
+ draw.tag_redraw_all_view3d()
-
def register():
- bpy.utils.register_module(__name__)
+ draw.callback_enable()
import console_python
console_python.execute.hooks.append((console_hook, ()))
def unregister():
- bpy.utils.unregister_module(__name__)
+ draw.callback_disable()
import console_python
console_python.execute.hooks.remove((console_hook, ()))
-
- draw.callbacks_clear()
Modified: trunk/py/scripts/addons/space_view3d_math_vis/draw.py
===================================================================
--- trunk/py/scripts/addons/space_view3d_math_vis/draw.py 2012-12-20 09:41:07 UTC (rev 4082)
+++ trunk/py/scripts/addons/space_view3d_math_vis/draw.py 2012-12-20 13:32:14 UTC (rev 4083)
@@ -1,4 +1,4 @@
-#====================== BEGIN GPL LICENSE BLOCK ======================
+# ##### 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
@@ -14,25 +14,57 @@
# 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 ========================
+# ##### END GPL LICENSE BLOCK #####
+# <pep8 compliant>
+
import bpy
import blf
from . import utils
from mathutils import Vector, Matrix
+SpaceView3D = bpy.types.SpaceView3D
+callback_handle = []
-callbacks = {}
+def tag_redraw_all_view3d():
+ context = bpy.context
-def callbacks_clear():
- for region, handle_pixel, handle_view in callbacks.values():
- region.callback_remove(handle_pixel)
- region.callback_remove(handle_view)
- callbacks.clear()
+ # Py cant access notifers
+ for window in context.window_manager.windows:
+ for area in window.screen.areas:
+ if area.type == 'VIEW_3D':
+ for region in area.regions:
+ if region.type == 'WINDOW':
+ region.tag_redraw()
-def draw_callback_px(self, context):
+def callback_enable():
+ if callback_handle:
+ return
+
+ handle_pixel = SpaceView3D.draw_handler_add(draw_callback_px, (), 'WINDOW', 'POST_PIXEL')
+ handle_view = SpaceView3D.draw_handler_add(draw_callback_view, (), 'WINDOW', 'POST_VIEW')
+ callback_handle[:] = handle_pixel, handle_view
+
+ tag_redraw_all_view3d()
+
+
+def callback_disable():
+ if not callback_handle:
+ return
+
+ handle_pixel, handle_view = callback_handle
+ SpaceView3D.draw_handler_remove(handle_pixel, 'WINDOW')
+ SpaceView3D.draw_handler_remove(handle_view, 'WINDOW')
+ callback_handle[:] = []
+
+ tag_redraw_all_view3d()
+
+
+def draw_callback_px():
+ context = bpy.context
+
from bgl import glColor3f
font_id = 0 # XXX, need to find out how best to get this.
blf.size(font_id, 12, 72)
@@ -93,7 +125,9 @@
draw_text(key, loc)
-def draw_callback_view(self, context):
+def draw_callback_view():
+ context = bpy.context
+
from bgl import glEnable, glDisable, glColor3f, glVertex3f, glPointSize, glLineWidth, glBegin, glEnd, glLineStipple, GL_POINTS, GL_LINE_STRIP, GL_LINES, GL_LINE_STIPPLE
data_matrix, data_quat, data_euler, data_vector, data_vector_array = utils.console_math_data()
Modified: trunk/py/scripts/addons/space_view3d_math_vis/utils.py
===================================================================
--- trunk/py/scripts/addons/space_view3d_math_vis/utils.py 2012-12-20 09:41:07 UTC (rev 4082)
+++ trunk/py/scripts/addons/space_view3d_math_vis/utils.py 2012-12-20 13:32:14 UTC (rev 4083)
@@ -1,4 +1,4 @@
-#====================== BEGIN GPL LICENSE BLOCK ======================
+# ##### 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
@@ -14,8 +14,10 @@
# 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 ========================
+# ##### END GPL LICENSE BLOCK #####
+# <pep8 compliant>
+
def console_namespace():
import console_python
get_consoles = console_python.get_console
@@ -25,6 +27,7 @@
return console.locals
return {}
+
def console_math_data():
from mathutils import Matrix, Vector, Quaternion, Euler
@@ -66,4 +69,3 @@
data_vector_array[key] = var
return data_matrix, data_quat, data_euler, data_vector, data_vector_array
-
More information about the Bf-extensions-cvs
mailing list