Tarot: bidding phase

- quick_app: command line is now parsed, "profile" option allow to select it
- xml_tools: list-single is now managed
- plugin tarot: method and signal to manage contract (contrat): tarotChooseContrat & tarotGameContratChoosed
- wix: Q&D Form hack to manage more generic form (not only registration), used to show contract selection form
This commit is contained in:
Goffi 2010-05-27 19:26:19 +09:30
commit 2f2a611ba3
8 changed files with 195 additions and 36 deletions

View file

@ -22,6 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
from logging import debug, info, error from logging import debug, info, error
from tools.jid import JID from tools.jid import JID
from sat_bridge_frontend.DBus import DBusBridgeFrontend from sat_bridge_frontend.DBus import DBusBridgeFrontend
from optparse import OptionParser
import pdb import pdb
import gettext import gettext
@ -34,6 +35,7 @@ class QuickApp():
self.rosterList = {} self.rosterList = {}
self.profiles = {} self.profiles = {}
self.single_profile = single_profile self.single_profile = single_profile
self.check_options()
## bridge ## ## bridge ##
self.bridge=DBusBridgeFrontend() self.bridge=DBusBridgeFrontend()
@ -48,6 +50,7 @@ class QuickApp():
self.bridge.register("roomNewSubject", self.roomNewSubject) self.bridge.register("roomNewSubject", self.roomNewSubject)
self.bridge.register("tarotGameStarted", self.tarotGameStarted) self.bridge.register("tarotGameStarted", self.tarotGameStarted)
self.bridge.register("tarotGameNew", self.tarotGameNew) self.bridge.register("tarotGameNew", self.tarotGameNew)
self.bridge.register("tarotChooseContrat", self.tarotChooseContrat)
self.bridge.register("subscribe", self.subscribe) self.bridge.register("subscribe", self.subscribe)
self.bridge.register("paramUpdate", self.paramUpdate) self.bridge.register("paramUpdate", self.paramUpdate)
self.bridge.register("contactDeleted", self.contactDeleted) self.bridge.register("contactDeleted", self.contactDeleted)
@ -63,6 +66,20 @@ class QuickApp():
"""Tell if the profile is currently followed by the application""" """Tell if the profile is currently followed by the application"""
return profile in self.profiles.keys() return profile in self.profiles.keys()
def check_options(self):
"""Check command line options"""
usage=_("""
%prog [options]
%prog --help for options list
""")
parser = OptionParser(usage=usage)
parser.add_option("-p", "--profile", help=_("Select the profile to use"))
(self.options, args) = parser.parse_args()
return args
def plug_profile(self, profile_key='@DEFAULT@'): def plug_profile(self, profile_key='@DEFAULT@'):
"""Tell application which profile must be used""" """Tell application which profile must be used"""
if self.single_profile and self.profiles: if self.single_profile and self.profiles:
@ -134,6 +151,8 @@ class QuickApp():
return return
debug(_("Connected")) debug(_("Connected"))
self.setStatusOnline(True) self.setStatusOnline(True)
self.bridge.joinMUC('conference.necton2.int', 'test', self.profiles[self.profile]['whoami'].node, self.profile) #gof:
def disconnected(self, profile): def disconnected(self, profile):
"""called when the connection is closed""" """called when the connection is closed"""
@ -262,9 +281,16 @@ class QuickApp():
debug (_("New Tarot Game")) debug (_("New Tarot Game"))
print "room: %s, hand: %s" % (room_jid,hand) print "room: %s, hand: %s" % (room_jid,hand)
if self.chat_wins.has_key(room_jid): if self.chat_wins.has_key(room_jid):
print "gof:",self.chat_wins[room_jid].getGame("Tarot")
self.chat_wins[room_jid].getGame("Tarot").newGame(hand) self.chat_wins[room_jid].getGame("Tarot").newGame(hand)
def tarotChooseContrat(self, room_jid, xml_data, profile):
"""Called when the player has too select his contrat"""
if not self.__check_profile(profile):
return
debug (_("Tarot: need to select a contrat"))
if self.chat_wins.has_key(room_jid):
self.chat_wins[room_jid].getGame("Tarot").chooseContrat(xml_data)
def subscribe(self, type, raw_jid, profile): def subscribe(self, type, raw_jid, profile):

