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

Commit 3bcb85c352b6bf86dda46f2379bbd993d78832b6

Remove asserts and properly reinitialize PyGame display, if needed

The asserts where there to 1. avoid calling run_pygame more than once,
and 2. initialize PyGame display only after SDL_WINDOWID environment
variable was set.

This commit removes the asserts.  1. is solved using a _initialized
flag.  And 2. is solved by checking if the display was set, and using
pygame.display.quit to uninitialize it.
  
2727
2828 self._socket = Gtk.Socket()
2929 self.add(self._socket)
30
31 self._initialized = False
32
3033 self.show_all()
3134
3235 def run_pygame(self, main_fn):
4040 GObject.idle_add(self._run_pygame_cb, main_fn)
4141
4242 def _run_pygame_cb(self, main_fn):
43 assert pygame.display.get_surface() is None, "PygameCanvas.run_pygame can only be called once."
43 # PygameCanvas.run_pygame can only be called once
44 if self._initialized:
45 return
4446
4547 # Preinitialize Pygame with the X window ID.
46 assert pygame.display.get_init() == False, "Pygame must not be initialized before calling PygameCanvas.run_pygame."
4748 os.environ['SDL_WINDOWID'] = str(self._socket.get_id())
49 if pygame.display.get_surface() is not None:
50 pygame.display.quit()
4851 pygame.init()
4952
5053 # Restore the default cursor.
6262
6363 # Run the Pygame main loop.
6464 main_fn()
65
66 self._initialized = True
6567 return False
6668
6769 def get_pygame_widget(self):