[gnome-games/sudoku-tube] Actually display the peer's puzzle in side-grid
- From: Zhang Sen <zhangsen src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnome-games/sudoku-tube] Actually display the peer's puzzle in side-grid
- Date: Mon, 6 Jul 2009 02:34:18 +0000 (UTC)
commit b9c57886b68f274d492ca1cb268a65fe8da0abbf
Author: Zhang Sen <zh jesse gmail com>
Date: Mon Jul 6 10:31:35 2009 +0800
Actually display the peer's puzzle in side-grid
Also several small fix: rename a method; define obj_path as class attribute;
define a method to get the puzzle.
gnome-sudoku/src/lib/main.py | 26 +++++++++++++++++++-------
gnome-sudoku/src/lib/networking.py | 2 +-
gnome-sudoku/src/lib/tp_tube.py | 2 +-
3 files changed, 21 insertions(+), 9 deletions(-)
---
diff --git a/gnome-sudoku/src/lib/main.py b/gnome-sudoku/src/lib/main.py
index a7815ae..38e55a5 100644
--- a/gnome-sudoku/src/lib/main.py
+++ b/gnome-sudoku/src/lib/main.py
@@ -52,6 +52,7 @@ class UI (gconf_wrapper.GConfWrapper):
'auto_save_interval':60 # auto-save interval in seconds...
}
tube_service = 'org.gnome.Sudoku'
+ _server_obj_path = "/Game"
def __init__ (self):
gconf_wrapper.GConfWrapper.__init__(self,
@@ -113,6 +114,7 @@ class UI (gconf_wrapper.GConfWrapper):
def _open_game(self, game_type, puzzle):
"""Finally enter the puzzle"""
+ self._puzzle = puzzle
if game_type == game_selector.NewOrSavedGameSelector.NEW_GAME:
self.gsd.change_grid(puzzle, 9)
elif game_type == game_selector.NewOrSavedGameSelector.SAVED_GAME:
@@ -331,13 +333,24 @@ class UI (gconf_wrapper.GConfWrapper):
)
def _get_server(self, bus):
- return bus.get_object(object_path="/Game")
+ return bus.get_object(object_path=self._server_obj_path)
+
+ def get_puzzle(self):
+ """Return the puzzle as a string
+
+ so a remote peer can use it to construct their own game"""
+ return self._puzzle # should be a string
def _tube_received_cb(self, bus):
game_server = self._get_server(bus)
puzzle = str(game_server.get_puzzle())
- logger.info("get puzzle from server: %s" % puzzle)
- self._open_game(game_selector.NewOrSavedGameSelector.NEW_GAME, puzzle)
+ logger.info("get puzzle from server")
+ logger.debug("puzzle: %s" % puzzle)
+ self._open_side_puzzle(puzzle)
+
+ def _open_side_puzzle(self, puzzle):
+ self._side_gsd.change_grid(puzzle, 9)
+ self._side_gsd.show()
def new_cb (self, *args):
if self._close_current_game():
@@ -351,15 +364,14 @@ class UI (gconf_wrapper.GConfWrapper):
logger.info("selected: %s\nconnection: %s\nhandle: %d" % (
choice[2].alias, choice[0].service_name, choice[1]))
tp_tube.offer_tube(choice[0], choice[1], self.tube_service,
- self._tube_open_cb)
+ self._tube_offered_cb)
else:
logger.info("None selected")
- def _tube_open_cb(self, bus, obj_path):
+ def _tube_offered_cb(self, bus):
"""Called when the peer accepts our tube"""
- server = networking.GameServer(bus, obj_path, self)
+ server = networking.GameServer(bus, self._server_obj_path, self)
logger.info("server created")
- self._side_gsd.show()
def _close_current_game (self):
"""Close current running game
diff --git a/gnome-sudoku/src/lib/networking.py b/gnome-sudoku/src/lib/networking.py
index ae8ebf2..d9dcb34 100644
--- a/gnome-sudoku/src/lib/networking.py
+++ b/gnome-sudoku/src/lib/networking.py
@@ -19,4 +19,4 @@ class GameServer(dbus.service.Object):
in_signature="", out_signature="s")
def get_puzzle(self):
logger.info("client is asking for the puzzle")
- return self.game._game
+ return self.game.get_puzzle()
diff --git a/gnome-sudoku/src/lib/tp_tube.py b/gnome-sudoku/src/lib/tp_tube.py
index 5061bb2..317c7be 100644
--- a/gnome-sudoku/src/lib/tp_tube.py
+++ b/gnome-sudoku/src/lib/tp_tube.py
@@ -28,7 +28,7 @@ def offer_tube(conn, handle, tube_service, tube_open_cb):
if state == TUBE_CHANNEL_STATE_OPEN:
logger.info("Tube state changed ->open")
tube_conn = dbus.connection.Connection(address)
- tube_open_cb(bus=tube_conn, obj_path="/Game")
+ tube_open_cb(bus=tube_conn)
elif state == TUBE_CHANNEL_STATE_REMOTE_PENDING:
logger.info("Tube state changed ->remote-pending")
else:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]