From ea34d78e90d00587d1036d8847d966e2a759099e Mon Sep 17 00:00:00 2001 From: Simon Schampijer Date: Sat, 30 Jun 2007 17:55:53 +0000 Subject: A lot of fixes and at least the graphics come up already. On monday I will continue work on the tubes - this should be finished on monday :) happy week-end --- diff --git a/game.py b/game.py index 2f32652..81c304d 100644 --- a/game.py +++ b/game.py @@ -33,6 +33,7 @@ class ConnectGame(ExportedGObject): self._get_buddy = get_buddy self.activity = activity + self.turn = None # list indexed by player ID # 0, 1 are players 0, 1 # 2+ are the spectator queue, 2 is to play next @@ -86,7 +87,7 @@ class ConnectGame(ExportedGObject): up to date with the game state. """ - @method(dbus_interface=IFACE, in_signature='a(nn)', out_signature='') + @method(dbus_interface=IFACE, in_signature='a(nn)as', out_signature='') def Welcome(self, grid, bus_names): """To be called on the incoming player by the other players to inform them of the game state. @@ -122,7 +123,7 @@ class ConnectGame(ExportedGObject): path=PATH, sender_keyword='sender') @signal(dbus_interface=IFACE, signature='nsn') - def Flip(self, tilenum): + def Flip(self, tilenum, obj, color): """Signal that the local player has flipped a tile.""" def hello_cb(self, sender=None): @@ -142,7 +143,7 @@ class ConnectGame(ExportedGObject): "I go first") self.change_turn() - def flip_cb(self, tilenum, sender=None): + def flip_cb(self, tilenum, obj, color, sender=None): handle = self.tube.bus_name_to_handle[sender] _logger.debug('Flipped tile(%d) from %s', tilenum, sender) @@ -157,7 +158,7 @@ class ConnectGame(ExportedGObject): def change_turn(self): pass -''' + ''' try: bus_name = self.ordered_bus_names[self.get_active_player()] buddy = self._get_buddy(self.tube.bus_name_to_handle[bus_name]) @@ -186,7 +187,7 @@ class ConnectGame(ExportedGObject): return 1 else: return 0 -''' + ''' def _button_press_cb(self, tile, event, tilenum=None): if self.turn is None: _logger.debug('Ignoring flip - not my turn') @@ -198,5 +199,5 @@ class ConnectGame(ExportedGObject): color = self.model.pairs[pairkey][2] logger.debug('obj=%s color=%s'%(obj, color)) - self.Flipp(tilenum, obj, color) + self.Flip(tilenum, obj, color) diff --git a/memosonoactivity.py b/memosonoactivity.py index e82e6b5..92c0dd4 100755 --- a/memosonoactivity.py +++ b/memosonoactivity.py @@ -26,11 +26,13 @@ import logging import dbus import telepathy import telepathy.client +import hippo from sugar.activity.activity import Activity from sugar.activity.activity import ActivityToolbox from sugar.presence import presenceservice +from tubeconn import TubeConnection from playview import PlayView from buddiespanel import BuddiesPanel from infopanel import InfoPanel @@ -45,7 +47,7 @@ class MemosonoActivity(Activity): def __init__(self, handle): Activity.__init__(self, handle) - logger.debug('Starting Memosono activity...') + logging.debug('Starting Memosono activity...') self.set_title(_('Memsosono Activity')) @@ -54,17 +56,16 @@ class MemosonoActivity(Activity): self.model.def_grid() self.pv = PlayView( len(self.model.grid) ) - self.pv.show() self.buddies_panel = BuddiesPanel() self.info_panel = InfoPanel() vbox = hippo.CanvasBox(spacing=4, - orientation=hippo.ORIENTATION_VERTICAL) + orientation=hippo.ORIENTATION_VERTICAL) hbox = hippo.CanvasBox(spacing=4, - orientation=hippo.ORIENTATION_HORIZONTAL) + orientation=hippo.ORIENTATION_HORIZONTAL) hbox.append(self.buddies_panel) hbox.append(self.pv, hippo.PACK_EXPAND) @@ -77,9 +78,11 @@ class MemosonoActivity(Activity): self.set_canvas(canvas) self.show_all() - + toolbox = ActivityToolbox(self) + self.set_toolbox(toolbox) + toolbox.show() + self.pservice = presenceservice.get_instance() - self.owner = self.pservice.get_owner() bus = dbus.Bus() name, path = self.pservice.get_preferred_connection() @@ -87,10 +90,20 @@ class MemosonoActivity(Activity): self.tp_conn_path = path self.conn = telepathy.client.Connection(name, path) self.initiating = None + self.game = None - + + toolbox = ActivityToolbox(self) + self.set_toolbox(toolbox) + toolbox.show() + + self.info_panel.show('To play, share!') + self.connect('shared', self._shared_cb) + owner = self.pservice.get_owner() + self.owner = owner + if self._shared_activity: # we are joining the activity self.buddies_panel.add_watcher(owner) @@ -102,8 +115,9 @@ class MemosonoActivity(Activity): self._joined_cb() else: # we are creating the activity - self.pv.buddies_panel .add_player(self.owner) - + self.buddies_panel.add_player(owner) + #self.buddies_panel.set_is_playing(owner) + #self.buddies_panel.set_count(owner, 69) def _shared_cb(self, activity): logging.debug('My Memosono activity was shared') @@ -111,7 +125,7 @@ class MemosonoActivity(Activity): self._setup() for buddy in self._shared_activity.get_joined_buddies(): - self.pv.buddies_panel.add_watcher(buddy) + self.buddies_panel.add_watcher(buddy) self._shared_activity.connect('buddy-joined', self._buddy_joined_cb) self._shared_activity.connect('buddy-left', self._buddy_left_cb) @@ -184,7 +198,7 @@ class MemosonoActivity(Activity): return for buddy in self._shared_activity.get_joined_buddies(): - self.pv.buddies_panel.add_watcher(buddy) + self.buddies_panel.add_watcher(buddy) logging.debug('Joined an existing Connect game') logging.debug('Joined a game. Waiting for my turn...') @@ -196,6 +210,30 @@ class MemosonoActivity(Activity): reply_handler=self._list_tubes_reply_cb, error_handler=self._list_tubes_error_cb) + def _get_buddy(self, cs_handle): + """Get a Buddy from a channel specific handle.""" + logging.debug('Trying to find owner of handle %u...', cs_handle) + group = self.text_chan[telepathy.CHANNEL_INTERFACE_GROUP] + my_csh = group.GetSelfHandle() + logging.debug('My handle in that group is %u', my_csh) + if my_csh == cs_handle: + handle = self.conn.GetSelfHandle() + logging.debug('CS handle %u belongs to me, %u', cs_handle, handle) + elif group.GetGroupFlags() & telepathy.CHANNEL_GROUP_FLAG_CHANNEL_SPECIFIC_HANDLES: + handle = group.GetHandleOwners([cs_handle])[0] + logging.debug('CS handle %u belongs to %u', cs_handle, handle) + else: + handle = cs_handle + logging.debug('non-CS handle %u belongs to itself', handle) + + # XXX: deal with failure to get the handle owner + assert handle != 0 + + # XXX: we're assuming that we have Buddy objects for all contacts - + # this might break when the server becomes scalable. + return self.pservice.get_buddy_by_telepathy_handle(self.tp_conn_name, + self.tp_conn_path, handle) + def _new_tube_cb(self, id, initiator, type, service, params, state): logging.debug('New tube: ID=%d initator=%d type=%d service=%s ' 'params=%r state=%d', id, initiator, type, service, @@ -210,16 +248,16 @@ class MemosonoActivity(Activity): self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES], id, group_iface=self.text_chan[telepathy.CHANNEL_INTERFACE_GROUP]) self.game = ConnectGame(tube_conn, self.pv, self.model, self.initiating, - self.pv.buddies_panel, self.info_panel, self.owner, + self.buddies_panel, self.info_panel, self.owner, self._get_buddy, self) - def _buddy_joined_cb (self, activity, buddy): + def _buddy_joined_cb(self, activity, buddy): logging.debug('buddy joined') - self.pv.buddies_panel.add_watcher(buddy) + self.buddies_panel.add_watcher(buddy) - def _buddy_left_cb (self, activity, buddy): + def _buddy_left_cb(self, activity, buddy): logging.debug('buddy left') - self.pv.buddies_panel.remove_watcher(buddy) + self.buddies_panel.remove_watcher(buddy) diff --git a/model.py b/model.py index 3545c0b..fcd319d 100644 --- a/model.py +++ b/model.py @@ -71,7 +71,7 @@ class Model(object): doc.freeDoc() def def_grid(self): - print 'pairs: %s' %self.model.pairs + print 'pairs: %s' %self.pairs ### create grid from pairs information for key in self.pairs.iterkeys(): self.grid.append((key, 0)) diff --git a/playview.py b/playview.py index 45d478f..af75a2a 100644 --- a/playview.py +++ b/playview.py @@ -8,16 +8,11 @@ from sugar.graphics import font from playtile import PlayTile -class PlayView(hippo.Canvas): - def __init__(self, numtiles): - hippo.Canvas.__init__(self) +class PlayView(hippo.CanvasBox, hippo.CanvasItem): + def __init__(self, numtiles, **kargs): + hippo.CanvasBox.__init__(self, **kargs) - root = hippo.CanvasBox() - root.props.orientation = hippo.ORIENTATION_HORIZONTAL - - tilebox = hippo.CanvasBox() - tilebox.props.orientation = hippo.ORIENTATION_VERTICAL - root.append(tilebox) + self.props.orientation = hippo.ORIENTATION_VERTICAL self.tiles = [] @@ -27,16 +22,13 @@ class PlayView(hippo.Canvas): if tile_num == 0 or ((tile_num)%4) == 0: box = hippo.CanvasBox() box.props.orientation = hippo.ORIENTATION_HORIZONTAL - tilebox.append(box) + self.append(box) tile = PlayTile(tile_num) self.tiles.append(tile) box.append(tile) - tile_num+=1 - - self.set_root(root) - self.show() + tile_num+=1 def flip(self, tile_num, obj, color): tile = self.tiles[tile_num] -- cgit v0.9.1