core, frontends: callMenu is now async and don't use callback_id anymore

This commit is contained in:
Goffi 2013-12-24 15:18:31 +01:00
commit 71c1def32a
4 changed files with 93 additions and 56 deletions

View file

@ -97,6 +97,9 @@ class DBusBridgeFrontend(BridgeFrontend):
def addContact(self, entity_jid, profile_key="@DEFAULT@"):
return self.db_core_iface.addContact(entity_jid, profile_key)
def asyncCallMenu(self, category, name, menu_type, profile_key, callback=None, errback=None):
return unicode(self.db_core_iface.asyncCallMenu(category, name, menu_type, profile_key, reply_handler=callback, error_handler=lambda err:errback(err._dbus_error_name[len(const_ERROR_PREFIX)+1:])))
def asyncConnect(self, profile_key="@DEFAULT@", callback=None, errback=None):
return self.db_core_iface.asyncConnect(profile_key, reply_handler=callback, error_handler=lambda err:errback(err._dbus_error_name[len(const_ERROR_PREFIX)+1:]))
@ -106,9 +109,6 @@ class DBusBridgeFrontend(BridgeFrontend):
def asyncGetParamA(self, name, category, attribute="value", security_limit=-1, profile_key="@DEFAULT@", callback=None, errback=None):
return unicode(self.db_core_iface.asyncGetParamA(name, category, attribute, security_limit, profile_key, reply_handler=callback, error_handler=lambda err:errback(err._dbus_error_name[len(const_ERROR_PREFIX)+1:])))
def callMenu(self, category, name, menu_type, profile_key):
return unicode(self.db_core_iface.callMenu(category, name, menu_type, profile_key))
def confirmationAnswer(self, id, accepted, data, profile):
return self.db_core_iface.confirmationAnswer(id, accepted, data, profile)

View file

@ -56,6 +56,8 @@ def getPresence():
class Const(object):
PRESENCE = getPresence()
MENU_NORMAL = "NORMAL"
# from plugin_misc_text_syntaxes
_SYNTAX_XHTML = "XHTML"
_SYNTAX_CURRENT = "@CURRENT@"

View file

@ -281,8 +281,15 @@ class PrimitivusApp(QuickApp, InputHistory):
except AttributeError:
return input
def _dynamicMenuCb(self, xmlui):
misc = {}
ui = XMLUI(self, xml_data = xmlui)
ui.show('popup')
def __buildMenuRoller(self):
def _dynamicMenuEb(self, failure):
self.showDialog(_(u"Error while calling menu"), type="error")
def _buildMenuRoller(self):
menu = sat_widgets.Menu(self.loop)
general = _("General")
menu.addMenu(general, _("Connect"), self.onConnectRequest)
@ -301,29 +308,28 @@ class PrimitivusApp(QuickApp, InputHistory):
#FIXME: do this in a more generic way (in quickapp)
add_menus = self.bridge.getMenus()
def add_menu_cb(menu):
category, item = menu
id = self.bridge.callMenu(category, item, "NORMAL", self.profile)
self.current_action_ids.add(id)
category, name = menu
self.bridge.asyncCallMenu(category, name, Const.MENU_NORMAL, self.profile, callback=self._dynamicMenuCb, errback=self._dynamicMenuEb)
for new_menu in add_menus:
category,item,type = new_menu
assert(type=="NORMAL") #TODO: manage other types
menu.addMenu(unicode(category), unicode(item), add_menu_cb)
type_, category, name = new_menu
assert(type_=="NORMAL") #TODO: manage other types
menu.addMenu(unicode(category), unicode(name), add_menu_cb)
menu_roller = sat_widgets.MenuRoller([(_('Main menu'),menu)])
return menu_roller
def __buildMainWidget(self):
def _buildMainWidget(self):
self.contact_list = ContactList(self, on_click=self.contactSelected, on_change=lambda w: self.redraw())
#self.center_part = urwid.Columns([('weight',2,self.contact_list),('weight',8,Chat('',self))])
self.center_part = urwid.Columns([('weight', 2, self.contact_list), ('weight', 8, urwid.Filler(urwid.Text('')))])
self.editBar = EditBar(self)
self.menu_roller = self.__buildMenuRoller()
self.menu_roller = self._buildMenuRoller()
self.main_widget = sat_widgets.FocusFrame(self.center_part, header=self.menu_roller, footer=self.editBar, focus_part='footer')
return self.main_widget
def plug_profile(self, profile_key='@DEFAULT@'):
self.loop.widget = self.__buildMainWidget()
self.loop.widget = self._buildMainWidget()
self.redraw()
QuickApp.plug_profile(self, profile_key)

View file

@ -115,6 +115,17 @@ class MainWindow(wx.Frame, QuickApp):
self.menuBar.EnableTop(i, True)
super(MainWindow, self).plug_profile(profile_key)
def _dynamicMenuCb(self, xmlui):
XMLUI(self, xml_data = xmlui)
def _dynamicMenuEb(self, failure):
dlg = wx.MessageDialog(self, _(u"Error while calling menu"),
_('Error'),
wx.OK | wx.ICON_ERROR
)
dlg.ShowModal()
dlg.Destroy()
def createMenus(self):
info(_("Creating menus"))
connectMenu = wx.Menu()
@ -142,8 +153,8 @@ class MainWindow(wx.Frame, QuickApp):
#FIXME: do this in a more generic way (in quickapp)
add_menus = self.bridge.getMenus()
for menu in add_menus:
category,item,type = menu
assert(type=="NORMAL") #TODO: manage other types
type_,category,name = menu
assert(type_=="NORMAL") #TODO: manage other types
menu_idx = self.menuBar.FindMenu(category)
current_menu = None
if menu_idx == wx.NOT_FOUND:
@ -154,12 +165,11 @@ class MainWindow(wx.Frame, QuickApp):
current_menu = self.menuBar.GetMenu(menu_idx)
assert(current_menu != None)
item_id = wx.NewId()
help_string = self.bridge.getMenuHelp(category, item, type)
current_menu.Append(item_id, item, help = help_string)
help_string = self.bridge.getMenuHelp(category, name, type_)
current_menu.Append(item_id, name, help = help_string)
#now we register the event
def event_answer(e):
id = self.bridge.callMenu(category, item, type, self.profile)
self.current_action_ids.add(id)
self.bridge.asyncCallMenu(category, name, Const.MENU_NORMAL, self.profile, callback=self._dynamicMenuCb, errback=self._dynamicMenuEb)
wx.EVT_MENU(self, item_id, event_answer)