# HG changeset patch # User Goffi # Date 1355092460 -3600 # Node ID c0035e5e2d08806cd535b1278fea1cdc24388fac # Parent 88512fbeb1288f4c9401130c44c97d5f7bb1ddfd browser side: misc dialog improvment: - size fix - new "options" parameter, NO_CLOSE option to show a dialog without close button - new close method to simulate close button click diff -r 88512fbeb128 -r c0035e5e2d08 browser_side/dialog.py --- a/browser_side/dialog.py Sun Dec 09 23:30:27 2012 +0100 +++ b/browser_side/dialog.py Sun Dec 09 23:34:20 2012 +0100 @@ -129,26 +129,34 @@ class GenericDialog(DialogBox): """Dialog which just show a widget and a close button""" - def __init__(self, title, widget, callback = None): + def __init__(self, title, main_widget, callback = None, options = None): """Simple notice dialog box @param title: HTML put in the header - @param body: widget put in the body""" + @param main_widget: widget put in the body + @param callback: method to call on closing + @param options: one or more of the following options: + - NO_CLOSE: don't add a close button""" DialogBox.__init__(self, centered=True) self.callback = callback + if not options: + options = [] _body = VerticalPanel() _body.setSize('100%','100%') _body.setSpacing(4) - _body.add(widget) - _body.setCellWidth(widget, '100%') - _close_button = Button("Close", self.onClose) - _body.add(_close_button) - _body.setCellHorizontalAlignment(_close_button, HasAlignment.ALIGN_CENTER) + _body.add(main_widget) + _body.setCellWidth(main_widget, '100%') + _body.setCellHeight(main_widget, '100%') + if not 'NO_CLOSE' in options: + _close_button = Button("Close", self.onClose) + _body.add(_close_button) + _body.setCellHorizontalAlignment(_close_button, HasAlignment.ALIGN_CENTER) self.setHTML(title) self.setWidget(_body) - if isinstance(widget, Frame): - #Need this hack to have correct size for About box + Social Contract - #in Gecko & Webkit - self.panel.setWidth('100%') + self.panel.setSize('100%', '100%') #Need this hack to have correct size in Gecko & Webkit + + def close(self): + """Same effect as clicking the close button""" + self.onClose(None) def onClose(self, sender): self.hide() @@ -157,8 +165,8 @@ class InfoDialog(GenericDialog): - def __init__(self, title, body, callback = None): - GenericDialog.__init__(self, title, HTML(body), callback) + def __init__(self, title, body, callback = None, options = None): + GenericDialog.__init__(self, title, HTML(body), callback, options) class PopupPanelWrapper(PopupPanel): """This wrapper catch Escape event to avoid request cancellation by Firefox"""