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

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2009-11-19 20:12:08 +0300
committerCampbell Barton <ideasman42@gmail.com>2009-11-19 20:12:08 +0300
commite61c90e4162040f564e154da055995e2ed280fdf (patch)
tree70cfb3cde5608c03839acb460ddb6b53b57f39f9 /release/scripts/modules/rna_prop_ui.py
parentac8ff25b2d6465e3ad2b79c359d74b4bab4985e4 (diff)
operators were copying the properties from the rna operator into the class instance.
however this meant the invoke function could not modify properties for exec to use (unless it called exec directly after) since the popup for eg would re-instance the python class each time. now use the operator properties directly through rna without an automatic copy. now an operator attribute is accessed like this... self.path --> self.properties.path
Diffstat (limited to 'release/scripts/modules/rna_prop_ui.py')
-rw-r--r--release/scripts/modules/rna_prop_ui.py162
1 files changed, 119 insertions, 43 deletions
diff --git a/release/scripts/modules/rna_prop_ui.py b/release/scripts/modules/rna_prop_ui.py
index 7f741e46bd0..e4d3de2cef0 100644
--- a/release/scripts/modules/rna_prop_ui.py
+++ b/release/scripts/modules/rna_prop_ui.py
@@ -26,6 +26,7 @@ EVIL_PROP_VALUE = EVIL_PROP + '_value'
EVIL_PROP_PROP = EVIL_PROP + '_prop'
EVIL_PROP_PROP_ORIG = EVIL_PROP + '_prop_orig'
+
# nasty!, use a scene property to store the active edit item
def evil_prop_init():
Scene = bpy.types.Scene
@@ -35,6 +36,42 @@ def evil_prop_init():
Scene.StringProperty(attr=EVIL_PROP_PROP)
Scene.StringProperty(attr=EVIL_PROP_PROP_ORIG)
+def rna_idprop_ui_get(item, create=True):
+ try:
+ return item['_RNA_UI']
+ except:
+ if create:
+ item['_RNA_UI'] = {}
+ return item['_RNA_UI']
+ else:
+ return None
+
+
+def rna_idprop_ui_prop_get(item, prop, create=True):
+
+ rna_ui = rna_idprop_ui_get(item, create)
+
+ if rna_ui == None:
+ return None
+
+ try:
+ return rna_ui[prop]
+ except:
+ rna_ui[prop] = {}
+ return rna_ui[prop]
+
+
+def rna_idprop_ui_prop_clear(item, prop):
+ rna_ui = rna_idprop_ui_get(item, False)
+
+ if rna_ui == None:
+ return
+
+ try:
+ del rna_ui[prop]
+ except:
+ pass
+
def draw(layout, context, context_member, use_edit = True):
@@ -70,7 +107,7 @@ def draw(layout, context, context_member, use_edit = True):
del row
for key, val in items:
-
+ print("KEY - " + key)
if key == '_RNA_UI':
continue
@@ -86,6 +123,7 @@ def draw(layout, context, context_member, use_edit = True):
box = row.box()
+ '''
if use_edit and key == global_prop_orig and context_member == global_path:
split = box.split(percentage=0.75)
@@ -94,10 +132,12 @@ def draw(layout, context, context_member, use_edit = True):
row.itemR(scene, EVIL_PROP_VALUE)
row = split.column()
- prop = row.itemO("wm.properties_edit_end", properties=True, text="done")
+ prop = row.itemO("wm.properties_edit", properties=True, text="done")
assign_props(prop, val_draw, key)
else:
+ '''
+ if 1:
if use_edit:
split = box.split(percentage=0.75)
row = split.row()
@@ -114,7 +154,7 @@ def draw(layout, context, context_member, use_edit = True):
if use_edit:
row = split.row(align=True)
- prop = row.itemO("wm.properties_edit_begin", properties=True, text="edit")
+ prop = row.itemO("wm.properties_edit", properties=True, text="edit")
assign_props(prop, val_draw, key)
prop = row.itemO("wm.properties_remove", properties=True, text="", icon='ICON_ZOOMOUT')
@@ -125,7 +165,7 @@ from bpy.props import *
rna_path = StringProperty(name="Property Edit",
- description="Property path edit", maxlen=1024, default="")
+ description="Property path edit", maxlen=1024, default="", hidden=True)
rna_value = StringProperty(name="Property Value",
description="Property value edit", maxlen=1024, default="")
@@ -133,69 +173,104 @@ rna_value = StringProperty(name="Property Value",
rna_property = StringProperty(name="Property Name",
description="Property name edit", maxlen=1024, default="")
-class WM_OT_properties_edit_begin(bpy.types.Operator):
- '''Internal use (edit a property path)'''
- bl_idname = "wm.properties_edit_begin"
- bl_label = "Edit Property"
-
- path = rna_path
- value = rna_value
- property = rna_property
-
- def execute(self, context):
- scene = context.scene
-
- setattr(scene, EVIL_PROP_PATH, self.path)
- setattr(scene, EVIL_PROP_VALUE, self.value)
- setattr(scene, EVIL_PROP_PROP, self.property)
- setattr(scene, EVIL_PROP_PROP_ORIG, self.property)
-
- return ('FINISHED',)
-
+rna_min = FloatProperty(name="Min", default=0.0)
+rna_min = FloatProperty(name="Max", default=1.0)
-class WM_OT_properties_edit_end(bpy.types.Operator):
+class WM_OT_properties_edit(bpy.types.Operator):
'''Internal use (edit a property path)'''
- bl_idname = "wm.properties_edit_end"
- bl_label = "Edit Property"
+ bl_idname = "wm.properties_edit"
+ bl_label = "Edit Property!"
path = rna_path
value = rna_value
property = rna_property
+
+ min = FloatProperty(name="Min", default=0.0)
+ max = FloatProperty(name="Max", default=1.0)
+ description = StringProperty(name="Tip", default="")
+
+ # the class instance is not persistant, need to store in the class
+ # not ideal but changes as the op runs.
+ _last_prop = ['']
def execute(self, context):
-
- scene = context.scene
- global_path = getattr(scene, EVIL_PROP_PATH)
- global_value = getattr(scene, EVIL_PROP_VALUE)
- global_prop = getattr(scene, EVIL_PROP_PROP)
-
- setattr(scene, EVIL_PROP_PATH, "")
- setattr(scene, EVIL_PROP_VALUE, "")
- setattr(scene, EVIL_PROP_PROP, "")
- setattr(scene, EVIL_PROP_PROP_ORIG, "")
-
+ global_path = self.properties.path
+ global_value = self.properties.value
+ global_prop = self.properties.property
+ global_prop_old = self._last_prop[0]
+
try:
value = eval(global_value)
except:
value = global_value
if type(value) == str:
- value = '"' + value + '"'
-
+ value = '"' + value + '"'
# First remove
- exec_str = "del context.%s['%s']" % (global_path, self.property)
+ item = eval("context.%s" % global_path)
+
+ rna_idprop_ui_prop_clear(item, global_prop_old)
+ exec_str = "del item['%s']" % global_prop_old
# print(exec_str)
exec(exec_str)
# Reassign
- exec_str = "context.%s['%s'] = %s" % (global_path, global_prop, value)
+ exec_str = "item['%s'] = %s" % (global_prop, value)
# print(exec_str)
exec(exec_str)
+ prop_type = type(item[global_prop])
+
+ prop_ui = rna_idprop_ui_prop_get(item, global_prop)
+
+ if prop_type in (float, int):
+
+ prop_ui['soft_min'] = prop_ui['min'] = prop_type(self.properties.min)
+ prop_ui['soft_max'] = prop_ui['max'] = prop_type(self.properties.max)
+
return ('FINISHED',)
+ def invoke(self, context, event):
+
+ self._last_prop[:] = [self.properties.property]
+
+ item = eval("context.%s" % self.properties.path)
+
+ # setup defaults
+ prop_ui = rna_idprop_ui_prop_get(item, self.properties.property, False) # dont create
+ if prop_ui:
+ self.properties.min = prop_ui.get("min", -1000000000)
+ self.properties.min = prop_ui.get("max", 1000000000)
+ self.properties.description = prop_ui.get("description", "")
+
+ if 0:
+ _message= "PyConsole, press Ctrl+D to unlock the BGE"
+ import sys
+
+ # evaluate commands in current namespace
+ frame= sys._getframe()
+ namespace = frame.f_globals.copy()
+ namespace.update(frame.f_locals)
+
+ import code
+
+ # Autocomp in python, not as comprehensive as IPython
+ import rlcompleter
+
+ try: # ick, some pythons dont have this
+ import readline
+ readline.parse_and_bind("tab: complete")
+ except:
+ pass
+
+ code.interact(banner=_message, local=namespace)
+
+ wm = context.manager
+ wm.invoke_props_popup(self, event)
+ return ('RUNNING_MODAL',)
+
class WM_OT_properties_add(bpy.types.Operator):
'''Internal use (edit a property path)'''
@@ -231,6 +306,7 @@ class WM_OT_properties_remove(bpy.types.Operator):
property = rna_property
def execute(self, context):
- item = eval("context.%s" % self.path)
- del item[self.property]
+ item = eval("context.%s" % self.properties.path)
+ del item[self.properties.property]
return ('FINISHED',)
+