blender/release/scripts/startup/bl_ui/properties_mask_common.py

347 lines
10 KiB
Python
Raw Normal View History

# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
2012-07-29 12:07:06 +00:00
# <pep8-80 compliant>
# panels get subclassed (not registered directly)
# menus are referenced `as is`
import bpy
This commit frees list ui items from their dependencies to Panel, and hence from all the limitations this implied (mostly, the "only one list per panel" one). It introduces a new (py-extendable and registrable) RNA type, UIList (roughly similar to Panel one), which currently contains only "standard" list's scroll pos and size (but may be expended to include e.g. some filtering data, etc.). This now makes lists completely independent from Panels! This UIList has a draw_item callback which allows to customize items' drawing from python, that all addons can now use. Incidentally, this also greatly simplifies the C code of this widget, as we do not code any "special case" here anymore! To make all this work, other changes were also necessary: * Now all buttons (uiBut struct) have a 'custom_data' void pointer, used currently to store the uiList struct associated with a given uiLayoutListBox. * DynamicPaintSurface now exposes a new bool, use_color_preview (readonly), saying whether that surface has some 3D view preview data or not. * UILayout class has now four new (static) functions, to get the actual icon of any RNA object (important e.g. with materials or textures), and to get an enum item's UI name, description and icon. * UILayout's label() func now takes an optional 'icon_value' integer parameter, which if not zero will override the 'icon' one (mandatory to use "custom" icons as generated for material/texture/... previews). Note: not sure whether we should add that one to all UILayout's prop funcs? Note: will update addons using template list asap.
2012-12-28 09:20:16 +00:00
from bpy.types import Menu, UIList
class MASK_UL_layers(UIList):
2013-01-15 23:15:32 +00:00
def draw_item(self, context, layout, data, item, icon,
active_data, active_propname, index):
# assert(isinstance(item, bpy.types.MaskLayer)
This commit frees list ui items from their dependencies to Panel, and hence from all the limitations this implied (mostly, the "only one list per panel" one). It introduces a new (py-extendable and registrable) RNA type, UIList (roughly similar to Panel one), which currently contains only "standard" list's scroll pos and size (but may be expended to include e.g. some filtering data, etc.). This now makes lists completely independent from Panels! This UIList has a draw_item callback which allows to customize items' drawing from python, that all addons can now use. Incidentally, this also greatly simplifies the C code of this widget, as we do not code any "special case" here anymore! To make all this work, other changes were also necessary: * Now all buttons (uiBut struct) have a 'custom_data' void pointer, used currently to store the uiList struct associated with a given uiLayoutListBox. * DynamicPaintSurface now exposes a new bool, use_color_preview (readonly), saying whether that surface has some 3D view preview data or not. * UILayout class has now four new (static) functions, to get the actual icon of any RNA object (important e.g. with materials or textures), and to get an enum item's UI name, description and icon. * UILayout's label() func now takes an optional 'icon_value' integer parameter, which if not zero will override the 'icon' one (mandatory to use "custom" icons as generated for material/texture/... previews). Note: not sure whether we should add that one to all UILayout's prop funcs? Note: will update addons using template list asap.
2012-12-28 09:20:16 +00:00
mask = item
if self.layout_type in {'DEFAULT', 'COMPACT'}:
split = layout.split()
split.label(text=mask.name, translate=False, icon_value=icon)
This commit frees list ui items from their dependencies to Panel, and hence from all the limitations this implied (mostly, the "only one list per panel" one). It introduces a new (py-extendable and registrable) RNA type, UIList (roughly similar to Panel one), which currently contains only "standard" list's scroll pos and size (but may be expended to include e.g. some filtering data, etc.). This now makes lists completely independent from Panels! This UIList has a draw_item callback which allows to customize items' drawing from python, that all addons can now use. Incidentally, this also greatly simplifies the C code of this widget, as we do not code any "special case" here anymore! To make all this work, other changes were also necessary: * Now all buttons (uiBut struct) have a 'custom_data' void pointer, used currently to store the uiList struct associated with a given uiLayoutListBox. * DynamicPaintSurface now exposes a new bool, use_color_preview (readonly), saying whether that surface has some 3D view preview data or not. * UILayout class has now four new (static) functions, to get the actual icon of any RNA object (important e.g. with materials or textures), and to get an enum item's UI name, description and icon. * UILayout's label() func now takes an optional 'icon_value' integer parameter, which if not zero will override the 'icon' one (mandatory to use "custom" icons as generated for material/texture/... previews). Note: not sure whether we should add that one to all UILayout's prop funcs? Note: will update addons using template list asap.
2012-12-28 09:20:16 +00:00
row = split.row(align=True)
row.prop(mask, "alpha", text="", emboss=False)
row.prop(mask, "hide", text="", emboss=False)
row.prop(mask, "hide_select", text="", emboss=False)
row.prop(mask, "hide_render", text="", emboss=False)
elif self.layout_type in {'GRID'}:
layout.alignment = 'CENTER'
layout.label(text="", icon_value=icon)
2012-07-25 13:44:07 +00:00
class MASK_PT_mask:
# subclasses must define...
#~ bl_space_type = 'CLIP_EDITOR'
#~ bl_region_type = 'UI'
bl_label = "Mask Settings"
bl_options = {'DEFAULT_CLOSED'}
2012-07-25 13:44:07 +00:00
@classmethod
def poll(cls, context):
space_data = context.space_data
return space_data.mask and space_data.mode == 'MASK'
def draw(self, context):
layout = self.layout
sc = context.space_data
mask = sc.mask
col = layout.column(align=True)
col.prop(mask, "frame_start")
col.prop(mask, "frame_end")
2012-07-25 13:44:07 +00:00
class MASK_PT_layers:
# subclasses must define...
#~ bl_space_type = 'CLIP_EDITOR'
#~ bl_region_type = 'UI'
bl_label = "Mask Layers"
@classmethod
def poll(cls, context):
2012-07-25 13:44:07 +00:00
space_data = context.space_data
return space_data.mask and space_data.mode == 'MASK'
def draw(self, context):
layout = self.layout
sc = context.space_data
mask = sc.mask
active_layer = mask.layers.active
rows = 5 if active_layer else 2
row = layout.row()
2013-01-15 23:15:32 +00:00
row.template_list("MASK_UL_layers", "", mask, "layers",
mask, "active_layer_index", rows=rows)
sub = row.column(align=True)
sub.operator("mask.layer_new", icon='ZOOMIN', text="")
sub.operator("mask.layer_remove", icon='ZOOMOUT', text="")
if active_layer:
sub.separator()
props = sub.operator("mask.layer_move", icon='TRIA_UP', text="")
props.direction = 'UP'
props = sub.operator("mask.layer_move", icon='TRIA_DOWN', text="")
props.direction = 'DOWN'
layout.prop(active_layer, "name")
# blending
row = layout.row(align=True)
row.prop(active_layer, "alpha")
row.prop(active_layer, "invert", text="", icon='IMAGE_ALPHA')
layout.prop(active_layer, "blend")
layout.prop(active_layer, "falloff")
class MASK_PT_spline():
# subclasses must define...
#~ bl_space_type = 'CLIP_EDITOR'
#~ bl_region_type = 'UI'
bl_label = "Active Spline"
@classmethod
def poll(cls, context):
sc = context.space_data
mask = sc.mask
2012-07-25 13:44:07 +00:00
if mask and sc.mode == 'MASK':
return mask.layers.active and mask.layers.active.splines.active
return False
def draw(self, context):
layout = self.layout
sc = context.space_data
mask = sc.mask
spline = mask.layers.active.splines.active
col = layout.column()
col.prop(spline, "offset_mode")
col.prop(spline, "weight_interpolation")
2012-07-29 12:07:06 +00:00
row = col.row()
row.prop(spline, "use_cyclic")
row.prop(spline, "use_fill")
col.prop(spline, "use_self_intersection_check")
class MASK_PT_point():
# subclasses must define...
#~ bl_space_type = 'CLIP_EDITOR'
#~ bl_region_type = 'UI'
bl_label = "Active Point"
@classmethod
def poll(cls, context):
sc = context.space_data
mask = sc.mask
2012-07-25 13:44:07 +00:00
if mask and sc.mode == 'MASK':
mask_layer_active = mask.layers.active
return (mask_layer_active and
mask_layer_active.splines.active_point)
return False
def draw(self, context):
layout = self.layout
sc = context.space_data
mask = sc.mask
point = mask.layers.active.splines.active_point
parent = point.parent
col = layout.column()
col.prop(point, "handle_type")
col = layout.column()
# Currently only parenting yo movie clip is allowed, so do not
# ver-oplicate things for now and use single template_ID
#col.template_any_ID(parent, "id", "id_type", text="")
col.label("Parent:")
col.prop(parent, "id", text="")
if parent.id_type == 'MOVIECLIP' and parent.id:
clip = parent.id
tracking = clip.tracking
col.prop_search(parent, "parent", tracking,
"objects", icon='OBJECT_DATA', text="Object:")
if parent.parent in tracking.objects:
object = tracking.objects[parent.parent]
col.prop_search(parent, "sub_parent", object,
"tracks", icon='ANIM_DATA', text="Track:")
else:
col.prop_search(parent, "sub_parent", tracking,
"tracks", icon='ANIM_DATA', text="Track:")
class MASK_PT_display():
# subclasses must define...
#~ bl_space_type = 'CLIP_EDITOR'
#~ bl_region_type = 'UI'
bl_label = "Mask Display"
bl_options = {'DEFAULT_CLOSED'}
2012-07-25 13:44:07 +00:00
@classmethod
def poll(cls, context):
space_data = context.space_data
return space_data.mask and space_data.mode == 'MASK'
def draw(self, context):
layout = self.layout
2012-07-25 13:44:07 +00:00
space_data = context.space_data
2012-07-25 13:44:07 +00:00
layout.prop(space_data, "mask_draw_type", text="")
layout.prop(space_data, "show_mask_smooth")
class MASK_PT_tools():
# subclasses must define...
#~ bl_space_type = 'CLIP_EDITOR'
#~ bl_region_type = 'TOOLS'
bl_label = "Mask Tools"
2012-07-25 13:44:07 +00:00
@classmethod
def poll(cls, context):
space_data = context.space_data
return space_data.mask and space_data.mode == 'MASK'
def draw(self, context):
layout = self.layout
col = layout.column(align=True)
col.label(text="Transform:")
col.operator("transform.translate")
col.operator("transform.rotate")
col.operator("transform.resize", text="Scale")
props = col.operator("transform.transform", text="Scale Feather")
props.mode = 'MASK_SHRINKFATTEN'
col = layout.column(align=True)
col.label(text="Spline:")
col.operator("mask.delete")
col.operator("mask.cyclic_toggle")
col.operator("mask.switch_direction")
col.operator("mask.handle_type_set")
col = layout.column(align=True)
col.label(text="Parenting:")
col.operator("mask.parent_set")
col.operator("mask.parent_clear")
2012-08-13 09:13:19 +00:00
col = layout.column(align=True)
col.label(text="Animation:")
col.operator("mask.shape_key_clear")
col.operator("mask.shape_key_insert")
col.operator("mask.shape_key_feather_reset")
col.operator("mask.shape_key_rekey")
class MASK_MT_mask(Menu):
bl_label = "Mask"
def draw(self, context):
layout = self.layout
layout.operator("mask.delete")
layout.separator()
layout.operator("mask.cyclic_toggle")
layout.operator("mask.switch_direction")
layout.operator("mask.normals_make_consistent")
layout.operator("mask.feather_weight_clear") # TODO, better place?
layout.separator()
layout.operator("mask.parent_clear")
layout.operator("mask.parent_set")
layout.separator()
layout.menu("MASK_MT_visibility")
layout.menu("MASK_MT_transform")
layout.menu("MASK_MT_animation")
class MASK_MT_visibility(Menu):
bl_label = "Show/Hide"
def draw(self, context):
layout = self.layout
layout.operator("mask.hide_view_clear", text="Show Hidden")
layout.operator("mask.hide_view_set", text="Hide Selected")
props = layout.operator("mask.hide_view_set", text="Hide Unselected")
props.unselected = True
class MASK_MT_transform(Menu):
bl_label = "Transform"
def draw(self, context):
layout = self.layout
layout.operator("transform.translate")
layout.operator("transform.rotate")
layout.operator("transform.resize")
props = layout.operator("transform.transform", text="Scale Feather")
props.mode = 'MASK_SHRINKFATTEN'
class MASK_MT_animation(Menu):
bl_label = "Animation"
def draw(self, context):
layout = self.layout
layout.operator("mask.shape_key_clear")
layout.operator("mask.shape_key_insert")
layout.operator("mask.shape_key_feather_reset")
layout.operator("mask.shape_key_rekey")
class MASK_MT_select(Menu):
bl_label = "Select"
def draw(self, context):
layout = self.layout
sc = context.space_data
layout.operator("mask.select_border")
layout.operator("mask.select_circle")
layout.separator()
layout.operator("mask.select_all").action = 'TOGGLE'
layout.operator("mask.select_all", text="Inverse").action = 'INVERT'
if __name__ == "__main__": # only for live edit.
bpy.utils.register_module(__name__)