[gnome-games/sudoku-pygobject] sudoku: pygobject porting



commit 95256499c58a8a25887824dedcce22a69d1773bc
Author: Thomas Hindoe Paaboel Andersen <phomes gmail com>
Date:   Sun Jan 16 03:36:47 2011 +0100

    sudoku: pygobject porting
    
    Port random things the script did not catch. Main window opens now.
    Commented out some broken things for now. Look for #thpa

 gnome-sudoku/src/lib/dialog_swallower.py          |    4 +-
 gnome-sudoku/src/lib/game_selector.py             |   21 +++++-----
 gnome-sudoku/src/lib/gsudoku.py                   |    6 ++-
 gnome-sudoku/src/lib/gtk_goodies/gconf_wrapper.py |   13 +++---
 gnome-sudoku/src/lib/main.py                      |   46 ++++++++++++---------
 gnome-sudoku/src/lib/sudoku_thumber.py            |    7 +--
 6 files changed, 51 insertions(+), 46 deletions(-)
---
diff --git a/gnome-sudoku/src/lib/dialog_swallower.py b/gnome-sudoku/src/lib/dialog_swallower.py
index 0c8f4db..e0b75be 100644
--- a/gnome-sudoku/src/lib/dialog_swallower.py
+++ b/gnome-sudoku/src/lib/dialog_swallower.py
@@ -19,7 +19,7 @@ class SwappableArea (Gtk.Notebook):
         gobject.GObject.__init__(self)
         self.set_show_tabs(False)
         self.set_show_border(False)
-        self.main_page = self.append_page(main_area)
+        self.main_page = self.append_page(main_area, None)
 
     def swallow_window (self, d):
         child = d.get_child()
@@ -28,7 +28,7 @@ class SwappableArea (Gtk.Notebook):
 
     def swallow_widget (self, w):
         w.unparent()
-        return self.append_page(w)
+        return self.append_page(w, None)
 
     def response_cb (self, w, response, data=None):
         Gtk.main_quit()
diff --git a/gnome-sudoku/src/lib/game_selector.py b/gnome-sudoku/src/lib/game_selector.py
index 06875a8..33690a0 100644
--- a/gnome-sudoku/src/lib/game_selector.py
+++ b/gnome-sudoku/src/lib/game_selector.py
@@ -1,6 +1,7 @@
 # -*- coding: utf-8 -*-
 from gi.repository import Gdk
 from gi.repository import Gtk
+from gi.repository import cairo
 import gobject
 import os.path
 import sudoku, saver, sudoku_maker
@@ -115,7 +116,7 @@ class NewOrSavedGameSelector:
     @simple_debug
     def make_new_game_model (self):
         # Description, Pixbuf, Puzzle (str)
-        self.new_game_model = Gtk.ListStore(str, Gdk.Pixbuf, str)
+        self.new_game_model = Gtk.ListStore(str, cairo.Surface, str)
         saved_games_to_exclude = [
             g['game'].split('\n')[0] for g in self.saved_games
             ]
@@ -144,10 +145,10 @@ class NewOrSavedGameSelector:
                     continue
             grid = sudoku.sudoku_grid_from_string(puzzle).grid
             self.new_game_model.append(('<b><i>' + label + '</i></b>',
-                                        sudoku_thumber.make_pixbuf(grid,
-                                                                   None,
-                                                                   color_from_difficulty(diff_val)
-                                                                   ),
+                                        sudoku_thumber.make_surface(grid,
+                                                                    None,
+                                                                    color_from_difficulty(diff_val)
+                                                                    ),
                                         puzzle
                                         ))
 
@@ -181,7 +182,7 @@ class NewOrSavedGameSelector:
     @simple_debug
     def make_saved_game_model (self):
         # Description, Image, Last-Access time (for sorting), Puzzle (jar)
