Cleanup: assign variables & use 'match' to avoid redundant lookups

Also use more verbose names for RNA subtype enum variables.
This commit is contained in:
Campbell Barton 2023-04-28 16:36:15 +10:00
parent 5fa8f7746c
commit 2bb4abdc27
4 changed files with 22 additions and 17 deletions

@ -43,9 +43,10 @@ def get_context_modifier(context):
if context.area.type == 'PROPERTIES':
modifier = context.modifier
else:
if context.object is None:
ob = context.object
if ob is None:
return False
modifier = context.object.modifiers.active
modifier = ob.modifiers.active
if modifier is None or modifier.type != 'NODES':
return None
return modifier
@ -207,7 +208,8 @@ class NewGeometryNodesModifier(Operator):
return geometry_modifier_poll(context)
def execute(self, context):
modifier = context.object.modifiers.new(data_("GeometryNodes"), "NODES")
ob = context.object
modifier = ob.modifiers.new(data_("GeometryNodes"), 'NODES')
if not modifier:
return {'CANCELLED'}

@ -1357,10 +1357,10 @@ rna_custom_property_type_items = (
('PYTHON', "Python", "Edit a python value directly, for unsupported property types"),
)
rna_generic_subtype_none_item = ('NONE', "Plain Data", "Data values without special behavior")
rna_custom_property_subtype_none_item = ('NONE', "Plain Data", "Data values without special behavior")
rna_number_subtype_items = (
rna_generic_subtype_none_item,
rna_custom_property_subtype_number_items = (
rna_custom_property_subtype_none_item,
('PIXEL', "Pixel", ""),
('PERCENTAGE', "Percentage", ""),
('FACTOR', "Factor", ""),
@ -1371,8 +1371,8 @@ rna_number_subtype_items = (
('TEMPERATURE', "Temperature", ""),
)
rna_vector_subtype_items = (
rna_generic_subtype_none_item,
rna_custom_property_subtype_vector_items = (
rna_custom_property_subtype_none_item,
('COLOR', "Linear Color", "Color in the linear space"),
('COLOR_GAMMA', "Gamma-Corrected Color", "Color in the gamma corrected space"),
('EULER', "Euler Angles", "Euler rotation angles in radians"),
@ -1388,11 +1388,12 @@ class WM_OT_properties_edit(Operator):
bl_options = {'REGISTER', 'INTERNAL'}
def subtype_items_cb(self, context):
if self.property_type == 'FLOAT':
return rna_number_subtype_items
elif self.property_type == 'FLOAT_ARRAY':
return rna_vector_subtype_items
return []
match self.property_type:
case 'FLOAT':
return rna_custom_property_subtype_number_items
case 'FLOAT_ARRAY':
return rna_custom_property_subtype_vector_items
return ()
def property_type_update_cb(self, context):
self.subtype = 'NONE'

@ -110,7 +110,8 @@ class DATA_PT_bone_groups(ArmatureButtonsPanel, Panel):
@classmethod
def poll(cls, context):
return (context.object and context.object.type == 'ARMATURE' and context.object.pose)
ob = context.object
return (ob and ob.type == 'ARMATURE' and ob.pose)
def draw(self, context):
layout = self.layout

@ -276,7 +276,7 @@ class OBJECT_PT_instancing_size(ObjectButtonsPanel, Panel):
@classmethod
def poll(cls, context):
ob = context.object
return ob.instance_type == 'FACES'
return (ob is not None) and (ob.instance_type == 'FACES')
def draw_header(self, context):
@ -304,7 +304,8 @@ class OBJECT_PT_lineart(ObjectButtonsPanel, Panel):
def draw(self, context):
layout = self.layout
lineart = context.object.lineart
ob = context.object
lineart = ob.lineart
layout.use_property_split = True
@ -385,7 +386,7 @@ class OBJECT_PT_visibility(ObjectButtonsPanel, Panel):
col.prop(ob, "hide_viewport", text="Viewports", toggle=False, invert_checkbox=True)
col.prop(ob, "hide_render", text="Renders", toggle=False, invert_checkbox=True)
if context.object.type == 'GPENCIL':
if ob.type == 'GPENCIL':
col = layout.column(heading="Grease Pencil")
col.prop(ob, "use_grease_pencil_lights", toggle=False)