diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-11-22 08:43:45 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-11-22 08:43:45 +0300 |
commit | 26a2d2d3a99c1dda6237f078c40a4c9d9820b1c7 (patch) | |
tree | ec7b566984ad856c6cf6cdab64c2362bfe9ad2c5 /space_view3d_math_vis/__init__.py | |
parent | e76cef723ded343eb255ccc3db9183d859e0b55c (diff) |
tool to visualize console mathutils vars
Diffstat (limited to 'space_view3d_math_vis/__init__.py')
-rw-r--r-- | space_view3d_math_vis/__init__.py | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/space_view3d_math_vis/__init__.py b/space_view3d_math_vis/__init__.py new file mode 100644 index 00000000..a73ec1cc --- /dev/null +++ b/space_view3d_math_vis/__init__.py @@ -0,0 +1,100 @@ +#====================== 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_addon_info = { + "name": "Math Vis (Console)", + "author": "Campbell Barton", + "version": (0, 1), + "blender": (2, 5, 5), + "api": 33110, + "location": "3D View Toolbar, Python Console", + "description": "Display console defined mathutils variables in the 3D view", + "wiki_url": "", + "tracker_url": "", + "category": "3D View"} + +if "bpy" in locals(): + from imp import reload + reload(utils) + 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(): + import console_python + console_python.execute.hooks.append((console_hook, ())) + +def unregister(): + import console_python + console_python.execute.hooks.remove((console_hook, ())) + + draw.callbacks_clear() |