Mercurial > libervia-web
comparison src/browser/sat_browser/menu.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 | a8fddccf5b84 |
children | 801eb94aa869 |
comparison
equal
deleted
inserted
replaced
675:941e53b3af5c | 676:849ffb24d5bf |
---|---|
19 | 19 |
20 import pyjd # this is dummy in pyjs | 20 import pyjd # this is dummy in pyjs |
21 from sat.core.log import getLogger | 21 from sat.core.log import getLogger |
22 log = getLogger(__name__) | 22 log = getLogger(__name__) |
23 | 23 |
24 from sat.core.i18n import _ | |
25 | |
26 from pyjamas.ui.SimplePanel import SimplePanel | |
27 from pyjamas.ui.HTML import HTML | 24 from pyjamas.ui.HTML import HTML |
28 from pyjamas.ui.Frame import Frame | 25 from pyjamas.ui.Frame import Frame |
29 from pyjamas import Window | |
30 | 26 |
31 from constants import Const as C | 27 from constants import Const as C |
32 import file_tools | 28 import file_tools |
33 import xmlui | 29 import xmlui |
34 import chat | 30 import chat |
35 import widget | |
36 import dialog | 31 import dialog |
37 import contact_group | 32 import contact_group |
38 import base_menu | 33 import base_menu |
39 from base_menu import MenuCmd | 34 from sat_browser import html_tools |
40 | 35 |
41 | 36 |
42 unicode = str # FIXME: pyjamas workaround | 37 unicode = str # FIXME: pyjamas workaround |
43 | 38 |
44 | 39 |
50 def __init__(self, host): | 45 def __init__(self, host): |
51 styles = {'moved_popup': 'menuLastPopup', 'menu_bar': 'mainMenuBar'} | 46 styles = {'moved_popup': 'menuLastPopup', 'menu_bar': 'mainMenuBar'} |
52 base_menu.GenericMenuBar.__init__(self, host, vertical=False, styles=styles) | 47 base_menu.GenericMenuBar.__init__(self, host, vertical=False, styles=styles) |
53 | 48 |
54 @classmethod | 49 @classmethod |
55 def getCategoryHTML(cls, menu_name_i18n, type_): | 50 def getCategoryHTML(cls, category): |
56 return cls.ITEM_TPL % (type_, menu_name_i18n) | 51 name = html_tools.html_sanitize(category.name) |
52 return cls.ITEM_TPL % (category.icon, name) if category.icon is not None else name | |
57 | 53 |
58 def createMenus(self): | 54 ## callbacks |
59 self.addMenuItem("General", [_("General"), _("Web widget")], 'home', MenuCmd(self, "onWebWidget")) | |
60 self.addMenuItem("General", [_("General"), _("Disconnect")], 'home', MenuCmd(self, "onDisconnect")) | |
61 self.addCategory("Contacts", _("Contacts"), 'social') # save the position for this category | |
62 self.addMenuItem("Groups", [_("Groups"), _("Discussion")], 'social', MenuCmd(self, "onJoinRoom")) | |
63 self.addMenuItem("Groups", [_("Groups"), _("Collective radio")], 'social', MenuCmd(self, "onCollectiveRadio")) | |
64 self.addMenuItem("Games", [_("Games"), _("Tarot")], 'games', MenuCmd(self, "onTarotGame")) | |
65 self.addMenuItem("Games", [_("Games"), _("Xiangqi")], 'games', MenuCmd(self, "onXiangqiGame")) | |
66 | |
67 # additional menus | |
68 self.addCachedMenus(C.MENU_GLOBAL) | |
69 | |
70 # menu items that should be displayed after the automatically added ones | |
71 self.addMenuItem("Contacts", [_("Contacts"), _("Manage groups")], 'social', MenuCmd(self, "onManageContactGroups")) | |
72 | |
73 self.addSeparator() | |
74 | |
75 self.addMenuItem("Help", [_("Help"), _("Social contract")], 'help', MenuCmd(self, "onSocialContract")) | |
76 self.addMenuItem("Help", [_("Help"), _("About")], 'help', MenuCmd(self, "onAbout")) | |
77 self.addMenuItem("Settings", [_("Settings"), _("Account")], 'settings', MenuCmd(self, "onAccount")) | |
78 self.addMenuItem("Settings", [_("Settings"), _("Parameters")], 'settings', MenuCmd(self, "onParameters")) | |
79 | |
80 # XXX: temporary, will change when a full profile will be managed in SàT | |
81 self.addMenuItem("Settings", [_("Settings"), _("Upload avatar")], 'settings', MenuCmd(self, "onAvatarUpload")) | |
82 | 55 |
83 # General menu | 56 # General menu |
84 def onWebWidget(self): | |
85 web_widget = self.host.displayWidget(widget.WebWidget, C.WEB_PANEL_DEFAULT_URL) | |
86 self.host.setSelected(web_widget) | |
87 | 57 |
88 def onDisconnect(self): | 58 def onDisconnect(self): |
89 def confirm_cb(answer): | 59 def confirm_cb(answer): |
90 if answer: | 60 if answer: |
91 self.host.disconnect(C.PROF_KEY_NONE) | 61 self.host.disconnect(C.PROF_KEY_NONE) |
92 _dialog = dialog.ConfirmDialog(confirm_cb, text="Do you really want to disconnect ?") | 62 _dialog = dialog.ConfirmDialog(confirm_cb, text="Do you really want to disconnect ?") |
93 _dialog.show() | 63 _dialog.show() |
64 | |
65 #Contact menu | |
66 | |
67 def onManageContactGroups(self): | |
68 """Open the contact groups manager.""" | |
69 | |
70 def onCloseCallback(): | |
71 pass | |
72 | |
73 contact_group.ContactGroupEditor(self.host, None, onCloseCallback) | |
74 | |
75 #Group menu | |
76 def onJoinRoom(self): | |
77 | |
78 def invite(room_jid, contacts): | |
79 for contact in contacts: | |
80 self.host.bridge.call('inviteMUC', None, unicode(contact), unicode(room_jid)) | |
81 def join(room_jid, contacts): | |
82 if self.host.whoami: | |
83 nick = self.host.whoami.node | |
84 contact_list = self.host.contact_list | |
85 if room_jid is None or room_jid not in contact_list.getSpecials(C.CONTACT_SPECIAL_GROUP): | |
86 room_jid_s = unicode(room_jid) if room_jid else '' | |
87 self.host.bridge.call('joinMUC', lambda room_jid: invite(room_jid, contacts), room_jid_s, nick) | |
88 else: | |
89 self.host.displayWidget(chat.Chat, room_jid, type_="group", new_tab=room_jid) | |
90 invite(room_jid, contacts) | |
91 | |
92 dialog.RoomAndContactsChooser(self.host, join, ok_button="Join", visible=(True, False)) | |
93 | |
94 # Help menu | |
94 | 95 |
95 def onSocialContract(self): | 96 def onSocialContract(self): |
96 _frame = Frame('contrat_social.html') | 97 _frame = Frame('contrat_social.html') |
97 _frame.setStyleName('infoFrame') | 98 _frame.setStyleName('infoFrame') |
98 _dialog = dialog.GenericDialog("Contrat Social", _frame) | 99 _dialog = dialog.GenericDialog("Contrat Social", _frame) |
109 Any help welcome :) | 110 Any help welcome :) |
110 <p style='font-size:small;text-align:center'>This project is dedicated to Roger Poisson</p> | 111 <p style='font-size:small;text-align:center'>This project is dedicated to Roger Poisson</p> |
111 """) | 112 """) |
112 _dialog = dialog.GenericDialog("About", _about) | 113 _dialog = dialog.GenericDialog("About", _about) |
113 _dialog.show() | 114 _dialog.show() |
114 | |
115 #Contact menu | |
116 def onManageContactGroups(self): | |
117 """Open the contact groups manager.""" | |
118 | |
119 def onCloseCallback(): | |
120 pass | |
121 | |
122 contact_group.ContactGroupEditor(self.host, None, onCloseCallback) | |
123 | |
124 #Group menu | |
125 def onJoinRoom(self): | |
126 | |
127 def invite(room_jid, contacts): | |
128 for contact in contacts: | |
129 self.host.bridge.call('inviteMUC', None, unicode(contact), unicode(room_jid)) | |
130 | |
131 def join(room_jid, contacts): | |
132 if self.host.whoami: | |
133 nick = self.host.whoami.node | |
134 contact_list = self.host.contact_list | |
135 if room_jid is None or room_jid not in contact_list.getSpecials(C.CONTACT_SPECIAL_GROUP): | |
136 room_jid_s = unicode(room_jid) if room_jid else '' | |
137 self.host.bridge.call('joinMUC', lambda room_jid: invite(room_jid, contacts), room_jid_s, nick) | |
138 else: | |
139 self.host.displayWidget(chat.Chat, room_jid, type_="group", new_tab=room_jid) | |
140 invite(room_jid, contacts) | |
141 | |
142 dialog.RoomAndContactsChooser(self.host, join, ok_button="Join", visible=(True, False)) | |
143 | |
144 def onCollectiveRadio(self): | |
145 def callback(room_jid, contacts): | |
146 contacts = [unicode(contact) for contact in contacts] | |
147 room_jid_s = unicode(room_jid) if room_jid else '' | |
148 self.host.bridge.call('launchRadioCollective', None, contacts, room_jid_s) | |
149 dialog.RoomAndContactsChooser(self.host, callback, ok_button="Choose", title="Collective Radio", visible=(False, True)) | |
150 | |
151 #Game menu | |
152 def onTarotGame(self): | |
153 def onPlayersSelected(room_jid, other_players): | |
154 other_players = [unicode(contact) for contact in other_players] | |
155 room_jid_s = unicode(room_jid) if room_jid else '' | |
156 self.host.bridge.call('launchTarotGame', None, other_players, room_jid_s) | |
157 dialog.RoomAndContactsChooser(self.host, onPlayersSelected, 3, title="Tarot", title_invite="Please select 3 other players", visible=(False, True)) | |
158 | |
159 def onXiangqiGame(self): | |
160 Window.alert("A Xiangqi game is planed, but not available yet") | |
161 | 115 |
162 #Settings menu | 116 #Settings menu |
163 | 117 |
164 def onAccount(self): | 118 def onAccount(self): |
165 def gotUI(xml_ui): | 119 def gotUI(xml_ui): |