Mercurial > libervia-web
diff browser_side/menu.py @ 218:4e6467efd6bf
browser_side: small improvements for parameters panel
- auto-select the first tab
- remove the parameters item if there's nothing to display
author | souliane <souliane@mailoo.org> |
---|---|
date | Sat, 07 Sep 2013 19:54:41 +0200 |
parents | e830a0c60d32 |
children | 09e4de9df5b7 |
line wrap: on
line diff
--- a/browser_side/menu.py Sun Sep 08 12:34:00 2013 +0200 +++ b/browser_side/menu.py Sat Sep 07 19:54:41 2013 +0200 @@ -42,30 +42,33 @@ import dialog import re + class MenuCmd: def __init__(self, object, handler): - self._object = object + self._object = object self._handler = handler def execute(self): handler = getattr(self._object, self._handler) handler() + class LiberviaMenuBar(MenuBar): def __init__(self): MenuBar.__init__(self, vertical=False) - + def doItemAction(self, item, fireCommand): MenuBar.doItemAction(self, item, fireCommand) if item == self.items[-1] and self.popup: self.popup.setPopupPosition(Window.getClientWidth() - - self.popup.getOffsetWidth() - 22, - self.getAbsoluteTop() + - self.getOffsetHeight() - 1) + self.popup.getOffsetWidth() - 22, + self.getAbsoluteTop() + + self.getOffsetHeight() - 1) self.popup.addStyleName('menuLastPopup') + class AvatarUpload(FormPanel): def __init__(self, close_cb=None): @@ -98,18 +101,18 @@ def setCloseCb(self, close_cb): self.close_cb = close_cb - + def onCloseBtnClick(self): if self.close_cb: self.close_cb() else: print ("WARNING: no close method defined") - + def onSubmitBtnClick(self): self.message.setHTML('<strong>Submitting, please wait...</strong>') self.upload_btn.setEnabled(False) self.submit() - + def onSubmit(self, event): pass @@ -119,6 +122,7 @@ Window.alert('Something went wrong while submitting file') self.close_cb() + class Menu(SimplePanel): def __init__(self, host): @@ -147,27 +151,29 @@ menu_help = MenuBar(vertical=True) menu_help.addItem("Social contract", MenuCmd(self, "onSocialContract")) menu_help.addItem("About", MenuCmd(self, "onAbout")) - - menu_settings = MenuBar(vertical=True) - menu_settings.addItem("Parameters", MenuCmd(self, "onParameters")) - menu_settings.addItem("Upload avatar", MenuCmd(self, "onAvatarUpload")) # XXX: temporary, will change when a full profile will be managed in SàT - + + self.menu_settings = MenuBar(vertical=True) + self.item_params = self.menu_settings.addItem("Parameters", + MenuCmd(self, "onParameters")) + # XXX: temporary, will change when a full profile will be managed in SàT + self.menu_settings.addItem("Upload avatar", MenuCmd(self, "onAvatarUpload")) + menubar = LiberviaMenuBar() - + for _name, _icon, _menu in [('General', 'home', menu_general), ('Contacts', 'social', menu_contacts), ('Groups', 'social', menu_group), ('Games', 'games', menu_games)]: menubar.addItem(MenuItem(_item_tpl % (_icon, _name), True, _menu)) - + _separator = MenuItem('', None) _separator.setStyleName('menuSeparator') menubar.addItem(_separator, None) - + for _name, _icon, _menu in [('Help', 'help', menu_help), - ('Settings', 'settings', menu_settings)]: + ('Settings', 'settings', self.menu_settings)]: menubar.addItem(MenuItem(_item_tpl % (_icon, _name), True, _menu)) - + self.add(menubar) #General menu @@ -175,7 +181,6 @@ web_panel = panels.WebPanel(self.host, "http://www.goffi.org") self.host.addTab(web_panel, "Web widget") - def onDisconnect(self): def confirm_cb(answer): if answer: @@ -252,7 +257,7 @@ def onRemoveContact(self): _dialog = None _contacts_list = ListBox() - + def secondConfirmCb(confirm): if confirm: for contact in _contacts_list.getSelectedValues(): @@ -303,7 +308,7 @@ _dialog.setHTML('Group discussions') _dialog.setWidget(_main_panel) _dialog.show() - + def onCollectiveRadio(self): def onContactsSelected(contacts): print("let's go :)") @@ -326,7 +331,8 @@ def onParameters(self): def gotParams(xmlui): - # TODO: don't display the dialog if xmlui contains no param node + if not xmlui: + return body = XMLUI(self.host, xmlui) _dialog = dialog.GenericDialog("Parameters", body, options=['NO_CLOSE']) body.setCloseCb(_dialog.close) @@ -334,6 +340,10 @@ _dialog.show() self.host.bridge.call('getParamsUI', gotParams) + def removeItemParams(self): + """Remove the Parameters item from the Settings menu bar.""" + self.menu_settings.removeItem(self.item_params) + def onAvatarUpload(self): body = AvatarUpload() _dialog = dialog.GenericDialog("Avatar upload", body, options=['NO_CLOSE'])