changeset 153:f197b52796ee

Primitivus: begining of management for actionResult
author Goffi <goffi@goffi.org>
date Sat, 31 Jul 2010 00:34:05 +0800
parents b1f1955d96b3
children c701f3031ada
files frontends/primitivus/card_game.py frontends/primitivus/chat.py frontends/primitivus/contact_list.py frontends/primitivus/primitivus
diffstat 4 files changed, 37 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/primitivus/card_game.py	Sat Jul 31 00:32:51 2010 +0800
+++ b/frontends/primitivus/card_game.py	Sat Jul 31 00:34:05 2010 +0800
@@ -94,7 +94,7 @@
         """Return a list of selected cards"""
         _selected = []
         for wid in self.columns.widget_list:
-            if wid.__class__ == CardDisplayer and wid.isSelected():
+            if isinstance(wid, CardDisplayer) and wid.isSelected():
                 _selected.append(wid.getCard())
         return _selected
 
@@ -169,7 +169,7 @@
         @param location: where to put the card (top, left, bottom or right)
         @param card: Card to play or None"""
         assert location in ['top','left','bottom','right']
-        assert card.__class__ == Card or card == None
+        assert isinstance(card,Card) or card == None
         if [getattr(self, place) for place in ['top','left','bottom','right']].count(None) == 0:
             #If the table is full of card, we remove them
             self.top = self.left = self.bottom = self.right = None
@@ -290,7 +290,7 @@
             #it's not our turn, we ignore the click
             card_wid.select(False)
             return
-        if self.center.widget_list[1].original_widget.__class__ == Hand: #if we have a hand displayed
+        if isinstance(self.center.widget_list[1].original_widget, Hand): #if we have a hand displayed
             self.center.widget_list[1] = urwid.Filler(self.table) #we show again the table
             if self.state == "chien":
                 self.to_show = []
--- a/frontends/primitivus/chat.py	Sat Jul 31 00:32:51 2010 +0800
+++ b/frontends/primitivus/chat.py	Sat Jul 31 00:34:05 2010 +0800
@@ -108,7 +108,7 @@
             for wid in self.content:
                 wid._invalidate()
         elif key == "meta l": #user wants to (un)hide widget decoration
-            show = not self._w.__class__ == custom_widgets.LabelLine
+            show = not isinstance(self._w, custom_widgets.LabelLine)
             self.showDecoration(show)
             self._invalidate()
         elif key == "meta s": #user wants to (un)hide group's subject
@@ -223,7 +223,7 @@
         self.host.redraw()
 
     def printMessage(self, from_jid, msg, profile, timestamp=""):
-        assert (from_jid.__class__ == JID)
+        assert isinstance(from_jid, JID)
         my_jid = self.host.profiles[profile]['whoami']
         self.content.append(ChatText(self, timestamp or None, my_jid, from_jid, msg))
         self.text_list.set_focus(len(self.content)-1)
--- a/frontends/primitivus/contact_list.py	Sat Jul 31 00:32:51 2010 +0800
+++ b/frontends/primitivus/contact_list.py	Sat Jul 31 00:34:05 2010 +0800
@@ -124,11 +124,12 @@
     def clear_contacts(self):
         """clear all the contact list"""
         self.groups={}
+        self.selected = None
 
     def replace(self, jid, groups=[None]):
         """add a contact to the list if doesn't exist, else update it"""
-        assert groups.__class__ == list
-        assert jid.__class__ == JID
+        assert isinstance(groups, list)
+        assert isinstance(jid, JID)
         if not groups:
             groups=[None]
         for group in groups:
--- a/frontends/primitivus/primitivus	Sat Jul 31 00:32:51 2010 +0800
+++ b/frontends/primitivus/primitivus	Sat Jul 31 00:34:05 2010 +0800
@@ -37,16 +37,9 @@
 from tools.jid  import JID"""
 import logging
 from logging import debug, info, error
-#import locale
 import sys, os
 from tools.jid  import JID
-#from curses import ascii
-#import locale
-#from signal import signal, SIGWINCH 
-#import fcntl
-#import struct
-#import termios
-#from boxsizer import BoxSizer
+from xmlui import XMLUI
 
 
 ### logging configuration FIXME: put this elsewhere ###
@@ -125,7 +118,7 @@
 
     def inputFilter(self, input, raw):
         for i in input:
-            if i.__class__==tuple:
+            if isinstance(i,tuple):
                 if i[0] == 'mouse press':
                     if i[1] == 4: #Mouse wheel up
                         input[input.index(i)] = 'up'
@@ -246,6 +239,33 @@
         if JID(self.contactList.selected).short != sender.short:
             self.contactList.putAlert(sender)
 
+    def actionResult(self, type, id, data):
+        if not id in self.current_action_ids:
+            debug (_('unknown id, ignoring'))
+            return
+        if type == "SUPPRESS":
+            self.current_action_ids.remove(id)
+        elif type == "XMLUI":
+            self.current_action_ids.remove(id)
+            debug (_("XML user interface received"))
+            misc = {}
+            #FIXME FIXME FIXME: must clean all this crap !
+            title = _('Form')
+            if data['type'] == _('registration'):
+                title = _('Registration')
+                misc['target'] = data['target']
+                misc['action_back'] = self.bridge.gatewayRegister
+            ui = XMLUI(self, title=title, xml_data = data['xml'], misc = misc)
+            assert(len(self.center_part.widget_list)==2)
+            self.center_part.widget_list[1] = ui
+            self.menu_roller.removeMenu(_('Chat menu'))
+            self.contactList.selected = None
+            self.redraw()
+        else:
+            error (_("FIXME FIXME FIXME: type [%s] not implemented") % type)
+            raise NotImplementedError
+
+    ##DIALOGS CALLBACKS##
     def onJoinRoom(self, button, edit):
         self.removePopUp()
         room_jid = JID(edit.get_edit_text())
@@ -298,9 +318,6 @@
             pop_up_widget = custom_widgets.ConfirmDialog(_("Are you sure you want to delete the contact [%s] ?" % contact), yes_cb=self.onRemoveContact, no_cb=self.removePopUp)
             self.showPopUp(pop_up_widget)
 
-
-
-
     def onAboutRequest(self, menu):
         self.showPopUp(custom_widgets.Alert(_("About"), const_APP_NAME + " v" + self.bridge.getVersion(), ok_cb=self.removePopUp))