1
2 """
3 Contains the most controls like buttons and sliders for more convenient use
4 """
5 __docformat__ = "restructuredtext"
6
7 import base as uibase
8 import util as uiutil
9
10 from mrv.maya.util import noneToList
11
12 import logging
13 log = logging.getLogger("mrv.maya.ui.control")
14
15
16
18 """Base class for elements having labels"""
19 _properties_ = ( "l", "label",
20 "al", "align" ,
21 "rs", "recomputeSize" )
22
24 """Class contributing Simple Slider Events"""
25 _events_ = ( "cc", "changeCommand",
26 "dc", "dragCommand" )
27
28 _properties_ = ( "min", "minValue",
29 "max", "maxValue",
30 "v", "value",
31 "s", "step",
32 "hr", "horizontal" )
33
35 """Base class for boolean controls"""
36 _events_ = ( "onCommand", "onc",
37 "offCommand", "ofc",
38 "changeCommand", "cc" )
39
41 """Base class for checkboxes"""
42 _properties_ = ( "value", "v" )
43
47
48
50 """Base allowing access to all grouped controls
51
52 :note: using short property names to ... keep it sane """
53
54 _properties_ = [ "cw", "columnWidth",
55 "cat", "columnAttach",
56 "rat", "rowAttach",
57 "cal", "columnAlign",
58 "adj", "adjustableColumn" ]
59
60
61 for flag in ( "cw","columnWidth", "ct", "columnAttach",
62 "co", "columnOffset", "cl", "columnAlign",
63 "ad", "adjustableColumn" ):
64 start = 1
65 if flag in ( "cl", "columnAlign", "ad", "adjustableColumn" ):
66 start = 2
67
68 for i in range( start, 7 ):
69 _properties_.append( flag + str( i ) )
70
71
73 """base class for all optionMenu like controls"""
74 __metaclass__ = uibase.typ.MetaClassCreatorUI
75
76 _events_ = ( "cc", "changeCommand" )
77 _properties_ = ( "ils", "itemListShort",
78 "ill", "itemListLong",
79 "l", "label",
80 "ni", "numberOfItems",
81 "sl", "select",
82 "v", "value" )
83
85 _events_ = ( "rfc", "receiveFocusCommand",
86 "ec", "enterCommand",
87 "cc", "changeCommand" )
88
89 _properties_ = ( "ed", "editable" )
90
91
92 -class TextFieldBase( object ):
93 """Base just containing properties and events"""
94 __metaclass__ = uibase.typ.MetaClassCreatorUI
95
96 _properties_ = ( "fn", "font",
97 "it", "insertText",
98 "ip", "insertPosition"
99 "fi", "fileName",
100 "tx", "text" )
101
102 -class TextFieldGroupBase( TextFieldBase ):
103 """Common base for the group text fields"""
104 _events_ = ( "cc", "changeCommand" ,
105 "fcc", "forceChangeCommand" )
106
108 """base class for all sliders"""
109 _properties_ = ( "el", "extraLabel",
110 "fieldMinValue", "fmn",
111 "fieldMaxValue", "fmx",
112 "fieldStep", "fs",
113 "sliderStep", "ss" )
114
115
117 """base class for all boolean groups"""
118 _events_ = list()
119
120
121 for flag in ( "on","onCommand",
122 "of", "offCommand",
123 "cc", "changeCommand" ):
124
125 for i in range( 1, 5 ):
126 _events_.append( flag + str( i ) )
127
128
129 _properties_ = list()
130
131 for flag in ( "en","enable",
132 "da", "data",
133 "l", "label",
134 "la","labelArray" ):
135
136 start = 1
137 if flag in ( "la", "labelArray" ):
138 start = 2
139
140 for i in range( start, 5 ):
141 _properties_.append( flag + str( i ) )
142
143
144
151
152 -class IconTextBase( object ):
153 """Base class for all icon text like controls"""
154
155 __metaclass__ = uibase.typ.MetaClassCreatorUI
156
157
158 _properties_ = ( "image", "i",
159 "image1", "i1",
160 "image2", "i2",
161 "image3", "i3",
162 "disabledImage", "di",
163 "highlightImage", "hi",
164 "imageOverlayLabel", "iol",
165 "style", "st",
166 "selectionImage", "si",
167 "highlightImage", "hi",
168 "labelOffset", "lo",
169 "font", "fn"
170 )
171
172 _events_ = ( "handleNodeDropCallback", "hnd",
173 "labelEditingCallback", "lec" )
174
175
176
177
181
182
184 """Note: inherits booleanBase multiple times, this does no harm"""
185 _properties_ = list()
186
187 for flag in ( "v","value",
188 "va", "valueArray" ):
189 for i in range( 1, 5 ):
190 if flag in ( "va", "valueArray" ) and i == 1:
191 continue
192
193 _properties_.append( flag + str( i ) )
194
195
196
197
208
209
211 """Class just for multiple inheritance - this cannot be expressed in the hierarchy
212 file"""
213 _events_ = ( "c", "command" )
214
215
217 """Keeps common properties"""
218 __metaclass__ = uibase.typ.MetaClassCreatorUI
219
220 _properties_ = ( "global", "gl",
221 "select", "sl",
222 "disableCommands", "dcm",
223 "numberOfCollectionItems", "nci",
224 "collectionItemArray", "cia" )
225
226
228 """Required for multiple inhertance"""
229 pass
230
231
233 """Required for multiple inhertance
234 :note: it inherits exists() and a few others which are actually not supported for
235 some reason"""
236 pass
237
238
242
243
245 """Required for multiple inhertance"""
246 pass
247
248
249 -class IconTextCheckBox( CheckBoxBase, IconTextBase ):
250 """Class just for multiple inheritance - this cannot be expressed in the hierarchy
251 file"""
252 pass
253
255 """Class just for multiple inheritance - this cannot be expressed in the hierarchy
256 file"""
257 pass
258
259 -class TextField( FieldBase, TextFieldBase ):
260 """Class just for multiple inheritance - this cannot be expressed in the hierarchy
261 file"""
262 pass
263
279
280
282 """Class defining attributes and events for the text-scroll list"""
283 _properties_ = ( "append", "a",
284 "appendPosition", "ap",
285 "allItems", "ai",
286 "allowAutomaticSelection", "aas",
287 "allowMultiSelection", "ams",
288 "numberOfItems", "ni",
289 "numberOfRows", "nr",
290 "numberOfSelectedItems", "nsi",
291 "removeAll", "ra"
292 "removeItem", "ri",
293 "removeIndexedItem", "rii",
294 "selectItem", "si",
295 "selectIndexedItem", "sii",
296 "deselectAll", "da",
297 "deselectItem", "di",
298 "deselectIndexedItem", "dii",
299 "showIndexedItem", "shi",
300 "font", "fn" )
301
302 _events_ = ( "doubleClickCommand", "dcc",
303 "deleteKeyCommand", "dkc",
304 "selectCommand", "sc" )
305
306
307
309 """:return: list of currently available items"""
310 return noneToList(self.p_allItems)
311
313 """:return: First selected index - the index is 1-based, or -1 if there
314 is nothing selected
315 :note: even if multiple selections are possible"""
316 sel = self.selectedIndices()
317 if not sel:
318 return -1
319 return sel[0]
320
322 """:return: tuple of all selected 1-based indices, or an empty tuple if there
323 is nothing selected"""
324 try:
325 return tuple(noneToList(self.p_selectIndexedItem))
326 except RuntimeError:
327 return tuple()
328
329
331 """:return: the first selected item, or None if nothing is selected"""
332 items = self.selectedItems()
333 return (items and items[0]) or None
334
336 """:return: list of all selected items as strings, or an empty list if nothing
337 is selected"""
338 try:
339 return noneToList(self.p_selectItem)
340 except RuntimeError:
341 return list()
342
343
345 """Set the given items to be shown.
346 :param items: iterable of items
347 if empty, the control will be empty after this call.
348 :return: self"""
349 self.p_removeAll = True
350 for item in items:
351 self.p_append = str(item)
352
353 return self
354
356 """Add the given item to the end of the list
357 :return: self"""
358 self.p_append = str(item)
359 return self
360
362 """Add multiple items to the end of the list
363 :return: self"""
364 for item in items:
365 self.addItem(item)
366
367 return self
368
370 """Set the given item selected, or clear the selection
371 :param item: item to select, or clear the selection if None is given
372 :note: it is not considered an error if the item doesnt exist - following
373 maya's behaviour
374 :return: self"""
375 if item is None:
376 self.p_deselectAll = True
377 return
378
379
380 self.p_selectItem = item
381 return self
382
384 """Remove the given item from the list. It is not an error if it doesn't
385 exist in the first place
386 :return: self"""
387 items = self.items()
388 try:
389 index = items.index(item)
390 self.p_removeIndexedItem = index+1
391 except ValueError:
392
393 pass
394
395 return self
396
397
398
399
400
401 -class TextFieldGrp( GroupBase, TextFieldGroupBase ):
402 """Class just for multiple inheritance - this cannot be expressed in the hierarchy
403 file"""
404
405
407 """Class just for multiple inheritance - this cannot be expressed in the hierarchy
408 file"""
409
410 -class Text( LabelBase ):
411 _properties_ = ( "font", "fn" )
412
414 _properties_ = ( "style", "st",
415 "horizontal", "hr" )
416
418 """Class just for multiple inheritance - this cannot be expressed in the hierarchy
419 file
420
421 :note: Order of inheritance matters due to method resolution order !"""
422
423 _is_menu = True
424
425
426
428 """Class just for multiple inheritance - this cannot be expressed in the hierarchy
429 file
430
431 :note: Order of inheritance matters due to method resolution order !"""
432
433 _is_menu = True
434
435
436
437
439 """The optionMenuGrp cannot be set as a parent as it is classified as control layout.
440 A problem arises if you actually try to add new menuItems to it after it's creation which
441 does not work as it is not a menu"""
442 log.warn("setActive: OptionMenuGrp's instances cannot be setActive after creation due to a Maya API logic error - you will set the layout active, not the contained option menu")
443 return super( OptionMenuGrp, self ).setActive()
444
446 """See `setActive`"""
447 log.warn("setParentActive: OptionMenuGrp instances will change the parent of their control layout only, not the menu parent of the optionMenu")
448 super( OptionMenuGrp, self ).setParentActive()
449
450