~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to release/scripts/addons/space_view3d_math_vis/__init__.py

  • Committer: Bazaar Package Importer
  • Author(s): Kevin Roy
  • Date: 2011-02-08 22:20:54 UTC
  • mfrom: (1.4.2 upstream)
  • mto: (14.2.6 sid) (1.5.1)
  • mto: This revision was merged to the branch mainline in revision 27.
  • Revision ID: james.westby@ubuntu.com-20110208222054-kk0gwa4bu8h5lyq4
Tags: upstream-2.56.1-beta-svn34076
ImportĀ upstreamĀ versionĀ 2.56.1-beta-svn34076

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#====================== BEGIN GPL LICENSE BLOCK ======================
 
2
#
 
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.
 
7
#
 
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.
 
12
#
 
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.
 
16
#
 
17
#======================= END GPL LICENSE BLOCK ========================
 
18
 
 
19
bl_addon_info = {
 
20
    "name": "Math Vis (Console)",
 
21
    "author": "Campbell Barton",
 
22
    "version": (0, 1),
 
23
    "blender": (2, 5, 5),
 
24
    "api": 33110,
 
25
    "location": "3D View Toolbar, Python Console",
 
26
    "description": "Display console defined mathutils variables in the 3D view",
 
27
    "wiki_url": "",
 
28
    "tracker_url": "",
 
29
    "category": "3D View"}
 
30
 
 
31
if "bpy" in locals():
 
32
    import imp
 
33
    imp.reload(utils)
 
34
    imp.reload(draw)
 
35
else:
 
36
    from . import utils, draw
 
37
 
 
38
import bpy
 
39
 
 
40
 
 
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"
 
45
 
 
46
    def draw(self, context):
 
47
        layout = self.layout
 
48
        view = context.space_data
 
49
 
 
50
        col = layout.column(align=True) 
 
51
 
 
52
        callbacks = draw.callbacks
 
53
        ok = False
 
54
        for region in context.area.regions:
 
55
            if callbacks.get(hash(region)):
 
56
                ok = True
 
57
                break
 
58
 
 
59
        col.operator("view3d.math_vis_toggle", emboss=False, icon='CHECKBOX_HLT' if ok else 'CHECKBOX_DEHLT')
 
60
 
 
61
 
 
62
 
 
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"
 
67
 
 
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)
 
73
        if cb_data is None:
 
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
 
77
        else:
 
78
            region.callback_remove(cb_data[1])
 
79
            region.callback_remove(cb_data[2])
 
80
            del callbacks[region_id]
 
81
 
 
82
        context.area.tag_redraw()
 
83
        return {'FINISHED'}
 
84
 
 
85
 
 
86
def console_hook():
 
87
    for region, handle_pixel, handle_view in draw.callbacks.values():
 
88
        region.tag_redraw()
 
89
 
 
90
 
 
91
def register():
 
92
    import console_python
 
93
    console_python.execute.hooks.append((console_hook, ()))
 
94
 
 
95
def unregister():
 
96
    import console_python
 
97
    console_python.execute.hooks.remove((console_hook, ()))
 
98
 
 
99
    draw.callbacks_clear()