View file

@ -125,6 +125,9 @@ class DBusBridgeFrontend(BridgeFrontend):
def tarotGameReady(self, user, referee, profile_key='@DEFAULT@'): def tarotGameReady(self, user, referee, profile_key='@DEFAULT@'):
return self.db_comm_iface.tarotGameReady(user, referee, profile_key) return self.db_comm_iface.tarotGameReady(user, referee, profile_key)
def tarotGameContratChoosed(self, user, referee, contrat, profile_key='@DEFAULT@'):
return self.db_comm_iface.tarotGameContratChoosed(user, referee, contrat, profile_key)
def sendFile(self, to, path, profile_key='@DEFAULT@'): def sendFile(self, to, path, profile_key='@DEFAULT@'):
return self.db_comm_iface.sendFile(to, path, profile_key) return self.db_comm_iface.sendFile(to, path, profile_key)

View file

@ -26,8 +26,7 @@ import os.path, glob
import pdb import pdb
from logging import debug, info, error from logging import debug, info, error
from tools.jid import JID from tools.jid import JID
from quick_frontend.quick_chat import QuickChat from form import Form
from contact_list import ContactList
CARD_WIDTH = 74 CARD_WIDTH = 74
CARD_HEIGHT = 136 CARD_HEIGHT = 136
@ -140,6 +139,21 @@ class CardPanel(wx.Panel):
self.hand.sort() self.hand.sort()
self.my_turn = True self.my_turn = True
def contratSelected(self, data):
"""Called when the contrat has been choosed
@param data: form result"""
debug (_("Contrat choosed"))
print "\n\n\n===============>>>> \o/ :) :) :) ", data, "\n\n\n"
contrat = data[0][1]
self.parent.host.bridge.tarotGameContratChoosed(self.user, self.referee, contrat or 'Passe', self.parent.host.profile)
def chooseContrat(self, xml_data):
"""Called when the player as to select hist contrat
@param xml_data: SàT xml representation of the form"""
misc = {'callback': self.contratSelected}
form = Form(self.parent.host, xml_data, title = _('Please choose your contrat'), options = ['NO_CANCEL'], misc = misc)
def _is_on_hand(self, pos_x, pos_y): def _is_on_hand(self, pos_x, pos_y):
"""Return True if the coordinate are on the hand cards""" """Return True if the coordinate are on the hand cards"""
if pos_x > self.orig_x and pos_y > self.orig_y \ if pos_x > self.orig_x and pos_y > self.orig_y \

View file

