Quit, Reset per GObject-Signal-Handler
authorJoachim Breitner <mail@joachim-breitner.de>
Wed, 23 May 2007 10:04:28 +0000 (10:04 +0000)
committerJoachim Breitner <mail@joachim-breitner.de>
Wed, 23 May 2007 10:04:28 +0000 (10:04 +0000)
cairoboard.py
ozeanien.py

index 8a4d49d..a4f7267 100644 (file)
@@ -24,6 +24,7 @@ BH_X = 2 * GRIDPAD + 10*GRIDWIDTH
 BH_Y = 5 * GRIDWIDTH
 
 class CairoBoard(gtk.DrawingArea):
+
     def __init__(self,fabric, board):
         assert board
         self.board = board
@@ -44,6 +45,7 @@ class CairoBoard(gtk.DrawingArea):
                 gtk.gdk.POINTER_MOTION_MASK)
         self.connect_after("expose-event",self.do_expose_event)
         self.connect("motion-notify-event",self.hover)
+        self.connect("button-press-event",   self.press)
 
         self.set_size_request(
             2 * GRIDPAD + 9 * GRIDWIDTH + 2 * GRIDWIDTH,
@@ -63,6 +65,17 @@ class CairoBoard(gtk.DrawingArea):
     def reset(self):
         self.queue_draw()
 
+    def press(self, widget, event):
+        # Doppelclick ignorieren
+        if event.type != gtk.gdk.BUTTON_PRESS:
+            return
+
+        if self.event2quit(event):
+            self.emit("quit-clicked")
+
+        if self.event2reset(event):
+            self.emit("reset-clicked")
+
     def do_expose_event(self,widget,event):
         gc = self.window.new_gc()
         gc.set_clip_rectangle(event.area)
@@ -188,6 +201,10 @@ class CairoBoard(gtk.DrawingArea):
         cr.show_text("RESET")
         self.reset_rect = (20 + ax + 20, 1*GRIDPAD + 6*GRIDWIDTH + 10 - h, w, h)
 
+# GObject signals
+gobject.signal_new("quit-clicked", CairoBoard, gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ())
+gobject.signal_new("reset-clicked", CairoBoard, gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ())
+
 
 class CairoSlot:
     def __init__(self, fabric, slot):
index da9bbad..11b936b 100644 (file)
@@ -51,6 +51,8 @@ class Game:
 
         self.boarddraw.connect("button-press-event",   self.press)
         self.boarddraw.connect("button-release-event", self.release)
+        self.boarddraw.connect("quit-clicked", lambda w: self.window.destroy())
+        self.boarddraw.connect("reset-clicked", lambda w: self.reset())
 
         self.boarddraw.show()
 
@@ -63,14 +65,6 @@ class Game:
         if event.type != gtk.gdk.BUTTON_PRESS:
             return
 
-        if self.boarddraw.event2quit(event):
-            self.window.destroy()
-            return
-
-        if self.boarddraw.event2reset(event):
-            self.reset()
-            return
-
         slot = self.boarddraw.event2slot(event)
 
         if self.board.get_state() == SHIPPING: