comparison src/browser/sat_browser/main_panel.py @ 676:849ffb24d5bf frontends_multi_profiles

browser side: menus refactorisation: - use of the new quick_frontends.quick_menus module, resulting in a big code simplification in Libervia - menu are added in there respective modules: main menus are done directely in libervia_main, while tarot and radiocol menus are done in game_tarot and game_radiocol - launchAction has the same signature as in QuickApp - base_menu: there are now 2 classes to launch an action: MenuCmd which manage quick_menus classes, and SimpleCmd to launch a generic callback - base_menu: MenuNode has been removed as logic is now in quick_menus - base_menu: GenericMenuBar.update method can be called to fully (re)build the menus - base_widget: removed WidgetSubMenuBar which is no more useful (GenericMenuBar do the same thing) - plugin_menu_context is used in LiberviaWidget and other classes with menus to indicate which menu types must be used - otr menus hooks are temporarily removed, will be fixed soon
author Goffi <goffi@goffi.org>
date Tue, 17 Mar 2015 20:42:02 +0100
parents ebb602d8b3f2
children a90cc8fc9605
comparison
equal deleted inserted replaced
675:941e53b3af5c 676:849ffb24d5bf
34 from pyjamas.ui.ClickListener import ClickHandler 34 from pyjamas.ui.ClickListener import ClickHandler
35 from pyjamas.Timer import Timer 35 from pyjamas.Timer import Timer
36 from pyjamas.ui import HasVerticalAlignment 36 from pyjamas.ui import HasVerticalAlignment
37 37
38 38
39 import base_menu
40 import menu 39 import menu
41 import dialog 40 import dialog
42 import base_widget 41 import base_widget
42 import base_menu
43 import libervia_widget 43 import libervia_widget
44 import editor_widget 44 import editor_widget
45 import contact_list 45 import contact_list
46 from constants import Const as C 46 from constants import Const as C
47 47
166 166
167 class PresenceStatusMenuBar(base_widget.WidgetMenuBar): 167 class PresenceStatusMenuBar(base_widget.WidgetMenuBar):
168 def __init__(self, parent): 168 def __init__(self, parent):
169 styles = {'menu_bar': 'presence-button'} 169 styles = {'menu_bar': 'presence-button'}
170 base_widget.WidgetMenuBar.__init__(self, parent, parent.host, styles=styles) 170 base_widget.WidgetMenuBar.__init__(self, parent, parent.host, styles=styles)
171 self.button = self.addCategory(u"◉", u"◉", '') 171 self.button = self.addCategory(u"◉")
172 presence_menu = self.button.getSubMenu()
172 for presence, presence_i18n in C.PRESENCE.items(): 173 for presence, presence_i18n in C.PRESENCE.items():
173 html = u'<span class="%s">◉</span> %s' % (contact_list.buildPresenceStyle(presence), presence_i18n) 174 html = u'<span class="%s">◉</span> %s' % (contact_list.buildPresenceStyle(presence), presence_i18n)
174 self.addMenuItem([u"◉", presence], [u"◉", html], '', base_menu.MenuCmd(self, 'changePresenceCb', presence), asHTML=True) 175 presence_menu.addItem(html, True, base_menu.SimpleCmd(lambda presence=presence: self.changePresenceCb(presence)))
175 self.parent_panel = parent 176 self.parent_panel = parent
176 177
177 def changePresenceCb(self, presence=''): 178 def changePresenceCb(self, presence=''):
178 """Callback to notice the backend of a new presence set by the user. 179 """Callback to notice the backend of a new presence set by the user.
179 @param presence (unicode): the new presence is a value in ('', 'chat', 'away', 'dnd', 'xa') 180 @param presence (unicode): the new presence is a value in ('', 'chat', 'away', 'dnd', 'xa')
187 188
188 class PresenceStatusPanel(HorizontalPanel, ClickHandler): 189 class PresenceStatusPanel(HorizontalPanel, ClickHandler):
189 190
190 def __init__(self, host, presence="", status=""): 191 def __init__(self, host, presence="", status=""):
191 self.host = host 192 self.host = host
193 self.plugin_menu_context = []
192 HorizontalPanel.__init__(self, Width='100%') 194 HorizontalPanel.__init__(self, Width='100%')
193 self.menu = PresenceStatusMenuBar(self) 195 self.presence_bar = PresenceStatusMenuBar(self)
194 self.status_panel = StatusPanel(host, status=status) 196 self.status_panel = StatusPanel(host, status=status)
195 self.setPresence(presence) 197 self.setPresence(presence)
196 198
197 panel = HorizontalPanel() 199 panel = HorizontalPanel()
198 panel.add(self.menu) 200 panel.add(self.presence_bar)
199 panel.add(self.status_panel) 201 panel.add(self.status_panel)
200 panel.setCellVerticalAlignment(self.menu, 'baseline') 202 panel.setCellVerticalAlignment(self.presence_bar, 'baseline')
201 panel.setCellVerticalAlignment(self.status_panel, 'baseline') 203 panel.setCellVerticalAlignment(self.status_panel, 'baseline')
202 panel.setStyleName("presenceStatusPanel") 204 panel.setStyleName("presenceStatusPanel")
203 self.add(panel) 205 self.add(panel)
204 206
205 self.status_panel.edit(False) 207 self.status_panel.edit(False)
215 def status(self): 217 def status(self):
216 return self.status_panel._original_content['text'] 218 return self.status_panel._original_content['text']
217 219
218 def setPresence(self, presence): 220 def setPresence(self, presence):
219 self._presence = presence 221 self._presence = presence
220 contact_list.setPresenceStyle(self.menu.button, self._presence) 222 contact_list.setPresenceStyle(self.presence_bar.button, self._presence)
221 223
222 def setStatus(self, status): 224 def setStatus(self, status):
223 self.status_panel.setContent({'text': status}) 225 self.status_panel.setContent({'text': status})
224 self.status_panel.setDisplayContent() 226 self.status_panel.setDisplayContent()
225 227
240 242
241 # menu and status panel 243 # menu and status panel
242 self.header = VerticalPanel(StyleName="header") 244 self.header = VerticalPanel(StyleName="header")
243 self.menu = menu.MainMenuBar(host) 245 self.menu = menu.MainMenuBar(host)
244 self.header.add(self.menu) 246 self.header.add(self.menu)
245 247
246 # contacts 248 # contacts
247 self.contacts_switch = Button(u'«', self._contactsSwitch) 249 self.contacts_switch = Button(u'«', self._contactsSwitch)
248 self.contacts_switch.addStyleName('contactsSwitch') 250 self.contacts_switch.addStyleName('contactsSwitch')
249 251
250 # tab panel 252 # tab panel
251 self.tab_panel = libervia_widget.MainTabPanel(host) 253 self.tab_panel = libervia_widget.MainTabPanel(host)
252 self.tab_panel.addWidgetsTab(_(u"Discussions"), select=True, locked=True) 254 self.tab_panel.addWidgetsTab(_(u"Discussions"), select=True, locked=True)
253 255
254 # XXX: widget's addition order is important! 256 # XXX: widget's addition order is important!
255 self.add(self.header, DockPanel.NORTH) 257 self.add(self.header, DockPanel.NORTH)
256 self.add(self.tab_panel, DockPanel.CENTER) 258 self.add(self.tab_panel, DockPanel.CENTER)
257 self.setCellWidth(self.tab_panel, '100%') 259 self.setCellWidth(self.tab_panel, '100%')
258 self.setCellHeight(self.tab_panel, '100%') 260 self.setCellHeight(self.tab_panel, '100%')