Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2012-12-20 17:32:14 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-12-20 17:32:14 +0400
commit6332e745a7e1987a19e463a323858cc0ad3409e7 (patch)
tree57d927427aac8ef3065ff9165d09a2848141d81a /space_view3d_math_vis
parent2872d0440fd1fdb4048cfd0a135f4763562cf96e (diff)
update for changes to the rna api
Diffstat (limited to 'space_view3d_math_vis')
-rw-r--r--space_view3d_math_vis/__init__.py50
-rw-r--r--space_view3d_math_vis/draw.py54
-rw-r--r--space_view3d_math_vis/utils.py8
3 files changed, 52 insertions, 60 deletions
diff --git a/space_view3d_math_vis/__init__.py b/space_view3d_math_vis/__init__.py
index d772cb46..56828951 100644
--- a/space_view3d_math_vis/__init__.py
+++ b/space_view3d_math_vis/__init__.py
@@ -42,62 +42,18 @@ else:
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()
diff --git a/space_view3d_math_vis/draw.py b/space_view3d_math_vis/draw.py
index 509881e0..46004d3a 100644
--- a/space_view3d_math_vis/draw.py
+++ b/space_view3d_math_vis/draw.py
@@ -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
+ # 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 callbacks_clear():
- for region, handle_pixel, handle_view in callbacks.values():
- region.callback_remove(handle_pixel)
- region.callback_remove(handle_view)
- callbacks.clear()
+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
-def draw_callback_px(self, 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 @@ def draw_callback_px(self, context):
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()
diff --git a/space_view3d_math_vis/utils.py b/space_view3d_math_vis/utils.py
index a89a9ffb..318beffa 100644
--- a/space_view3d_math_vis/utils.py
+++ b/space_view3d_math_vis/utils.py
@@ -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,7 +14,9 @@
# 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
@@ -25,6 +27,7 @@ def console_namespace():
return console.locals
return {}
+
def console_math_data():
from mathutils import Matrix, Vector, Quaternion, Euler
@@ -66,4 +69,3 @@ def console_math_data():
data_vector_array[key] = var
return data_matrix, data_quat, data_euler, data_vector, data_vector_array
-