~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to release/scripts/modules/rna_prop_ui.py

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-07-23 08:54:18 UTC
  • mfrom: (14.2.16 sid)
  • mto: (14.2.19 sid)
  • mto: This revision was merged to the branch mainline in revision 42.
  • Revision ID: package-import@ubuntu.com-20120723085418-9foz30v6afaf5ffs
Tags: 2.63a-2
* debian/: Cycles support added (Closes: #658075)
  For now, this top feature has been enabled only
  on [any-amd64 any-i386] architectures because
  of OpenImageIO failing on all others
* debian/: scripts installation path changed
  from /usr/lib to /usr/share:
  + debian/patches/: patchset re-worked for path changing
  + debian/control: "Breaks" field added on yafaray-exporter

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
 
37
37
    rna_ui = rna_idprop_ui_get(item, create)
38
38
 
39
 
    if rna_ui == None:
 
39
    if rna_ui is None:
40
40
        return None
41
41
 
42
42
    try:
49
49
def rna_idprop_ui_prop_clear(item, prop):
50
50
    rna_ui = rna_idprop_ui_get(item, False)
51
51
 
52
 
    if rna_ui == None:
 
52
    if rna_ui is None:
53
53
        return
54
54
 
55
55
    try:
58
58
        pass
59
59
 
60
60
 
61
 
def draw(layout, context, context_member, use_edit=True):
 
61
def rna_idprop_context_value(context, context_member, property_type):
 
62
    space = context.space_data
 
63
 
 
64
    if space is None or isinstance(space, bpy.types.SpaceProperties):
 
65
        pin_id = space.pin_id
 
66
    else:
 
67
        pin_id = None
 
68
 
 
69
    if pin_id and isinstance(pin_id, property_type):
 
70
        rna_item = pin_id
 
71
        context_member = "space_data.pin_id"
 
72
    else:
 
73
        rna_item = eval("context." + context_member)
 
74
 
 
75
    return rna_item, context_member
 
76
 
 
77
 
 
78
def draw(layout, context, context_member, property_type, use_edit=True):
62
79
 
63
80
    def assign_props(prop, val, key):
64
81
        prop.data_path = context_member
69
86
        except:
70
87
            pass
71
88
 
72
 
    rna_item = eval("context." + context_member)
 
89
    rna_item, context_member = rna_idprop_context_value(context, context_member, property_type)
73
90
 
74
91
    # poll should really get this...
75
92
    if not rna_item:
76
93
        return
77
94
 
 
95
    assert(isinstance(rna_item, property_type))
 
96
 
78
97
    items = rna_item.items()
79
98
    items.sort()
80
99
 
84
103
        props.data_path = context_member
85
104
        del row
86
105
 
 
106
    rna_properties = {prop.identifier for prop in rna_item.bl_rna.properties if prop.is_runtime} if items else None
 
107
 
87
108
    for key, val in items:
88
109
 
89
110
        if key == '_RNA_UI':
90
111
            continue
91
112
 
92
113
        row = layout.row()
93
 
        convert_to_pyobject = getattr(val, "convert_to_pyobject", None)
 
114
        to_dict = getattr(val, "to_dict", None)
 
115
        to_list = getattr(val, "to_list", None)
94
116
 
95
 
        val_orig = val
96
 
        if convert_to_pyobject:
97
 
            val_draw = val = val.convert_to_pyobject()
98
 
            val_draw = str(val_draw)
 
117
        # val_orig = val  # UNUSED
 
118
        if to_dict:
 
119
            val = to_dict()
 
120
            val_draw = str(val)
 
121
        elif to_list:
 
122
            val = to_list()
 
123
            val_draw = str(val)
99
124
        else:
100
125
            val_draw = val
101
126
 
110
135
        row.label(text=key)
111
136
 
112
137
        # explicit exception for arrays
113
 
        if convert_to_pyobject and not hasattr(val_orig, "len"):
 
138
        if to_dict or to_list:
114
139
            row.label(text=val_draw)
115
140
        else:
116
 
            row.prop(rna_item, '["%s"]' % key, text="")
 
141
            if key in rna_properties:
 
142
                row.prop(rna_item, key, text="")
 
143
            else:
 
144
                row.prop(rna_item, '["%s"]' % key, text="")
117
145
 
118
146
        if use_edit:
119
147
            row = split.row(align=True)
120
 
            prop = row.operator("wm.properties_edit", text="edit")
121
 
            assign_props(prop, val_draw, key)
122
 
 
123
 
            prop = row.operator("wm.properties_remove", text="", icon='ZOOMOUT')
124
 
            assign_props(prop, val_draw, key)
125
 
 
126
 
 
127
 
class PropertyPanel(bpy.types.Panel):
 
148
            props = row.operator("wm.properties_edit", text="edit")
 
149
            assign_props(props, val_draw, key)
 
150
 
 
151
            props = row.operator("wm.properties_remove", text="", icon='ZOOMOUT')
 
152
            assign_props(props, val_draw, key)
 
153
 
 
154
 
 
155
class PropertyPanel():
128
156
    """
129
157
    The subclass should have its own poll function
130
158
    and the variable '_context_path' MUST be set.
131
159
    """
132
160
    bl_label = "Custom Properties"
133
 
    bl_default_closed = True
 
161
    bl_options = {'DEFAULT_CLOSED'}
 
162
 
 
163
    @classmethod
 
164
    def poll(cls, context):
 
165
        rna_item, context_member = rna_idprop_context_value(context, cls._context_path, cls._property_type)
 
166
        return bool(rna_item)
 
167
 
 
168
    """
 
169
    def draw_header(self, context):
 
170
        rna_item, context_member = rna_idprop_context_value(context, self._context_path, self._property_type)
 
171
        tot = len(rna_item.keys())
 
172
        if tot:
 
173
            self.layout().label("%d:" % tot)
 
174
    """
134
175
 
135
176
    def draw(self, context):
136
 
        draw(self.layout, context, self._context_path)
137
 
 
138
 
 
139
 
from bpy.props import *
140
 
 
141
 
 
142
 
rna_path = StringProperty(name="Property Edit",
143
 
    description="Property data_path edit", maxlen=1024, default="", options={'HIDDEN'})
144
 
 
145
 
rna_value = StringProperty(name="Property Value",
146
 
    description="Property value edit", maxlen=1024, default="")
147
 
 
148
 
rna_property = StringProperty(name="Property Name",
149
 
    description="Property name edit", maxlen=1024, default="")
150
 
 
151
 
rna_min = FloatProperty(name="Min", default=0.0, precision=3)
152
 
rna_max = FloatProperty(name="Max", default=1.0, precision=3)
153
 
 
154
 
 
155
 
class WM_OT_properties_edit(bpy.types.Operator):
156
 
    '''Internal use (edit a property data_path)'''
157
 
    bl_idname = "wm.properties_edit"
158
 
    bl_label = "Edit Property"
159
 
 
160
 
    data_path = rna_path
161
 
    property = rna_property
162
 
    value = rna_value
163
 
    min = rna_min
164
 
    max = rna_max
165
 
    description = StringProperty(name="Tip", default="")
166
 
 
167
 
    def execute(self, context):
168
 
        data_path = self.properties.data_path
169
 
        value = self.properties.value
170
 
        prop = self.properties.property
171
 
        prop_old = self._last_prop[0]
172
 
 
173
 
        try:
174
 
            value_eval = eval(value)
175
 
        except:
176
 
            value_eval = value
177
 
 
178
 
        # First remove
179
 
        item = eval("context.%s" % data_path)
180
 
 
181
 
        rna_idprop_ui_prop_clear(item, prop_old)
182
 
        exec_str = "del item['%s']" % prop_old
183
 
        # print(exec_str)
184
 
        exec(exec_str)
185
 
 
186
 
 
187
 
        # Reassign
188
 
        exec_str = "item['%s'] = %s" % (prop, repr(value_eval))
189
 
        # print(exec_str)
190
 
        exec(exec_str)
191
 
        self._last_prop[:] = [prop]
192
 
 
193
 
        prop_type = type(item[prop])
194
 
 
195
 
        prop_ui = rna_idprop_ui_prop_get(item, prop)
196
 
 
197
 
        if prop_type in (float, int):
198
 
 
199
 
            prop_ui['soft_min'] = prop_ui['min'] = prop_type(self.properties.min)
200
 
            prop_ui['soft_max'] = prop_ui['max'] = prop_type(self.properties.max)
201
 
 
202
 
        prop_ui['description'] = self.properties.description
203
 
 
204
 
        return {'FINISHED'}
205
 
 
206
 
    def invoke(self, context, event):
207
 
 
208
 
        self._last_prop = [self.properties.property]
209
 
 
210
 
        item = eval("context.%s" % self.properties.data_path)
211
 
 
212
 
        # setup defaults
213
 
        prop_ui = rna_idprop_ui_prop_get(item, self.properties.property, False) # dont create
214
 
        if prop_ui:
215
 
            self.properties.min = prop_ui.get("min", -1000000000)
216
 
            self.properties.max = prop_ui.get("max", 1000000000)
217
 
            self.properties.description = prop_ui.get("description", "")
218
 
 
219
 
        wm = context.manager
220
 
        # This crashes, TODO - fix
221
 
        #return wm.invoke_props_popup(self, event)
222
 
 
223
 
        wm.invoke_props_popup(self, event)
224
 
        return {'RUNNING_MODAL'}
225
 
 
226
 
 
227
 
class WM_OT_properties_add(bpy.types.Operator):
228
 
    '''Internal use (edit a property data_path)'''
229
 
    bl_idname = "wm.properties_add"
230
 
    bl_label = "Add Property"
231
 
 
232
 
    data_path = rna_path
233
 
 
234
 
    def execute(self, context):
235
 
        item = eval("context.%s" % self.properties.data_path)
236
 
 
237
 
        def unique_name(names):
238
 
            prop = 'prop'
239
 
            prop_new = prop
240
 
            i = 1
241
 
            while prop_new in names:
242
 
                prop_new = prop + str(i)
243
 
                i += 1
244
 
 
245
 
            return prop_new
246
 
 
247
 
        property = unique_name(item.keys())
248
 
 
249
 
        item[property] = 1.0
250
 
        return {'FINISHED'}
251
 
 
252
 
 
253
 
class WM_OT_properties_remove(bpy.types.Operator):
254
 
    '''Internal use (edit a property data_path)'''
255
 
    bl_idname = "wm.properties_remove"
256
 
    bl_label = "Remove Property"
257
 
 
258
 
    data_path = rna_path
259
 
    property = rna_property
260
 
 
261
 
    def execute(self, context):
262
 
        item = eval("context.%s" % self.properties.data_path)
263
 
        del item[self.properties.property]
264
 
        return {'FINISHED'}
 
177
        draw(self.layout, context, self._context_path, self._property_type)