| Trees | Indices | Help |
|
|---|
|
|
1 # -*- coding: utf-8 -*-
2 """
3 Module containing helpers to create the UI types at runtime.
4 """
5 __docformat__ = "restructuredtext"
6
7 import mrv.maya as mrvmaya
8 from mrv.util import uncapitalize
9 import mrv.maya.util as mutil
10 from mrv.path import make_path
11 _uipackage = __import__( "mrv.maya.ui", globals(), locals(), ['ui'] )
12 import maya.cmds as mcmds
13 from util import propertyQE, EventSenderUI
14
15
16 # CACHES
17 _typetree = None
18 _typemap = { "floatingWindow" : "window", "field" : "textField" }
19
20
21 #{ Initialization
23 """ Read a simple hiearchy file and create an Indexed tree from it"""
24 mfile = make_path( __file__ ).parent().parent() / "cache/UICommandsHierachy.hf"
25
26 # STORE THE TYPE TREE
27 global _typetree
28 _typetree = mrvmaya.dag_tree_from_tuple_list( mrvmaya.tuple_list_from_file( mfile ) )
29
30
32 """ Create Standin Classes that will delay the creation of the actual class till
33 the first instance is requested"""
34 mrvmaya.initWrappers( _uipackage.__dict__, _typetree.nodes_iter(), MetaClassCreatorUI )
35
36 #} END initialization
37
38
40 """ Builds the base hierarchy for the given classname based on our
41 typetree.
42 Additional support for :
43
44 **AUTOMATIC PROPERTY GENERATION**:
45 - if flags are simple get and set properties, these can be listed in the
46 _properties_ attribute ( list ). These must be queriable and editable
47
48 - Properties will be available as:
49 inst.p_myProperty to access myProperty ( equivalent to cmd -q|e -myProperty
50
51 - This only works if our class knows it's mel command in the __melcmd__ member
52 variable - inheritance for it does not work
53
54 **AUTOMATIC UI-EVENT GENERATION**:
55 - define names of mel events in _events_ as list of names
56
57 - these will be converted into Events sitting at attribute names like
58 e_eventName ( for even called 'eventName'
59
60 - assign an event:
61 windowinstance.e_restoreCommand = func
62 whereas func takes: ``func( windowinstance, *args, **kwargs )``
63
64 **ADDITIONAL CONFIGURAITON**:
65 - strong_event_handlers:
66 if True, events will use strong references to their handlers
67
68 """
69
70 melcmd_attrname = '__melcmd__'
71
72
74 """ Called to create the class with name """
75 # HANDLE MEL COMMAND
76 #######################
77 cmdname = uncapitalize( name )
78 if hasattr( mcmds, cmdname ):
79 melcmd = getattr( mcmds, cmdname )
80 clsmelcmd = staticmethod( melcmd )
81 clsdict['__melcmd__'] = clsmelcmd
82 else:
83 pass # don't bother, can be one of our own classes that will
84 #raise ValueError( "Did not find command for " + cmdname )
85
86 # HANDLE PROPERTIES
87 ####################
88 # read the properties attribute to find names to automatically create
89 # query and edit properties
90 propertynames = clsdict.get( "_properties_", list() )
91 for pname in propertynames:
92 attrname = "p_%s" % pname
93 # allow user overrides
94 if attrname not in clsdict:
95 clsdict[ attrname ] = propertyQE( pname )
96 # END for each property
97
98 # HANDLE EVENTS
99 ##################
100 # read the event description and create Event instances that will
101 # register themselves on first use, allowing multiple listeners per maya event
102 eventnames = clsdict.get( "_events_", list() )
103 event_kwargs = dict()
104 if clsdict.get( "strong_event_handlers", False ):
105 event_kwargs[ "weak" ] = False
106
107 for ename in eventnames:
108 attrname = "e_%s" % ename
109 # allow user overrides
110 if attrname not in clsdict:
111 clsdict[ attrname ] = EventSenderUI._UIEvent( ename, **event_kwargs )
112 # END for each event name
113
114 newcls = super( MetaClassCreatorUI, metacls ).__new__( _typetree, _uipackage,
115 metacls, name, bases, clsdict )
116
117 return newcls
118
| Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Tue Apr 19 18:00:19 2011 | http://epydoc.sourceforge.net |