@ -24,16 +24,19 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import wx import wx
import pdb import pdb
from xml.dom import minidom from xml.dom import minidom
from logging import debug, info, error from logging import debug, info, warning, error
from tools.jid import JID from tools.jid import JID
class Form(wx.Frame): class Form(wx.Frame):
def __init__(self, host, target, xml_data='', title="Form", type="Form"): """Create a form from a SàT xml"""
def __init__(self, host, xml_data='', title="Form", options=[], misc={}):
super(Form, self).__init__(None, title=title) super(Form, self).__init__(None, title=title)
self.host = host self.host = host
self.target = target self.options = options
self.misc = misc
self.ctl_list = [] # usefull to access ctrl self.ctl_list = [] # usefull to access ctrl
self.sizer = wx.BoxSizer(wx.VERTICAL) self.sizer = wx.BoxSizer(wx.VERTICAL)
@ -41,7 +44,8 @@ class Form(wx.Frame):
self.SetAutoLayout(True) self.SetAutoLayout(True)
#events #events
self.Bind(wx.EVT_CLOSE, self.onClose, self) if not 'NO_CANCEL' in self.options:
self.Bind(wx.EVT_CLOSE, self.onClose, self)
self.MakeModal() self.MakeModal()
@ -59,7 +63,7 @@ class Form(wx.Frame):
name = elem.getAttribute("name") name = elem.getAttribute("name")
label = elem.getAttribute("label") if elem.hasAttribute('label') else name label = elem.getAttribute("label") if elem.hasAttribute('label') else name
type = elem.getAttribute("type") type = elem.getAttribute("type")
value = elem.firstChild.wholeText if elem.firstChild else u'' #TODO: must check if the first child is really the text value value = elem.getAttribute("value") if elem.hasAttribute('value') else u''
sizer = wx.BoxSizer(wx.HORIZONTAL) sizer = wx.BoxSizer(wx.HORIZONTAL)
if type=="text": if type=="text":
ctrl = wx.StaticText(panel, -1, value) ctrl = wx.StaticText(panel, -1, value)
@ -73,6 +77,10 @@ class Form(wx.Frame):
ctrl = wx.TextCtrl(panel, -1, value, style=wx.TE_PASSWORD) ctrl = wx.TextCtrl(panel, -1, value, style=wx.TE_PASSWORD)
self.ctl_list.append({'name':name, 'type':type, 'control':ctrl}) self.ctl_list.append({'name':name, 'type':type, 'control':ctrl})
sizer.Add(label) sizer.Add(label)
elif type=="list":
label=wx.StaticText(panel, -1, label+": ")
ctrl = wx.ListBox(panel, -1, choices=[option.getAttribute("value") for option in elem.getElementsByTagName("option")], style=wx.LB_SINGLE)
self.ctl_list.append({'name':name, 'type':type, 'control':ctrl})
else: else:
error(_("FIXME FIXME FIXME: type [%s] is not implemented") % type) #FIXME ! error(_("FIXME FIXME FIXME: type [%s] is not implemented") % type) #FIXME !
raise NotImplementedError raise NotImplementedError
@ -80,14 +88,15 @@ class Form(wx.Frame):
#self.ctl_list[(name, category)] = ctrl #self.ctl_list[(name, category)] = ctrl
panel.sizer.Add(sizer, flag=wx.EXPAND) panel.sizer.Add(sizer, flag=wx.EXPAND)
submitButton = wx.Button(panel,wx.ID_OK, label="Submit")
cancelButton = wx.Button(panel,wx.ID_CANCEL)
dialogButtons = wx.StdDialogButtonSizer() dialogButtons = wx.StdDialogButtonSizer()
submitButton = wx.Button(panel,wx.ID_OK, label=_("Submit"))
dialogButtons.AddButton(submitButton) dialogButtons.AddButton(submitButton)
dialogButtons.AddButton(cancelButton)
dialogButtons.Realize()
panel.Bind(wx.EVT_BUTTON, self.onFormSubmitted, submitButton) panel.Bind(wx.EVT_BUTTON, self.onFormSubmitted, submitButton)
panel.Bind(wx.EVT_BUTTON, self.onFormCancelled, cancelButton) if not 'NO_CANCEL' in self.options:
cancelButton = wx.Button(panel,wx.ID_CANCEL)
dialogButtons.AddButton(cancelButton)
panel.Bind(wx.EVT_BUTTON, self.onFormCancelled, cancelButton)
dialogButtons.Realize()
panel.sizer.Add(dialogButtons, flag=wx.ALIGN_CENTER_HORIZONTAL) panel.sizer.Add(dialogButtons, flag=wx.ALIGN_CENTER_HORIZONTAL)
panel.SetSizer(panel.sizer) panel.SetSizer(panel.sizer)
@ -101,9 +110,17 @@ class Form(wx.Frame):
debug(_("Submitting form")) debug(_("Submitting form"))
data = [] data = []
for ctrl in self.ctl_list: for ctrl in self.ctl_list:
data.append((ctrl["name"], ctrl["control"].GetValue())) if isinstance(ctrl['control'], wx.ListBox):
id = self.host.bridge.gatewayRegister("SUBMIT",self.target, data) data.append((ctrl['name'], ctrl['control'].GetStringSelection()))
self.host.current_action_ids.add(id) else:
data.append((ctrl["name"], ctrl["control"].GetValue()))
if self.misc.has_key('action_back'): #FIXME FIXME FIXME: WTF ! Must be cleaned
id = self.misc['action_back']("SUBMIT",self.misc['target'], data)
self.host.current_action_ids.add(id)
elif self.misc.has_key('callback'):
self.misc['callback'](data)
else:
warning (_("The form data is not sent back, the type is not managed properly"))
self.MakeModal(False) self.MakeModal(False)
self.Destroy() self.Destroy()

