pep8 cleanup in ui and op dirs, added popup to select pattern

This commit is contained in:
Campbell Barton 2009-11-28 23:37:56 +00:00
parent 98a7a11e55
commit 8b897879cd
16 changed files with 1702 additions and 1707 deletions

File diff suppressed because it is too large Load Diff

@ -17,6 +17,42 @@
# ##### END GPL LICENSE BLOCK #####
import bpy
from bpy.props import *
class SelectPattern(bpy.types.Operator):
'''Select object matching a naming pattern.'''
bl_idname = "object.select_pattern"
bl_label = "Select Pattern"
bl_register = True
bl_undo = True
pattern = StringProperty(name="Pattern", description="Name filter using '*' and '?' wildcard chars", maxlen=32, default="*")
case_sensitive = BoolProperty(name="Case Sensitive", description="Do a case sensitive compare", default=False)
extend = BoolProperty(name="Extend", description="Extend the existing selection", default=True)
def execute(self, context):
import fnmatch
if self.properties.case_sensitive:
pattern_match = fnmatch.fnmatchcase
else:
pattern_match = lambda a, b: fnmatch.fnmatchcase(a.upper(), b.upper())
for ob in context.visible_objects:
if pattern_match(ob.name, self.properties.pattern):
ob.selected = True
elif not self.properties.extend:
ob.selected = False
return ('FINISHED',)
def invoke(self, context, event):
wm = context.manager
wm.invoke_props_popup(self, event)
return ('RUNNING_MODAL',)
class SubsurfSet(bpy.types.Operator):
'''Sets a Subdivision Surface Level (1-5)'''
@ -25,8 +61,8 @@ class SubsurfSet(bpy.types.Operator):
bl_label = "Subsurf Set"
bl_register = True
bl_undo = True
level = bpy.props.IntProperty(name="Level",
level = IntProperty(name="Level",
default=1, min=0, max=6)
def poll(self, context):
@ -41,12 +77,12 @@ class SubsurfSet(bpy.types.Operator):
if mod.levels != level:
mod.levels = level
return ('FINISHED',)
# adda new modifier
mod = ob.modifiers.new("Subsurf", 'SUBSURF')
mod.levels = level
return ('FINISHED',)
# Register the operator
bpy.ops.add(SelectPattern)
bpy.ops.add(SubsurfSet)

@ -4,12 +4,12 @@
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
@ -21,14 +21,14 @@ import os
class AddPresetBase(bpy.types.Operator):
'''Base preset class, only for subclassing
subclasses must define
subclasses must define
- preset_values
- preset_subdir '''
bl_idname = "render.preset_add"
bl_label = "Add Render Preset"
name = bpy.props.StringProperty(name="Name", description="Name of the preset, used to make the path name", maxlen= 64, default= "")
def _as_filename(self, name): # could reuse for other presets
for char in " !@#$%^&*(){}:\";'[]<>,./?":
name = name.replace('.', '_')
@ -44,7 +44,7 @@ class AddPresetBase(bpy.types.Operator):
target_path = bpy.utils.preset_paths(self.preset_subdir)[0] # we need some way to tell the user and system preset path
file_preset = open(os.path.join(target_path, filename), 'w')
for rna_path in self.preset_values:
file_preset.write("%s = %s\n" % (rna_path, eval(rna_path)))
@ -100,13 +100,13 @@ class AddPresetSSS(AddPresetBase):
]
preset_subdir = "sss"
class AddPresetCloth(AddPresetBase):
'''Add a Cloth Preset.'''
bl_idname = "cloth.preset_add"
bl_label = "Add Cloth Preset"
name = AddPresetBase.name
preset_values = [
"bpy.context.cloth.settings.quality",
"bpy.context.cloth.settings.mass",
@ -115,7 +115,7 @@ class AddPresetCloth(AddPresetBase):
"bpy.context.cloth.settings.spring_damping",
"bpy.context.cloth.settings.air_damping",
]
preset_subdir = "cloth"
bpy.ops.add(AddPresetRender)

File diff suppressed because it is too large Load Diff

