[gnome-games/sudoku-tube] Show puzzle info to receiver
- From: Zhang Sen <zhangsen src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-games/sudoku-tube] Show puzzle info to receiver
- Date: Sat, 15 Aug 2009 09:39:51 +0000 (UTC)
commit e9fa4b6855d3577ee64144705338280ff7e1ef2b
Author: Zhang Sen <zh jesse gmail com>
Date: Sat Aug 15 17:02:28 2009 +0800
Show puzzle info to receiver
gnome-sudoku/data/Makefile.am | 1 +
gnome-sudoku/data/network_game_offer.ui | 72 +++++++++++++++++++++++++++++++
gnome-sudoku/src/lib/main.py | 14 +------
gnome-sudoku/src/lib/sudoku.py | 15 ++++++
gnome-sudoku/src/lib/tube_handler.py | 28 ++++++++----
5 files changed, 107 insertions(+), 23 deletions(-)
---
diff --git a/gnome-sudoku/data/Makefile.am b/gnome-sudoku/data/Makefile.am
index 1b722af..208b59d 100644
--- a/gnome-sudoku/data/Makefile.am
+++ b/gnome-sudoku/data/Makefile.am
@@ -9,6 +9,7 @@ uidir = $(datadir)/gnome-sudoku
ui_DATA = \
contact_selector_dialog.ui \
main.ui \
+ network_game_offer.ui \
print_games.ui \
puzzle_generator.ui \
select_game.ui \
diff --git a/gnome-sudoku/data/network_game_offer.ui b/gnome-sudoku/data/network_game_offer.ui
new file mode 100644
index 0000000..3279b6f
--- /dev/null
+++ b/gnome-sudoku/data/network_game_offer.ui
@@ -0,0 +1,72 @@
+<?xml version="1.0"?>
+<interface>
+ <requires lib="gtk+" version="2.16"/>
+ <!-- interface-naming-policy project-wide -->
+ <object class="GtkDialog" id="dialog">
+ <property name="border_width">5</property>
+ <property name="title" translatable="yes">New game request</property>
+ <property name="type_hint">normal</property>
+ <property name="has_separator">False</property>
+ <child internal-child="vbox">
+ <object class="GtkVBox" id="dialog-vbox">
+ <property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">2</property>
+ <child>
+ <object class="GtkLabel" id="label">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">label</property>
+ <property name="selectable">True</property>
+ </object>
+ <packing>
+ <property name="padding">12</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child internal-child="action_area">
+ <object class="GtkHButtonBox" id="dialog-action_area">
+ <property name="visible">True</property>
+ <property name="layout_style">end</property>
+ <child>
+ <object class="GtkButton" id="button2">
+ <property name="label" translatable="yes">gtk-no</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_stock">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="button1">
+ <property name="label" translatable="yes">gtk-ok</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_stock">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="pack_type">end</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ <action-widgets>
+ <action-widget response="-6">button2</action-widget>
+ <action-widget response="-5">button1</action-widget>
+ </action-widgets>
+ </object>
+</interface>
diff --git a/gnome-sudoku/src/lib/main.py b/gnome-sudoku/src/lib/main.py
index 9715673..496e189 100644
--- a/gnome-sudoku/src/lib/main.py
+++ b/gnome-sudoku/src/lib/main.py
@@ -757,19 +757,7 @@ class SudokuGame(gconf_wrapper.GConfWrapper):
label = _("There is no current puzzle.")
)
return
- diff = self._difficulty
- information = _("Calculated difficulty: ")
- information += diff.value_string()
- information += " (%1.2f)" % diff.value
- information += "\n"
- information += _("Number of moves instantly fillable by elimination: ")
- information += str(int(diff.instant_elimination_fillable))
- information += "\n"
- information += _("Number of moves instantly fillable by filling: ")
- information += str(int(diff.instant_fill_fillable))
- information += "\n"
- information += _("Amount of trial-and-error required to solve: ")
- information += str(len(diff.guesses))
+ information = self._difficulty.to_string()
dialog_extras.show_message(parent = self.w,
title = _("Puzzle Statistics"),
label = _("Puzzle Statistics"),
diff --git a/gnome-sudoku/src/lib/sudoku.py b/gnome-sudoku/src/lib/sudoku.py
index d8cabea..01d7888 100644
--- a/gnome-sudoku/src/lib/sudoku.py
+++ b/gnome-sudoku/src/lib/sudoku.py
@@ -647,6 +647,21 @@ class DifficultyRating:
else:
return 'easy'
+ def to_string(self):
+ information = _("Calculated difficulty: ")
+ information += self.value_string()
+ information += " (%1.2f)" % self.value
+ information += "\n"
+ information += _("Number of moves instantly fillable by elimination: ")
+ information += str(int(self.instant_elimination_fillable))
+ information += "\n"
+ information += _("Number of moves instantly fillable by filling: ")
+ information += str(int(self.instant_fill_fillable))
+ information += "\n"
+ information += _("Amount of trial-and-error required to solve: ")
+ information += str(len(self.guesses))
+ return information
+
def get_difficulty_category_name (diff_float):
return DifficultyRating.label_by_cat.get(
get_difficulty_category(diff_float),
diff --git a/gnome-sudoku/src/lib/tube_handler.py b/gnome-sudoku/src/lib/tube_handler.py
index 329be8e..d3f54e6 100644
--- a/gnome-sudoku/src/lib/tube_handler.py
+++ b/gnome-sudoku/src/lib/tube_handler.py
@@ -1,12 +1,14 @@
# -*- coding: utf-8 -*-
import logging
+import os
import dbus
import dbus.service
import gtk
from dbus import PROPERTIES_IFACE
from dbus.mainloop.glib import DBusGMainLoop
+from gettext import gettext as _
from telepathy.client.conn import Connection
from telepathy.client.channel import Channel
@@ -19,6 +21,10 @@ from telepathy.interfaces import (
CHANNEL_TYPE_DBUS_TUBE,
CONN_INTERFACE_ALIASING)
+from defaults import UI_DIR
+import sudoku
+
+
DBusGMainLoop(set_as_default=True)
logger = logging.getLogger("main.tubehandler")
@@ -85,7 +91,7 @@ class TubeHandler(dbus.service.Object):
def _process_incoming_tube(self, params):
def reply_cb(dialog, response_id):
- if response_id == gtk.RESPONSE_ACCEPT:
+ if response_id == gtk.RESPONSE_OK:
logger.debug("accept tube")
self._address = self._tube_chan[CHANNEL_TYPE_DBUS_TUBE].Accept(
SOCKET_ACCESS_CONTROL_CREDENTIALS)
@@ -99,17 +105,19 @@ class TubeHandler(dbus.service.Object):
return # do nothing
self._puzzle = str(puzzle)
+ alias = _get_contact_alias(self._conn, self._peer_handle)
logger.debug('got offer: %s' % self._puzzle)
- dialog = gtk.Dialog("New game offer",
- parent=None,
- flags=gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
- buttons=(gtk.STOCK_OK, gtk.RESPONSE_ACCEPT,
- gtk.STOCK_NO, gtk.RESPONSE_REJECT))
- alias = _get_contact_alias(self._conn, self._peer_handle)
- label = gtk.Label("%s wants to play with you" % alias)
- label.show()
- dialog.vbox.pack_start(label)
+ builder = gtk.Builder()
+ builder.add_from_file(os.path.join(UI_DIR, 'network_game_offer.ui'))
+ dialog = builder.get_object("dialog")
+ dialog.set_default_response(gtk.RESPONSE_OK)
dialog.connect("response", reply_cb)
+
+ label = builder.get_object("label")
+ info = sudoku.SudokuRater(self._puzzle).difficulty()
+ label.set_text(_("%s wants to play with you.\n\n%s") %
+ (alias, info.to_string()))
+
dialog.run()
dialog.destroy()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]