mrv.maya.ui.layout
Covered: 130 lines
Missed: 6 lines
Skipped 40 lines
Percent: 95 %
  2
"""
  3
Contains the most important mel-layouts wrapped into easy to use python classes
  4
These are specialized and thus more powerful than the default wraps
  5
"""
  6
__docformat__ = "restructuredtext"
  7
import base as uibase
  8
import maya.cmds as cmds
  9
import mrv.maya.util as mutil
 10
import util as uiutil
 13
class Layout( uibase.SizedControl, uiutil.UIContainerBase ):
 14
	""" Structural base  for all Layouts allowing general queries and name handling
 15
	Layouts may track their children
 16
	"""
 17
	_properties_ = ( "nch", "numberOfChildren")
 19
	def __init__( self, *args, **kwargs ):
 20
		"""Initialize the layout"""
 21
		super( Layout, self ).__init__( *args, **kwargs )
 23
	def __getitem__( self, key ):
 24
		"""Implemented by `UIContainerBase`"""
 25
		return uiutil.UIContainerBase.__getitem__( self, key )
 27
	def children( self ):
 28
		""" :return: children of this layout """
 29
		childnames = mutil.noneToList( cmds.layout( self, q=1, ca=1 ) )
 31
		return uibase.wrapUI( [ "%s|%s" % ( self, c ) for c in childnames ] )
 33
	def setParentActive( self ):
 34
		"""Set the parent ( layout ) of this layout active - newly created items
 35
		will be children of the parent layout
 37
		:return: self
 38
		:note: can safely be called several times """
 39
		cmds.setParent(self._parentString())
 40
		return self
 43
	p_ca = property(children)
 44
	p_childArray = p_ca
 48
class FormLayout( Layout ):
 49
	""" Wrapper class for maya form layout """
 53
	kSides = ( "top", "bottom", "left", "right" )
 55
	class FormConstraint( object ):
 56
		""" defines the way a child is constrained, possibly to other children
 58
		:todo: proper constraint system, but could be complicated to make it really easy to use"""
 60
	def setup( self, **kwargs ):
 61
		"""Apply the given setup to the form layout, specified using kwargs
 63
		:param kwargs: arguments you would set use to setup the form layout"""
 64
		self.__melcmd__( self, e=1, **kwargs )
 67
class FrameLayout( Layout ):
 68
	"""Simple wrapper for a frame layout"""
 69
	_properties_ = (	"bw", "borderVisible",
 70
					   	"bs",  "borderStyle",
 71
						"cl", "collapse",
 72
						"cll", "collapsable",
 73
						"l", "label",
 74
						"lw", "labelWidth",
 75
						"lv", "labelVisible",
 76
						"la", "labelAlign",
 77
						"li", "labelIndent",
 78
						"fn", "font",
 79
						"mw", "marginWidth",
 80
						"mh", "marginHeight" )
 82
	_events_ = ( 	"cc", "collapseCommand",
 83
					"ec", "expandCommand",
 84
					"pcc", "preCollapseCommand",
 85
					"pec", "preExpandCommand" )
 88
class RowLayout( Layout ):
 89
	"""Wrapper for row column layout"""
 90
	_properties_ = [ 	"columnWidth", "cw",
 91
						"columnAttach", "cat",
 92
						"rowAttach", "rat",
 93
					  	"columnAlign", "cal",
 94
						"adjustableColumn", "adj",
 95
					  	"numberOfColumns", "nc" ]
 97
	for flag in ( 	"columnWidth", "cw", "columnAttach", "ct", "columnOffset",
 98
				  	"co", "columnAlign", "cl", "adjustableColumn", "ad" ):
 99
		for i in range( 1, 7 ):
100
			_properties_.append( flag + str( i ) )
103
class ColumnLayoutBase( Layout ):
104
	_properties_ = (   	"columnAlign", "cal",
105
						"columnAttach", "cat",
106
						"columnOffset", "co" ,
107
						"columnWidth", "cw",
108
						"rowSpacing", "rs" )
110
class RowColumnLayout( ColumnLayoutBase ):
111
	"""Wrapper for row column layout"""
112
	_properties_ = ( 	"numberOfColumns", "nc",
113
					  	"numberOfRows", "nr",
114
						"rowHeight", "rh",
115
						"rowOffset", "ro",
116
					  	"rowSpacing", "rs" )
119
class ColumnLayout( ColumnLayoutBase ):
120
	"""Wrapper class for a simple column layout"""
122
	_properties_ = ( 	"adjustableColumn", "adj" )
124
class ScrollLayout( Layout ):
125
	"""Wrapper for a scroll layout"""
126
	_properties_ = ( 	"scrollAreaWIdth", "saw",
127
					  	"scrollAreaHeight", "sah",
128
						"scrollAreaValue", "sav",
129
						"minChildWidth", "mcw",
130
						"scrollPage", "sp",
131
						"scrollByPixel", "sbp"	)
133
	_event_ = ( "resizeCommand", "rc" )
135
class TabLayout( Layout ):
136
	"""Simple wrapper for a tab layout"""
137
	_properties_ = (	"tv", "tabsVisible",
138
					   	"st",  "selectTab",
139
						"sti", "selectTabIndex",
140
						"tl", "tabLabel",
141
						"tli", "tabLabelIndex",
142
						"scr", "scrollable",
143
						"hst", "horizontalScrollBarThickness",
144
						"vst", "verticalScrollBarThickness",
145
						"imw", "innerMarginWidth",
146
						"imh", "innerMarginHeight",
147
						"i", "image",
148
						"iv", "imageVisible",
149
						"cr", "childResizable",
150
						"mcw", "minChildWidth",
151
						"mt", "moveTab" )
153
	_events_ = ( 	"cc", "changeCommand",
154
					"sc", "selectCommand",
155
					"psc", "preSelectCommand",
156
					"dcc", "doubleClickCommand" )
158
class PaneLayout(Layout):
159
	"""Simple wrapper for a pane layout"""
160
	_properties_ = (
161
						"cn", "configuration", 
162
						"sp", "setPane", 
163
						"ap", "activePane", 
164
						"api", "activePaneIndex", 
165
						"aft", "activeFrameThickness", 
166
						"st", "separatorThickness", 
167
						"ps", "paneSize", 
168
						"p1", "p2", "p3", "p4", "pane1", "pane2", "pane3", "pane4", 
169
						"pup", "paneUnderPointer",
170
						"nvp", "numberOfVisiblePanes", 
172
						"swp", "staticWidthPane", 
173
						"shp", "staticHeightPane"
174
					)
175
	_events_ = ("smc", "separatorMovedCommand")