Exemplo n.º 1
0
    def _run_pygame_cb(self, main_fn):
        assert pygame.display.get_surface(
        ) is None, "PygameCanvas.run_pygame can only be called once."

        # Preinitialize Pygame with the X window ID.
        assert pygame.display.get_init(
        ) == False, "Pygame must not be initialized before calling PygameCanvas.run_pygame."
        os.environ['SDL_WINDOWID'] = str(self._socket.get_id())
        pygame.init()

        # Restore the default cursor.
        #self._socket.get_window().set_cursor(None)
        self._socket.window.set_cursor(None)

        # Initialize the Pygame window.
        r = self.get_allocation()
        pygame.display.set_mode((r.width, r.height), pygame.RESIZABLE)

        # Hook certain Pygame functions with GTK equivalents.
        translator = event.Translator(self._mainwindow, self)
        translator.hook_pygame()

        # Run the Pygame main loop.
        main_fn()
        return False
Exemplo n.º 2
0
    def __init__(self,
                 activity,
                 pointer_hint=True,
                 main=None,
                 modules=[pygame]):
        GObject.GObject.__init__(self)

        global CANVAS
        assert CANVAS == None, "Only one PygameCanvas can be created, ever."
        CANVAS = self

        # Initialize Events translator before widget gets "realized".
        self.translator = event.Translator(activity, self)

        self._activity = activity
        self._main = main
        self._modules = modules

        self.set_can_focus(True)

        self._socket = Gtk.Socket()
        self._socket.connect('realize', self._realize_cb)
        self.add(self._socket)

        self.show_all()
Exemplo n.º 3
0
    def __init__(self, mainwindow, pointer_hint=True):
        gtk.EventBox.__init__(self)

        global CANVAS
        assert CANVAS == None, "Only one PygameCanvas can be created, ever."
        CANVAS = self

        # Initialize Events translator before widget gets "realized".
        self.translator = event.Translator(mainwindow, self)

        self._mainwindow = mainwindow

        self.set_flags(gtk.CAN_FOCUS)

        self._socket = gtk.Socket()
        self.add(self._socket)
        self.show_all()
Exemplo n.º 4
0
    def __init__(self, mainwindow, pointer_hint=True):
        GObject.GObject.__init__(self)

        global CANVAS
        assert CANVAS == None, "Only one PygameCanvas can be created, ever."
        CANVAS = self

        # Initialize Events translator before widget gets "realized".
        self.translator = event.Translator(mainwindow, self)

        self._mainwindow = mainwindow

        self.set_can_focus(True)

        self._socket = Gtk.Socket()
        self.add(self._socket)
        self.show_all()