comparison frontends/src/wix/main_window.py @ 773:eac23b1aad90

core: dynamics menus refactoring: - menu now use generic callback system, with extra data - asyncMenuCall is removed in favor of launchAction - menu_id (== callback_id) is used to identify menu instead of category/name/type tuple - i18n is managed throught deferred translation, and returned with _i18n suffix e.g.: menu (D_('File'), D_('Open')): (u'File', u'Open') is menu_path, (u'Fichier', u'Ouvrir') is french menu_path_i18n. - type actually can have the following values: - NORMAL: classical menu - JID_CONTEXT: contextual menu, used with any jid - ROSTER_JID_CONTEXT: like JID_CONTEXT, but restricted to jids in roster. - ROSTER_GROUP_CONTEXT: contextual menu, use with groups - security_limit is used, in the same way as for parameters - when using importMenu, callback can be an actual callback, or one already registered with registerCallback
author Goffi <goffi@goffi.org>
date Sun, 29 Dec 2013 17:10:14 +0100
parents bfabeedbf32e
children 5642939d254e
comparison
equal deleted inserted replaced
772:dd07fc737d6c 773:eac23b1aad90
113 self.contact_list.Show() 113 self.contact_list.Show()
114 self.sizer.Layout() 114 self.sizer.Layout()
115 for i in range(self.menuBar.GetMenuCount()): 115 for i in range(self.menuBar.GetMenuCount()):
116 self.menuBar.EnableTop(i, True) 116 self.menuBar.EnableTop(i, True)
117 super(MainWindow, self).plug_profile(profile_key) 117 super(MainWindow, self).plug_profile(profile_key)
118
119 def _dynamicMenuCb(self, xmlui):
120 XMLUI(self, xml_data = xmlui)
121
122 def _dynamicMenuEb(self, failure):
123 dlg = wx.MessageDialog(self, _(u"Error while calling menu"),
124 _('Error'),
125 wx.OK | wx.ICON_ERROR
126 )
127 dlg.ShowModal()
128 dlg.Destroy()
129 118
130 def createMenus(self): 119 def createMenus(self):
131 info(_("Creating menus")) 120 info(_("Creating menus"))
132 connectMenu = wx.Menu() 121 connectMenu = wx.Menu()
133 connectMenu.Append(idCONNECT, _("&Connect CTRL-c"),_(" Connect to the server")) 122 connectMenu.Append(idCONNECT, _("&Connect CTRL-c"),_(" Connect to the server"))
150 self.menuBar.Append(communicationMenu,_("&Communication")) 139 self.menuBar.Append(communicationMenu,_("&Communication"))
151 self.SetMenuBar(self.menuBar) 140 self.SetMenuBar(self.menuBar)
152 141
153 #additionals menus 142 #additionals menus
154 #FIXME: do this in a more generic way (in quickapp) 143 #FIXME: do this in a more generic way (in quickapp)
155 add_menus = self.bridge.getMenus() 144 add_menus = self.bridge.getMenus('', Const.NO_SECURITY_LIMIT)
156 for menu in add_menus: 145 for id_, type_, path, path_i18n in add_menus:
157 type_,category,name = menu
158 assert(type_=="NORMAL") #TODO: manage other types 146 assert(type_=="NORMAL") #TODO: manage other types
147 if len(path) != 2:
148 raise NotImplementedError("Menu with a path != 2 are not implemented yet")
149 category = path_i18n[0] # TODO: manage path with more than 2 levels
150 name = path_i18n[1]
159 menu_idx = self.menuBar.FindMenu(category) 151 menu_idx = self.menuBar.FindMenu(category)
160 current_menu = None 152 current_menu = None
161 if menu_idx == wx.NOT_FOUND: 153 if menu_idx == wx.NOT_FOUND:
162 #the menu is new, we create it 154 #the menu is new, we create it
163 current_menu = wx.Menu() 155 current_menu = wx.Menu()
164 self.menuBar.Append(current_menu, category) 156 self.menuBar.Append(current_menu, category)
165 else: 157 else:
166 current_menu = self.menuBar.GetMenu(menu_idx) 158 current_menu = self.menuBar.GetMenu(menu_idx)
167 assert(current_menu != None) 159 assert(current_menu != None)
168 item_id = wx.NewId() 160 item_id = wx.NewId()
169 help_string = self.bridge.getMenuHelp(category, name, type_) 161 help_string = self.bridge.getMenuHelp(id_, '')
170 current_menu.Append(item_id, name, help = help_string) 162 current_menu.Append(item_id, name, help=help_string)
171 #now we register the event 163 #now we register the event
172 def event_answer(e): 164 def event_answer(e):
173 self.bridge.asyncCallMenu(category, name, Const.MENU_NORMAL, self.profile, callback=self._dynamicMenuCb, errback=self._dynamicMenuEb) 165 self.launchAction(id_, None, profile_key = self.profile)
166
174 wx.EVT_MENU(self, item_id, event_answer) 167 wx.EVT_MENU(self, item_id, event_answer)
175 168
176 169
177 #events 170 #events
178 wx.EVT_MENU(self, idCONNECT, self.onConnectRequest) 171 wx.EVT_MENU(self, idCONNECT, self.onConnectRequest)