Mercurial > libervia-web
changeset 145:c0035e5e2d08
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
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 09 Dec 2012 23:34:20 +0100 |
parents | 88512fbeb128 |
children | d15fbb208ba0 |
files | browser_side/dialog.py |
diffstat | 1 files changed, 21 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- 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"""