comparison src/browser/sat_browser/panels.py @ 510:db3436c85fb1

browser_side: the status menu is now based on GenericMenuBar instead of PopupMenuPanel
author souliane <souliane@mailoo.org>
date Thu, 21 Aug 2014 16:44:39 +0200
parents ec3f30253040
children 3d8e8f693576
comparison
equal deleted inserted replaced
509:35ccb3ff8245 510:db3436c85fb1
50 from time import time 50 from time import time
51 51
52 import jid 52 import jid
53 import html_tools 53 import html_tools
54 import base_panels 54 import base_panels
55 import base_menu
55 import card_game 56 import card_game
56 import radiocol 57 import radiocol
57 import menu 58 import menu
58 import dialog 59 import dialog
59 import base_widget 60 import base_widget
1037 else: 1038 else:
1038 status = self.EMPTY_STATUS 1039 status = self.EMPTY_STATUS
1039 self.display.setHTML(addURLToText(status)) 1040 self.display.setHTML(addURLToText(status))
1040 1041
1041 1042
1043 class PresenceStatusMenuBar(base_widget.WidgetMenuBar):
1044 def __init__(self, parent):
1045 styles = {'menu_bar': 'presence-button'}
1046 base_widget.WidgetMenuBar.__init__(self, None, parent.host, styles=styles)
1047 self.button = self.addCategory(u"◉", u"◉", '')
1048 for presence, presence_i18n in C.PRESENCE.items():
1049 html = u'<span class="%s">◉</span> %s' % (contact.buildPresenceStyle(presence), presence_i18n)
1050 self.addMenuItem([u"◉", presence], [u"◉", html], '', base_menu.MenuCmd(self, 'changePresenceCb', presence), asHTML=True)
1051 self.parent_panel = parent
1052
1053 def changePresenceCb(self, presence):
1054 """Callback to notice the backend of a new presence set by the user.
1055 @param presence (str): the new presence is a value in ('', 'chat', 'away', 'dnd', 'xa')
1056 """
1057 self.host.bridge.call('setStatus', None, presence, self.parent_panel.status_panel.status)
1058
1059 @classmethod
1060 def getCategoryHTML(cls, menu_name_i18n, type_):
1061 return menu_name_i18n
1062
1063
1042 class PresenceStatusPanel(HorizontalPanel, ClickHandler): 1064 class PresenceStatusPanel(HorizontalPanel, ClickHandler):
1043 1065
1044 def __init__(self, host, presence="", status=""): 1066 def __init__(self, host, presence="", status=""):
1045 self.host = host 1067 self.host = host
1046 HorizontalPanel.__init__(self, Width='100%') 1068 HorizontalPanel.__init__(self, Width='100%')
1047 self.presence_button = Label(u"◉") 1069 self.menu = PresenceStatusMenuBar(self)
1048 self.presence_button.setStyleName("presence-button")
1049 self.status_panel = StatusPanel(host, status=status) 1070 self.status_panel = StatusPanel(host, status=status)
1050 self.setPresence(presence) 1071 self.setPresence(presence)
1051 entries = {}
1052 for value in C.PRESENCE.keys():
1053 entries.update({C.PRESENCE[value]: {"value": value}})
1054
1055 def callback(sender, key):
1056 self.setPresence(entries[key]["value"]) # order matters
1057 self.host.send([("STATUS", None)], self.status_panel.status)
1058
1059 self.presence_list = base_panels.PopupMenuPanel(entries, callback=callback, style={"menu": "gwt-ListBox"})
1060 self.presence_list.registerClickSender(self.presence_button)
1061 1072
1062 panel = HorizontalPanel() 1073 panel = HorizontalPanel()
1063 panel.add(self.presence_button) 1074 panel.add(self.menu)
1064 panel.add(self.status_panel) 1075 panel.add(self.status_panel)
1065 panel.setCellVerticalAlignment(self.presence_button, 'baseline') 1076 panel.setCellVerticalAlignment(self.menu, 'baseline')
1066 panel.setCellVerticalAlignment(self.status_panel, 'baseline') 1077 panel.setCellVerticalAlignment(self.status_panel, 'baseline')
1067 panel.setStyleName("marginAuto") 1078 panel.setStyleName("marginAuto")
1068 self.add(panel) 1079 self.add(panel)
1069 1080
1070 self.status_panel.edit(False) 1081 self.status_panel.edit(False)
1080 def status(self): 1091 def status(self):
1081 return self.status_panel._original_content['text'] 1092 return self.status_panel._original_content['text']
1082 1093
1083 def setPresence(self, presence): 1094 def setPresence(self, presence):
1084 self._presence = presence 1095 self._presence = presence
1085 contact.setPresenceStyle(self.presence_button, self._presence) 1096 contact.setPresenceStyle(self.menu.button, self._presence)
1086 1097
1087 def setStatus(self, status): 1098 def setStatus(self, status):
1088 self.status_panel.setContent({'text': status}) 1099 self.status_panel.setContent({'text': status})
1089 self.status_panel.setDisplayContent() 1100 self.status_panel.setDisplayContent()
1090 1101