View file

@ -109,9 +109,9 @@ class MainWindow(wx.Frame, QuickApp):
self.profile_pan = ProfileManager(self) self.profile_pan = ProfileManager(self)
#self.profile_pan.Hide() #gof: #self.profile_pan.Hide() #gof:
self.sizer.Add(self.profile_pan, 1, flag=wx.EXPAND) self.sizer.Add(self.profile_pan, 1, flag=wx.EXPAND)
if self.options.profile: #TODO: move this to quick_app
self.plug_profile(self.options.profile)
#Tarot = CardGame(self)
#Tarot.Show()#gof: temp for test
self.Show() self.Show()
@ -269,7 +269,14 @@ class MainWindow(wx.Frame, QuickApp):
elif type == "FORM": elif type == "FORM":
self.current_action_ids.remove(id) self.current_action_ids.remove(id)
debug (_("Form received")) debug (_("Form received"))
form=Form(self, title=_('Registration'), target = data['target'], type = data['type'], xml_data = data['xml']) 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
form=Form(self, title=title, xml_data = data['xml'], misc = misc)
elif type == "RESULT": elif type == "RESULT":
self.current_action_ids.remove(id) self.current_action_ids.remove(id)
if self.current_action_ids_cb.has_key(id): if self.current_action_ids_cb.has_key(id):

View file

