comparison frontends/quick_frontend/quick_app.py @ 91:39c672544593

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
author Goffi <goffi@goffi.org>
date Thu, 27 May 2010 19:26:19 +0930
parents 4020931569b8
children 2503de7fb4c7
comparison
equal deleted inserted replaced
90:4020931569b8 91:39c672544593
20 """ 20 """
21 21
22 from logging import debug, info, error 22 from logging import debug, info, error
23 from tools.jid import JID 23 from tools.jid import JID
24 from sat_bridge_frontend.DBus import DBusBridgeFrontend 24 from sat_bridge_frontend.DBus import DBusBridgeFrontend
25 from optparse import OptionParser
25 import pdb 26 import pdb
26 27
27 import gettext 28 import gettext
28 gettext.install('sat_frontend', "../i18n", unicode=True) 29 gettext.install('sat_frontend', "../i18n", unicode=True)
29 30
32 33
33 def __init__(self, single_profile=True): 34 def __init__(self, single_profile=True):
34 self.rosterList = {} 35 self.rosterList = {}
35 self.profiles = {} 36 self.profiles = {}
36 self.single_profile = single_profile 37 self.single_profile = single_profile
38 self.check_options()
37 39
38 ## bridge ## 40 ## bridge ##
39 self.bridge=DBusBridgeFrontend() 41 self.bridge=DBusBridgeFrontend()
40 self.bridge.register("connected", self.connected) 42 self.bridge.register("connected", self.connected)
41 self.bridge.register("disconnected", self.disconnected) 43 self.bridge.register("disconnected", self.disconnected)
46 self.bridge.register("roomUserJoined", self.roomUserJoined) 48 self.bridge.register("roomUserJoined", self.roomUserJoined)
47 self.bridge.register("roomUserLeft", self.roomUserLeft) 49 self.bridge.register("roomUserLeft", self.roomUserLeft)
48 self.bridge.register("roomNewSubject", self.roomNewSubject) 50 self.bridge.register("roomNewSubject", self.roomNewSubject)
49 self.bridge.register("tarotGameStarted", self.tarotGameStarted) 51 self.bridge.register("tarotGameStarted", self.tarotGameStarted)
50 self.bridge.register("tarotGameNew", self.tarotGameNew) 52 self.bridge.register("tarotGameNew", self.tarotGameNew)
53 self.bridge.register("tarotChooseContrat", self.tarotChooseContrat)
51 self.bridge.register("subscribe", self.subscribe) 54 self.bridge.register("subscribe", self.subscribe)
52 self.bridge.register("paramUpdate", self.paramUpdate) 55 self.bridge.register("paramUpdate", self.paramUpdate)
53 self.bridge.register("contactDeleted", self.contactDeleted) 56 self.bridge.register("contactDeleted", self.contactDeleted)
54 self.bridge.register("updatedValue", self.updatedValue, "request") 57 self.bridge.register("updatedValue", self.updatedValue, "request")
55 self.bridge.register("askConfirmation", self.askConfirmation, "request") 58 self.bridge.register("askConfirmation", self.askConfirmation, "request")
61 64
62 def __check_profile(self, profile): 65 def __check_profile(self, profile):
63 """Tell if the profile is currently followed by the application""" 66 """Tell if the profile is currently followed by the application"""
64 return profile in self.profiles.keys() 67 return profile in self.profiles.keys()
65 68
69 def check_options(self):
70 """Check command line options"""
71 usage=_("""
72 %prog [options]
73
74 %prog --help for options list
75 """)
76 parser = OptionParser(usage=usage)
77
78 parser.add_option("-p", "--profile", help=_("Select the profile to use"))
79
80 (self.options, args) = parser.parse_args()
81 return args
82
66 def plug_profile(self, profile_key='@DEFAULT@'): 83 def plug_profile(self, profile_key='@DEFAULT@'):
67 """Tell application which profile must be used""" 84 """Tell application which profile must be used"""
68 if self.single_profile and self.profiles: 85 if self.single_profile and self.profiles:
69 error(_('There is already one profile plugged (we are in single profile mode) !')) 86 error(_('There is already one profile plugged (we are in single profile mode) !'))
70 return 87 return
132 """called when the connection is made""" 149 """called when the connection is made"""
133 if not self.__check_profile(profile): 150 if not self.__check_profile(profile):
134 return 151 return
135 debug(_("Connected")) 152 debug(_("Connected"))
136 self.setStatusOnline(True) 153 self.setStatusOnline(True)
154 self.bridge.joinMUC('conference.necton2.int', 'test', self.profiles[self.profile]['whoami'].node, self.profile) #gof:
155
137 156
138 def disconnected(self, profile): 157 def disconnected(self, profile):
139 """called when the connection is closed""" 158 """called when the connection is closed"""
140 if not self.__check_profile(profile): 159 if not self.__check_profile(profile):
141 return 160 return
260 if not self.__check_profile(profile): 279 if not self.__check_profile(profile):
261 return 280 return
262 debug (_("New Tarot Game")) 281 debug (_("New Tarot Game"))
263 print "room: %s, hand: %s" % (room_jid,hand) 282 print "room: %s, hand: %s" % (room_jid,hand)
264 if self.chat_wins.has_key(room_jid): 283 if self.chat_wins.has_key(room_jid):
265 print "gof:",self.chat_wins[room_jid].getGame("Tarot")
266 self.chat_wins[room_jid].getGame("Tarot").newGame(hand) 284 self.chat_wins[room_jid].getGame("Tarot").newGame(hand)
285
286 def tarotChooseContrat(self, room_jid, xml_data, profile):
287 """Called when the player has too select his contrat"""
288 if not self.__check_profile(profile):
289 return
290 debug (_("Tarot: need to select a contrat"))
291 if self.chat_wins.has_key(room_jid):
292 self.chat_wins[room_jid].getGame("Tarot").chooseContrat(xml_data)
267 293
268 294
269 295
270 def subscribe(self, type, raw_jid, profile): 296 def subscribe(self, type, raw_jid, profile):
271 """Called when a subsciption management signal is received""" 297 """Called when a subsciption management signal is received"""