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:
authorGaia Clary <gaia.clary@machinimatrix.org>2016-12-01 22:23:52 +0300
committerGaia Clary <gaia.clary@machinimatrix.org>2016-12-01 22:24:01 +0300
commit3aaa6f21d001ed97b4d6a381f0c97d5086190913 (patch)
tree413bb1e23870f998726b77a6557eec3d396e54d8 /space_view3d_math_vis
parentecf6619d82058d808a4c17629e96db6b02b29b80 (diff)
Improved the user interface by addding a list widget to mathVis. Also got rid of the global variables
Diffstat (limited to 'space_view3d_math_vis')
-rw-r--r--space_view3d_math_vis/__init__.py113
-rw-r--r--space_view3d_math_vis/draw.py6
-rw-r--r--space_view3d_math_vis/utils.py122
3 files changed, 120 insertions, 121 deletions
diff --git a/space_view3d_math_vis/__init__.py b/space_view3d_math_vis/__init__.py
index 50e7cf87..8bccd950 100644
--- a/space_view3d_math_vis/__init__.py
+++ b/space_view3d_math_vis/__init__.py
@@ -40,8 +40,7 @@ else:
from . import utils, draw
import bpy
-from bpy.props import StringProperty, BoolProperty, BoolVectorProperty, FloatProperty, PointerProperty, CollectionProperty
-from .utils import get_var_states
+from bpy.props import StringProperty, BoolProperty, BoolVectorProperty, FloatProperty, IntProperty, PointerProperty, CollectionProperty
class PanelConsoleVars(bpy.types.Panel):
@@ -54,34 +53,25 @@ class PanelConsoleVars(bpy.types.Panel):
def draw(self, context):
layout = self.layout
- box = layout.box()
- col = box.column(align=True)
- variables = utils.get_math_data()
- var_states = get_var_states()
-
- for key in sorted(variables):
- ktype = variables[key]
- row = col.row(align=True)
- row.label(text='%s - %s' % (key, ktype.__name__))
-
- icon = 'RESTRICT_VIEW_OFF' if var_states.is_visible(key) else 'RESTRICT_VIEW_ON'
- prop = row.operator("mathvis.toggle_display", text='', icon=icon, emboss=False)
- prop.key = key
-
- icon = 'LOCKED' if var_states.is_locked(key) else 'UNLOCKED'
- prop = row.operator("mathvis.toggle_lock", text='', icon=icon, emboss=False)
- prop.key = key
-
- if var_states.is_locked(key):
- row.label(text='', icon='BLANK1')
- else:
- prop = row.operator("mathvis.delete_var", text='', icon='X', emboss=False)
- prop.key = key
+ state_props = bpy.context.window_manager.MathVisStatePropList
+
+ if len(state_props) == 0:
+ box = layout.box()
+ col = box.column(align=True)
+ col.label("No vars to display")
+ else:
+ layout.template_list('MathVisVarList',
+ 'MathVisStatePropList',
+ bpy.context.window_manager,
+ 'MathVisStatePropList',
+ bpy.context.window_manager.MathVisProp,
+ 'index',
+ rows=10)
col = layout.column()
- col.prop(bpy.context.scene.MathVisProp, "name_hide")
- col.prop(bpy.context.scene.MathVisProp, "bbox_hide")
- col.prop(bpy.context.scene.MathVisProp, "bbox_scale")
+ col.prop(bpy.context.window_manager.MathVisProp, "name_hide")
+ col.prop(bpy.context.window_manager.MathVisProp, "bbox_hide")
+ col.prop(bpy.context.window_manager.MathVisProp, "bbox_scale")
col.operator("mathvis.cleanup_console")
@@ -95,8 +85,7 @@ class DeleteVar(bpy.types.Operator):
def execute(self, context):
locals = utils.console_namespace()
- var_states = get_var_states()
- var_states.delete(self.key)
+ utils.VarStates.delete(self.key)
del locals[self.key]
draw.tag_redraw_all_view3d_areas()
return {'FINISHED'}
@@ -111,8 +100,7 @@ class ToggleDisplay(bpy.types.Operator):
key = StringProperty(name="Key")
def execute(self, context):
- var_states = get_var_states()
- var_states.toggle_display_state(self.key)
+ utils.VarStates.toggle_display_state(self.key)
draw.tag_redraw_all_view3d_areas()
return {'FINISHED'}
@@ -126,8 +114,7 @@ class ToggleLock(bpy.types.Operator):
key = StringProperty(name="Key")
def execute(self, context):
- var_states = get_var_states()
- var_states.toggle_lock_state(self.key)
+ utils.VarStates.toggle_lock_state(self.key)
draw.tag_redraw_all_view3d_areas()
return {'FINISHED'}
@@ -139,8 +126,7 @@ class ToggleMatrixBBoxDisplay(bpy.types.Operator):
bl_options = {'REGISTER'}
def execute(self, context):
- var_states = get_var_states()
- var_states.toggle_show_bbox()
+ utils.VarStates.toggle_show_bbox()
draw.tag_redraw_all_view3d_areas()
return {'FINISHED'}
@@ -162,6 +148,7 @@ def menu_func_cleanup(self, context):
def console_hook():
+ utils.VarStates.store_states()
draw.tag_redraw_all_view3d_areas()
context = bpy.context
for window in context.window_manager.windows:
@@ -173,11 +160,49 @@ def call_console_hook(self, context):
class MathVisStateProp(bpy.types.PropertyGroup):
- key = StringProperty()
+ ktype = StringProperty()
state = BoolVectorProperty(default=(False, False), size=2)
-class MathVisProp(bpy.types.PropertyGroup):
+class MathVisVarList(bpy.types.UIList):
+
+ def draw_item(self,
+ context,
+ layout,
+ data,
+ item,
+ icon,
+ active_data,
+ active_propname
+ ):
+
+ col = layout.column()
+ key = item.name
+ ktype = item.ktype
+ is_visible = item.state[0]
+ is_locked = item.state[1]
+
+ row = col.row(align=True)
+ row.label(text='%s - %s' % (key, ktype))
+
+ icon = 'RESTRICT_VIEW_OFF' if is_visible else 'RESTRICT_VIEW_ON'
+ prop = row.operator("mathvis.toggle_display", text='', icon=icon, emboss=False)
+ prop.key = key
+
+ icon = 'LOCKED' if is_locked else 'UNLOCKED'
+ prop = row.operator("mathvis.toggle_lock", text='', icon=icon, emboss=False)
+ prop.key = key
+
+ if is_locked:
+ row.label(text='', icon='BLANK1')
+ else:
+ prop = row.operator("mathvis.delete_var", text='', icon='X', emboss=False)
+ prop.key = key
+
+
+class MathVis(bpy.types.PropertyGroup):
+
+ index = IntProperty(name="index")
bbox_hide = BoolProperty(name="Hide BBoxes",
default=False,
@@ -199,20 +224,18 @@ def register():
import console_python
console_python.execute.hooks.append((console_hook, ()))
bpy.utils.register_module(__name__)
- bpy.types.Scene.MathVisProp = PointerProperty(type=MathVisProp)
- bpy.types.WindowManager.MathVisStateProp = CollectionProperty(type=MathVisStateProp)
+ bpy.types.WindowManager.MathVisProp = PointerProperty(type=MathVis)
+ bpy.types.WindowManager.MathVisStatePropList = CollectionProperty( type=MathVisStateProp)
bpy.types.CONSOLE_MT_console.prepend(menu_func_cleanup)
+
def unregister():
- context = bpy.context
- var_states = get_var_states()
- var_states.store_states()
draw.callback_disable()
import console_python
console_python.execute.hooks.remove((console_hook, ()))
bpy.types.CONSOLE_MT_console.remove(menu_func_cleanup)
- del bpy.types.Scene.MathVisProp
- del bpy.types.WindowManager.MathVisStateProp
+ del bpy.types.WindowManager.MathVisProp
+ del bpy.types.WindowManager.MathVisStatePropList
bpy.utils.unregister_module(__name__)
diff --git a/space_view3d_math_vis/draw.py b/space_view3d_math_vis/draw.py
index 1890c3e9..fa185514 100644
--- a/space_view3d_math_vis/draw.py
+++ b/space_view3d_math_vis/draw.py
@@ -69,7 +69,7 @@ def draw_callback_px():
data_matrix, data_quat, data_euler, data_vector, data_vector_array = utils.console_math_data()
- name_hide = context.scene.MathVisProp.name_hide
+ name_hide = context.window_manager.MathVisProp.name_hide
if name_hide:
return
@@ -156,8 +156,8 @@ def draw_callback_view():
data_matrix, data_quat, data_euler, data_vector, data_vector_array = utils.console_math_data()
# draw_matrix modifiers
- bbox_hide = context.scene.MathVisProp.bbox_hide
- bbox_scale = context.scene.MathVisProp.bbox_scale
+ bbox_hide = context.window_manager.MathVisProp.bbox_hide
+ bbox_scale = context.window_manager.MathVisProp.bbox_scale
# draw_matrix vars
zero = Vector((0.0, 0.0, 0.0))
diff --git a/space_view3d_math_vis/utils.py b/space_view3d_math_vis/utils.py
index 12c1c62a..b243428a 100644
--- a/space_view3d_math_vis/utils.py
+++ b/space_view3d_math_vis/utils.py
@@ -43,78 +43,48 @@ def is_display_list(listvar):
class VarStates:
- states = {}
-
- def store_states(self):
+ @staticmethod
+ def store_states():
# Store the display states, called upon unregister the Addon
# This is useful when you press F8 to reload the Addons.
# Then this function preserves the display states of the
# console variables.
- context = bpy.context
- if len(self.states) > 0:
- state_props = context.window_manager.MathVisStateProp
- state_props.clear()
- for key, state in self.states.items():
- if key:
- state_prop = state_props.add()
- state_prop.key = key
- state_prop.state = state
-
- def __init__(self):
- # Get the display state from the stored values (if exists)
- # This happens after you pressed F8 to reload the Addons.
- context = bpy.context
- if 'MathVisStateProp' in dir(bpy.types.WindowManager):
- state_props = context.window_manager.MathVisStateProp
- if state_props:
- for state_prop in state_props:
- key = state_prop.key
- state = state_prop.state
- self.states[key] = [state[0], state[1]]
- state_props.clear()
-
- def get(self, key, default):
- return self.states.get(key, default)
-
- def delete(self, key):
- if key in self.states:
- del self.states[key]
-
- def is_visible(self, key):
- if key in self.states:
- disp, lock = self.states[key]
- return disp
- return True
-
- def toggle_display_state(self, key):
- if key in self.states:
- disp, lock = self.states[key]
- self.states[key] = [not disp, lock]
- else:
- self.states[key] = [False, False]
-
- def is_locked(self, key):
- if key in self.states:
- disp, lock = self.states[key]
- return lock
- return False
-
- def toggle_lock_state(self, key):
- if key in self.states:
- disp, lock = self.states[key]
- self.states[key] = [disp, not lock]
+ state_props = bpy.context.window_manager.MathVisStatePropList
+ variables = get_math_data()
+ for key, ktype in variables.items():
+ if key and not key in state_props:
+ prop = state_props.add()
+ prop.name = key
+ prop.ktype = ktype.__name__
+ prop.state = [True, False]
+
+ @staticmethod
+ def get_index(key):
+ index = bpy.context.window_manager.MathVisStatePropList.find(key)
+ return index
+
+ @staticmethod
+ def delete(key):
+ state_props = bpy.context.window_manager.MathVisStatePropList
+ index = state_props.find(key)
+ if index != -1:
+ state_props.remove(index)
+
+ @staticmethod
+ def toggle_display_state(key):
+ state_props = bpy.context.window_manager.MathVisStatePropList
+ if key in state_props:
+ state_props[key].state[0] = not state_props[key].state[0]
else:
- self.states[key] = [True, True]
-
-global g_var_states
-g_var_states = None
+ print("Odd: Can not find key %s in MathVisStateProps" % (key))
-
-def get_var_states():
- global g_var_states
- if g_var_states == None:
- g_var_states = VarStates()
- return g_var_states
+ @staticmethod
+ def toggle_lock_state(key):
+ state_props = bpy.context.window_manager.MathVisStatePropList
+ if key in state_props:
+ state_props[key].state[1] = not state_props[key].state[1]
+ else:
+ print("Odd: Can not find key %s in MathVisStateProps" % (key))
def get_math_data():
@@ -143,14 +113,19 @@ def cleanup_math_data():
if not locals:
return
- var_states = get_var_states()
variables = get_math_data()
+
for key in variables.keys():
- if var_states.is_locked(key):
+ index = VarStates.get_index(key)
+ if index == -1:
+ continue
+
+ state_prop = bpy.context.window_manager.MathVisStatePropList.get(key)
+ if state_prop.state[1]:
continue
del locals[key]
- var_states.delete(key)
+ bpy.context.window_manager.MathVisStatePropList.remove(index)
def console_math_data():
@@ -161,15 +136,16 @@ def console_math_data():
data_euler = {}
data_vector = {}
data_vector_array = {}
- var_states = get_var_states()
for key, var in console_namespace().items():
if key[0] == "_":
continue
- disp, lock = var_states.get(key, [True, False])
- if not disp:
- continue
+ state_prop = bpy.context.window_manager.MathVisStatePropList.get(key)
+ if state_prop:
+ disp, lock = state_prop.state
+ if not disp:
+ continue
var_type = type(var)