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
5 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 tools.jid import JID
from sat_bridge_frontend.DBus import DBusBridgeFrontend
from optparse import OptionParser
import pdb
import gettext
@ -34,6 +35,7 @@ class QuickApp():
self.rosterList = {}
self.profiles = {}
self.single_profile = single_profile
self.check_options()
## bridge ##
self.bridge=DBusBridgeFrontend()
@ -48,6 +50,7 @@ class QuickApp():
self.bridge.register("roomNewSubject", self.roomNewSubject)
self.bridge.register("tarotGameStarted", self.tarotGameStarted)
self.bridge.register("tarotGameNew", self.tarotGameNew)
self.bridge.register("tarotChooseContrat", self.tarotChooseContrat)
self.bridge.register("subscribe", self.subscribe)
self.bridge.register("paramUpdate", self.paramUpdate)
self.bridge.register("contactDeleted", self.contactDeleted)
@ -63,6 +66,20 @@ class QuickApp():
"""Tell if the profile is currently followed by the application"""
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@'):
"""Tell application which profile must be used"""
if self.single_profile and self.profiles:
@ -134,6 +151,8 @@ class QuickApp():
return
debug(_("Connected"))
self.setStatusOnline(True)
self.bridge.joinMUC('conference.necton2.int', 'test', self.profiles[self.profile]['whoami'].node, self.profile) #gof:
def disconnected(self, profile):
"""called when the connection is closed"""
@ -262,9 +281,16 @@ class QuickApp():
debug (_("New Tarot Game"))
print "room: %s, hand: %s" % (room_jid,hand)
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)
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):

View file

@ -125,6 +125,9 @@ class DBusBridgeFrontend(BridgeFrontend):
def tarotGameReady(self, user, referee, profile_key='@DEFAULT@'):
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@'):
return self.db_comm_iface.sendFile(to, path, profile_key)

View file

@ -26,8 +26,7 @@ import os.path, glob
import pdb
from logging import debug, info, error
from tools.jid import JID
from quick_frontend.quick_chat import QuickChat
from contact_list import ContactList
from form import Form
CARD_WIDTH = 74
CARD_HEIGHT = 136
@ -140,6 +139,21 @@ class CardPanel(wx.Panel):
self.hand.sort()
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):
"""Return True if the coordinate are on the hand cards"""
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 pdb
from xml.dom import minidom
from logging import debug, info, error
from logging import debug, info, warning, error
from tools.jid import JID
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)
self.host = host
self.target = target
self.options = options
self.misc = misc
self.ctl_list = [] # usefull to access ctrl
self.sizer = wx.BoxSizer(wx.VERTICAL)
@ -41,7 +44,8 @@ class Form(wx.Frame):
self.SetAutoLayout(True)
#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()
@ -59,7 +63,7 @@ class Form(wx.Frame):
name = elem.getAttribute("name")
label = elem.getAttribute("label") if elem.hasAttribute('label') else name
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)
if type=="text":
ctrl = wx.StaticText(panel, -1, value)
@ -73,6 +77,10 @@ class Form(wx.Frame):
ctrl = wx.TextCtrl(panel, -1, value, style=wx.TE_PASSWORD)
self.ctl_list.append({'name':name, 'type':type, 'control':ctrl})
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:
error(_("FIXME FIXME FIXME: type [%s] is not implemented") % type) #FIXME !
raise NotImplementedError
@ -80,14 +88,15 @@ class Form(wx.Frame):
#self.ctl_list[(name, category)] = ctrl
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()
submitButton = wx.Button(panel,wx.ID_OK, label=_("Submit"))
dialogButtons.AddButton(submitButton)
dialogButtons.AddButton(cancelButton)
dialogButtons.Realize()
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.SetSizer(panel.sizer)
@ -101,9 +110,17 @@ class Form(wx.Frame):
debug(_("Submitting form"))
data = []
for ctrl in self.ctl_list:
data.append((ctrl["name"], ctrl["control"].GetValue()))
id = self.host.bridge.gatewayRegister("SUBMIT",self.target, data)
self.host.current_action_ids.add(id)
if isinstance(ctrl['control'], wx.ListBox):
data.append((ctrl['name'], ctrl['control'].GetStringSelection()))
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.Destroy()

View file

@ -109,10 +109,10 @@ class MainWindow(wx.Frame, QuickApp):
self.profile_pan = ProfileManager(self)
#self.profile_pan.Hide() #gof:
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()
def plug_profile(self, profile_key='@DEFAULT@'):
@ -269,7 +269,14 @@ class MainWindow(wx.Frame, QuickApp):
elif type == "FORM":
self.current_action_ids.remove(id)
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":
self.current_action_ids.remove(id)
if self.current_action_ids_cb.has_key(id):