changeset 182:556c2bd7c344

Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
author Goffi <goffi@goffi.org>
date Wed, 18 Aug 2010 12:45:48 +0800
parents a566f654929e
children 9ee4a1d0d7fb
files frontends/primitivus/custom_widgets.py frontends/primitivus/primitivus frontends/quick_frontend/quick_app.py frontends/wix/main_window.py sat_bridge/DBus.py tools/memory.py
diffstat 6 files changed, 74 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/primitivus/custom_widgets.py	Mon Aug 16 21:59:52 2010 +0800
+++ b/frontends/primitivus/custom_widgets.py	Wed Aug 18 12:45:48 2010 +0800
@@ -693,18 +693,23 @@
         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 @@
 
     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"""
--- a/frontends/primitivus/primitivus	Mon Aug 16 21:59:52 2010 +0800
+++ b/frontends/primitivus/primitivus	Wed Aug 18 12:45:48 2010 +0800
@@ -312,6 +312,34 @@
         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):
--- a/frontends/quick_frontend/quick_app.py	Mon Aug 16 21:59:52 2010 +0800
+++ b/frontends/quick_frontend/quick_app.py	Wed Aug 18 12:45:48 2010 +0800
@@ -48,6 +48,7 @@
         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 @@
         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 @@
         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 @@
             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):
--- a/frontends/wix/main_window.py	Mon Aug 16 21:59:52 2010 +0800
+++ b/frontends/wix/main_window.py	Wed Aug 18 12:45:48 2010 +0800
@@ -206,7 +206,7 @@
         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 @@
         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"""
--- a/sat_bridge/DBus.py	Mon Aug 16 21:59:52 2010 +0800
+++ b/sat_bridge/DBus.py	Wed Aug 18 12:45:48 2010 +0800
@@ -64,6 +64,11 @@
         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):
         debug("presence update signal (from:%s show:%s priority:%d statuses:%s profile:%s) sended" , entity, show, priority, statuses, profile)
@@ -288,7 +293,7 @@
 
             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 @@
         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)
--- a/tools/memory.py	Mon Aug 16 21:59:52 2010 +0800
+++ b/tools/memory.py	Wed Aug 18 12:45:48 2010 +0800
@@ -109,7 +109,7 @@
         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 @@
                 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 ""