comparison frontends/src/wix/main_window.py @ 755:e3ad48a2aab2

core, frontends: callMenu is now async and don't use callback_id anymore
author Goffi <goffi@goffi.org>
date Tue, 24 Dec 2013 15:18:31 +0100
parents 378af36155c2
children 93bd868b8fb6
comparison
equal deleted inserted replaced
754:f021bf27a557 755:e3ad48a2aab2
112 self.contact_list.Show() 112 self.contact_list.Show()
113 self.sizer.Layout() 113 self.sizer.Layout()
114 for i in range(self.menuBar.GetMenuCount()): 114 for i in range(self.menuBar.GetMenuCount()):
115 self.menuBar.EnableTop(i, True) 115 self.menuBar.EnableTop(i, True)
116 super(MainWindow, self).plug_profile(profile_key) 116 super(MainWindow, self).plug_profile(profile_key)
117
118 def _dynamicMenuCb(self, xmlui):
119 XMLUI(self, xml_data = xmlui)
120
121 def _dynamicMenuEb(self, failure):
122 dlg = wx.MessageDialog(self, _(u"Error while calling menu"),
123 _('Error'),
124 wx.OK | wx.ICON_ERROR
125 )
126 dlg.ShowModal()
127 dlg.Destroy()
117 128
118 def createMenus(self): 129 def createMenus(self):
119 info(_("Creating menus")) 130 info(_("Creating menus"))
120 connectMenu = wx.Menu() 131 connectMenu = wx.Menu()
121 connectMenu.Append(idCONNECT, _("&Connect CTRL-c"),_(" Connect to the server")) 132 connectMenu.Append(idCONNECT, _("&Connect CTRL-c"),_(" Connect to the server"))
140 151
141 #additionals menus 152 #additionals menus
142 #FIXME: do this in a more generic way (in quickapp) 153 #FIXME: do this in a more generic way (in quickapp)
143 add_menus = self.bridge.getMenus() 154 add_menus = self.bridge.getMenus()
144 for menu in add_menus: 155 for menu in add_menus:
145 category,item,type = menu 156 type_,category,name = menu
146 assert(type=="NORMAL") #TODO: manage other types 157 assert(type_=="NORMAL") #TODO: manage other types
147 menu_idx = self.menuBar.FindMenu(category) 158 menu_idx = self.menuBar.FindMenu(category)
148 current_menu = None 159 current_menu = None
149 if menu_idx == wx.NOT_FOUND: 160 if menu_idx == wx.NOT_FOUND:
150 #the menu is new, we create it 161 #the menu is new, we create it
151 current_menu = wx.Menu() 162 current_menu = wx.Menu()
152 self.menuBar.Append(current_menu, category) 163 self.menuBar.Append(current_menu, category)
153 else: 164 else:
154 current_menu = self.menuBar.GetMenu(menu_idx) 165 current_menu = self.menuBar.GetMenu(menu_idx)
155 assert(current_menu != None) 166 assert(current_menu != None)
156 item_id = wx.NewId() 167 item_id = wx.NewId()
157 help_string = self.bridge.getMenuHelp(category, item, type) 168 help_string = self.bridge.getMenuHelp(category, name, type_)
158 current_menu.Append(item_id, item, help = help_string) 169 current_menu.Append(item_id, name, help = help_string)
159 #now we register the event 170 #now we register the event
160 def event_answer(e): 171 def event_answer(e):
161 id = self.bridge.callMenu(category, item, type, self.profile) 172 self.bridge.asyncCallMenu(category, name, Const.MENU_NORMAL, self.profile, callback=self._dynamicMenuCb, errback=self._dynamicMenuEb)
162 self.current_action_ids.add(id)
163 wx.EVT_MENU(self, item_id, event_answer) 173 wx.EVT_MENU(self, item_id, event_answer)
164 174
165 175
166 #events 176 #events
167 wx.EVT_MENU(self, idCONNECT, self.onConnectRequest) 177 wx.EVT_MENU(self, idCONNECT, self.onConnectRequest)