[gnome-games/gnome-3-0] sudoku: gi port starts



commit dee1a5e5c3841f1f6575f4955adcbde55d26c03c
Author: John Stowers <john stowers gmail com>
Date:   Sat Apr 9 11:08:43 2011 +1200

    sudoku: gi port starts

 gnome-sudoku/src/lib/main.py           |   26 ++++++++++++++------------
 gnome-sudoku/src/lib/number_box.py     |   32 +++++++++++++++++++++-----------
 gnome-sudoku/src/lib/sudoku_thumber.py |    8 +++-----
 3 files changed, 38 insertions(+), 28 deletions(-)
---
diff --git a/gnome-sudoku/src/lib/main.py b/gnome-sudoku/src/lib/main.py
index c8389de..14e741b 100644
--- a/gnome-sudoku/src/lib/main.py
+++ b/gnome-sudoku/src/lib/main.py
@@ -835,18 +835,20 @@ class TrackerBox (Gtk.VBox):
 
     @simple_debug
     def pixbuf_transform_color (self, pixbuf, color):
-        """Return new pixbuf with color changed to color"""
-        pixbuf_str = pixbuf.get_pixels()
-        pixbuf_str_new = ""
-
-        for alpha in pixbuf_str[3::4]:
-            pixbuf_str_new += chr(int(color[0]*255))
-            pixbuf_str_new += chr(int(color[1]*255))
-            pixbuf_str_new += chr(int(color[2]*255))
-            pixbuf_str_new += alpha
-
-        return GdkPixbuf.Pixbuf.new_from_data(pixbuf_str_new, GdkPixbuf.Colorspace.RGB, True, 8,
-                                            pixbuf.get_width(), pixbuf.get_height(), pixbuf.get_rowstride())
+        return pixbuf
+
+#        """Return new pixbuf with color changed to color"""
+#        pixbuf_str = pixbuf.get_pixels()
+#        pixbuf_str_new = ""
+#
+#        for alpha in pixbuf_str[3::4]:
+#            pixbuf_str_new += chr(int(color[0]*255))
+#            pixbuf_str_new += chr(int(color[1]*255))
+#            pixbuf_str_new += chr(int(color[2]*255))
+#            pixbuf_str_new += alpha
+#
+#        return GdkPixbuf.Pixbuf.new_from_data(pixbuf_str_new, GdkPixbuf.Colorspace.RGB, True, 8,
+#                                            pixbuf.get_width(), pixbuf.get_height(), pixbuf.get_rowstride())
 
     @simple_debug
     def find_tracker (self, tracker_id):
diff --git a/gnome-sudoku/src/lib/number_box.py b/gnome-sudoku/src/lib/number_box.py
index 6ebded8..b4f1a5a 100644
--- a/gnome-sudoku/src/lib/number_box.py
+++ b/gnome-sudoku/src/lib/number_box.py
@@ -518,13 +518,21 @@ class NumberBox (Gtk.Widget):
         # Create a new Gdk.Window which we can draw on.
         # Also say that we want to receive exposure events by setting
         # the event_mask
+        #
+        # Its a little convoluted to construct the window this way, nevertheless note
+        #   "fields in GdkWindowAttr not covered by a bit in this enum are required;
+        #    for example, the width/height, wclass, and window_type fields are required,
+        #    they have no corresponding flag in GdkWindowAttributesType.
+        attr = Gdk.WindowAttr()
+        attr.width = self.allocation.width
+        attr.height = self.allocation.height
+        attr.window_type = Gdk.WindowType.CHILD
+        attr.wclass = Gdk.WindowWindowClass.OUTPUT
+        attr.event_mask = self.get_events() | Gdk.EventMask.EXPOSURE_MASK
+
         self.window = Gdk.Window(
-            self.get_parent_window(),
-            width = self.allocation.width,
-            height = self.allocation.height,
-            window_type = Gdk.WindowType.CHILD,
-            wclass = Gdk.WindowWindowClass.OUTPUT,
-            event_mask = self.get_events() | Gdk.EventMask.EXPOSURE_MASK)
+            self.get_parent_window(), attr,
+            Gdk.WindowAttributesType.WMCLASS)
 
         # Associate the Gdk.Window with ourselves, Gtk+ needs a reference
         # between the widget and the gdk window
@@ -532,12 +540,13 @@ class NumberBox (Gtk.Widget):
 
         # Attach the style to the Gdk.Window, a style contains colors and
         # GC contextes used for drawing
-        self.style.attach(self.window)
+        #self.style.attach(self.window)
 
         # The default color of the background should be what
         # the style (theme engine) tells us.
-        self.style.set_background(self.window, Gtk.StateType.NORMAL)
-        self.window.move_resize(*self.allocation)
+        #self.style.set_background(self.window, Gtk.StateType.NORMAL)
+
+        self.window.move_resize(self.allocation.x, self.allocation.y, self.allocation.width, self.allocation.height)
 
     def do_unrealize (self):
         # The do_unrealized method is responsible for freeing the GDK resources
@@ -569,14 +578,15 @@ class NumberBox (Gtk.Widget):
         # If we're realized, move and resize the window to the
         # requested coordinates/positions
         if self.get_realized():
-            self.window.move_resize(*allocation)
+            x, y, w, h = self.allocation.x, self.allocation.y, self.allocation.width, self.allocation.height
+            self.window.move_resize(self.allocation.x,self.allocation.y,self.allocation.width,self.allocation.height)
 
     def do_expose_event(self, event):
         # The do_expose_event is called when the widget is asked to draw itself
         # Remember that this will be called a lot of times, so it's usually
         # a good idea to write this code as optimized as it can be, don't
         # Create any resources in here.
-        x, y, w, h = self.allocation
+        x, y, w, h = self.allocation.x, self.allocation.y, self.allocation.width, self.allocation.height
         cr = self.window.cairo_create()
         self.draw_background_color(cr, w, h)
         if self.is_focus():
diff --git a/gnome-sudoku/src/lib/sudoku_thumber.py b/gnome-sudoku/src/lib/sudoku_thumber.py
index a9e2b13..482ffcd 100644
--- a/gnome-sudoku/src/lib/sudoku_thumber.py
+++ b/gnome-sudoku/src/lib/sudoku_thumber.py
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-from gi.repository import Gtk,GdkPixbuf
+from gi.repository import Gtk,Gdk,GdkPixbuf
 import cairo
 
 SUDOKU_SIZE = 9
@@ -133,8 +133,7 @@ def make_pixbuf (sudoku, played, border_color, line_color = (0.4, 0.4, 0.4)):
     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 = GdkPixbuf.Pixbuf.new_from_data(surface.get_data(), GdkPixbuf.Colorspace.RGB,
-                                          True, 8, surface.get_width(), surface.get_height(), surface.get_stride())
+    pixbuf = Gdk.pixbuf_get_from_surface(surface, 0, 0, surface.get_width(), surface.get_height())
     del surface
     return pixbuf
 
@@ -149,8 +148,7 @@ if __name__ == "__main__":
     surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 750, 750)
     cr = cairo.Context(surface)
     draw_sudoku(cr, sudoku, played,  size, 100, 250, border_color, line_color)
-    pb = GdkPixbuf.Pixbuf.new_from_data(surface.get_data(), GdkPixbuf.Colorspace.RGB,
-                                          True, 8, surface.get_width(), surface.get_height(), surface.get_stride())
+    pb = Gdk.pixbuf_get_from_surface(surface, 0, 0, surface.get_width(), surface.get_height())
     del surface
 
 



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