@ -31,7 +31,8 @@ import random
from zope.interface import implements from zope.interface import implements
from wokkel import disco, iwokkel, muc from wokkel import disco, iwokkel, data_form
from tools.xml_tools import XMLTools
from base64 import b64decode from base64 import b64decode
from hashlib import sha1 from hashlib import sha1
@ -64,10 +65,13 @@ class Tarot():
info(_("Plugin Tarot initialization")) info(_("Plugin Tarot initialization"))
self.host = host self.host = host
self.games={} self.games={}
self.contrats = [_('Passe'), _('Petite'), _('Garde'), _('Garde Sans'), _('Garde Contre')]
host.bridge.addMethod("tarotGameCreate", ".communication", in_sign='sass', out_sign='', method=self.createGame) #args: room_jid, players, profile host.bridge.addMethod("tarotGameCreate", ".communication", in_sign='sass', out_sign='', method=self.createGame) #args: room_jid, players, profile
host.bridge.addMethod("tarotGameReady", ".communication", in_sign='sss', out_sign='', method=self.newPlayerReady) #args: user, referee, profile host.bridge.addMethod("tarotGameReady", ".communication", in_sign='sss', out_sign='', method=self.newPlayerReady) #args: user, referee, profile
host.bridge.addMethod("tarotGameContratChoosed", ".communication", in_sign='ssss', out_sign='', method=self.contratChoosed) #args: user, referee, contrat, profile
host.bridge.addSignal("tarotGameStarted", ".communication", signature='ssass') #args: room_jid, referee, players, profile host.bridge.addSignal("tarotGameStarted", ".communication", signature='ssass') #args: room_jid, referee, players, profile
host.bridge.addSignal("tarotGameNew", ".communication", signature='sa(ss)s') #args: room_jid, hand, profile host.bridge.addSignal("tarotGameNew", ".communication", signature='sa(ss)s') #args: room_jid, hand, profile
host.bridge.addSignal("tarotChooseContrat", ".communication", signature='sss') #args: room_jid, xml_data, profile
self.deck_ordered = [] self.deck_ordered = []
for value in map(str,range(1,22))+['excuse']: for value in map(str,range(1,22))+['excuse']:
self.deck_ordered.append(("atout",value)) self.deck_ordered.append(("atout",value))
@ -111,6 +115,24 @@ class Tarot():
started_elt.addChild(player_elt) started_elt.addChild(player_elt)
return started_elt return started_elt
def __ask_contrat(self):
"""Create a element for asking contrat"""
contrat_elt = domish.Element(('','contrat'))
form = data_form.Form('form', title=_('contrat selection'))
field = data_form.Field('list-single', 'contrat', options=map(data_form.Option, self.contrats), required=True)
form.addField(field)
contrat_elt.addChild(form.toElement())
return contrat_elt
def __next_player(self, game_data):
"""It's next player turn
Increment player number & return player name"""
pl_idx = game_data['current_player'] = (game_data['current_player'] + 1) % len(game_data['players'])
return game_data['players'][pl_idx]
def createGame(self, room_jid_param, players, profile_key='@DEFAULT@'): def createGame(self, room_jid_param, players, profile_key='@DEFAULT@'):
"""Create a new game""" """Create a new game"""
debug (_("Creating Tarot game")) debug (_("Creating Tarot game"))
@ -123,9 +145,11 @@ class Tarot():
warning (_("Tarot game already started in room %s") % room_jid.userhost()) warning (_("Tarot game already started in room %s") % room_jid.userhost())
else: else:
status = {} status = {}
players_data = {}
for player in players: for player in players:
players_data[player] = {}
status[player] = "init" status[player] = "init"
self.games[room_jid.userhost()] = {'players':players, 'status':status, 'profile':profile, 'hand_size':18, 'player_start':0} self.games[room_jid.userhost()] = {'players':players, 'status':status, 'players_data':players_data, 'referee_profile':profile, 'hand_size':18, 'init_player':0, 'current_player': None}
for player in players: for player in players:
mess = self.createGameElt(jid.JID(room_jid.userhost()+'/'+player)) mess = self.createGameElt(jid.JID(room_jid.userhost()+'/'+player))
mess.firstChildElement().addChild(self.__create_started_elt(players)) mess.firstChildElement().addChild(self.__create_started_elt(players))
@ -139,7 +163,25 @@ class Tarot():
return return
debug ('new player ready: %s' % profile) debug ('new player ready: %s' % profile)
mess = self.createGameElt(jid.JID(referee)) mess = self.createGameElt(jid.JID(referee))
mess.firstChildElement().addElement('player_ready', content=user) ready_elt = mess.firstChildElement().addElement('player_ready')
ready_elt['user'] = user
self.host.profiles[profile].xmlstream.send(mess)
def contratChoosed(self, user, referee, contrat, profile_key='@DEFAULT@'):
"""Must be call by player when the contrat is selected
@param user: player's name
@param referee: arbiter jid
@contrat: contrat choosed (must be the exact same string than in the give list options)
@profile_key: profile
"""
profile = self.host.memory.getProfileName(profile_key)
if not profile:
error (_("profile %s is unknown") % profile_key)
return
debug (_('contrat [%(contrat)s] choosed by %(profile)s') % {'contrat':contrat, 'profile':profile})
mess = self.createGameElt(jid.JID(referee))
contrat_elt = mess.firstChildElement().addElement(('','contrat_choosed'), content=contrat)
contrat_elt['user'] = user
self.host.profiles[profile].xmlstream.send(mess) self.host.profiles[profile].xmlstream.send(mess)
@ -148,11 +190,14 @@ class Tarot():
debug (_('new Tarot game')) debug (_('new Tarot game'))
deck = self.deck_ordered[:] deck = self.deck_ordered[:]
random.shuffle(deck) random.shuffle(deck)
profile = self.games[room_jid.userhost()]['profile'] game_data = self.games[room_jid.userhost()]
players = self.games[room_jid.userhost()]['players'] referee_profile = game_data['referee_profile']
hand = self.games[room_jid.userhost()]['hand'] = {} players = game_data['players']
hand_size = self.games[room_jid.userhost()]['hand_size'] players_data = game_data['players_data']
chien = self.games[room_jid.userhost()]['chien'] = [] current_player = game_data['current_player']
hand = game_data['hand'] = {}
hand_size = game_data['hand_size']
chien = game_data['chien'] = []
for i in range(4): #TODO: distribute according to real Tarot rules (3 by 3 counter-clockwise, 1 card at once to chien) for i in range(4): #TODO: distribute according to real Tarot rules (3 by 3 counter-clockwise, 1 card at once to chien)
hand[players[i]] = deck[0:hand_size] hand[players[i]] = deck[0:hand_size]
del deck[0:hand_size] del deck[0:hand_size]
@ -163,7 +208,15 @@ class Tarot():
to_jid = jid.JID(room_jid.userhost()+"/"+player) #FIXME: gof: to_jid = jid.JID(room_jid.userhost()+"/"+player) #FIXME: gof:
mess = self.createGameElt(to_jid) mess = self.createGameElt(to_jid)
mess.firstChildElement().addChild(self.__hand_to_xml(hand[player])) mess.firstChildElement().addChild(self.__hand_to_xml(hand[player]))
self.host.profiles[profile].xmlstream.send(mess) self.host.profiles[referee_profile].xmlstream.send(mess)
players_data[player]['contrat'] = None
pl_idx = game_data['current_player'] = (game_data['init_player'] + 1) % len(players) #the player after the dealer start
player = players[pl_idx]
to_jid = jid.JID(room_jid.userhost()+"/"+player) #FIXME: gof:
mess = self.createGameElt(to_jid)
mess.firstChildElement().addChild(self.__ask_contrat())
self.host.profiles[referee_profile].xmlstream.send(mess)
def card_game_cmd(self, mess_elt, profile): def card_game_cmd(self, mess_elt, profile):
@ -171,23 +224,58 @@ class Tarot():
room_jid = jid.JID(mess_elt['from']) room_jid = jid.JID(mess_elt['from'])
game_elt = mess_elt.firstChildElement() game_elt = mess_elt.firstChildElement()
for elt in game_elt.elements(): #new game created for elt in game_elt.elements(): #new game created
if elt.name == 'started': if elt.name == 'started':
players = [] players = []
for player in elt.elements(): for player in elt.elements():
players.append(unicode(player)) players.append(unicode(player))
self.host.bridge.tarotGameStarted(room_jid.userhost(), room_jid.full(), players, profile) self.host.bridge.tarotGameStarted(room_jid.userhost(), room_jid.full(), players, profile)
elif elt.name == 'player_ready': elif elt.name == 'player_ready':
player = unicode(elt) player = elt['user']
status = self.games[room_jid.userhost()]['status'] status = self.games[room_jid.userhost()]['status']
nb_players = len(self.games[room_jid.userhost()]['players']) nb_players = len(self.games[room_jid.userhost()]['players'])
status[player] = 'ready' status[player] = 'ready'
debug (_('Player %(player)s is ready to start [status: %(status)s]') % {'player':player, 'status':status}) debug (_('Player %(player)s is ready to start [status: %(status)s]') % {'player':player, 'status':status})
if status.values().count('ready') == 2: #gof: nb_players: #everybody is ready, we can start the game if status.values().count('ready') == nb_players: #everybody is ready, we can start the game
self.newGame(room_jid) self.newGame(room_jid)
elif elt.name == 'hand': #a new hand has been received elif elt.name == 'hand': #a new hand has been received
self.host.bridge.tarotGameNew(room_jid.userhost(), self.__xml_to_hand(elt), profile) self.host.bridge.tarotGameNew(room_jid.userhost(), self.__xml_to_hand(elt), profile)
elif elt.name == 'contrat': #it's time to choose contrat
form = data_form.Form.fromElement(elt.firstChildElement())
xml_data = XMLTools.dataForm2xml(form)
self.host.bridge.tarotChooseContrat(room_jid.userhost(), xml_data, profile)
elif elt.name == 'contrat_choosed': #the player has chooser a contrat
#TODO: check we receive the contrat from the right person
#TODO: user proper XEP-0004 way for answering form
user = elt['user']
game_data = self.games[room_jid.userhost()]
players_data = game_data['players_data']
players_data[user]['contrat'] = unicode(elt)
contrats = [players_data[player]['contrat'] for player in game_data['players']]
if contrats.count(None):
#not everybody has choosed his contrat, it's next one turn
player = self.__next_player(game_data)
to_jid = jid.JID(room_jid.userhost()+"/"+player) #FIXME: gof:
mess = self.createGameElt(to_jid)
mess.firstChildElement().addChild(self.__ask_contrat())
self.host.profiles[game_data['referee_profile']].xmlstream.send(mess)
else:
#TODO: manage "everybody pass" case
best_contrat = [None, "Passe"]
for player in game_data['players']:
contrat = players_data[player]['contrat']
idx_best = self.contrats.index(best_contrat[1])
idx_pl = self.contrats.index(contrat)
if idx_pl > idx_best:
best_contrat[0] = player
best_contrat[1] = contrat
debug (_("%(player)s win the bid with %(contrat)s") % {'player':best_contrat[0],'contrat':best_contrat[1]})
def getHandler(self, profile): def getHandler(self, profile):
return CardGameHandler(self) return CardGameHandler(self)
@ -202,7 +290,6 @@ class CardGameHandler (XMPPHandler):
self.host = plugin_parent.host self.host = plugin_parent.host
def connectionInitialized(self): def connectionInitialized(self):
print "gof: ajout d'observer", CG_REQUEST
self.xmlstream.addObserver(CG_REQUEST, self.plugin_parent.card_game_cmd, profile = self.parent.profile) self.xmlstream.addObserver(CG_REQUEST, self.plugin_parent.card_game_cmd, profile = self.parent.profile)
def getDiscoInfo(self, requestor, target, nodeIdentifier=''): def getDiscoInfo(self, requestor, target, nodeIdentifier=''):