@ -33,7 +33,7 @@ class MESH_OT_delete_edgeloop(bpy.types.Operator):
bpy.ops.tfm.edge_slide(value=1.0)
bpy.ops.mesh.select_more()
bpy.ops.mesh.remove_doubles()
return ('FINISHED',)
rna_path_prop = StringProperty(name="Context Attributes",

@ -193,6 +193,7 @@ class BONE_PT_relations(BoneButtonsPanel):
sub.active = (not bone.parent or not bone.connected)
sub.prop(bone, "local_location", text="Local Location")
class BONE_PT_display(BoneButtonsPanel):
bl_label = "Display"

@ -481,7 +481,7 @@ class MATERIAL_PT_sss(MaterialButtonsPanel):
mat = active_node_mat(context.material)
sss = mat.subsurface_scattering
wide_ui = context.region.width > narrowui
layout.active = (sss.enabled) and (not mat.shadeless)
row = layout.row().split()

@ -21,6 +21,7 @@ import bpy
narrowui = 180
class ConstraintButtonsPanel(bpy.types.Panel):
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'

@ -28,7 +28,7 @@ from properties_physics_common import effector_weights_ui
def cloth_panel_enabled(md):
return md.point_cache.baked is False
class CLOTH_MT_presets(bpy.types.Menu):
'''
@ -227,7 +227,7 @@ class PHYSICS_PT_cloth_field_weights(PhysicButtonsPanel):
def draw(self, context):
cloth = context.cloth.settings
effector_weights_ui(self, context, cloth.effector_weights)
bpy.types.register(CLOTH_MT_presets)
bpy.types.register(PHYSICS_PT_cloth)

@ -401,8 +401,8 @@ class RENDER_PT_encoding(RenderButtonsPanel):
col.label(text="Mux:")
col.prop(rd, "ffmpeg_muxrate", text="Rate")
col.prop(rd, "ffmpeg_packetsize", text="Packet Size")
# Audio:
# Audio:
layout.prop(rd, "ffmpeg_multiplex_audio", text="Audio")
sub = layout.column()
@ -554,4 +554,4 @@ bpy.types.register(RENDER_PT_output)
bpy.types.register(RENDER_PT_encoding)
bpy.types.register(RENDER_PT_performance)
bpy.types.register(RENDER_PT_post_processing)
bpy.types.register(RENDER_PT_stamp)
bpy.types.register(RENDER_PT_stamp)

@ -149,14 +149,15 @@ class IMAGE_MT_uvs_transform(bpy.types.Menu):
layout.operator("tfm.translate")
layout.operator("tfm.rotate")
layout.operator("tfm.resize")
class IMAGE_MT_uvs_snap(bpy.types.Menu):
bl_label = "Snap"
def draw(self, context):
def draw(self, context):
layout = self.layout
layout.operator_context = 'EXEC_REGION_WIN'
layout.operator("uv.snap_selection", text="Selected to Pixels").target = 'PIXELS'
layout.operator("uv.snap_selection", text="Selected to Cursor").target = 'CURSOR'
layout.operator("uv.snap_selection", text="Selected to Adjacent Unselected").target = 'ADJACENT_UNSELECTED'
@ -166,6 +167,7 @@ class IMAGE_MT_uvs_snap(bpy.types.Menu):
layout.operator("uv.snap_cursor", text="Cursor to Pixels").target = 'PIXELS'
layout.operator("uv.snap_cursor", text="Cursor to Selection").target = 'SELECTION'
class IMAGE_MT_uvs_mirror(bpy.types.Menu):
bl_label = "Mirror"

@ -522,7 +522,7 @@ class SEQUENCER_PT_sound(SequencerButtonsPanel):
row.prop(strip.sound, "caching")
layout.prop(strip, "volume")
class SEQUENCER_PT_scene(SequencerButtonsPanel):
bl_label = "Scene"
@ -541,7 +541,7 @@ class SEQUENCER_PT_scene(SequencerButtonsPanel):
layout = self.layout
strip = act_strip(context)
layout.template_ID(strip, "scene")

@ -168,7 +168,6 @@ class TEXT_MT_templates(bpy.types.Menu):
bl_label = "Script Templates"
def draw(self, context):
import os
self.path_menu(bpy.utils.script_paths("templates"), "text.open")

@ -1465,4 +1465,4 @@ bpy.ops.add(WM_OT_keyconfig_export)
bpy.ops.add(WM_OT_keymap_edit)
bpy.ops.add(WM_OT_keymap_restore)
bpy.ops.add(WM_OT_keyitem_add)
bpy.ops.add(WM_OT_keyitem_remove)
bpy.ops.add(WM_OT_keyitem_remove)

@ -30,7 +30,7 @@ class VIEW3D_HT_header(bpy.types.Header):
# view = context.space_data
mode_string = context.mode
edit_object = context.edit_object
object = context.active_object
obj = context.active_object
toolsettings = context.scene.tool_settings
row = layout.row(align=True)
@ -48,7 +48,7 @@ class VIEW3D_HT_header(bpy.types.Header):
if edit_object:
sub.menu("VIEW3D_MT_edit_%s" % edit_object.type.lower())
elif object:
elif obj:
if mode_string not in ['PAINT_WEIGHT', 'PAINT_TEXTURE']:
sub.menu("VIEW3D_MT_%s" % mode_string.lower())
else:
@ -57,7 +57,7 @@ class VIEW3D_HT_header(bpy.types.Header):
layout.template_header_3D()
# Proportional editing
if object.mode in ('OBJECT', 'EDIT'):
if obj.mode in ('OBJECT', 'EDIT'):
row = layout.row(align=True)
row.prop(toolsettings, "proportional_editing", text="", icon_only=True)
if toolsettings.proportional_editing != 'DISABLED':
@ -69,7 +69,7 @@ class VIEW3D_HT_header(bpy.types.Header):
row.prop(toolsettings, "snap_element", text="", icon_only=True)
if toolsettings.snap_element != 'INCREMENT':
row.prop(toolsettings, "snap_target", text="", icon_only=True)
if object.mode == 'OBJECT':
if obj.mode == 'OBJECT':
row.prop(toolsettings, "snap_align_rotation", text="")
if toolsettings.snap_element == 'VOLUME':
row.prop(toolsettings, "snap_peel_object", text="")
@ -83,7 +83,7 @@ class VIEW3D_HT_header(bpy.types.Header):
props.animation = True
# Pose
if object.mode == 'POSE':
if obj.mode == 'POSE':
row = layout.row(align=True)
row.operator("pose.copy", text="", icon='ICON_COPYDOWN')
row.operator("pose.paste", text="", icon='ICON_PASTEDOWN')
@ -114,16 +114,16 @@ class VIEW3D_MT_transform(bpy.types.Menu):
# TODO: get rid of the custom text strings?
def draw(self, context):
layout = self.layout
layout.operator("tfm.translate", text="Grab/Move")
# TODO: sub-menu for grab per axis
layout.operator("tfm.rotate", text="Rotate")
# TODO: sub-menu for rot per axis
layout.operator("tfm.resize", text="Scale")
# TODO: sub-menu for scale per axis
layout.separator()
layout.operator("tfm.tosphere", text="To Sphere")
layout.operator("tfm.shear", text="Shear")
layout.operator("tfm.warp", text="Warp")
@ -133,15 +133,16 @@ class VIEW3D_MT_transform(bpy.types.Menu):
else:
layout.operator_context = 'EXEC_AREA'
layout.operator("tfm.transform", text="Align to Transform Orientation").mode = 'ALIGN' # XXX see alignmenu() in edit.c of b2.4x to get this working
layout.separator()
layout.operator_context = 'EXEC_AREA'
layout.operator("object.center_set", text="ObData to Centroid").type = 'CENTER'
layout.operator("object.center_set", text="Centroid to ObData").type = 'CENTER_NEW'
layout.operator("object.center_set", text="Centroid to 3D Cursor").type = 'CENTER_CURSOR'
class VIEW3D_MT_mirror(bpy.types.Menu):
bl_label = "Mirror"
@ -149,11 +150,11 @@ class VIEW3D_MT_mirror(bpy.types.Menu):
layout = self.layout
layout.operator("tfm.mirror", text="Interactive Mirror")
layout.separator()
layout.operator_context = 'INVOKE_REGION_WIN'
props = layout.operator("tfm.mirror", text="X Global")
props.constraint_axis = (True, False, False)
props.constraint_orientation = 'GLOBAL'
@ -163,10 +164,10 @@ class VIEW3D_MT_mirror(bpy.types.Menu):
props = layout.operator("tfm.mirror", text="Z Global")
props.constraint_axis = (False, False, True)
props.constraint_orientation = 'GLOBAL'
if context.edit_object:
layout.separator()
props = layout.operator("tfm.mirror", text="X Local")
props.constraint_axis = (True, False, False)
props.constraint_orientation = 'LOCAL'
@ -176,7 +177,8 @@ class VIEW3D_MT_mirror(bpy.types.Menu):
props = layout.operator("tfm.mirror", text="Z Local")
props.constraint_axis = (False, False, True)
props.constraint_orientation = 'LOCAL'
class VIEW3D_MT_snap(bpy.types.Menu):
bl_label = "Snap"
@ -594,7 +596,7 @@ class VIEW3D_MT_select_face(bpy.types.Menu):# XXX no matching enum
def draw(self, context):
layout = self.layout
# TODO
# see view3d_select_faceselmenu
@ -785,7 +787,7 @@ class VIEW3D_MT_hook(bpy.types.Menu):
layout.operator_context = 'EXEC_AREA'
layout.operator("object.hook_add_newob")
layout.operator("object.hook_add_selob")
if [mod.type == 'HOOK' for mod in context.active_object.modifiers]:
layout.separator()
layout.operator_menu_enum("object.hook_assign", "modifier")
@ -803,7 +805,7 @@ class VIEW3D_MT_vertex_group(bpy.types.Menu):
layout = self.layout
layout.operator_context = 'EXEC_AREA'
layout.operator("object.vertex_group_assign", text="Assign to New Group").new = True
ob = context.active_object
if ob.mode == 'EDIT':
if ob.vertex_groups and ob.active_vertex_group:
@ -812,7 +814,7 @@ class VIEW3D_MT_vertex_group(bpy.types.Menu):
layout.operator("object.vertex_group_remove_from", text="Remove from Active Group")
layout.operator("object.vertex_group_remove_from", text="Remove from All").all = True
layout.separator()
if ob.vertex_groups and ob.active_vertex_group:
layout.operator_menu_enum("object.vertex_group_set_active", "group", text="Set Active Group")
layout.operator("object.vertex_group_remove", text="Remove Active Group")
@ -898,7 +900,7 @@ class VIEW3D_MT_pose(bpy.types.Menu):
layout = self.layout
arm = context.active_object.data
layout.menu("VIEW3D_MT_transform")
layout.menu("VIEW3D_MT_snap")
if arm.drawtype in ('BBONE', 'ENVELOPE'):
@ -1238,7 +1240,7 @@ def draw_curve(self, context):
layout = self.layout
settings = context.tool_settings
layout.menu("VIEW3D_MT_transform")
layout.menu("VIEW3D_MT_mirror")
layout.menu("VIEW3D_MT_snap")
@ -1374,7 +1376,7 @@ class VIEW3D_MT_edit_meta(bpy.types.Menu):
layout.operator("ed.redo")
layout.separator()
layout.menu("VIEW3D_MT_transform")
layout.menu("VIEW3D_MT_mirror")
layout.menu("VIEW3D_MT_snap")
@ -1412,7 +1414,7 @@ class VIEW3D_MT_edit_lattice(bpy.types.Menu):
layout = self.layout
settings = context.tool_settings
layout.menu("VIEW3D_MT_transform")
layout.menu("VIEW3D_MT_mirror")
layout.menu("VIEW3D_MT_snap")
@ -1435,7 +1437,7 @@ class VIEW3D_MT_edit_armature(bpy.types.Menu):
edit_object = context.edit_object
arm = edit_object.data
layout.menu("VIEW3D_MT_transform")
layout.menu("VIEW3D_MT_mirror")
layout.menu("VIEW3D_MT_snap")
@ -1562,11 +1564,7 @@ class VIEW3D_PT_3dview_properties(bpy.types.Panel):
col.prop(view, "clip_start", text="Start")
col.prop(view, "clip_end", text="End")
layout.column().prop(scene, "cursor_location", text="3D Cursor:")
class VIEW3D_PT_3dview_name(bpy.types.Panel):
@ -1609,7 +1607,7 @@ class VIEW3D_PT_3dview_display(bpy.types.Panel):
view = context.space_data
gs = context.scene.game_data
ob = context.object
col = layout.column()
col.prop(view, "display_x_axis", text="X Axis")
col.prop(view, "display_y_axis", text="Y Axis")
@ -1620,7 +1618,7 @@ class VIEW3D_PT_3dview_display(bpy.types.Panel):
if ob and ob.type == 'MESH':
mesh = ob.data
col.prop(mesh, "all_edges")
col = layout.column()
col.prop(view, "display_floor", text="Grid Floor")
sub = col.column(align=True)
@ -1628,7 +1626,7 @@ class VIEW3D_PT_3dview_display(bpy.types.Panel):
sub.prop(view, "grid_lines", text="Lines")
sub.prop(view, "grid_spacing", text="Spacing")
sub.prop(view, "grid_subdivisions", text="Subdivisions")
col = layout.column()
col.label(text="Shading:")
col.prop(gs, "material_mode", text="")
@ -1826,7 +1824,7 @@ class VIEW3D_PT_context_properties(bpy.types.Panel):
return "object"
return ""
def poll(self, context):
member = self._active_context_member(context)
if member:
@ -1845,46 +1843,6 @@ class VIEW3D_PT_context_properties(bpy.types.Panel):
rna_prop_ui.draw(self.layout, context, member, False)
# Operators
from bpy.props import *
class OBJECT_OT_select_pattern(bpy.types.Operator):
'''Select object matching a naming pattern.'''
bl_idname = "object.select_pattern"
bl_label = "Select Pattern"
bl_register = True
bl_undo = True
pattern = StringProperty(name="Pattern", description="Name filter using '*' and '?' wildcard chars", maxlen=32, default="*")
case_sensitive = BoolProperty(name="Case Sensitive", description="Do a case sensitive compare", default=False)
extend = BoolProperty(name="Extend", description="Extend the existing selection", default=True)
def execute(self, context):
import fnmatch
if self.properties.case_sensitive:
pattern_match = fnmatch.fnmatchcase
else:
pattern_match = lambda a, b: fnmatch.fnmatchcase(a.upper(), b.upper())
for ob in context.visible_objects:
if pattern_match(ob.name, self.properties.pattern):
ob.selected = True
elif not self.properties.extend:
ob.selected = False
return ('FINISHED',)
# TODO - python cant do popups yet
'''
def invoke(self, context, event):
wm = context.manager
wm.add_fileselect(self)
return ('RUNNING_MODAL',)
'''
bpy.types.register(VIEW3D_HT_header) # Header
bpy.types.register(VIEW3D_MT_view) #View Menus
@ -1979,5 +1937,3 @@ bpy.types.register(VIEW3D_PT_transform_orientations)
bpy.types.register(VIEW3D_PT_etch_a_ton)
bpy.types.register(VIEW3D_PT_context_properties)
bpy.ops.add(OBJECT_OT_select_pattern)

@ -171,7 +171,7 @@ class VIEW3D_PT_tools_curveedit(View3DPanel):
col.operator("tfm.translate")
col.operator("tfm.rotate")
col.operator("tfm.resize", text="Scale")
col = layout.column(align=True)
col.operator("tfm.transform", text="Tilt").mode = 'TILT'
col.operator("tfm.transform", text="Shrink/Fatten").mode = 'CURVE_SHRINKFATTEN'