-        self.saved_game_model = Gtk.ListStore(str, Gdk.Pixbuf, int, gobject.TYPE_PYOBJECT)
+        self.saved_game_model = Gtk.ListStore(str, cairo.Surface, int, gobject.TYPE_PYOBJECT)
         for g in self.saved_games:
             game = g['game'].split('\n')[0]
             grid = sudoku.sudoku_grid_from_string(game)
@@ -212,10 +213,10 @@ class NewOrSavedGameSelector:
                 )
             self.saved_game_model.append((
                 desc,
-                sudoku_thumber.make_pixbuf(grid.grid,
-                                           sudoku.sudoku_grid_from_string(g['game'].split('\n')[1].replace(' ', '')).grid,
-                                           color_from_difficulty(sdifficulty.value)
-                                           ),
+                sudoku_thumber.make_surface(grid.grid,
+                                            sudoku.sudoku_grid_from_string(g['game'].split('\n')[1].replace(' ', '')).grid,
+                                            color_from_difficulty(sdifficulty.value)
+                                            ),
                 g['saved_at'],
                 g
                 ))
diff --git a/gnome-sudoku/src/lib/gsudoku.py b/gnome-sudoku/src/lib/gsudoku.py
index cea4363..750da5d 100644
--- a/gnome-sudoku/src/lib/gsudoku.py
+++ b/gnome-sudoku/src/lib/gsudoku.py
@@ -27,7 +27,9 @@ class SudokuNumberGrid (Gtk.AspectFrame):
                 e.x = x
                 e.y = y
                 self.table.attach(e, x, x+1, y, y+1,
-                                  )
+                                  Gtk.AttachOptions.EXPAND | Gtk.AttachOptions.FILL,
+                                  Gtk.AttachOptions.EXPAND | Gtk.AttachOptions.FILL,
+                                  0, 0)
                 self.__entries__[(x, y)] = e
         gobject.GObject.__init__(self, obey_child = False)
         self.set_shadow_type(Gtk.ShadowType.NONE)
@@ -57,7 +59,7 @@ class SudokuNumberGrid (Gtk.AspectFrame):
     def set_bg_color (self, color):
         if type(color) == str:
             try:
-                color = Gdk.color_parse(color)
+                color = Gdk.color_parse(color)[1]
             except:
                 print 'set_bg_color handed Bad color', color
                 return
diff --git a/gnome-sudoku/src/lib/gtk_goodies/gconf_wrapper.py b/gnome-sudoku/src/lib/gtk_goodies/gconf_wrapper.py
index 0078097..3672f2d 100644
--- a/gnome-sudoku/src/lib/gtk_goodies/gconf_wrapper.py
+++ b/gnome-sudoku/src/lib/gtk_goodies/gconf_wrapper.py
@@ -4,7 +4,6 @@
 # by Johan Dahlin
 
 from gi.repository import GConf
-from gconf import VALUE_BOOL, VALUE_INT, VALUE_STRING, VALUE_FLOAT
 from types import StringType, IntType, FloatType, BooleanType
 
 verbose = False
@@ -13,11 +12,11 @@ class GConfError (Exception):
     pass
 
 
-class GConf:
+class GConfWrap:
     def __init__ (self, appname, allowed={}):
         self._domain = '/apps/%s/' % appname
         self._allowed = allowed
-        self._gconf_client = GConf.Client.get_default ()
+        self._gconf_client = GConf.Client.get_default()
 
     def __getitem__ (self, attr):
         return self.get_value (attr)
@@ -66,13 +65,13 @@ class GConf:
         if value == None:
             raise GConfError("gconf_client returned a None!")
         ValueType = value.type
-        if ValueType == VALUE_BOOL:
+        if ValueType == GConf.ValueType.BOOL:
             return value.get_bool ()
-        elif ValueType == VALUE_INT:
+        elif ValueType == GConf.ValueType.INT:
             return value.get_int ()
-        elif ValueType == VALUE_STRING:
+        elif ValueType == GConf.ValueType.STRING:
             return value.get_string ()
-        elif ValueType == VALUE_FLOAT:
+        elif ValueType == GConf.ValueType.FLOAT:
             return value.get_float ()
    
     def set_value (self, key, value):
