Tarot Game plugin: first draft

- SàT: beginning of the plugin
- Tarot Plugin: 1 method createTarotGame et 1 signal tarotGameStarted
- wix: added "Game" menu in group chat to start Tarot game
This commit is contained in:
Goffi 2010-05-07 17:09:30 +09:30
commit fe4db2366b
5 changed files with 42 additions and 5 deletions

View file

@ -46,6 +46,7 @@ class QuickApp():
self.bridge.register("roomUserJoined", self.roomUserJoined)
self.bridge.register("roomUserLeft", self.roomUserLeft)
self.bridge.register("roomNewSubject", self.roomNewSubject)
self.bridge.register("tarotGameStarted", self.tarotGameStarted)
self.bridge.register("subscribe", self.subscribe)
self.bridge.register("paramUpdate", self.paramUpdate)
self.bridge.register("contactDeleted", self.contactDeleted)
@ -215,6 +216,7 @@ class QuickApp():
room_jid=room_id+'@'+room_service
self.chat_wins[room_jid].setUserNick(user_nick)
self.chat_wins[room_jid].setType("group")
self.chat_wins[room_jid].id = room_jid
self.chat_wins[room_jid].setPresents([user_nick]+room_nicks)
@ -244,6 +246,11 @@ class QuickApp():
if self.chat_wins.has_key(room_jid):
self.chat_wins[room_jid].setSubject(subject)
debug (_("new subject for room [%(room_jid)s]: %(subject)s") % {'room_jid':room_jid, "subject":subject})
def tarotGameStarted(self, room_jid, players, profile):
if not self.__check_profile(profile):
return
print "Tarot Game Started \o/"
def subscribe(self, type, raw_jid, profile):

View file

@ -30,7 +30,9 @@ class QuickChat():
self.target = target
self.host = host
self.type = type
self.id = ""
self.nick = None
self.occupants = set()
def setType(self, type):
"""Set the type of the chat

View file

@ -119,6 +119,9 @@ class DBusBridgeFrontend(BridgeFrontend):
def joinMUC(self, service, roomId, nick, profile_key='@DEFAULT@'):
return self.db_comm_iface.joinMUC(service, roomId, nick, profile_key)
def createTarotGame(self, room_jid, players, profile_key='@DEFAULT@'):
return self.db_comm_iface.createTarotGame(room_jid, players, profile_key)
def sendFile(self, to, path, profile_key='@DEFAULT@'):
return self.db_comm_iface.sendFile(to, path, profile_key)

View file

@ -24,13 +24,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import wx
import os.path
import pdb
from logging import debug, info, error
from logging import debug, info, error, warning
from tools.jid import JID
from quick_frontend.quick_chat import QuickChat
from contact_list import ContactList
idSEND = 1
idTAROT = 2
class Chat(wx.Frame, QuickChat):
"""The chat Window for one to one conversations"""
@ -85,19 +86,22 @@ class Chat(wx.Frame, QuickChat):
self.__createPresents()
self.subjectBox.Show()
self.__eraseMenus()
self.__createMenus_group()
self.historyPrint(profile=self.host.profile)
elif type is 'one2one' and self.splitter.IsSplit():
self.splitter.Unsplit(self.present_panel)
del self.present_panel
self.GetMenuBar().Show()
self.subjectBox.Hide()
self.__eraseMenus()
self.__createMenus_O2O()
self.nick = None
else:
self.subjectBox.Hide()
self.__eraseMenus()
self.__createMenus_O2O()
self.historyPrint(profile=self.host.profile)
def setPresents(self, nicks):
"""Set the users presents in the contact list for a group chat
@param nicks: list of nicknames
@ -107,7 +111,9 @@ class Chat(wx.Frame, QuickChat):
error (_("[INTERNAL] trying to set presents nicks for a non group chat window"))
return
for nick in nicks:
self.present_panel.presents.replace(nick)
self.present_panel.presents.replace(nick)
if nick != self.nick:
self.occupants.add(nick)
def replaceUser(self, nick):
@ -117,6 +123,8 @@ class Chat(wx.Frame, QuickChat):
error (_("[INTERNAL] trying to replace user for a non group chat window"))
return
self.present_panel.presents.replace(nick)
if nick != self.nick:
self.occupants.add(nick)
def removeUser(self, nick):
"""Remove a user from the group list"""
@ -125,6 +133,7 @@ class Chat(wx.Frame, QuickChat):
error (_("[INTERNAL] trying to remove user for a non group chat window"))
return
self.present_panel.presents.remove(nick)
self.occupants.remove(nick)
def setSubject(self, subject):
"""Set title for a group chat"""
@ -153,6 +162,18 @@ class Chat(wx.Frame, QuickChat):
#events
wx.EVT_MENU(self, idSEND, self.onSendFile)
def __createMenus_group(self):
"""create menu bar for group chat"""
info("Creating menus")
self.__eraseMenus()
menuBar = self.GetMenuBar()
actionMenu = wx.Menu()
actionMenu.Append(idTAROT, _("Start &Tarot game CTRL-t"),_(" Start a Tarot card game")) #tmp
menuBar.Append(actionMenu,_("&Games"))
#events
wx.EVT_MENU(self, idTAROT, self.onStartTarot)
def __del__(self):
wx.Frame.__del__(self)
@ -200,3 +221,7 @@ class Chat(wx.Frame, QuickChat):
id = self.host.bridge.sendFile(full_jid, filename)
self.host.waitProgress(id, _("File Transfer"), _("Copying %s") % os.path.basename(filename))
def onStartTarot(self, e):
debug (_("Starting Tarot game"))
warning (_("FIXME: temporary menu, must be changed"))
self.host.bridge.createTarotGame(self.id, list(self.occupants), self.host.profile)

View file

@ -111,8 +111,8 @@ class MainWindow(wx.Frame, QuickApp):
#self.profile_pan.Hide() #gof:
self.sizer.Add(self.profile_pan, 1, flag=wx.EXPAND)
Tarot = CardGame(self)
Tarot.Show()#gof: temp for test
#Tarot = CardGame(self)
#Tarot.Show()#gof: temp for test
self.Show()