From b3bff009e8f6fcb9e0f583ae0c2220f3f4a45cfa Mon Sep 17 00:00:00 2001 From: Goffi Date: Wed, 18 Aug 2010 12:45:48 +0800 Subject: [PATCH] Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core --- frontends/primitivus/custom_widgets.py | 21 +++++++++++-------- frontends/primitivus/primitivus | 28 ++++++++++++++++++++++++++ frontends/quick_frontend/quick_app.py | 25 ++++++++++++++++------- frontends/wix/main_window.py | 6 ++++-- sat_bridge/DBus.py | 10 ++++++++- tools/memory.py | 4 ++-- 6 files changed, 74 insertions(+), 20 deletions(-) diff --git a/frontends/primitivus/custom_widgets.py b/frontends/primitivus/custom_widgets.py index d95f34cb..ad788089 100644 --- a/frontends/primitivus/custom_widgets.py +++ b/frontends/primitivus/custom_widgets.py @@ -693,18 +693,23 @@ class GenericDialog(urwid.WidgetWrap): buttons = None if "OK/CANCEL" in style: - buttons = [urwid.Button(_("Cancel"), kwargs['cancel_cb']), - urwid.Button(_("Ok"), kwargs['ok_cb'], kwargs['ok_value'])] + cancel_arg = [kwargs['cancel_value']] if kwargs.has_key('cancel_value') else [] + ok_arg = [kwargs['ok_value']] if kwargs.has_key('ok_value') else [] + buttons = [urwid.Button(_("Cancel"), kwargs['cancel_cb'], *cancel_arg), + urwid.Button(_("Ok"), kwargs['ok_cb'], *ok_arg)] elif "YES/NO" in style: - buttons = [urwid.Button(_("Yes"), kwargs['yes_cb']), - urwid.Button(_("No"), kwargs['no_cb'], kwargs['yes_value'])] + yes_arg = [kwargs['yes_value']] if kwargs.has_key('yes_value') else [] + no_arg = [kwargs['no_value']] if kwargs.has_key('no_value') else [] + buttons = [urwid.Button(_("Yes"), kwargs['yes_cb'], *yes_arg), + urwid.Button(_("No"), kwargs['no_cb'], *no_arg)] if "OK" in style: - buttons = [urwid.Button(_("Ok"), kwargs['ok_cb'], kwargs['ok_value'])] + ok_arg = [kwargs['ok_value']] if kwargs.has_key('ok_value') else [] + buttons = [urwid.Button(_("Ok"), kwargs['ok_cb'], *ok_arg)] if buttons: buttons_flow = urwid.GridFlow(buttons, max([len(button.get_label()) for button in buttons])+4, 1, 1, 'center') body_content = urwid.SimpleListWalker(widgets_lst) frame_body = urwid.ListBox(body_content) - frame = urwid.Frame(frame_body, frame_header, buttons_flow if buttons else None) + frame = FocusFrame(frame_body, frame_header, buttons_flow if buttons else None, 'footer' if buttons else 'body') decorated_frame = urwid.LineBox(frame) urwid.WidgetWrap.__init__(self, decorated_frame) @@ -715,14 +720,14 @@ class InputDialog(GenericDialog): def __init__(self, title, instrucions, style=['OK/CANCEL'], default_txt = '', **kwargs): instr_wid = urwid.Text(instrucions+':') - edit_box = urwid.Edit(edit_text=default_txt) + edit_box = AdvancedEdit(edit_text=default_txt) GenericDialog.__init__(self, [instr_wid,edit_box], title, style, ok_value=edit_box, **kwargs) class ConfirmDialog(GenericDialog): """Dialog with buttons for confirm or cancel an action""" def __init__(self, title, style=['YES/NO'], **kwargs): - GenericDialog.__init__(self, [], title, style, yes_value=None, **kwargs) + GenericDialog.__init__(self, [], title, style, **kwargs) class Alert(GenericDialog): """Dialog with just a message and a OK button""" diff --git a/frontends/primitivus/primitivus b/frontends/primitivus/primitivus index f77d34d4..b179341e 100755 --- a/frontends/primitivus/primitivus +++ b/frontends/primitivus/primitivus @@ -312,6 +312,34 @@ class PrimitivusApp(QuickApp): if JID(self.contactList.selected).short != sender.short: self.contactList.putAlert(sender) + def _dialogOkCb(self, widget, data): + self.removePopUp() + answer_cb = data[0] + answer_data = [data[1]] if data[1] else [] + answer_cb(True, *answer_data) + + def _dialogCancelCb(self, widget, data): + self.removePopUp() + answer_cb = data[0] + answer_data = [data[1]] if data[1] else [] + answer_cb(False, *answer_data) + + + def showDialog(self, message, title="", type="info", answer_cb = None, answer_data = None): + if type == 'info': + popup = custom_widgets.Alert(unicode(title), unicode(message), ok_cb=answer_cb or self.removePopUp) #FIXME: remove unicode here when DBus Bridge will no return dbus.String anymore + flags = wx.OK | wx.ICON_INFORMATION + elif type == 'error': + popup = custom_widgets.Alert(unicode(title), unicode(message), ok_cb=answer_cb or self.removePopUp) #FIXME: remove unicode here when DBus Bridge will no return dbus.String anymore + elif type == 'yes/no': + popup = custom_widgets.ConfirmDialog(unicode(message), + yes_cb=self._dialogOkCb, yes_value = (answer_cb, answer_data), + no_cb=self._dialogCancelCb, no_value = (answer_cb, answer_data)) + else: + popup = custom_widgets.Alert(unicode(title), unicode(message), ok_cb=answer_cb or self.removePopUp) #FIXME: remove unicode here when DBus Bridge will no return dbus.String anymore + error(_('unmanaged dialog type: %s'), type) + self.showPopUp(popup) + def onNotification(self, notBar): """Called when a new notification has been received""" if not isinstance(self.main_widget, custom_widgets.FocusFrame): diff --git a/frontends/quick_frontend/quick_app.py b/frontends/quick_frontend/quick_app.py index 7336628e..9137d07d 100644 --- a/frontends/quick_frontend/quick_app.py +++ b/frontends/quick_frontend/quick_app.py @@ -48,6 +48,7 @@ class QuickApp(): self.bridge.register("disconnected", self.disconnected) self.bridge.register("newContact", self.newContact) self.bridge.register("newMessage", self.newMessage) + self.bridge.register("newAlert", self.newAlert) self.bridge.register("presenceUpdate", self.presenceUpdate) self.bridge.register("roomJoined", self.roomJoined) self.bridge.register("roomUserJoined", self.roomUserJoined) @@ -199,6 +200,13 @@ class QuickApp(): self.current_action_ids_cb = {} self.chat_wins[win.short].printMessage(sender, msg, profile) + def newAlert(self, msg, title, type, profile): + if not self.check_profile(profile): + return + assert type in ['INFO','ERROR'] + self.showDialog(unicode(msg),unicode(title),type.lower()) + + def setStatusOnline(self, online=True): pass @@ -344,7 +352,14 @@ class QuickApp(): debug (_("Cards played are not valid: %s") % invalid_cards) if self.chat_wins.has_key(room_jid): self.chat_wins[room_jid].getGame("Tarot").invalidCards(phase, played_cards, invalid_cards) - + + def _subscribe_cb(self, answer, data): + entity, profile = data + if answer: + self.bridge.subscription("subscribed", entity.short, profile_key = profile) + else: + self.bridge.subscription("unsubscribed", entity.short, profile_key = profile) + def subscribe(self, type, raw_jid, profile): """Called when a subsciption management signal is received""" if not self.check_profile(profile): @@ -358,13 +373,9 @@ class QuickApp(): self.showDialog(_("The contact %s has refused your subscription") % entity.short, _('Subscription refusal'), 'error') elif type=="subscribe": # this is a subscriptionn request, we have to ask for user confirmation - answer = self.showDialog(_("The contact %s wants to subscribe to your presence.\nDo you accept ?") % entity.short, _('Subscription confirmation'), 'yes/no') - if answer: - self.bridge.subscription("subscribed", entity.short, profile_key = profile) - else: - self.bridge.subscription("unsubscribed", entity.short, profile_key = profile) + answer = self.showDialog(_("The contact %s wants to subscribe to your presence.\nDo you accept ?") % entity.short, _('Subscription confirmation'), 'yes/no', answer_cb = self._subscribe_cb, answer_data=(entity, profile)) - def showDialog(self, message, title, type="info"): + def showDialog(self, message, title, type="info", answer_cb = None): raise NotImplementedError def showAlert(self, message): diff --git a/frontends/wix/main_window.py b/frontends/wix/main_window.py index 9c93d559..26a9d34b 100644 --- a/frontends/wix/main_window.py +++ b/frontends/wix/main_window.py @@ -206,7 +206,7 @@ class MainWindow(wx.Frame, QuickApp): popup.Show() wx.CallLater(5000,popup.Destroy) - def showDialog(self, message, title="", type="info"): + def showDialog(self, message, title="", type="info", answer_cb = None, answer_data = None): if type == 'info': flags = wx.OK | wx.ICON_INFORMATION elif type == 'error': @@ -219,7 +219,9 @@ class MainWindow(wx.Frame, QuickApp): dlg = wx.MessageDialog(self, message, title, flags) answer = dlg.ShowModal() dlg.Destroy() - return True if (answer == wx.ID_YES or answer == wx.ID_OK) else False + if answer_cb: + data = [answer_data] if answer_data else [] + answer_cb(True if (answer == wx.ID_YES or answer == wx.ID_OK) else False, *data) def setStatusOnline(self, online=True): """enable/disable controls, must be called when local user online status change""" diff --git a/sat_bridge/DBus.py b/sat_bridge/DBus.py index a6e95e9e..3f365a8e 100755 --- a/sat_bridge/DBus.py +++ b/sat_bridge/DBus.py @@ -63,6 +63,11 @@ class DbusObject(dbus.service.Object): def newMessage(self, from_jid, msg, type, to, profile): debug("new message signal (from:%s msg:%s type:%s to:%s) sended", from_jid, msg, type, to) + @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, + signature='ssss') + def newAlert(self, msg, title, type, profile): + debug("new alert signal (title:%s type:%s msg:%s profile:%s) sended", type, title, msg, profile) + @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, signature='ssia{ss}s') def presenceUpdate(self, entity, show, priority, statuses, profile): @@ -288,7 +293,7 @@ class DbusObject(dbus.service.Object): if in_sign[i] == 'a': i+=1 - if in_sign[i]!='{' and in_sign[i]!='(': #FIXME: gof: must manage tuples out of arrays + if in_sign[i]!='{' and in_sign[i]!='(': #FIXME: must manage tuples out of arrays i+=1 continue #we have a simple type for the array while (True): #we have a dict or a list of tuples @@ -346,6 +351,9 @@ class DBusBridge(Bridge): debug("sending message...") self.dbus_bridge.newMessage(from_jid, msg, type, to, profile) + def newAlert(self, msg, title="", type="INFO", profile='@NONE@'): + self.dbus_bridge.newAlert(type, title, msg, profile) + def presenceUpdate(self, entity, show, priority, statuses, profile): debug("updating presence for %s",entity) self.dbus_bridge.presenceUpdate(entity, show, priority, statuses, profile) diff --git a/tools/memory.py b/tools/memory.py index 6cc8ad5d..864543a6 100644 --- a/tools/memory.py +++ b/tools/memory.py @@ -109,7 +109,7 @@ class Param(): debug("Parameters init") self.host = host self.default_profile = None - self.params = {'goffi':{}} #gof: + self.params = {} self.params_gen = {} host.set_const('savefile_param_xml', SAVEFILE_PARAM_XML) host.set_const('savefile_param_data', SAVEFILE_PARAM_DATA) @@ -150,7 +150,7 @@ class Param(): info(_('No default profile, returning first one')) #TODO: manage real default profile default = self.params.keys()[0] self.host.memory.setPrivate('Profile_default', default) - return default #FIXME: gof: temporary, must use real default value, and fallback to first one if it doesn't exists + return default #FIXME: temporary, must use real default value, and fallback to first one if it doesn't exists if not self.params.has_key(profile_key): info (_('Trying to access an unknown profile')) return ""