1
2 """
3 Contains some default dialogs as well as layouts suitable for layout dialogs
4 """
5 __docformat__ = "restructuredtext"
6
7 import base as uibase
8 import maya.cmds as cmds
9 import maya.utils as mutils
10 import mrv.util as util
11 from mrv.interface import iPrompt, iChoiceDialog, iProgressIndicator
12
13 import logging
14 log = logging.getLogger("mrv.maya.ui.dialog")
15
16
18 """ Base for all dialog classes """
19
20
22 """ Wrapper class for maya prompt dialog"""
23
24 - def __init__( self, title, message, okText, cancelText, **kwargs ):
25 """ Create a prompt dialog and allow to query the result
26 :note: return default text in batch mode, given with 'text' key"""
27 if cmds.about( batch=1 ):
28 return kwargs.get( 'text', kwargs.get( 't', '' ) )
29
30 ret = cmds.promptDialog( t = title, m = message, b = [okText,cancelText],
31 db = okText, cb = cancelText,**kwargs )
32 self._text = None
33 if ret == okText:
34 self._text = cmds.promptDialog( q=1, text = 1 )
35
37 """:return: the entered text or None if the box has been aborted"""
38 return self._text
39
40
42 """Implements the prompt interface using a prompt dialog"""
43
45 """Aquire the information using a prompt dialog
46
47 :return: prompted value if input was confirmed using confirmToken, or the cancelValue
48 if cancelToken was pressed
49 :note: tokens correspond to buttons
50 :note: handles batch mode correctly"""
51 if cmds.about( batch = 1 ):
52 return super( Prompt, self ).prompt( )
53
54 default_text = ( self.confirmDefault is not None and self.confirmDefault ) or ""
55
56 tokens = [ self.confirmToken ]
57 token_kwargs = { "db" : self.confirmToken }
58 if self.cancelToken is not None:
59 tokens.append( self.cancelToken )
60 token_kwargs[ "cb" ] = self.cancelToken
61
62 token_kwargs.update( self._kwargs )
63
64 ret = cmds.promptDialog( t="Prompt", m = self.msg, b = tokens, text = default_text, **token_kwargs )
65
66 if ret == self.cancelToken:
67 return self.cancelDefault
68
69 if ret == self.confirmToken:
70 return cmds.promptDialog( q=1, text = 1 )
71
72 return self.confirmDefault
73
74
76 """Maya implementation of the generic choice dialog interface"""
77
79 """Return the choice made by the user"""
80
81 if cmds.about( b=1 ):
82 return self.default_choice
83
84 return cmds.confirmDialog( t = self.title,
85 m = self.message,
86 b = [ str( c ) for c in self.choices ],
87 db = self.default_choice,
88 cb = self.cancel_choice,
89 ds = self.cancel_choice )
90
91
93 """Simple progress window wrapping the default maya progress window"""
95 """Everything that iProgress indicator and Maya Progress Window support"""
96 min = kwargs.pop( "min", kwargs.pop( "minValue" , 0 ) )
97 max = kwargs.pop( "max", kwargs.pop( "maxValue", 100 ) )
98
99 relative = kwargs.pop( "is_relative", 1 )
100 super( ProgressWindow, self ).__init__( min = min, max = max, is_relative = relative )
101
102
103 kwargs.pop( "s", kwargs.pop( "step", 0 ) )
104 kwargs.pop( "pr", kwargs.pop( "progress", 0 ) )
105 kwargs.pop( "ep", kwargs.pop( "endProgress", 0 ) )
106 kwargs.pop( "ic", kwargs.pop( "isCancelled", 0 ) )
107 kwargs.pop( "e", kwargs.pop( "edit", 0 ) )
108
109 self.kwargs = kwargs
110
111 - def refresh( self, message = None ):
112 """Finally show the progress window"""
113 mn,mx = ( self.isRelative() and ( 0,100) ) or self.range()
114 p = self.get()
115
116 myargs = dict()
117 myargs[ "e" ] = 1
118 myargs[ "min" ] = mn
119 myargs[ "max" ] = mx
120 myargs[ "pr" ] = p
121 myargs[ "status" ] = message or ( "Progress %s" % ( "." * ( int(p) % 4 ) ) )
122
123 try:
124 cmds.progressWindow( **myargs )
125 except RuntimeError,e:
126 log.warn(str( e ))
127 pass
128
129
134
136 """Close the progress window"""
137
138 super( ProgressWindow, self ).end( )
139 mutils.executeDeferred( cmds.progressWindow, ep=1 )
140
142 """:return: True if the action should be cancelled, False otherwise"""
143 return cmds.progressWindow( q=1, ic=1 )
144
146 """:return : true if the process can be aborted"""
147 return cmds.progressWindow( q=1, ii=1 )
148
152