diff --git a/gnome-sudoku/src/lib/main.py b/gnome-sudoku/src/lib/main.py
index cf3e52b..246d8a3 100644
--- a/gnome-sudoku/src/lib/main.py
+++ b/gnome-sudoku/src/lib/main.py
@@ -11,6 +11,7 @@ import threading
 import gobject
 from gi.repository import Gdk
 from gi.repository import Gtk
+from gi.repository import cairo
 from gi.repository import Pango
 from gettext import gettext as _
 from gettext import ngettext
@@ -30,7 +31,8 @@ from simple_debug import simple_debug, options
 
 ICON_FACTORY = Gtk.IconFactory()
 STOCK_PIXBUFS = {}
-for filename, stock_id in [('footprints.png', 'tracks'), ]:
+for filename, stock_id in []:
+#thpa for filename, stock_id in [('footprints.png', 'tracks'), ]:
     try:
         pb = Gdk.pixbuf_new_from_file(os.path.join(IMAGE_DIR, filename))
     except gobject.GError, e:
@@ -41,9 +43,9 @@ for filename, stock_id in [('footprints.png', 'tracks'), ]:
     ICON_FACTORY.add(stock_id, iconset)
     ICON_FACTORY.add_default()
 
-Gtk.stock_add([('tracks',
-                _('Track moves'),
-                0, 0, ""), ])
+#thpa Gtk.stock_add([('tracks',
+#thpa                 _('Track moves'),
+#thpa                 0, 0, ""), ])
 
 def inactivate_new_game_etc (fun):
     def inactivate_new_game_etc_ (ui, *args, **kwargs):
@@ -63,7 +65,7 @@ def inactivate_new_game_etc (fun):
             '/MenuBar/Tools/Tracker',
             ]
         for p in paths:
-            action = ui.uimanager.get_action(p)
+            action = None #thpa ui.uimanager.get_action(p)
             if not action:
                 action = ui.uimanager.get_widget(p)
             if not action:
@@ -72,7 +74,7 @@ def inactivate_new_game_etc (fun):
                 action.set_sensitive(False)
         ret = fun(ui, *args, **kwargs)
         for p in paths:
-            action = ui.uimanager.get_action(p)
+            action = None #thpa ui.uimanager.get_action(p)
             if not action:
                 action = ui.uimanager.get_widget(p)
             if not action:
