def __init__(self, handle): # i18n: bundle_path = os.environ["SUGAR_BUNDLE_PATH"] i18n_path = os.path.join(bundle_path, "po") gettext.bindtextdomain("messages", i18n_path) gettext.textdomain("messages") activity.Activity.__init__(self, handle) self.canvas = PygameCanvas(self) self.set_canvas(self.canvas) self.chess = CeibalChess() self.chess.set_close_callback(self.close) self.show() gobject.idle_add(self.start_cb, None)
def __init__(self, handle): super(GenioActivity, self).__init__(handle) # Build the activity toolbar. #self.build_toolbar() # Create the game instance. self.game = MainClass() # Build the Pygame canvas. self._pygamecanvas = PygameCanvas(self) # Note that set_canvas implicitly calls read_file when # resuming from the Journal. self.set_canvas(self._pygamecanvas) self._pygamecanvas.grab_focus() # Start the game running. self._pygamecanvas.run_pygame(self.game.main)
class ChessActivity(activity.Activity): """ ChessActivity provides the basic configuration for setting up and running Ceibal-Chess as an Activity and for embedding pygame in a gtk window. For all the methods of activity.Activity please visit: http://api.sugarlabs.org/epydocs/sugar.activity.activity-pysrc.html For the logic behind the GTK-pygame wrapping, visit: http://wiki.sugarlabs.org/go/Development_Team/Sugargame """ def __init__(self, handle): # i18n: bundle_path = os.environ["SUGAR_BUNDLE_PATH"] i18n_path = os.path.join(bundle_path, "po") gettext.bindtextdomain("messages", i18n_path) gettext.textdomain("messages") activity.Activity.__init__(self, handle) self.canvas = PygameCanvas(self) self.set_canvas(self.canvas) self.chess = CeibalChess() self.chess.set_close_callback(self.close) self.show() gobject.idle_add(self.start_cb, None) # rc = CeibalChess().start(1200, 900) # sys.exit(rc) def start_cb(self, param): log.info("Starting pygame widget...") self.canvas.run_pygame(self.chess.start) def read_file(self, filepath): pass def write_file(self, filepath): pass def can_close(self): log.info("Activity requested to stop...") self.chess.stop() return True
class ChessActivity(activity.Activity): ''' ChessActivity provides the basic configuration for setting up and running Ceibal-Chess as an Activity and for embedding pygame in a gtk window. For all the methods of activity.Activity please visit: http://api.sugarlabs.org/epydocs/sugar.activity.activity-pysrc.html For the logic behind the GTK-pygame wrapping, visit: http://wiki.sugarlabs.org/go/Development_Team/Sugargame ''' def __init__(self, handle): # i18n: bundle_path = os.environ["SUGAR_BUNDLE_PATH"] i18n_path = os.path.join(bundle_path, "po") gettext.bindtextdomain("messages", i18n_path) gettext.textdomain("messages") activity.Activity.__init__(self, handle) self.canvas = PygameCanvas(self) self.set_canvas(self.canvas) self.chess = CeibalChess() self.chess.set_close_callback(self.close) self.show() gobject.idle_add(self.start_cb, None) #rc = CeibalChess().start(1200, 900) #sys.exit(rc) def start_cb(self, param): log.info("Starting pygame widget...") self.canvas.run_pygame(self.chess.start) def read_file(self, filepath): pass def write_file(self, filepath): pass def can_close(self): log.info("Activity requested to stop...") self.chess.stop() return True
class MegamenteActivity(activity.Activity): def __init__(self, handle): super(MegamenteActivity, self).__init__(handle) # Build the activity toolbar. #self.build_toolbar() # Create the game instance. self.game = MainClass() # Build the Pygame canvas. self._pygamecanvas = PygameCanvas(self) # Note that set_canvas implicitly calls read_file when # resuming from the Journal. self.set_canvas(self._pygamecanvas) self._pygamecanvas.grab_focus() # Start the game running. self._pygamecanvas.run_pygame(self.game.main)
def __init__(self, handle): self.game_init = False # Tells if game engine was initialized self.loaded_game = None Activity.__init__(self, handle) # Creates the activiy box for toolbars self.toolbox = ActivityToolbox(self) self.set_toolbox(self.toolbox) self.toolbox.show() # Retrieves the Activity standard toolbar self.activity_toolbar = self.toolbox.get_activity_toolbar() # Creates other toolbars # Game toolbar gets created on demand # Library toolbar gets created on demand self.guides_toolbar = gtk.Toolbar() self.credits_toolbar = gtk.Toolbar() self.indexes = ["activity"] # right now only activity toolbar # Create startup windows self.startup_window = startup_window.StartupWindow(self._start_cb, self._load_last_cb) # Create the canvas to embbed pygame self.pygame_canvas = PygameCanvas(self, False) # Create Health Library Window self.health_library = content_window.ContentWindow() # Create Guides Window self.guides = guides_window.GuidesWindow() # Create Credits Window self.credits = credits.Credits() self.startup_window.show() self.pygame_canvas.show() self.health_library.show() self.guides.show() self.credits.show() self.items = gtk.Notebook() self.items.set_show_tabs(False) self.items.set_show_border(False) self.items.append_page(self.startup_window) self.items.append_page(self.pygame_canvas) self.items.append_page(self.health_library) self.items.append_page(self.guides) self.items.append_page(self.credits) self.items.show() self.set_canvas(self.items) logging.debug("Create main") self.game = game.Main() self.game.set_game_over_callback(self.game_over_callback) self.toolbox.connect('current-toolbar-changed', self.change_mode) self.make_toolbox(False) self.toolbox.set_current_toolbar(0) # Start in activity tab # force the toolbar change self.change_mode(None, self.toolbox.get_current_toolbar()) game.set_library_function = self.set_library # Sets the callback to put links in the library self.show()
class SaludameActivity(Activity): ''' Clase llamada por sugar cuando se ejecuta la actividad. El nombre de esta clase está señalada en el archivo activity/activity.info ''' def __init__(self, handle): self.game_init = False # Tells if game engine was initialized self.loaded_game = None Activity.__init__(self, handle) # Creates the activiy box for toolbars self.toolbox = ActivityToolbox(self) self.set_toolbox(self.toolbox) self.toolbox.show() # Retrieves the Activity standard toolbar self.activity_toolbar = self.toolbox.get_activity_toolbar() # Creates other toolbars # Game toolbar gets created on demand # Library toolbar gets created on demand self.guides_toolbar = gtk.Toolbar() self.credits_toolbar = gtk.Toolbar() self.indexes = ["activity"] # right now only activity toolbar # Create startup windows self.startup_window = startup_window.StartupWindow(self._start_cb, self._load_last_cb) # Create the canvas to embbed pygame self.pygame_canvas = PygameCanvas(self, False) # Create Health Library Window self.health_library = content_window.ContentWindow() # Create Guides Window self.guides = guides_window.GuidesWindow() # Create Credits Window self.credits = credits.Credits() self.startup_window.show() self.pygame_canvas.show() self.health_library.show() self.guides.show() self.credits.show() self.items = gtk.Notebook() self.items.set_show_tabs(False) self.items.set_show_border(False) self.items.append_page(self.startup_window) self.items.append_page(self.pygame_canvas) self.items.append_page(self.health_library) self.items.append_page(self.guides) self.items.append_page(self.credits) self.items.show() self.set_canvas(self.items) logging.debug("Create main") self.game = game.Main() self.game.set_game_over_callback(self.game_over_callback) self.toolbox.connect('current-toolbar-changed', self.change_mode) self.make_toolbox(False) self.toolbox.set_current_toolbar(0) # Start in activity tab # force the toolbar change self.change_mode(None, self.toolbox.get_current_toolbar()) game.set_library_function = self.set_library # Sets the callback to put links in the library self.show() def make_toolbox(self, add_game): toolbars = len(self.indexes) for i in range(toolbars, 0, -1): self.toolbox.remove_toolbar(i) self.indexes = ["activity"] # activity toolbar never gets removed if add_game: self.toolbox.add_toolbar(_("Game"), self.get_game_toolbar()) self.indexes += ["game"] self.indexes += ["library", "guides", "credits"] self.toolbox.add_toolbar(_("Health Library"), self.health_library.get_toolbar()) self.toolbox.add_toolbar(_("Guides"), self.guides_toolbar) self.toolbox.add_toolbar(_("Credits"), self.credits_toolbar) def change_mode(self, notebook, index): game.pause = True self.pygame_canvas.translator.unhook_pygame() self.health_library.ditch() self.guides.ditch() self.guides.ditch() gc.collect() # Collects garbaje if self.indexes[index] == "activity": self.items.set_current_page(0) if self.indexes[index] == "game": game.pause = False self.show_game() self.items.set_current_page(1) elif self.indexes[index] == "library": self.items.set_current_page(2) elif self.indexes[index] == "guides": self.items.set_current_page(3) elif self.indexes[index] == "credits": self.credits.before_show() self.items.set_current_page(4) #Override activity.Activity's can_close method def can_close(self): game.running = False return True def _start_cb(self, gender, name): #self.create_in_journal() self.metadata['title'] = _("Saludame") + " " + name self.game.gender = gender self.game.name = name self.startup_window.set_welcome() if self.game.started: self.game.main(True) self.make_toolbox(True) self.toolbox.set_current_toolbar(1) # Move to game tab def show_game(self): if self.game.started: self.game.windows_controller.reload_main = True # Repaints the whole screen if self.game_init: self.pygame_canvas.translator.hook_pygame() else: self.game_init = True # Start pygame self.pygame_canvas.run_pygame(lambda:self.game.main(True)) # Indico que llame a la función local para iniciar el juego pygame def set_library(self, link, anchor=None): self.toolbox.set_current_toolbar(2) self.health_library.set_url(link, anchor) def _load_last_cb(self, event): metadata = self.get_last_game() if metadata: self.metadata['title'] = metadata['title'] self.make_toolbox(True) self.toolbox.set_current_toolbar(1) def game_over_callback(self): self.make_toolbox(False) self.toolbox.set_current_toolbar(0) # Move to game tab def write_file(self, file_path): if self.game.started: try: self.game.save_game(file_path) except Exception,e: print "Error writting to file" print e raise e else:
def __init__(self, app, files=[]): Gtk.Window.__init__(self, title="Saludame", application=app) self.__new_game = '' self.__data = {} self.set_icon_from_file(os.path.join(BASEPATH, "assets/saludame.svg")) self.set_resizable(False) self.set_position(Gtk.WindowPosition.CENTER) self.maximize() self.size = (800, 600) self.headerBar = Gtk.HeaderBar() self.headerBar.get_style_context().add_class("header") self.headerBar.set_show_close_button(True) self.headerBar.set_title(_("Saludame")) self.set_titlebar(self.headerBar) self.startup_window = StartupWindow(self._start_cb, self._load_last_cb) self.pygame_canvas = PygameCanvas() self.health_library = ContentWindow() self.guides = GuidesWindow() self.credits = Credits() self.notebook = Gtk.Notebook() self.notebook.get_style_context().add_class("mynotebook") self.notebook.append_page(self.startup_window, Gtk.Label(_("Activity"))) self.notebook.append_page(self.pygame_canvas, Gtk.Label(_("Game"))) self.notebook.append_page(self.health_library, Gtk.Label(_("Health Library"))) self.notebook.append_page(self.guides, Gtk.Label(_("Guides"))) self.notebook.append_page(self.credits, Gtk.Label(_("Credits"))) self.add(self.notebook) logging.debug("Create main") self.game = Main() self.game.set_game_over_callback(self.game_over_callback) game.set_library_function = self.set_library self.healt_toolbar = self.health_library.get_toolbar() self.game_toolbar = self.get_game_toolbar() self.headerBar.pack_start(self.healt_toolbar) self.headerBar.pack_start(self.game_toolbar) self.notebook.connect('switch_page', self.__switch_page) self.connect("delete-event", self.__salir) self.connect("realize", self.__realize) self.show_all() self.notebook.get_children()[1].hide() self.healt_toolbar.hide() self.game_toolbar.hide() self.notebook.set_current_page(0)