Mercurial > libervia-web
comparison 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 |
comparison
equal
deleted
inserted
replaced
217:f7ec248192de | 218:4e6467efd6bf |
---|---|
40 from xmlui import XMLUI | 40 from xmlui import XMLUI |
41 import panels | 41 import panels |
42 import dialog | 42 import dialog |
43 import re | 43 import re |
44 | 44 |
45 | |
45 class MenuCmd: | 46 class MenuCmd: |
46 | 47 |
47 def __init__(self, object, handler): | 48 def __init__(self, object, handler): |
48 self._object = object | 49 self._object = object |
49 self._handler = handler | 50 self._handler = handler |
50 | 51 |
51 def execute(self): | 52 def execute(self): |
52 handler = getattr(self._object, self._handler) | 53 handler = getattr(self._object, self._handler) |
53 handler() | 54 handler() |
54 | 55 |
56 | |
55 class LiberviaMenuBar(MenuBar): | 57 class LiberviaMenuBar(MenuBar): |
56 | 58 |
57 def __init__(self): | 59 def __init__(self): |
58 MenuBar.__init__(self, vertical=False) | 60 MenuBar.__init__(self, vertical=False) |
59 | 61 |
60 def doItemAction(self, item, fireCommand): | 62 def doItemAction(self, item, fireCommand): |
61 MenuBar.doItemAction(self, item, fireCommand) | 63 MenuBar.doItemAction(self, item, fireCommand) |
62 if item == self.items[-1] and self.popup: | 64 if item == self.items[-1] and self.popup: |
63 self.popup.setPopupPosition(Window.getClientWidth() - | 65 self.popup.setPopupPosition(Window.getClientWidth() - |
64 self.popup.getOffsetWidth() - 22, | 66 self.popup.getOffsetWidth() - 22, |
65 self.getAbsoluteTop() + | 67 self.getAbsoluteTop() + |
66 self.getOffsetHeight() - 1) | 68 self.getOffsetHeight() - 1) |
67 self.popup.addStyleName('menuLastPopup') | 69 self.popup.addStyleName('menuLastPopup') |
70 | |
68 | 71 |
69 class AvatarUpload(FormPanel): | 72 class AvatarUpload(FormPanel): |
70 | 73 |
71 def __init__(self, close_cb=None): | 74 def __init__(self, close_cb=None): |
72 FormPanel.__init__(self) | 75 FormPanel.__init__(self) |
96 self.add(self.vPanel) | 99 self.add(self.vPanel) |
97 self.addFormHandler(self) | 100 self.addFormHandler(self) |
98 | 101 |
99 def setCloseCb(self, close_cb): | 102 def setCloseCb(self, close_cb): |
100 self.close_cb = close_cb | 103 self.close_cb = close_cb |
101 | 104 |
102 def onCloseBtnClick(self): | 105 def onCloseBtnClick(self): |
103 if self.close_cb: | 106 if self.close_cb: |
104 self.close_cb() | 107 self.close_cb() |
105 else: | 108 else: |
106 print ("WARNING: no close method defined") | 109 print ("WARNING: no close method defined") |
107 | 110 |
108 def onSubmitBtnClick(self): | 111 def onSubmitBtnClick(self): |
109 self.message.setHTML('<strong>Submitting, please wait...</strong>') | 112 self.message.setHTML('<strong>Submitting, please wait...</strong>') |
110 self.upload_btn.setEnabled(False) | 113 self.upload_btn.setEnabled(False) |
111 self.submit() | 114 self.submit() |
112 | 115 |
113 def onSubmit(self, event): | 116 def onSubmit(self, event): |
114 pass | 117 pass |
115 | 118 |
116 def onSubmitComplete(self, event): | 119 def onSubmitComplete(self, event): |
117 result = event.getResults() | 120 result = event.getResults() |
118 if result != "OK": | 121 if result != "OK": |
119 Window.alert('Something went wrong while submitting file') | 122 Window.alert('Something went wrong while submitting file') |
120 self.close_cb() | 123 self.close_cb() |
121 | 124 |
125 | |
122 class Menu(SimplePanel): | 126 class Menu(SimplePanel): |
123 | 127 |
124 def __init__(self, host): | 128 def __init__(self, host): |
125 self.host = host | 129 self.host = host |
126 SimplePanel.__init__(self) | 130 SimplePanel.__init__(self) |
145 menu_games.addItem("Xiangqi", MenuCmd(self, "onXiangqiGame")) | 149 menu_games.addItem("Xiangqi", MenuCmd(self, "onXiangqiGame")) |
146 | 150 |
147 menu_help = MenuBar(vertical=True) | 151 menu_help = MenuBar(vertical=True) |
148 menu_help.addItem("Social contract", MenuCmd(self, "onSocialContract")) | 152 menu_help.addItem("Social contract", MenuCmd(self, "onSocialContract")) |
149 menu_help.addItem("About", MenuCmd(self, "onAbout")) | 153 menu_help.addItem("About", MenuCmd(self, "onAbout")) |
150 | 154 |
151 menu_settings = MenuBar(vertical=True) | 155 self.menu_settings = MenuBar(vertical=True) |
152 menu_settings.addItem("Parameters", MenuCmd(self, "onParameters")) | 156 self.item_params = self.menu_settings.addItem("Parameters", |
153 menu_settings.addItem("Upload avatar", MenuCmd(self, "onAvatarUpload")) # XXX: temporary, will change when a full profile will be managed in SàT | 157 MenuCmd(self, "onParameters")) |
154 | 158 # XXX: temporary, will change when a full profile will be managed in SàT |
159 self.menu_settings.addItem("Upload avatar", MenuCmd(self, "onAvatarUpload")) | |
160 | |
155 menubar = LiberviaMenuBar() | 161 menubar = LiberviaMenuBar() |
156 | 162 |
157 for _name, _icon, _menu in [('General', 'home', menu_general), | 163 for _name, _icon, _menu in [('General', 'home', menu_general), |
158 ('Contacts', 'social', menu_contacts), | 164 ('Contacts', 'social', menu_contacts), |
159 ('Groups', 'social', menu_group), | 165 ('Groups', 'social', menu_group), |
160 ('Games', 'games', menu_games)]: | 166 ('Games', 'games', menu_games)]: |
161 menubar.addItem(MenuItem(_item_tpl % (_icon, _name), True, _menu)) | 167 menubar.addItem(MenuItem(_item_tpl % (_icon, _name), True, _menu)) |
162 | 168 |
163 _separator = MenuItem('', None) | 169 _separator = MenuItem('', None) |
164 _separator.setStyleName('menuSeparator') | 170 _separator.setStyleName('menuSeparator') |
165 menubar.addItem(_separator, None) | 171 menubar.addItem(_separator, None) |
166 | 172 |
167 for _name, _icon, _menu in [('Help', 'help', menu_help), | 173 for _name, _icon, _menu in [('Help', 'help', menu_help), |
168 ('Settings', 'settings', menu_settings)]: | 174 ('Settings', 'settings', self.menu_settings)]: |
169 menubar.addItem(MenuItem(_item_tpl % (_icon, _name), True, _menu)) | 175 menubar.addItem(MenuItem(_item_tpl % (_icon, _name), True, _menu)) |
170 | 176 |
171 self.add(menubar) | 177 self.add(menubar) |
172 | 178 |
173 #General menu | 179 #General menu |
174 def onWebWidget(self): | 180 def onWebWidget(self): |
175 web_panel = panels.WebPanel(self.host, "http://www.goffi.org") | 181 web_panel = panels.WebPanel(self.host, "http://www.goffi.org") |
176 self.host.addTab(web_panel, "Web widget") | 182 self.host.addTab(web_panel, "Web widget") |
177 | |
178 | 183 |
179 def onDisconnect(self): | 184 def onDisconnect(self): |
180 def confirm_cb(answer): | 185 def confirm_cb(answer): |
181 if answer: | 186 if answer: |
182 print "déconnexion" | 187 print "déconnexion" |
250 _dialog.show() | 255 _dialog.show() |
251 | 256 |
252 def onRemoveContact(self): | 257 def onRemoveContact(self): |
253 _dialog = None | 258 _dialog = None |
254 _contacts_list = ListBox() | 259 _contacts_list = ListBox() |
255 | 260 |
256 def secondConfirmCb(confirm): | 261 def secondConfirmCb(confirm): |
257 if confirm: | 262 if confirm: |
258 for contact in _contacts_list.getSelectedValues(): | 263 for contact in _contacts_list.getSelectedValues(): |
259 self.host.bridge.call('delContact', None, contact) | 264 self.host.bridge.call('delContact', None, contact) |
260 else: | 265 else: |
301 _main_panel.add(button_panel) | 306 _main_panel.add(button_panel) |
302 _dialog = DialogBox(centered=True) | 307 _dialog = DialogBox(centered=True) |
303 _dialog.setHTML('Group discussions') | 308 _dialog.setHTML('Group discussions') |
304 _dialog.setWidget(_main_panel) | 309 _dialog.setWidget(_main_panel) |
305 _dialog.show() | 310 _dialog.show() |
306 | 311 |
307 def onCollectiveRadio(self): | 312 def onCollectiveRadio(self): |
308 def onContactsSelected(contacts): | 313 def onContactsSelected(contacts): |
309 print("let's go :)") | 314 print("let's go :)") |
310 self.host.bridge.call('launchRadioCollective', None, contacts) | 315 self.host.bridge.call('launchRadioCollective', None, contacts) |
311 dialog.ContactsChooser(self.host, onContactsSelected, None, text="Please select contacts to invite").getContacts() | 316 dialog.ContactsChooser(self.host, onContactsSelected, None, text="Please select contacts to invite").getContacts() |
324 | 329 |
325 #Settings menu | 330 #Settings menu |
326 | 331 |
327 def onParameters(self): | 332 def onParameters(self): |
328 def gotParams(xmlui): | 333 def gotParams(xmlui): |
329 # TODO: don't display the dialog if xmlui contains no param node | 334 if not xmlui: |
335 return | |
330 body = XMLUI(self.host, xmlui) | 336 body = XMLUI(self.host, xmlui) |
331 _dialog = dialog.GenericDialog("Parameters", body, options=['NO_CLOSE']) | 337 _dialog = dialog.GenericDialog("Parameters", body, options=['NO_CLOSE']) |
332 body.setCloseCb(_dialog.close) | 338 body.setCloseCb(_dialog.close) |
333 _dialog.setSize('80%', '80%') | 339 _dialog.setSize('80%', '80%') |
334 _dialog.show() | 340 _dialog.show() |
335 self.host.bridge.call('getParamsUI', gotParams) | 341 self.host.bridge.call('getParamsUI', gotParams) |
336 | 342 |
343 def removeItemParams(self): | |
344 """Remove the Parameters item from the Settings menu bar.""" | |
345 self.menu_settings.removeItem(self.item_params) | |
346 | |
337 def onAvatarUpload(self): | 347 def onAvatarUpload(self): |
338 body = AvatarUpload() | 348 body = AvatarUpload() |
339 _dialog = dialog.GenericDialog("Avatar upload", body, options=['NO_CLOSE']) | 349 _dialog = dialog.GenericDialog("Avatar upload", body, options=['NO_CLOSE']) |
340 body.setCloseCb(_dialog.close) | 350 body.setCloseCb(_dialog.close) |
341 _dialog.setSize('40%', '40%') | 351 _dialog.setSize('40%', '40%') |