1 # ##### BEGIN GPL LICENSE BLOCK #####
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.
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.
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.
17 # ##### END GPL LICENSE BLOCK #####
22 from bpy.types import Menu, Operator
23 from bpy.props import StringProperty, BoolProperty, IntProperty, \
24 FloatProperty, EnumProperty
26 from rna_prop_ui import rna_idprop_ui_prop_get, rna_idprop_ui_prop_clear
29 class MESH_OT_delete_edgeloop(Operator):
30 '''Delete an edge loop by merging the faces on each side to a single face loop'''
31 bl_idname = "mesh.delete_edgeloop"
32 bl_label = "Delete Edge Loop"
34 def execute(self, context):
35 if 'FINISHED' in bpy.ops.transform.edge_slide(value=1.0):
36 bpy.ops.mesh.select_more()
37 bpy.ops.mesh.remove_doubles()
42 rna_path_prop = StringProperty(name="Context Attributes",
43 description="rna context string", maxlen=1024, default="")
45 rna_reverse_prop = BoolProperty(name="Reverse",
46 description="Cycle backwards", default=False)
48 rna_relative_prop = BoolProperty(name="Relative",
49 description="Apply relative to the current value (delta)",
53 def context_path_validate(context, data_path):
56 value = eval("context.%s" % data_path) if data_path else Ellipsis
57 except AttributeError:
58 if "'NoneType'" in str(sys.exc_info()[1]):
59 # One of the items in the rna path is None, just ignore this
62 # We have a real error in the rna path, dont ignore that
68 def execute_context_assign(self, context):
69 if context_path_validate(context, self.data_path) is Ellipsis:
70 return {'PASS_THROUGH'}
72 if getattr(self, "relative", False):
73 exec("context.%s+=self.value" % self.data_path)
75 exec("context.%s=self.value" % self.data_path)
80 class BRUSH_OT_active_index_set(Operator):
81 '''Set active sculpt/paint brush from it's number'''
82 bl_idname = "brush.active_index_set"
83 bl_label = "Set Brush Number"
85 mode = StringProperty(name="mode",
86 description="Paint mode to set brush for", maxlen=1024)
87 index = IntProperty(name="number",
88 description="Brush number")
90 _attr_dict = {"sculpt": "use_paint_sculpt",
91 "vertex_paint": "use_paint_vertex",
92 "weight_paint": "use_paint_weight",
93 "image_paint": "use_paint_image"}
95 def execute(self, context):
96 attr = self._attr_dict.get(self.mode)
100 for i, brush in enumerate((cur for cur in bpy.data.brushes if getattr(cur, attr))):
102 getattr(context.tool_settings, self.mode).brush = brush
108 class WM_OT_context_set_boolean(Operator):
109 '''Set a context value.'''
110 bl_idname = "wm.context_set_boolean"
111 bl_label = "Context Set Boolean"
112 bl_options = {'UNDO', 'INTERNAL'}
114 data_path = rna_path_prop
115 value = BoolProperty(name="Value",
116 description="Assignment value", default=True)
118 execute = execute_context_assign
121 class WM_OT_context_set_int(Operator): # same as enum
122 '''Set a context value.'''
123 bl_idname = "wm.context_set_int"
124 bl_label = "Context Set"
125 bl_options = {'UNDO', 'INTERNAL'}
127 data_path = rna_path_prop
128 value = IntProperty(name="Value", description="Assign value", default=0)
129 relative = rna_relative_prop
131 execute = execute_context_assign
134 class WM_OT_context_scale_int(Operator):
135 '''Scale an int context value.'''
136 bl_idname = "wm.context_scale_int"
137 bl_label = "Context Set"
138 bl_options = {'UNDO', 'INTERNAL'}
140 data_path = rna_path_prop
141 value = FloatProperty(name="Value", description="Assign value", default=1.0)
142 always_step = BoolProperty(name="Always Step",
143 description="Always adjust the value by a minimum of 1 when 'value' is not 1.0.",
146 def execute(self, context):
147 if context_path_validate(context, self.data_path) is Ellipsis:
148 return {'PASS_THROUGH'}
151 data_path = self.data_path
153 if value == 1.0: # nothing to do
156 if getattr(self, "always_step", False):
163 exec("context.%s = %s(round(context.%s * value), context.%s + %s)" % (data_path, func, data_path, data_path, add))
165 exec("context.%s *= value" % self.data_path)
170 class WM_OT_context_set_float(Operator): # same as enum
171 '''Set a context value.'''
172 bl_idname = "wm.context_set_float"
173 bl_label = "Context Set Float"
174 bl_options = {'UNDO', 'INTERNAL'}
176 data_path = rna_path_prop
177 value = FloatProperty(name="Value",
178 description="Assignment value", default=0.0)
179 relative = rna_relative_prop
181 execute = execute_context_assign
184 class WM_OT_context_set_string(Operator): # same as enum
185 '''Set a context value.'''
186 bl_idname = "wm.context_set_string"
187 bl_label = "Context Set String"
188 bl_options = {'UNDO', 'INTERNAL'}
190 data_path = rna_path_prop
191 value = StringProperty(name="Value",
192 description="Assign value", maxlen=1024, default="")
194 execute = execute_context_assign
197 class WM_OT_context_set_enum(Operator):
198 '''Set a context value.'''
199 bl_idname = "wm.context_set_enum"
200 bl_label = "Context Set Enum"
201 bl_options = {'UNDO', 'INTERNAL'}
203 data_path = rna_path_prop
204 value = StringProperty(name="Value",
205 description="Assignment value (as a string)",
206 maxlen=1024, default="")
208 execute = execute_context_assign
211 class WM_OT_context_set_value(Operator):
212 '''Set a context value.'''
213 bl_idname = "wm.context_set_value"
214 bl_label = "Context Set Value"
215 bl_options = {'UNDO', 'INTERNAL'}
217 data_path = rna_path_prop
218 value = StringProperty(name="Value",
219 description="Assignment value (as a string)",
220 maxlen=1024, default="")
222 def execute(self, context):
223 if context_path_validate(context, self.data_path) is Ellipsis:
224 return {'PASS_THROUGH'}
225 exec("context.%s=%s" % (self.data_path, self.value))
229 class WM_OT_context_toggle(Operator):
230 '''Toggle a context value.'''
231 bl_idname = "wm.context_toggle"
232 bl_label = "Context Toggle"
233 bl_options = {'UNDO', 'INTERNAL'}
235 data_path = rna_path_prop
237 def execute(self, context):
239 if context_path_validate(context, self.data_path) is Ellipsis:
240 return {'PASS_THROUGH'}
242 exec("context.%s=not (context.%s)" %
243 (self.data_path, self.data_path))
248 class WM_OT_context_toggle_enum(Operator):
249 '''Toggle a context value.'''
250 bl_idname = "wm.context_toggle_enum"
251 bl_label = "Context Toggle Values"
252 bl_options = {'UNDO', 'INTERNAL'}
254 data_path = rna_path_prop
255 value_1 = StringProperty(name="Value", \
256 description="Toggle enum", maxlen=1024, default="")
258 value_2 = StringProperty(name="Value", \
259 description="Toggle enum", maxlen=1024, default="")
261 def execute(self, context):
263 if context_path_validate(context, self.data_path) is Ellipsis:
264 return {'PASS_THROUGH'}
266 exec("context.%s = ['%s', '%s'][context.%s!='%s']" % \
267 (self.data_path, self.value_1,\
268 self.value_2, self.data_path,
274 class WM_OT_context_cycle_int(Operator):
275 '''Set a context value. Useful for cycling active material, '''
276 '''vertex keys, groups' etc.'''
277 bl_idname = "wm.context_cycle_int"
278 bl_label = "Context Int Cycle"
279 bl_options = {'UNDO', 'INTERNAL'}
281 data_path = rna_path_prop
282 reverse = rna_reverse_prop
284 def execute(self, context):
285 data_path = self.data_path
286 value = context_path_validate(context, data_path)
287 if value is Ellipsis:
288 return {'PASS_THROUGH'}
295 exec("context.%s=value" % data_path)
297 if value != eval("context.%s" % data_path):
298 # relies on rna clamping int's out of the range
300 value = (1 << 31) - 1
304 exec("context.%s=value" % data_path)
309 class WM_OT_context_cycle_enum(Operator):
310 '''Toggle a context value.'''
311 bl_idname = "wm.context_cycle_enum"
312 bl_label = "Context Enum Cycle"
313 bl_options = {'UNDO', 'INTERNAL'}
315 data_path = rna_path_prop
316 reverse = rna_reverse_prop
318 def execute(self, context):
320 value = context_path_validate(context, self.data_path)
321 if value is Ellipsis:
322 return {'PASS_THROUGH'}
326 # Have to get rna enum values
327 rna_struct_str, rna_prop_str = self.data_path.rsplit('.', 1)
328 i = rna_prop_str.find('[')
330 # just incse we get "context.foo.bar[0]"
332 rna_prop_str = rna_prop_str[0:i]
334 rna_struct = eval("context.%s.rna_type" % rna_struct_str)
336 rna_prop = rna_struct.properties[rna_prop_str]
338 if type(rna_prop) != bpy.types.EnumProperty:
339 raise Exception("expected an enum property")
341 enums = rna_struct.properties[rna_prop_str].enum_items.keys()
342 orig_index = enums.index(orig_value)
344 # Have the info we need, advance to the next item
347 advance_enum = enums[-1]
349 advance_enum = enums[orig_index - 1]
351 if orig_index == len(enums) - 1:
352 advance_enum = enums[0]
354 advance_enum = enums[orig_index + 1]
357 exec("context.%s=advance_enum" % self.data_path)
361 class WM_OT_context_cycle_array(Operator):
362 '''Set a context array value.
363 Useful for cycling the active mesh edit mode.'''
364 bl_idname = "wm.context_cycle_array"
365 bl_label = "Context Array Cycle"
366 bl_options = {'UNDO', 'INTERNAL'}
368 data_path = rna_path_prop
369 reverse = rna_reverse_prop
371 def execute(self, context):
372 data_path = self.data_path
373 value = context_path_validate(context, data_path)
374 if value is Ellipsis:
375 return {'PASS_THROUGH'}
379 array.insert(0, array.pop())
381 array.append(array.pop(0))
384 exec("context.%s=cycle(context.%s[:])" % (data_path, data_path))
389 class WM_MT_context_menu_enum(Menu):
391 data_path = "" # BAD DESIGN, set from operator below.
393 def draw(self, context):
394 data_path = self.data_path
395 value = context_path_validate(bpy.context, data_path)
396 if value is Ellipsis:
397 return {'PASS_THROUGH'}
398 base_path, prop_string = data_path.rsplit(".", 1)
399 value_base = context_path_validate(context, base_path)
401 values = [(i.name, i.identifier) for i in value_base.bl_rna.properties[prop_string].enum_items]
403 for name, identifier in values:
404 prop = self.layout.operator("wm.context_set_enum", text=name)
405 prop.data_path = data_path
406 prop.value = identifier
409 class WM_OT_context_menu_enum(Operator):
410 bl_idname = "wm.context_menu_enum"
411 bl_label = "Context Enum Menu"
412 bl_options = {'UNDO', 'INTERNAL'}
413 data_path = rna_path_prop
415 def execute(self, context):
416 data_path = self.data_path
417 WM_MT_context_menu_enum.data_path = data_path
418 bpy.ops.wm.call_menu(name="WM_MT_context_menu_enum")
419 return {'PASS_THROUGH'}
422 class WM_OT_context_set_id(Operator):
423 '''Toggle a context value.'''
424 bl_idname = "wm.context_set_id"
425 bl_label = "Set Library ID"
426 bl_options = {'UNDO', 'INTERNAL'}
428 data_path = rna_path_prop
429 value = StringProperty(name="Value",
430 description="Assign value", maxlen=1024, default="")
432 def execute(self, context):
434 data_path = self.data_path
436 # match the pointer type from the target property to bpy.data.*
437 # so we lookup the correct list.
438 data_path_base, data_path_prop = data_path.rsplit(".", 1)
439 data_prop_rna = eval("context.%s" % data_path_base).rna_type.properties[data_path_prop]
440 data_prop_rna_type = data_prop_rna.fixed_type
444 for prop in bpy.data.rna_type.properties:
445 if prop.rna_type.identifier == "CollectionProperty":
446 if prop.fixed_type == data_prop_rna_type:
447 id_iter = prop.identifier
451 value_id = getattr(bpy.data, id_iter).get(value)
452 exec("context.%s=value_id" % data_path)
457 doc_id = StringProperty(name="Doc ID",
458 description="", maxlen=1024, default="", options={'HIDDEN'})
460 doc_new = StringProperty(name="Edit Description",
461 description="", maxlen=1024, default="")
463 data_path_iter = StringProperty(
464 description="The data path relative to the context, must point to an iterable.")
466 data_path_item = StringProperty(
467 description="The data path from each iterable to the value (int or float)")
470 class WM_OT_context_collection_boolean_set(Operator):
471 '''Set boolean values for a collection of items'''
472 bl_idname = "wm.context_collection_boolean_set"
473 bl_label = "Context Collection Boolean Set"
474 bl_options = {'UNDO', 'REGISTER', 'INTERNAL'}
476 data_path_iter = data_path_iter
477 data_path_item = data_path_item
479 type = EnumProperty(items=(
480 ('TOGGLE', "Toggle", ""),
481 ('ENABLE', "Enable", ""),
482 ('DISABLE', "Disable", ""),
486 def execute(self, context):
487 data_path_iter = self.data_path_iter
488 data_path_item = self.data_path_item
490 items = list(getattr(context, data_path_iter))
495 value_orig = eval("item." + data_path_item)
499 if value_orig == True:
501 elif value_orig == False:
504 self.report({'WARNING'}, "Non boolean value found: %s[ ].%s" %
505 (data_path_iter, data_path_item))
508 items_ok.append(item)
510 if self.type == 'ENABLE':
512 elif self.type == 'DISABLE':
517 exec_str = "item.%s = %s" % (data_path_item, is_set)
518 for item in items_ok:
524 class WM_OT_context_modal_mouse(Operator):
525 '''Adjust arbitrary values with mouse input'''
526 bl_idname = "wm.context_modal_mouse"
527 bl_label = "Context Modal Mouse"
528 bl_options = {'GRAB_POINTER', 'BLOCKING', 'INTERNAL'}
530 data_path_iter = data_path_iter
531 data_path_item = data_path_item
533 input_scale = FloatProperty(default=0.01, description="Scale the mouse movement by this value before applying the delta")
534 invert = BoolProperty(default=False, description="Invert the mouse input")
535 initial_x = IntProperty(options={'HIDDEN'})
537 def _values_store(self, context):
538 data_path_iter = self.data_path_iter
539 data_path_item = self.data_path_item
541 self._values = values = {}
543 for item in getattr(context, data_path_iter):
545 value_orig = eval("item." + data_path_item)
549 # check this can be set, maybe this is library data.
551 exec("item.%s = %s" % (data_path_item, value_orig))
555 values[item] = value_orig
557 def _values_delta(self, delta):
558 delta *= self.input_scale
562 data_path_item = self.data_path_item
563 for item, value_orig in self._values.items():
564 if type(value_orig) == int:
565 exec("item.%s = int(%d)" % (data_path_item, round(value_orig + delta)))
567 exec("item.%s = %f" % (data_path_item, value_orig + delta))
569 def _values_restore(self):
570 data_path_item = self.data_path_item
571 for item, value_orig in self._values.items():
572 exec("item.%s = %s" % (data_path_item, value_orig))
576 def _values_clear(self):
579 def modal(self, context, event):
580 event_type = event.type
582 if event_type == 'MOUSEMOVE':
583 delta = event.mouse_x - self.initial_x
584 self._values_delta(delta)
586 elif 'LEFTMOUSE' == event_type:
590 elif event_type in {'RIGHTMOUSE', 'ESC'}:
591 self._values_restore()
594 return {'RUNNING_MODAL'}
596 def invoke(self, context, event):
597 self._values_store(context)
600 self.report({'WARNING'}, "Nothing to operate on: %s[ ].%s" %
601 (self.data_path_iter, self.data_path_item))
605 self.initial_x = event.mouse_x
607 context.window_manager.modal_handler_add(self)
608 return {'RUNNING_MODAL'}
611 class WM_OT_url_open(Operator):
612 "Open a website in the Webbrowser"
613 bl_idname = "wm.url_open"
616 url = StringProperty(name="URL", description="URL to open")
618 def execute(self, context):
620 _webbrowser_bug_fix()
621 webbrowser.open(self.url)
625 class WM_OT_path_open(Operator):
626 "Open a path in a file browser"
627 bl_idname = "wm.path_open"
630 filepath = StringProperty(name="File Path", maxlen=1024, subtype='FILE_PATH')
632 def execute(self, context):
637 filepath = bpy.path.abspath(self.filepath)
638 filepath = os.path.normpath(filepath)
640 if not os.path.exists(filepath):
641 self.report({'ERROR'}, "File '%s' not found" % filepath)
644 if sys.platform[:3] == "win":
645 subprocess.Popen(['start', filepath], shell=True)
646 elif sys.platform == 'darwin':
647 subprocess.Popen(['open', filepath])
650 subprocess.Popen(['xdg-open', filepath])
652 # xdg-open *should* be supported by recent Gnome, KDE, Xfce
658 class WM_OT_doc_view(Operator):
659 '''Load online reference docs'''
660 bl_idname = "wm.doc_view"
661 bl_label = "View Documentation"
664 if bpy.app.version_cycle == "release":
665 _prefix = "http://www.blender.org/documentation/blender_python_api_%s%s_release" % ("_".join(str(v) for v in bpy.app.version[:2]), bpy.app.version_char)
667 _prefix = "http://www.blender.org/documentation/blender_python_api_%s" % "_".join(str(v) for v in bpy.app.version)
669 def _nested_class_string(self, class_string):
671 class_obj = getattr(bpy.types, class_string, None).bl_rna
673 ls.insert(0, class_obj)
674 class_obj = class_obj.nested
675 return '.'.join(class_obj.identifier for class_obj in ls)
677 def execute(self, context):
678 id_split = self.doc_id.split('.')
679 if len(id_split) == 1: # rna, class
680 url = '%s/bpy.types.%s.html' % (self._prefix, id_split[0])
681 elif len(id_split) == 2: # rna, class.prop
682 class_name, class_prop = id_split
684 if hasattr(bpy.types, class_name.upper() + '_OT_' + class_prop):
685 url = '%s/bpy.ops.%s.html#bpy.ops.%s.%s' % \
686 (self._prefix, class_name, class_name, class_prop)
689 # detect if this is a inherited member and use that name instead
690 rna_parent = getattr(bpy.types, class_name).bl_rna
691 rna_prop = rna_parent.properties[class_prop]
692 rna_parent = rna_parent.base
693 while rna_parent and rna_prop == rna_parent.properties.get(class_prop):
694 class_name = rna_parent.identifier
695 rna_parent = rna_parent.base
697 # It so happens that epydoc nests these, not sphinx
698 # class_name_full = self._nested_class_string(class_name)
699 url = '%s/bpy.types.%s.html#bpy.types.%s.%s' % \
700 (self._prefix, class_name, class_name, class_prop)
703 return {'PASS_THROUGH'}
706 _webbrowser_bug_fix()
712 class WM_OT_doc_edit(Operator):
713 '''Load online reference docs'''
714 bl_idname = "wm.doc_edit"
715 bl_label = "Edit Documentation"
720 _url = "http://www.mindrones.com/blender/svn/xmlrpc.php"
722 def _send_xmlrpc(self, data_dict):
723 print("sending data:", data_dict)
729 docblog = xmlrpc.client.ServerProxy(self._url)
730 docblog.metaWeblog.newPost(1, user, pwd, data_dict, 1)
732 def execute(self, context):
735 doc_new = self.doc_new
737 class_name, class_prop = doc_id.split('.')
740 self.report({'ERROR'}, "No input given for '%s'" % doc_id)
743 # check if this is an operator
744 op_name = class_name.upper() + '_OT_' + class_prop
745 op_class = getattr(bpy.types, op_name, None)
747 # Upload this to the web server
751 rna = op_class.bl_rna
752 doc_orig = rna.description
753 if doc_orig == doc_new:
754 return {'RUNNING_MODAL'}
756 print("op - old:'%s' -> new:'%s'" % (doc_orig, doc_new))
757 upload["title"] = 'OPERATOR %s:%s' % (doc_id, doc_orig)
759 rna = getattr(bpy.types, class_name).bl_rna
760 doc_orig = rna.properties[class_prop].description
761 if doc_orig == doc_new:
762 return {'RUNNING_MODAL'}
764 print("rna - old:'%s' -> new:'%s'" % (doc_orig, doc_new))
765 upload["title"] = 'RNA %s:%s' % (doc_id, doc_orig)
767 upload["description"] = doc_new
769 self._send_xmlrpc(upload)
773 def draw(self, context):
775 layout.label(text="Descriptor ID: '%s'" % self.doc_id)
776 layout.prop(self, "doc_new", text="")
778 def invoke(self, context, event):
779 wm = context.window_manager
780 return wm.invoke_props_dialog(self, width=600)
783 rna_path = StringProperty(name="Property Edit",
784 description="Property data_path edit", maxlen=1024, default="", options={'HIDDEN'})
786 rna_value = StringProperty(name="Property Value",
787 description="Property value edit", maxlen=1024, default="")
789 rna_property = StringProperty(name="Property Name",
790 description="Property name edit", maxlen=1024, default="")
792 rna_min = FloatProperty(name="Min", default=0.0, precision=3)
793 rna_max = FloatProperty(name="Max", default=1.0, precision=3)
796 class WM_OT_properties_edit(Operator):
797 '''Internal use (edit a property data_path)'''
798 bl_idname = "wm.properties_edit"
799 bl_label = "Edit Property"
800 bl_options = {'REGISTER'} # only because invoke_props_popup requires.
803 property = rna_property
807 description = StringProperty(name="Tip", default="")
809 def execute(self, context):
810 data_path = self.data_path
814 prop_old = getattr(self, "_last_prop", [None])[0]
817 self.report({'ERROR'}, "Direct execution not supported")
821 value_eval = eval(value)
826 item = eval("context.%s" % data_path)
828 rna_idprop_ui_prop_clear(item, prop_old)
829 exec_str = "del item['%s']" % prop_old
834 exec_str = "item['%s'] = %s" % (prop, repr(value_eval))
837 self._last_prop[:] = [prop]
839 prop_type = type(item[prop])
841 prop_ui = rna_idprop_ui_prop_get(item, prop)
843 if prop_type in {float, int}:
845 prop_ui['soft_min'] = prop_ui['min'] = prop_type(self.min)
846 prop_ui['soft_max'] = prop_ui['max'] = prop_type(self.max)
848 prop_ui['description'] = self.description
850 # otherwise existing buttons which reference freed
851 # memory may crash blender [#26510]
852 # context.area.tag_redraw()
853 for win in context.window_manager.windows:
854 for area in win.screen.areas:
859 def invoke(self, context, event):
861 if not self.data_path:
862 self.report({'ERROR'}, "Data path not set")
865 self._last_prop = [self.property]
867 item = eval("context.%s" % self.data_path)
870 prop_ui = rna_idprop_ui_prop_get(item, self.property, False) # dont create
872 self.min = prop_ui.get("min", -1000000000)
873 self.max = prop_ui.get("max", 1000000000)
874 self.description = prop_ui.get("description", "")
876 wm = context.window_manager
877 return wm.invoke_props_dialog(self)
880 class WM_OT_properties_add(Operator):
881 '''Internal use (edit a property data_path)'''
882 bl_idname = "wm.properties_add"
883 bl_label = "Add Property"
887 def execute(self, context):
888 item = eval("context.%s" % self.data_path)
890 def unique_name(names):
894 while prop_new in names:
895 prop_new = prop + str(i)
900 property = unique_name(item.keys())
906 class WM_OT_properties_context_change(Operator):
907 "Change the context tab in a Properties Window"
908 bl_idname = "wm.properties_context_change"
911 context = StringProperty(name="Context", maxlen=32)
913 def execute(self, context):
914 context.space_data.context = (self.context)
918 class WM_OT_properties_remove(Operator):
919 '''Internal use (edit a property data_path)'''
920 bl_idname = "wm.properties_remove"
921 bl_label = "Remove Property"
924 property = rna_property
926 def execute(self, context):
927 item = eval("context.%s" % self.data_path)
928 del item[self.property]
932 class WM_OT_keyconfig_activate(Operator):
933 bl_idname = "wm.keyconfig_activate"
934 bl_label = "Activate Keyconfig"
936 filepath = StringProperty(name="File Path", maxlen=1024)
938 def execute(self, context):
939 bpy.utils.keyconfig_set(self.filepath)
943 class WM_OT_appconfig_default(Operator):
944 bl_idname = "wm.appconfig_default"
945 bl_label = "Default Application Configuration"
947 def execute(self, context):
950 context.window_manager.keyconfigs.active = context.window_manager.keyconfigs.default
952 filepath = os.path.join(bpy.utils.preset_paths("interaction")[0], "blender.py")
954 if os.path.exists(filepath):
955 bpy.ops.script.execute_preset(filepath=filepath, menu_idname="USERPREF_MT_interaction_presets")
960 class WM_OT_appconfig_activate(Operator):
961 bl_idname = "wm.appconfig_activate"
962 bl_label = "Activate Application Configuration"
964 filepath = StringProperty(name="File Path", maxlen=1024)
966 def execute(self, context):
968 bpy.utils.keyconfig_set(self.filepath)
970 filepath = self.filepath.replace("keyconfig", "interaction")
972 if os.path.exists(filepath):
973 bpy.ops.script.execute_preset(filepath=filepath, menu_idname="USERPREF_MT_interaction_presets")
978 class WM_OT_sysinfo(Operator):
979 '''Generate System Info'''
980 bl_idname = "wm.sysinfo"
981 bl_label = "System Info"
983 def execute(self, context):
985 sys_info.write_sysinfo(self)
989 class WM_OT_copy_prev_settings(Operator):
990 '''Copy settings from previous version'''
991 bl_idname = "wm.copy_prev_settings"
992 bl_label = "Copy Previous Settings"
994 def execute(self, context):
997 ver = bpy.app.version
998 ver_old = ((ver[0] * 100) + ver[1]) - 1
999 path_src = bpy.utils.resource_path('USER', ver_old // 100, ver_old % 100)
1000 path_dst = bpy.utils.resource_path('USER')
1002 if os.path.isdir(path_dst):
1003 self.report({'ERROR'}, "Target path %r exists" % path_dst)
1004 elif not os.path.isdir(path_src):
1005 self.report({'ERROR'}, "Source path %r exists" % path_src)
1007 shutil.copytree(path_src, path_dst)
1009 # in 2.57 and earlier windows installers, system scripts were copied
1010 # into the configuration directory, don't want to copy those
1011 system_script = os.path.join(path_dst, 'scripts/modules/bpy_types.py')
1012 if os.path.isfile(system_script):
1013 shutil.rmtree(os.path.join(path_dst, 'scripts'))
1014 shutil.rmtree(os.path.join(path_dst, 'plugins'))
1016 # dont loose users work if they open the splash later.
1017 if bpy.data.is_saved is bpy.data.is_dirty is False:
1018 bpy.ops.wm.read_homefile()
1020 self.report({'INFO'}, "Reload Start-Up file to restore settings.")
1023 return {'CANCELLED'}
1026 def _webbrowser_bug_fix():
1030 if os.environ.get("DISPLAY"):
1032 # BSD licenced code copied from python, temp fix for bug
1033 # http://bugs.python.org/issue11432, XXX == added code
1034 def _invoke(self, args, remote, autoraise):
1035 # XXX, added imports
1041 if remote and self.raise_opts:
1042 # use autoraise argument only for remote invocation
1043 autoraise = int(autoraise)
1044 opt = self.raise_opts[autoraise]
1048 cmdline = [self.name] + raise_opt + args
1050 if remote or self.background:
1051 inout = io.open(os.devnull, "r+")
1053 # for TTY browsers, we need stdin/out
1055 # if possible, put browser in separate process group, so
1056 # keyboard interrupts don't affect browser as well as Python
1057 setsid = getattr(os, 'setsid', None)
1059 setsid = getattr(os, 'setpgrp', None)
1061 p = subprocess.Popen(cmdline, close_fds=True, # XXX, stdin=inout,
1062 stdout=(self.redirect_stdout and inout or None),
1063 stderr=inout, preexec_fn=setsid)
1065 # wait five secons. If the subprocess is not finished, the
1066 # remote invocation has (hopefully) started a new instance.
1074 # if remote call failed, open() will try direct invocation
1076 elif self.background:
1077 if p.poll() is None:
1085 webbrowser.UnixBrowser._invoke = _invoke