diff options
author | Agustin Zubiaga <aguz@sugarlabs.org> | 2012-07-10 00:10:09 (GMT) |
---|---|---|
committer | Agustin Zubiaga <aguz@sugarlabs.org> | 2012-07-10 00:10:09 (GMT) |
commit | 7877567fbb46120a6bb4ba25b427abc00cced424 (patch) | |
tree | 9d6416ec8f949d50e128ca749195c10b6a82e843 | |
parent | 6470362d3540d2d5519fa2922af87a32bc4569de (diff) |
Fixing all of stupid bugs
-rw-r--r-- | activity.py | 5 | ||||
-rw-r--r-- | game.py | 62 |
2 files changed, 32 insertions, 35 deletions
diff --git a/activity.py b/activity.py index b0474bc..bb452f3 100644 --- a/activity.py +++ b/activity.py @@ -21,7 +21,6 @@ import random from gi.repository import Gtk -from gi.repository import Gdk from sugar3.activity import activity from sugar3.activity.widgets import ActivityButton @@ -60,8 +59,6 @@ class Guess(activity.Activity): self.set_toolbar_box(toolbarbox) self._eventbox = Gtk.EventBox() - self._eventbox.modify_bg(Gtk.StateFlags.NORMAL, - Gdk.color_parse('white')) self._game = Game() self._eventbox.add(self._game) self.set_canvas(self._eventbox) @@ -69,4 +66,4 @@ class Guess(activity.Activity): reload_btn.connect('clicked', self._game.reload) self.show_all() - self._game.add_vessels(3, random.randrange(1, 4)) + self._game.add_glasses(3, random.randrange(1, 4)) @@ -34,8 +34,7 @@ class Game(Gtk.Fixed): super(Game, self).__init__() self._background = GdkPixbuf.Pixbuf.new_from_file_at_size( - 'icons/table.svg', - Gdk.Screen.width(), Gdk.Screen.height()) + 'icons/table.svg', Gdk.Screen.width(), Gdk.Screen.height()) bg_image = Gtk.Image.new_from_pixbuf(self._background) self.put(bg_image, 0, 0) @@ -46,10 +45,10 @@ class Game(Gtk.Fixed): self.score = 0 - self._vessels_box = Gtk.Box() - self._vessels_box.set_spacing(30) - self._vessels_box.positioned = False - self.put(self._vessels_box, 0, 0) + self._glasses_box = Gtk.Box() + self._glasses_box.set_spacing(30) + self._glasses_box.positioned = False + self.put(self._glasses_box, 0, 0) self._image_ball = None @@ -67,11 +66,11 @@ class Game(Gtk.Fixed): self._smily.set_from_pixbuf(pixbuf) self.clear(self._image_ball) - self._vessels_box.positioned = False + self._glasses_box.positioned = False self.queue_draw() random.seed() - self.add_vessels(3, random.randrange(1, 4)) + self.add_glasses(3, random.randrange(1, 4)) def lose(self): if not self.score <= 0: @@ -90,34 +89,34 @@ class Game(Gtk.Fixed): self._smily.set_from_pixbuf(pixbuf) def clear(self, ball=None): - for widget in self._vessels_box.get_children(): - self._vessels_box.remove(widget) + for widget in self._glasses_box.get_children(): + self._glasses_box.remove(widget) widget.destroy() if ball: self.remove(ball) - def add_vessels(self, vessels, ball): + def add_glasses(self, glasses, ball): ball -= 1 - self._vessels_box.vessels_list = [] - for i in range(vessels): - _vessel = Vessel(i == ball, self, self._vessels_box) - self._vessels_box.vessels_list.append(_vessel) - self._vessels_box.add(_vessel) + self._glasses_box.glasses_list = [] + for i in range(glasses): + _glass = glass(i == ball, self, self._glasses_box) + self._glasses_box.glasses_list.append(_glass) + self._glasses_box.add(_glass) - self._vessels_box.show_all() + self._glasses_box.show_all() def _draw_event_cb(self, widget, ctx): alloc = widget.get_allocation() - if not self._vessels_box.positioned: - vessels_box_alloc = self._vessels_box.get_allocation() + if not self._glasses_box.positioned: + glasses_box_alloc = self._glasses_box.get_allocation() - xpos = (alloc.width - vessels_box_alloc.width) / 2 - ypos = (alloc.height - vessels_box_alloc.height) / 2 + xpos = (alloc.width - glasses_box_alloc.width) / 2 + ypos = (alloc.height - glasses_box_alloc.height) / 2 - self.move(self._vessels_box, xpos, ypos) + self.move(self._glasses_box, xpos, ypos) - self._vessels_box.positioned = True + self._glasses_box.positioned = True if not self._smily.positioned: smily_alloc = self._smily.get_allocation() @@ -128,10 +127,10 @@ class Game(Gtk.Fixed): self._smily.positioned = True -class Vessel(Gtk.EventBox): +class glass(Gtk.EventBox): def __init__(self, ball, game, parent): - super(Vessel, self).__init__() + super(glass, self).__init__() self._image = Gtk.Image() self._image.set_from_file('icons/vessel.svg') @@ -157,18 +156,19 @@ class Vessel(Gtk.EventBox): self._clicked = bool(widget) self._timeout = GObject.timeout_add(40, self._move_up) else: - for vessel in self._parent.vessels_list: - if vessel._ball: - vessel.selected(None, None) + for glass in self._parent.glasses_list: + if glass._ball: + glass.selected(None, None) def _move_up(self): alloc = self._parent.get_allocation() if not self._image_ball.shown: + glass_alloc = self.get_allocation() image_alloc = self._image_ball.get_allocation() - xpos = alloc.x + 5 - ypos = alloc.y + alloc.height - image_alloc.height - 30 + xpos = glass_alloc.x + 5 + ypos = glass_alloc.y + glass_alloc.height - image_alloc.height - 30 self._game.move(self._image_ball, xpos, ypos) self._image_ball.show() @@ -204,6 +204,6 @@ class Window(Gtk.Window): if __name__ == '__main__': window = Window() - window._game.add_vessels(3, random.randrange(1, 4)) + window._game.add_glasses(3, random.randrange(1, 4)) Gtk.main() |