@@ -153,9 +155,10 @@ class UI (gconf_wrapper.GConfWrapper):
         and allow a tester to set up a game programmatically.
         """
         gconf_wrapper.GConfWrapper.__init__(self,
-                                            gconf_wrapper.GConf('gnome-sudoku')
+                                            gconf_wrapper.GConfWrap('gnome-sudoku')
                                             )
         self.setup_gui()
+
         self.timer = timer.ActiveTimer(self.w)
         self.gsd.set_timer(self.timer)
         self.won = False
@@ -321,20 +324,21 @@ class UI (gconf_wrapper.GConfWrapper):
         # Add menu bar and toolbar...
         mb = self.uimanager.get_widget('/MenuBar')
         mb.show()
-        self.vb.pack_start(mb, fill = False, expand = False)
+        self.vb.pack_start(mb, False, False, 0)
         self.tb = self.uimanager.get_widget('/Toolbar')
-        self.vb.pack_start(self.tb, fill = False, expand = False)
+        self.vb.pack_start(self.tb, False, False, 0)
         self.main_area = Gtk.HBox()
         self.swallower = dialog_swallower.SwappableArea(self.main_area)
         self.swallower.show()
-        self.vb.pack_start(self.swallower, True, padding = 12)
-        self.main_area.pack_start(self.gsd, padding = 6)
+        self.vb.pack_start(self.swallower, True, True, 12)
+        self.main_area.pack_start(self.gsd, True, True, 6)
         self.main_actions.set_visible(True)
         self.game_box = Gtk.VBox()
         self.main_area.show()
         self.vb.show()
         self.game_box.show()
-        self.main_area.pack_start(self.game_box, False, padding = 12)
+        self.main_area.pack_start(self.game_box, False, False, 12)
+        self.w.show() #thpa: this, or: error in gtk_widget_real_realize (!gtk_widget_get_has_window (widget))
         self.w.add(self.vb)
 
     def setup_toggles (self):
@@ -742,13 +746,14 @@ class TrackerBox (Gtk.VBox):
         self.tinfo.ui = self
         self.vb = self.builder.get_object('vbox1')
         self.vb.unparent()
-        self.pack_start(self.vb, expand = True, fill = True)
+        self.pack_start(self.vb, True, True, 0)
         self.setup_actions()
         self.setup_tree()
         self.show_all()
 
     @simple_debug
     def reset (self):
+        return #thpa
 
         for tree in self.tracker_model:
             if tree[0] > -1:
@@ -758,22 +763,23 @@ class TrackerBox (Gtk.VBox):
 
     @simple_debug
     def setup_tree (self):
+        return #thpa
         self.tracker_tree = self.builder.get_object('TrackerTreeView')
-        self.tracker_model = Gtk.ListStore(int, Gdk.Pixbuf, str)
+        self.tracker_model = Gtk.ListStore(int, cairo.Surface, str)
         self.tracker_model.set_sort_column_id(0, Gtk.SortType.ASCENDING)
         self.tracker_tree.set_model(self.tracker_model)
         col1 = Gtk.TreeViewColumn("", Gtk.CellRendererPixbuf(), pixbuf = 1)
         rend = Gtk.CellRendererText()
         col2 = Gtk.TreeViewColumn("", rend, text = 2)
-        col2.set_cell_data_func(rend, self.draw_tracker_name)
+        col2.set_cell_data_func(rend, self.draw_tracker_name, None)
         self.tracker_tree.append_column(col2)
         self.tracker_tree.append_column(col1)
         # Our initial row...
-        pixbuf = self.pixbuf_transform_color(
-            STOCK_PIXBUFS['tracks'],
-            (0, 0, 0)
-            )
-        self.tracker_model.append([-1, pixbuf, _('Untracked')])
+#thpa        pixbuf = self.pixbuf_transform_color(
+#thpa            STOCK_PIXBUFS['tracks'],
+#thpa            (0, 0, 0)
+#thpa            )
+#thpa        self.tracker_model.append([-1, pixbuf, _('Untracked')])
         self.tracker_tree.get_selection().connect('changed', self.selection_changed_cb)
 
     @simple_debug
diff --git a/gnome-sudoku/src/lib/sudoku_thumber.py b/gnome-sudoku/src/lib/sudoku_thumber.py
index ec57a23..4f67824 100644
--- a/gnome-sudoku/src/lib/sudoku_thumber.py
+++ b/gnome-sudoku/src/lib/sudoku_thumber.py
@@ -129,15 +129,12 @@ def draw_sudoku (cr, sudoku, played, size, offset_x = 0, offset_y = 0, border_co
                            pos[y] + offset_y + (height/2.0))
                 cr.show_text(letter)
 
-def make_pixbuf (sudoku, played, border_color, line_color = (0.4, 0.4, 0.4)):
+def make_surface (sudoku, played, border_color, line_color = (0.4, 0.4, 0.4)):
     size = 126
     surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, size, size)
     cr = cairo.Context(surface)
     draw_sudoku(cr, sudoku, played,  size, 0, 0, border_color, line_color)
-    pixbuf = Gdk.pixbuf_new_from_data(surface.get_data(), Gdk.COLORSPACE_RGB,
-                                          True, 8, surface.get_width(), surface.get_height(), surface.get_stride())
-    del surface
-    return pixbuf
+    return surface
 
 if __name__ == "__main__":
     sudoku = [[0, 0, 2, 3, 4, 5, 6, 0, 0]] * SUDOKU_SIZE



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]