Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAgustin Zubiaga <aguz@sugarlabs.org>2012-07-10 23:30:41 (GMT)
committer Agustin Zubiaga <aguz@sugarlabs.org>2012-07-10 23:30:41 (GMT)
commitf3d6d180825d03582446004b1c895ca745888501 (patch)
treeb77d596c4781790c259aa472749560ab8d270621
parentf297920a5a5f7adb886acae097bcda9703c4ed7a (diff)
Sensitive in restart button
-rw-r--r--activity.py14
-rw-r--r--game.py13
2 files changed, 21 insertions, 6 deletions
diff --git a/activity.py b/activity.py
index bb452f3..d9140fd 100644
--- a/activity.py
+++ b/activity.py
@@ -21,6 +21,7 @@
import random
from gi.repository import Gtk
+from gettext import gettext as _
from sugar3.activity import activity
from sugar3.activity.widgets import ActivityButton
@@ -45,8 +46,10 @@ class Guess(activity.Activity):
separator = Gtk.SeparatorToolItem()
toolbarbox.toolbar.insert(separator, -1)
- reload_btn = ToolButton('gtk-refresh')
- toolbarbox.toolbar.insert(reload_btn, -1)
+ self._reload_btn = ToolButton('gtk-refresh')
+ self._reload_btn.set_sensitive(False)
+ self._reload_btn.set_tooltip(_('Restart'))
+ toolbarbox.toolbar.insert(self._reload_btn, -1)
separator = Gtk.SeparatorToolItem()
separator.set_draw(False)
@@ -60,10 +63,15 @@ class Guess(activity.Activity):
self._eventbox = Gtk.EventBox()
self._game = Game()
+ self._game.connect('won', self._win_or_lose_cb)
+ self._game.connect('lost', self._win_or_lose_cb)
self._eventbox.add(self._game)
self.set_canvas(self._eventbox)
- reload_btn.connect('clicked', self._game.reload)
+ self._reload_btn.connect('clicked', self._game.reload)
self.show_all()
self._game.add_glasses(3, random.randrange(1, 4))
+
+ def _win_or_lose_cb(self, widget):
+ self._reload_btn.set_sensitive(True)
diff --git a/game.py b/game.py
index e175bff..1f17a37 100644
--- a/game.py
+++ b/game.py
@@ -32,6 +32,10 @@ SMILY_SIZE = 80
class Game(Gtk.Fixed):
+ __gsignals__ = {
+ 'won': (GObject.SignalFlags.RUN_FIRST, None, []),
+ 'lost': (GObject.SignalFlags.RUN_FIRST, None, [])}
+
def __init__(self):
super(Game, self).__init__()
@@ -63,6 +67,7 @@ class Game(Gtk.Fixed):
self.connect('draw', self._draw_event_cb)
def reload(self, widget):
+ widget.set_sensitive(False)
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size('icons/neutral.svg',
SMILY_SIZE, SMILY_SIZE)
self._smily.set_from_pixbuf(pixbuf)
@@ -82,6 +87,7 @@ class Game(Gtk.Fixed):
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size('icons/lose.svg',
SMILY_SIZE, SMILY_SIZE)
self._smily.set_from_pixbuf(pixbuf)
+ self.emit('lost')
def win(self):
self.score += 10
@@ -89,6 +95,7 @@ class Game(Gtk.Fixed):
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size('icons/win.svg',
SMILY_SIZE, SMILY_SIZE)
self._smily.set_from_pixbuf(pixbuf)
+ self.emit('won')
def clear(self, ball=None):
for widget in self._glasses_box.get_children():
@@ -102,7 +109,7 @@ class Game(Gtk.Fixed):
ball -= 1
self._glasses_box.glasses_list = []
for i in range(glasses):
- _glass = glass(i == ball, self, self._glasses_box)
+ _glass = Glass(i == ball, self, self._glasses_box)
self._glasses_box.glasses_list.append(_glass)
self._glasses_box.add(_glass)
@@ -129,10 +136,10 @@ class Game(Gtk.Fixed):
self._smily.positioned = True
-class glass(Gtk.EventBox):
+class Glass(Gtk.EventBox):
def __init__(self, ball, game, parent):
- super(glass, self).__init__()
+ super(Glass, self).__init__()
self._image = Gtk.Image()
self._image.set_from_file('icons/vessel.svg')