View file

@ -82,7 +82,7 @@ class XEP_0045():
@param profile: profile to check @param profile: profile to check
@return: True if the profile is known and connected, else False""" @return: True if the profile is known and connected, else False"""
if not profile or not self.clients.has_key(profile) or not self.host.isConnected(profile): if not profile or not self.clients.has_key(profile) or not self.host.isConnected(profile):
error (_('Unknown or disconnected profile')) error (_('Unknown or disconnected profile (%s)') % profile)
if self.clients.has_key(profile): if self.clients.has_key(profile):
del self.clients[profile] del self.clients[profile]
return False return False

View file

@ -50,6 +50,8 @@ class XMLTools:
__field_type = "string" __field_type = "string"
elif field.fieldType == 'text-private': elif field.fieldType == 'text-private':
__field_type = "password" __field_type = "password"
elif field.fieldType == 'list-single':
__field_type = "list"
else: else:
error (u"FIXME FIXME FIXME: Type [%s] is not managed yet by SàT" % field.fieldType) error (u"FIXME FIXME FIXME: Type [%s] is not managed yet by SàT" % field.fieldType)
__field_type = "string" __field_type = "string"
@ -59,9 +61,12 @@ class XMLTools:
elem.setAttribute('type', __field_type) elem.setAttribute('type', __field_type)
elem.setAttribute('label', field.label or "") elem.setAttribute('label', field.label or "")
if field.value: if field.value:
text = doc.createTextNode(field.value) elem.setAttribute('value', field.value)
elem.appendChild(text)
top_element.appendChild(elem) top_element.appendChild(elem)
for option in field.options:
opt = doc.createElement('option')
opt.setAttribute('value', option.value)
elem.appendChild(opt)
result = doc.toxml() result = doc.toxml()
doc.unlink() doc.unlink()
return result return result