comparison browser_side/dialog.py @ 231:fab7aa366576

browser_side: dialogs take **kwargs arguments + unibox helper method - add the **kwargs arguments to the dialog classes, especially to pass the Width='xxx' setting - add a method getTargetAndData to UniBox, for external use and to get the message recipient and body without dealing with the target hooks, selected panels...
author souliane <souliane@mailoo.org>
date Tue, 08 Oct 2013 13:38:42 +0200
parents 67e24c342e7f
children dec76d4536ad
comparison
equal deleted inserted replaced
230:266e9678eec0 231:fab7aa366576
93 self.callback(self.contacts_list.getSelectedValues()) 93 self.callback(self.contacts_list.getSelectedValues())
94 94
95 def onCancel(self, sender): 95 def onCancel(self, sender):
96 self.hide() 96 self.hide()
97 97
98
98 class GenericConfirmDialog(DialogBox): 99 class GenericConfirmDialog(DialogBox):
99 100
100 def __init__(self, widgets, callback, title='Confirmation'): 101 def __init__(self, widgets, callback, title='Confirmation', **kwargs):
101 """ 102 """
102 Dialog to confirm an action 103 Dialog to confirm an action
103 @param callback: method to call when contacts have been choosed 104 @param callback: method to call when contacts have been choosed
104 """ 105 """
105 self.callback = callback 106 self.callback = callback
106 DialogBox.__init__(self, centered=True) 107 DialogBox.__init__(self, centered=True, **kwargs)
107 108
108 content = VerticalPanel() 109 content = VerticalPanel()
109 content.setWidth('100%') 110 content.setWidth('100%')
110 for wid in widgets: 111 for wid in widgets:
111 content.add(wid) 112 content.add(wid)
127 self.callback(False) 128 self.callback(False)
128 129
129 130
130 class ConfirmDialog(GenericConfirmDialog): 131 class ConfirmDialog(GenericConfirmDialog):
131 132
132 def __init__(self, callback, text='Are you sure ?', title='Confirmation'): 133 def __init__(self, callback, text='Are you sure ?', title='Confirmation', **kwargs):
133 GenericConfirmDialog.__init__(self, [HTML(text)], callback, title) 134 GenericConfirmDialog.__init__(self, [HTML(text)], callback, title, **kwargs)
134 135
135 136
136 class GenericDialog(DialogBox): 137 class GenericDialog(DialogBox):
137 """Dialog which just show a widget and a close button""" 138 """Dialog which just show a widget and a close button"""
138 139
139 def __init__(self, title, main_widget, callback=None, options=None): 140 def __init__(self, title, main_widget, callback=None, options=None, **kwargs):
140 """Simple notice dialog box 141 """Simple notice dialog box
141 @param title: HTML put in the header 142 @param title: HTML put in the header
142 @param main_widget: widget put in the body 143 @param main_widget: widget put in the body
143 @param callback: method to call on closing 144 @param callback: method to call on closing
144 @param options: one or more of the following options: 145 @param options: one or more of the following options:
145 - NO_CLOSE: don't add a close button""" 146 - NO_CLOSE: don't add a close button"""
146 DialogBox.__init__(self, centered=True) 147 DialogBox.__init__(self, centered=True, **kwargs)
147 self.callback = callback 148 self.callback = callback
148 if not options: 149 if not options:
149 options = [] 150 options = []
150 _body = VerticalPanel() 151 _body = VerticalPanel()
151 _body.setSize('100%','100%') 152 _body.setSize('100%','100%')
168 def onClose(self, sender): 169 def onClose(self, sender):
169 self.hide() 170 self.hide()
170 if self.callback: 171 if self.callback:
171 self.callback() 172 self.callback()
172 173
174
173 class InfoDialog(GenericDialog): 175 class InfoDialog(GenericDialog):
174 176
175 def __init__(self, title, body, callback = None, options = None): 177 def __init__(self, title, body, callback=None, options=None, **kwargs):
176 GenericDialog.__init__(self, title, HTML(body), callback, options) 178 GenericDialog.__init__(self, title, HTML(body), callback, options, **kwargs)
179
177 180
178 class PopupPanelWrapper(PopupPanel): 181 class PopupPanelWrapper(PopupPanel):
179 """This wrapper catch Escape event to avoid request cancellation by Firefox""" 182 """This wrapper catch Escape event to avoid request cancellation by Firefox"""
180 183
181 def onEventPreview(self, event): 184 def onEventPreview(self, event):
182 if event.type in ["keydown", "keypress", "keyup"] and event.keyCode == KEY_ESCAPE: 185 if event.type in ["keydown", "keypress", "keyup"] and event.keyCode == KEY_ESCAPE:
183 #needed to prevent request cancellation in Firefox 186 #needed to prevent request cancellation in Firefox
184 event.preventDefault() 187 event.preventDefault()
185 return PopupPanel.onEventPreview(self, event) 188 return PopupPanel.onEventPreview(self, event)
189
186 190
187 class ExtTextBox(TextBox): 191 class ExtTextBox(TextBox):
188 """Extended TextBox""" 192 """Extended TextBox"""
189 193
190 def __init__(self, *args, **kwargs): 194 def __init__(self, *args, **kwargs):