Web · Wiki · Activities · Blog · Lists · Chat · Meeting · Bugs · Git · Translate · Archive · People · Donate

Commit d3f13b941ac97695fdf83efb272f41f468c88bf7

Fixes for event handling issues.  Also clean up the test activity slightly.
  
77CANVAS = None
88
99class PygameCanvas(gtk.EventBox):
10 def __init__(self, mainwindow):
10
11 """
12 mainwindow is the activity intself.
13 """
14 def __init__(self, mainwindow, pointer_hint = True):
1115 gtk.EventBox.__init__(self)
1216
1317 global CANVAS
1418 assert CANVAS == None, "Only one PygameCanvas can be created, ever."
1519 CANVAS = self
1620
21 # Initialize Events translator before widget gets "realized".
22 self.translator = event.Translator(mainwindow, self)
23
1724 self._mainwindow = mainwindow
1825
1926 self.set_flags(gtk.CAN_FOCUS)
4545 pygame.init()
4646
4747 # Restore the default cursor.
48 self._socket.get_window().set_cursor(None)
48 self._socket.window.set_cursor(None)
4949
5050 # Initialize the Pygame window.
5151 r = self.get_allocation()
5252 pygame.display.set_mode((r.width, r.height), pygame.RESIZABLE)
5353
5454 # Hook certain Pygame functions with GTK equivalents.
55 translator = event.Translator(self._mainwindow, self)
56 translator.hook_pygame()
55 self.translator.hook_pygame()
5756
5857 # Run the Pygame main loop.
5958 main_fn()
  
4444 self._inner_evb = inner_evb
4545
4646 # Enable events
47 self._mainwindow.set_events(
47 # (add instead of set here because the main window is already realized)
48 self._mainwindow.add_events(
4849 gtk.gdk.KEY_PRESS_MASK | \
4950 gtk.gdk.KEY_RELEASE_MASK \
5051 )
8989 pygame.mouse.get_pos = self._get_mouse_pos
9090
9191 def _expose_cb(self, event, widget):
92 pygame.event.post(pygame.event.Event(pygame.VIDEOEXPOSE))
92 if pygame.display.get_init():
93 pygame.event.post(pygame.event.Event(pygame.VIDEOEXPOSE))
9394 return True
9495
9596 def _resize_cb(self, widget, event):
  
2626
2727 # Build the Pygame canvas.
2828 self._pygamecanvas = sugargame.canvas.PygameCanvas(self)
29
2930 # Note that set_canvas implicitly calls read_file when resuming from the Journal.
3031 self.set_canvas(self._pygamecanvas)
3132
32 # Start the game running.
33 # Start the game running (self.game.run is called when the activity constructor returns).
3334 self._pygamecanvas.run_pygame(self.game.run)
3435
3536 def build_toolbar(self):
4141
4242 toolbar = gtk.Toolbar()
4343 toolbar.insert(stop_play, 0)
44 toolbar.insert(gtk.SeparatorToolItem(), 1)
4544
4645 toolbox = sugar.activity.activity.ActivityToolbox(self)
4746 toolbox.add_toolbar(_("Pygame"), toolbar)