def build_canvas(self):
        """Construct the PyGame or PyGameCairo canvas for drawing"""
        assert self.game_handler or self.game_name, 'You must specify a game_handler or game_name on your Activity (%r)' % (
            self.game_handler or self.game_name)
        if self.pygame_mode != 'Cairo':
            self._pgc = self.PYGAME_CANVAS_CLASS(*self.game_size)
            self.set_canvas(self._pgc)
            self._pgc.grab_focus()
            self._pgc.connect_game(self.game_handler or self.game_name)
            gtk.gdk.threads_init()
            return self._pgc
        else:
            import hippo
            self._drawarea = gtk.DrawingArea()
            canvas = hippo.Canvas()
            canvas.grab_focus()
            self.set_canvas(canvas)
            self.show_all()

            import pygamecairo
            pygamecairo.install()

            pygamecairo.display.init(canvas)
            app = self.game_handler or self.game_name
            if ':' not in app:
                app += ':main'
            mod_name, fn_name = app.split(':')
            mod = __import__(mod_name, globals(), locals(), [])
            fn = getattr(mod, fn_name)
            fn()
    def build_canvas( self ):
        """Construct the Pygame or PygameCairo canvas for drawing"""
        assert self.game_handler or self.game_name, 'You must specify a game_handler or game_name on your Activity (%r)'%(
            self.game_handler or self.game_name
        )
        if self.pygame_mode != 'Cairo':
            size = max(gtk.gdk.screen_width(), gtk.gdk.screen_height())
            self._pgc = self.PYGAME_CANVAS_CLASS(*(size, size))
            self.set_canvas(self._pgc)
            self._pgc.grab_focus()
            self._pgc.connect_game(self.game_handler or self.game_name)
            # XXX Bad coder, do not hide in a widely subclassed operation
            # map signal does not appear to show up on socket instances
            gtk.gdk.threads_init()
            return self._pgc
        else:
            import hippo
            self._drawarea = gtk.DrawingArea()
            canvas = hippo.Canvas()
            canvas.grab_focus()
            self.set_canvas(canvas)
            self.show_all()

            import pygamecairo
            pygamecairo.install()

            pygamecairo.display.init(canvas)
            app = self.game_handler or self.game_name
            if ':' not in app:
                app += ':main'
            mod_name, fn_name = app.split(':')
            mod = __import__(mod_name, globals(), locals(), [])
            fn = getattr(mod, fn_name)
            fn()
Example #3
0
    def build_canvas(self):
        """Construct the PyGame or PyGameCairo canvas for drawing"""
        assert (
            self.game_handler or self.game_name
        ), "You must specify a game_handler or game_name on your Activity (%r)" % (self.game_handler or self.game_name)
        if self.pygame_mode != "Cairo":
            self._pgc = self.PYGAME_CANVAS_CLASS(*self.game_size)
            self.set_canvas(self._pgc)
            self._pgc.grab_focus()
            self._pgc.connect_game(self.game_handler or self.game_name)
            gtk.gdk.threads_init()
            return self._pgc
        else:
            import hippo

            self._drawarea = gtk.DrawingArea()
            canvas = hippo.Canvas()
            canvas.grab_focus()
            self.set_canvas(canvas)
            self.show_all()

            import pygamecairo

            pygamecairo.install()

            pygamecairo.display.init(canvas)
            app = self.game_handler or self.game_name
            if ":" not in app:
                app += ":main"
            mod_name, fn_name = app.split(":")
            mod = __import__(mod_name, globals(), locals(), [])
            fn = getattr(mod, fn_name)
            fn()
Example #4
0
    def __init__(self, handle):
        super(PyGameActivity, self).__init__(handle)

        self.set_title(self.game_title)

        toolbar = activity.ActivityToolbar(self)
        toolbar.show()
        self.set_toolbox(toolbar)

        def shared_cb(*args, **kwargs):
            mesh.activity_shared(self)

        def joined_cb(*args, **kwargs):
            mesh.activity_joined(self)

        self.connect("shared", shared_cb)
        self.connect("joined", joined_cb)

        if self.get_shared():
            # if set at this point, it means we've already joined (i.e.,
            # launched from Neighborhood)
            joined_cb()

        toolbar.title.unset_flags(gtk.CAN_FOCUS)

        assert self.game_handler or self.game_name, 'You must specify a handler module (%r)' % (
            self.game_handler or self.game_name)

        if self.pygame_mode != 'Cairo':

            self._pgc = PyGameCanvas(*self.game_size)
            self.set_canvas(self._pgc)
            self._pgc.grab_focus()
            self._pgc.connect_game(self.game_handler or self.game_name)
            gtk.gdk.threads_init()

        else:
            self._drawarea = gtk.DrawingArea()
            canvas = hippo.Canvas()
            canvas.grab_focus()
            self.set_canvas(canvas)
            self.show_all()

            import pygamecairo
            pygamecairo.install()

            pygamecairo.display.init(canvas)
            app = self.game_handler or self.game_name
            if ':' not in app:
                app += ':main'
            mod_name, fn_name = app.split(':')
            mod = __import__(mod_name, globals(), locals(), [])
            fn = getattr(mod, fn_name)
            fn()
Example #5
0
    def build_canvas( self ):
        """Construct the Pygame or PygameCairo canvas for drawing"""
        assert self.game_handler or self.game_name, 'You must specify a game_handler or game_name on your Activity (%r)'%(
            self.game_handler or self.game_name
        )

        #hack to show feedback below the canvas for ILF
        main_vbox = gtk.VBox()
        self.statusbar = gtk.Statusbar()
        self.statusbar.push(0, "")
        self.statusbar.set_has_resize_grip(False)
        main_vbox.pack_start(self.statusbar, False, False, 0)
        self.statusbar.show()

        if self.pygame_mode != 'Cairo':
            self._pgc = self.PYGAME_CANVAS_CLASS(*self.game_size)

            #hack
            main_vbox.pack_end(self._pgc)
            main_vbox.show()
            self.set_canvas(main_vbox)
            #self.show_all() my line ;)
            #self.set_canvas(self._pgc)
            self._pgc.grab_focus()
            self._pgc.connect_game(self.game_handler or self.game_name)
            # XXX Bad coder, do not hide in a widely subclassed operation
            # map signal does not appear to show up on socket instances
            gtk.gdk.threads_init()
            return self._pgc
        else:
            import hippo
            self._drawarea = gtk.DrawingArea()
            canvas = hippo.Canvas()
            canvas.grab_focus()

            #hack
            main_vbox.pack_end(self._pgc)
            main_vbox.show()
            self.set_canvas(main_vbox)
            #self.set_canvas(canvas)
            self.show_all()

            import pygamecairo
            pygamecairo.install()

            pygamecairo.display.init(canvas)
            app = self.game_handler or self.game_name
            if ':' not in app:
                app += ':main'
            mod_name, fn_name = app.split(':')
            mod = __import__(mod_name, globals(), locals(), [])
            fn = getattr(mod, fn_name)
            fn()