|
44 |
_ = locales.Translation( 'univention.management.console.dialog' ).translate |
44 |
_ = locales.Translation( 'univention.management.console.dialog' ).translate |
45 |
|
45 |
|
46 |
class Wizard( Element ): |
46 |
class Wizard( Element ): |
|
|
47 |
"""Low-level graphical representation for a Wizard page.""" |
47 |
def __init__( self, title = '' ): |
48 |
def __init__( self, title = '' ): |
48 |
Element.__init__( self ) |
49 |
Element.__init__( self ) |
49 |
self._title = title |
50 |
self._title = title |
|
51 |
self._image = None |
52 |
self._image = None |
52 |
|
53 |
|
53 |
def set_image( self, image ): |
54 |
def set_image( self, image ): |
|
|
55 |
"""Set top-left image to instance of umcd.Image.""" |
54 |
self._image = image |
56 |
self._image = image |
55 |
|
57 |
|
56 |
def add_option( self, text, option ): |
58 |
def add_option( self, text, option ): |
|
|
59 |
"""Add widget to this Wizard page.""" |
57 |
self._content.add_row( [ option, text ] ) |
60 |
self._content.add_row( [ option, text ] ) |
58 |
|
61 |
|
59 |
def add_buttons( self, *args ): |
62 |
def add_buttons( self, *args ): |
|
|
63 |
"""Add buttons to this Wizard page.""" |
60 |
if self._image: |
64 |
if self._image: |
61 |
self._content.add_row( [ Fill( 2 ) ] ) |
65 |
self._content.add_row( [ Fill( 2 ) ] ) |
62 |
self._content.add_row( [ '', args ] ) |
66 |
self._content.add_row( [ '', args ] ) |
|
65 |
self._content.add_row( [ args ] ) |
69 |
self._content.add_row( [ args ] ) |
66 |
|
70 |
|
67 |
def setup( self ): |
71 |
def setup( self ): |
|
|
72 |
"""Convert Wizard to dialog element.""" |
68 |
if self._image: |
73 |
if self._image: |
69 |
self._image[ 'width' ] = '100' |
74 |
self._image[ 'width' ] = '100' |
70 |
return Frame( [ List( content = [ [ Cell( self._image, { 'valign' : 'top' } ), self._content ] ], attributes = { 'width' : '100%' } ) ], self._title ) |
75 |
return Frame( [ List( content = [ [ Cell( self._image, { 'valign' : 'top' } ), self._content ] ], attributes = { 'width' : '100%' } ) ], self._title ) |
|
77 |
# dialog class above. An example can be found in the UVMM UMC module |
82 |
# dialog class above. An example can be found in the UVMM UMC module |
78 |
|
83 |
|
79 |
class Page( object ): |
84 |
class Page( object ): |
|
|
85 |
"""High-level implementation of a wizard page.""" |
80 |
def __init__( self, title = '', description = '' ): |
86 |
def __init__( self, title = '', description = '' ): |
81 |
self.title = title |
87 |
self.title = title |
82 |
self.description = description |
88 |
self.description = description |
|
86 |
self.hint = None |
92 |
self.hint = None |
87 |
|
93 |
|
88 |
def setup( self, command, options, prev = True, next = True, finish = False, cancel = True ): |
94 |
def setup( self, command, options, prev = True, next = True, finish = False, cancel = True ): |
|
|
95 |
"""Convert this page into graphical representation. Returns a Wizard instance containing description, hint, options and buttons.""" |
89 |
wizard = Wizard( self.title ) |
96 |
wizard = Wizard( self.title ) |
90 |
# add description |
97 |
# add description |
91 |
if self.description: |
98 |
if self.description: |
|
129 |
if next: |
136 |
if next: |
130 |
opts = copy_module.copy( options ) |
137 |
opts = copy_module.copy( options ) |
131 |
opts[ 'action' ] = 'next' |
138 |
opts[ 'action' ] = 'next' |
132 |
next_btn = Button( _( 'Next' ), actions = ( Action( umcp.SimpleCommand( command, opts ), items ), ), attributes = { 'class' : 'button_right' }, default = True ) |
139 |
next_btn = Button( _( 'Next' ), actions = ( Action( umcp.SimpleCommand( command, opts ), items ), ), attributes = { 'class' : 'button_right' }, default = True, close_dialog = False ) |
133 |
elif finish: |
140 |
elif finish: |
134 |
opts = copy_module.copy( options ) |
141 |
opts = copy_module.copy( options ) |
135 |
opts[ 'action' ] = 'finish' |
142 |
opts[ 'action' ] = 'finish' |
|
153 |
opts[ 'action' ] = 'prev' |
160 |
opts[ 'action' ] = 'prev' |
154 |
prev = umcp.SimpleCommand( command, opts ) |
161 |
prev = umcp.SimpleCommand( command, opts ) |
155 |
prev.verify_options = False |
162 |
prev.verify_options = False |
156 |
prev_btn = Cell( Button( _( 'Previous' ), actions = ( Action( prev, items ), ), attributes = { 'class' : 'cancel' } ), attributes = { 'type' : 'button_padding' } ) |
163 |
prev_btn = Cell( Button( _( 'Previous' ), actions = ( Action( prev, items ), ), attributes = { 'class' : 'cancel' }, close_dialog = False ), attributes = { 'type' : 'button_padding' } ) |
157 |
else: |
164 |
else: |
158 |
prev_btn = '' |
165 |
prev_btn = '' |
159 |
|
166 |
|
|
166 |
return wizard.setup() |
173 |
return wizard.setup() |
167 |
|
174 |
|
168 |
class WizardResult( object ): |
175 |
class WizardResult( object ): |
|
|
176 |
"""Encapsulate result of a Wizard page. value=True to continue to next page, value=False & text to stay on the current page.""" |
169 |
def __init__( self, value =True, text = '' ): |
177 |
def __init__( self, value =True, text = '' ): |
170 |
self.value = value |
178 |
self.value = value |
171 |
self.text = text |
179 |
self.text = text |
172 |
|
180 |
|
173 |
def __nonzero__( self ): |
181 |
def __nonzero__( self ): |
|
|
182 |
"""Return True, if the Wizard page in complete and the next Wizard should switch to the next page.""" |
174 |
return self.value |
183 |
return self.value |
175 |
|
184 |
|
176 |
class IWizard( list ): |
185 |
class IWizard( list ): |
|
|
186 |
"""High-level implementation of a wizard containing a list of wizard pages, stacked on top of each other in card layout fashion.""" |
177 |
def __init__( self, command = '' ): |
187 |
def __init__( self, command = '' ): |
178 |
list.__init__( self ) |
188 |
list.__init__( self ) |
179 |
self.current = None |
189 |
self.current = None |
|
182 |
self._result = None |
192 |
self._result = None |
183 |
|
193 |
|
184 |
def replace_title( self, title ): |
194 |
def replace_title( self, title ): |
|
|
195 |
"""Set title of all pages.""" |
185 |
for page in self: |
196 |
for page in self: |
186 |
page.title = title |
197 |
page.title = title |
187 |
|
198 |
|
188 |
def result( self ): |
199 |
def result( self ): |
|
|
200 |
"""Return the result storged by the last Wizard page.""" |
189 |
return self._result |
201 |
return self._result |
190 |
|
202 |
|
191 |
def action( self, object ): |
203 |
def action( self, object ): |
|
|
204 |
"""Call the function responsible for handling the action (object.options['action']), falling back to 'next'.""" |
192 |
if 'action' in object.options: |
205 |
if 'action' in object.options: |
193 |
action = object.options[ 'action' ] |
206 |
action = object.options[ 'action' ] |
194 |
del object.options[ 'action' ] |
207 |
del object.options[ 'action' ] |
|
201 |
return WizardResult( False, 'Unknown wizard action: %s' % action ) |
214 |
return WizardResult( False, 'Unknown wizard action: %s' % action ) |
202 |
|
215 |
|
203 |
def setup( self, object, prev = None, next = None, finish = None, cancel = None ): |
216 |
def setup( self, object, prev = None, next = None, finish = None, cancel = None ): |
|
|
217 |
"""Create graphical representation for the current Wizard page.""" |
204 |
if prev == True: |
218 |
if prev == True: |
205 |
force_prev = True |
219 |
force_prev = True |
206 |
else: |
220 |
else: |
207 |
force_prev = False |
221 |
force_prev = False |
208 |
if prev == None: |
222 |
if prev is None: |
209 |
prev = True |
223 |
prev = True |
210 |
if next == None: |
224 |
if next is None: |
211 |
next = True |
225 |
next = True |
212 |
if finish == None: |
226 |
if finish is None: |
213 |
finish = False |
227 |
finish = False |
214 |
if cancel == None: |
228 |
if cancel is None: |
215 |
cancel = True |
229 |
cancel = True |
216 |
if self.current == ( len( self ) - 1 ): # last page |
230 |
if self.current == ( len( self ) - 1 ): # last page |
217 |
next = False |
231 |
next = False |
|
219 |
finish = True |
233 |
finish = True |
220 |
elif not self.current: |
234 |
elif not self.current: |
221 |
prev = force_prev |
235 |
prev = force_prev |
222 |
return self[ self.current ].setup( self.command, object.options, prev = prev, next = next, finish = finish, cancel = cancel ) |
|
|
223 |
|
236 |
|
|
|
237 |
page = self[self.current] |
238 |
return page.setup(self.command, object.options, prev=prev, next=next, finish=finish, cancel=cancel) |
239 |
|
224 |
def finish( self, object ): |
240 |
def finish( self, object ): |
|
|
241 |
"""Convert the internally collected data of this Wizard into the external representation.""" |
225 |
return WizardResult( False, 'finish is not implemented!' ) |
242 |
return WizardResult( False, 'finish is not implemented!' ) |
226 |
|
243 |
|
227 |
def next( self, object ): |
244 |
def next( self, object ): |
|
|
245 |
"""Transition to the next Wizard page.""" |
228 |
if self.current == None: |
246 |
if self.current == None: |
229 |
self.current = 0 |
247 |
self.current = 0 |
230 |
elif self.current == ( len( self ) - 1 ): |
248 |
elif self.current == ( len( self ) - 1 ): |
|
234 |
|
252 |
|
235 |
return WizardResult() |
253 |
return WizardResult() |
236 |
|
254 |
|
237 |
|
|
|
238 |
def prev( self, object ): |
255 |
def prev( self, object ): |
|
|
256 |
"""Transition to the previous Wizard page.""" |
239 |
if self.current == 0: |
257 |
if self.current == 0: |
240 |
return None |
258 |
return None |
241 |
else: |
259 |
else: |
|
244 |
return WizardResult() |
262 |
return WizardResult() |
245 |
|
263 |
|
246 |
def cancel( self, object ): |
264 |
def cancel( self, object ): |
|
|
265 |
"""Cancel the complete Wizard.""" |
247 |
return WizardResult( False, 'cancel is not implemented!' ) |
266 |
return WizardResult( False, 'cancel is not implemented!' ) |
248 |
|
267 |
|
249 |
def reset( self ): |
268 |
def reset( self ): |
|
|
269 |
"""Reset Wizard back to initial values.""" |
250 |
self.current = None |
270 |
self.current = None |
251 |
self._result = None |
271 |
self._result = None |
252 |
|
|
|