def play_signal_cb(self, x, y, sender=None): """Somebody placed a stone. """ if sender == self.tube.get_unique_name(): # sender is my bus name, so ignore my own signal return logger.debug('Buddy %s placed a stone at %s x %s', sender, x, y) # Call our Play callback self.Play_cb(x, y, sender)
def __init__(self, handle): # Initialize the parent Activity.__init__(self, handle) logger.debug('Initiating JPeces') self.java_path = self.get_java_path() if self.java_path != "": self.create_script(os.getenv("JPECES_SCRIPT")) sys.exit(0)
def insert_cb(self, widget, x, y, announce=True, ai_play=False): ''' The insert function. It makes the play and manages turn changing stone drawing, etc. Parameters x and y are the coordinates of the play ((0,0) is top left), widget points to the widget that emitted the signal connected to this function, announce is True when we need to announce this play to other people collaborating, and ai_play is True when this is called by the AI, so we know not to ask for an AI play again ''' # Check if it's our turn only if it's a local play (announce is True) # Calls by other players will always be out of turn for us. if announce and self.get_currentcolor() != self.get_playercolor(): logger.debug('Play at %s x %s was out-of-turn!', x, y) self.infopanel.show(_('It\'s not your turn!')) return False # Make the play only if it wasn't a pass move. if x != -1: self.pass_count = 0 error = self.game.illegal(x, y, self.get_currentcolor()) if error: self.infopanel.show(error) return False # Make the play captures = self.game.play((x, y), self.get_currentcolor()) if self.ai_activated and not ai_play: self.notify_ai(x, y, self.get_currentcolor()) self.gameToolbar.grey_out_size_change() if captures: self.redraw_captures(captures) self.show_score() self.board.draw_stone(self.board.context, x, y, self.get_currentcolor(), widget) self.board.queue_draw() # Player passed else: self.pass_count += 1 # Announce the local play if self.get_shared() and announce: self.collaboration.Play(x, y) self.change_turn() if x == -1: self.infopanel.show(_('Opponent passed')) # If this is the second consecutive pass, the game ends if self.pass_count == 2: self.game_end() return # If we are playing a local game with AI turned off, change the color if not self.get_shared() and not self.ai_activated: self.change_player_color() # Else, if the AI is on, and this wasn't played by it, request a play by it. elif self.ai_activated: self.change_player_color() if not ai_play: self.play_ai()
def add_hello_handler(self): logger.debug('Adding hello handler.') self.tube.add_signal_receiver(self.hello_signal_cb, 'Hello', IFACE, path=PATH, sender_keyword='sender') self.tube.add_signal_receiver(self.play_signal_cb, 'Play', IFACE, path=PATH, sender_keyword='sender')
def _new_tube_cb(self, id, initiator, type, service, params, state): logger.debug('New tube: ID=%d initator=%d type=%d service=%s ' 'params=%r state=%d', id, initiator, type, service, params, state) if (type == telepathy.TUBE_TYPE_DBUS and service == SERVICE): if state == telepathy.TUBE_STATE_LOCAL_PENDING: self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].AcceptDBusTube(id) self.tube = SugarTubeConnection(self.conn, self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES], id, group_iface=self.text_chan[telepathy.CHANNEL_INTERFACE_GROUP]) super(CollaborationWrapper, self).__init__(self.tube, PATH) self.tube.watch_participants(self.participant_change_cb)
def World(self, undostack, taken_color, size): """To be called on the incoming XO after they Hello.""" if not self.world: logger.debug('Somebody called World and sent me undostack: %s', undostack) self.activity.board_size_change(None, size) self.bootstrap(list(undostack)) self.activity.set_player_color(self.activity.invert_color(taken_color)) #self.players = players # now I can World others self.add_hello_handler() else: self.world = True logger.debug("I've already been welcomed, doing nothing")
def restart_game(self, widget=None): logger.debug('Received restart signal!') self.CurrentColor = 'B' self.PlayerColor = 'B' self.pass_count = 0 self.game.clear() self.board.territories = None self.board.status = self.game.status self.board.do_expose_event() self.show_score() self.board.set_sensitive(True) self.buttons_box.set_sensitive(True) self.lastX = -1 self.lastY = -1 if self.ai_activated: self.ai.clear()
def write_file(self, file_path): logger.debug('Writing file: %s', file_path) # Strip the undostack undostack = self.game.undostack[:] strippedstack = [] for pos, color, captures in undostack: strippedstack.append(pos) f = open(file_path, 'w') try: cPickle.dump(strippedstack, f, cPickle.HIGHEST_PROTOCOL) finally: f.close() self.metadata['our-color'] = self.get_playercolor() self.metadata['shared'] = str(self.get_shared()) self.metadata['size'] = str(self.size) self.metadata['ai'] = str(self.ai_activated)
def read_file(self, file_path): logger.debug('Reading file: %s', file_path) f = open(file_path, 'r') try: newstack = cPickle.load(f) finally: f.close() if self.get_shared(): logger.debug('The game we are loading is shared!') self.PlayerColor = self.metadata.get('our-color', 'B') if self.size != self.metadata.get('size', DEFAULT_SIZE): self.board_size_change(None, int(self.metadata.get('size', DEFAULT_SIZE))) self.bootstrap(newstack) if self.metadata.get('ai', None) == 'True': self.gameToolbar._size_combo.set_sensitive(False) self.gameToolbar._ai_button.set_active(True) # This triggers the 'toggled' signal too
def hello_signal_cb(self, sender=None): """Somebody Helloed me. World them.""" if sender == self.tube.get_unique_name(): # sender is my bus name, so ignore my own signal return logger.debug('Newcomer %s has joined', sender) logger.debug('Welcoming newcomer and sending them the game state') # Strip the undostack to reduce net traffic =) strippedstack = [] for pos, color, captures in self.undostack: strippedstack.append(pos) # FIXME: A spectator needs to send the color that was taken, not its own self.tube.get_object(sender, PATH).World(strippedstack, self.activity.get_playercolor(), self.activity.size, dbus_interface=IFACE) self.activity.board.set_sensitive(True)
def read_file(self, file_path): logger.debug('Reading file: %s', file_path) f = open(file_path, 'r') try: newstack = cPickle.load(f) finally: f.close() if self.get_shared(): logger.debug('The game we are loading is shared!') self.PlayerColor = self.metadata.get('our-color', 'B') if self.size != self.metadata.get('size', DEFAULT_SIZE): self.board_size_change( None, int(self.metadata.get('size', DEFAULT_SIZE))) self.bootstrap(newstack) if self.metadata.get('ai', None) == 'True': self.gameToolbar._size_combo.set_sensitive(False) self.gameToolbar._ai_button.set_active( True) # This triggers the 'toggled' signal too
def _get_buddy(self, cs_handle): """Get a Buddy from a channel specific handle.""" logger.debug('Trying to find owner of handle %u...', cs_handle) group = self.text_chan[telepathy.CHANNEL_INTERFACE_GROUP] my_csh = group.GetSelfHandle() logger.debug('My handle in that group is %u', my_csh) if my_csh == cs_handle: handle = self.conn.GetSelfHandle() logger.debug('CS handle %u belongs to me, %u', cs_handle, handle) elif group.GetGroupFlags() & telepathy.CHANNEL_GROUP_FLAG_CHANNEL_SPECIFIC_HANDLES: handle = group.GetHandleOwners([cs_handle])[0] logger.debug('CS handle %u belongs to %u', cs_handle, handle) else: handle = cs_handle logger.debug('non-CS handle %u belongs to itself', handle) # XXX: deal with failure to get the handle owner assert handle != 0 return self.presence_service.get_buddy_by_telepathy_handle( self.conn.service_name, self.conn.object_path, handle)
def _sharing_setup(self): if self.activity._shared_activity is None: logger.error('Failed to share or join activity') return self.conn = self.activity._shared_activity.telepathy_conn self.tubes_chan = self.activity._shared_activity.telepathy_tubes_chan self.text_chan = self.activity._shared_activity.telepathy_text_chan self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].connect_to_signal( 'NewTube', self._new_tube_cb) self.activity._shared_activity.connect('buddy-joined', self._buddy_joined_cb) self.activity._shared_activity.connect('buddy-left', self._buddy_left_cb) # Optional - included for example: # Find out who's already in the shared activity: for buddy in self.activity._shared_activity.get_joined_buddies(): logger.debug('Buddy %s is already in the activity', buddy.props.nick)
def bootstrap(self, plays): ''' Take our game to the state it would have if @plays were manually played''' logger.debug('Bootstraping...') self.board.do_expose_event() # HACK: Looks like read_file is called before the board is exposed for pos in plays: logger.debug('Playing at %s with color %s', pos, self.get_currentcolor()) captures = self.game.play((pos[0], pos[1]), self.get_currentcolor()) if captures: self.redraw_captures(captures) self.change_turn() self.change_player_color() logger.debug('Color after bootstraping is %s', self.get_currentcolor()) self.show_score() self.board.do_expose_event()
def bootstrap(self, plays): ''' Take our game to the state it would have if @plays were manually played''' logger.debug('Bootstraping...') self.board.do_expose_event( ) # HACK: Looks like read_file is called before the board is exposed for pos in plays: logger.debug('Playing at %s with color %s', pos, self.get_currentcolor()) captures = self.game.play((pos[0], pos[1]), self.get_currentcolor()) if captures: self.redraw_captures(captures) self.change_turn() self.change_player_color() logger.debug('Color after bootstraping is %s', self.get_currentcolor()) self.show_score() self.board.do_expose_event()
def Hello(self): """Say Hello to whoever else is in the tube.""" logger.debug('I said Hello.')
def _buddy_joined_cb (self, activity, buddy): """Called when a buddy joins the shared activity. """ logger.debug('Buddy %s joined', buddy.props.nick) self.buddy_joined(buddy)
def __init__(self, handle): # Initialize the parent Activity.__init__(self, handle) logger.debug('Initiating Tuxmath') # Set the activity toolbox toolbox = ActivityToolbox(self) self.set_toolbox(toolbox) self.ceibaljam_icon_path = os.getenv( "SUGAR_BUNDLE_PATH") + "/images/ceibaljam.png" # # There's a good explanation of the use of boxes in PyGTK here: # http://www.pygtk.org/pygtk2tutorial/sec-DetailsOfBoxes.html # box_canvas = gtk.VBox(False, 0) self.set_canvas(box_canvas) # Title box_title = gtk.VBox(False, 0) label_title = gtk.Label(_("Tuxmath")) label_title.set_justify(gtk.JUSTIFY_CENTER) label_title.modify_font(pango.FontDescription("Arial 22")) box_title.add(gtk.Label("\n\n\n")) box_title.add(label_title) box_title.add(gtk.Label("\n")) # Author box_author = gtk.VBox(False, 0) box_author.add(gtk.Label("")) box_author.add(gtk.Label(_("Created by Tux4kids"))) label_author_url = gtk.Label( '<b>http://tux4kids.alioth.debian.org</b>') label_author_url.set_use_markup(True) box_author.add(label_author_url) # Options box box_options = gtk.VBox(False, 0) label_options = gtk.Label(_("Options:")) label_options.set_justify(gtk.JUSTIFY_LEFT) self.checkbtn_sound = gtk.CheckButton(label=_("No sound")) self.checkbtn_sound.set_active(True) self.checkbtn_negatives = gtk.CheckButton( label=_("Include negative numbers")) self.checkbtn_negatives.set_active(False) # Pack the checkboxes in HBoxes to center them hbox1 = gtk.HBox(False, 0) hbox1.add(gtk.Label("")) hbox1.add(gtk.Label("")) hbox1.add(gtk.Label("")) hbox1.add(gtk.Label("")) hbox1.add(gtk.Label("")) hbox1.add(gtk.Label("")) hbox1.add(gtk.Label("")) hbox1.add(self.checkbtn_sound) hbox1.add(gtk.Label("")) hbox1.add(gtk.Label("")) hbox1.add(gtk.Label("")) hbox1.add(gtk.Label("")) hbox1.add(gtk.Label("")) hbox1.add(gtk.Label("")) box_options.add(hbox1) #box_options.add(gtk.Label("")) #box_options.add(label_options) #box_options.add(self.checkbtn_sound) #box_options.add(self.checkbtn_negatives) # Credits box_credits = gtk.VBox(False, 0) box_credits.add(gtk.Label("")) box_credits.add( gtk.Label( _('Spanish translation and pedagogical evaluation by %(TEACHER)s' ) % {'TEACHER': 'Ana Cichero'})) label_teacher_email = gtk.Label('<b>[email protected]</b>') label_teacher_email.set_use_markup(True) box_credits.add(label_teacher_email) box_credits.add( gtk.Label( _('Sugarized by %(SUGARIZER)s') % {'SUGARIZER': 'Marcos Orfila'})) label_sugarizer_website = gtk.Label( '<b>http://www.marcosorfila.com</b>') label_sugarizer_website.set_use_markup(True) box_credits.add(label_sugarizer_website) box_credits.add(gtk.Label("")) # Footer box (Activities on CeibalJAM! website) box_footer = gtk.VBox(False, 0) box_footer.add(gtk.Label("")) box_footer.add( gtk.Label( _('Find more activities on %(CEIBALJAM)s website:') % {'CEIBALJAM': 'CeibalJAM!'})) label_ceibaljam_website = gtk.Label( '<b>http://activities.ceibaljam.org</b>') label_ceibaljam_website.set_use_markup(True) box_footer.add(label_ceibaljam_website) box_footer.add(gtk.Label("")) # CeibalJAM! image box_ceibaljam_image = gtk.VBox(False, 0) image_ceibaljam = gtk.Image() image_ceibaljam.set_from_file(self.ceibaljam_icon_path) box_ceibaljam_image.pack_end(image_ceibaljam, False, False, 0) # Buttons box box_buttons = gtk.HBox(False, 0) self.button_play = gtk.Button(_("Play")) self.button_play.connect("clicked", self._button_play_clicked_cb) self.button_exit = gtk.Button(_("Exit")) self.button_exit.connect("clicked", self._button_exit_clicked_cb) box_buttons.add(gtk.VBox()) box_buttons.add(self.button_play) box_buttons.add(gtk.VBox()) box_buttons.add(self.button_exit) box_buttons.add(gtk.VBox()) # Get all the boxes together box_canvas.pack_start(box_title, False, False, 0) box_canvas.pack_start(box_options, False, False, 0) box_canvas.pack_end(gtk.Label("\n\n"), False, False, 0) box_canvas.pack_end(box_buttons, False, False, 0) box_canvas.pack_end(gtk.Label("\n"), False, False, 0) box_canvas.pack_end(box_footer, False, False, 0) box_canvas.pack_end(box_ceibaljam_image, False, False, 0) box_canvas.pack_end(box_credits, False, False, 0) box_canvas.pack_end(box_author, False, False, 0) self.button_play.grab_focus() self.show_all()
def notify_ai(self, x, y, color): logger.debug('Notifying AI of play by %s at %s x %s', color, x, y) self.ai.make_play(color, x, y)
def __init__(self, handle): # Initialize the parent Activity.__init__(self, handle) logger.debug('Initiating MathGraph32') # Set the activity toolbox toolbox = ActivityToolbox(self) self.set_toolbox(toolbox) self.ceibaljam_icon_path = os.getenv("SUGAR_BUNDLE_PATH") + "/images/ceibaljam.png" self.java_path = self.get_java_path() # # There's a good explanation of the use of boxes in PyGTK here: # http://www.pygtk.org/pygtk2tutorial/sec-DetailsOfBoxes.html # box_canvas = gtk.VBox(False, 0) self.set_canvas(box_canvas) # Title box_title = gtk.VBox(False, 0) label_title = gtk.Label(_("MathGraph32")) label_title.set_justify(gtk.JUSTIFY_CENTER) label_title.modify_font(pango.FontDescription("Arial 22")) box_title.add(gtk.Label("\n\n")) box_title.add(label_title) box_title.add(gtk.Label("\n")) # Author box_author = gtk.VBox(False, 0) #box_author.add(gtk.Label("")) box_author.add(gtk.Label(_("Created by Yves Biton"))) label_author_url = gtk.Label('<b>http://www.mathgraph32.org</b>') label_author_url.set_use_markup(True) box_author.add(label_author_url) # Credits box_credits = gtk.VBox(False, 0) box_credits.add(gtk.Label("")) box_credits.add(gtk.Label(_('Spanish translation and pedagogical evaluation by %(TEACHER)s') % { 'TEACHER': 'Luis Belcredi' })) label_teacher_email= gtk.Label('<b>http://xsubcero.50webs.biz</b>') label_teacher_email.set_use_markup(True) box_credits.add(label_teacher_email) box_credits.add(gtk.Label("")) box_credits.add(gtk.Label(_('Sugarized by %(SUGARIZER)s') % { 'SUGARIZER': 'Marcos Orfila' })) label_sugarizer_website = gtk.Label('<b>http://www.marcosorfila.com</b>') label_sugarizer_website.set_use_markup(True) box_credits.add(label_sugarizer_website) box_credits.add(gtk.Label("")) # Footer box (Activities on CeibalJAM! website) box_footer = gtk.VBox(False, 0) box_footer.add(gtk.Label("")) box_footer.add(gtk.Label(_('Find more activities on %(CEIBALJAM)s website:') % { 'CEIBALJAM': 'CeibalJAM!'})) label_ceibaljam_website = gtk.Label('<b>http://activities.ceibaljam.org</b>') label_ceibaljam_website.set_use_markup(True) box_footer.add(label_ceibaljam_website) box_footer.add(gtk.Label("")) # CeibalJAM! image box_ceibaljam_image = gtk.VBox(False, 0) image_ceibaljam = gtk.Image() image_ceibaljam.set_from_file(self.ceibaljam_icon_path) box_ceibaljam_image.pack_end(image_ceibaljam, False, False, 0) # Get all the boxes together box_canvas.pack_start(box_title, False, False, 0) box_canvas.pack_start(box_author, False, False, 0) box_canvas.pack_start(gtk.Label("\n"), False, False, 0) if self.java_path == "": box_java_not_found = gtk.VBox(False, 0) label_java_not_found = gtk.Label('<span foreground="red"><b>' + _("Java was not found!") + '</b></span>') label_java_not_found.set_justify(gtk.JUSTIFY_CENTER) label_java_not_found.set_use_markup(True) label_java_not_found.modify_font(pango.FontDescription("Arial 20")) box_java_not_found.add(label_java_not_found) box_java_not_found.add(gtk.Label(_('You can download the Java activity from %(CEIBALJAM)s website (see below)') % { 'CEIBALJAM': 'CeibalJAM!'})) box_canvas.pack_start(box_java_not_found, False, False, 0) box_canvas.pack_start(gtk.Label(""), False, False, 0) else: box_java_found = gtk.VBox(False, 0) label_version_info_title = gtk.Label('<b>' + _("Java version found:") + '</b>') label_version_info_title.set_use_markup(True) version_information = commands.getoutput(self.java_path + " -version") label_version_info = gtk.Label(version_information) label_version_info.set_justify(gtk.JUSTIFY_CENTER) box_java_found.add(label_version_info_title) box_java_found.add(label_version_info) box_canvas.pack_start(box_java_found, False, False, 0) box_canvas.pack_end(gtk.Label("\n"), False, False, 0) self.add_buttons(box_canvas) box_canvas.pack_end(box_footer, False, False, 0) box_canvas.pack_end(box_ceibaljam_image, False, False, 0) box_canvas.pack_end(box_credits, False, False, 0) if self.java_path != '': self.button_play.grab_focus() else: self.button_exit.grab_focus() self.show_all()
def Play(self, x, y): """Say Hello to whoever else is in the tube.""" logger.debug('Signaling players of stone placement at:%s x %s.', x, y)
def play_ai(self): if self.get_currentcolor() == self.get_playercolor(): x, y = self.ai.get_move(self.get_currentcolor()) logger.debug('Got play %s x %s from AI', x, y) self.insert_cb(None, x, y, ai_play=True)
def participant_change_cb(self, added, removed): logger.debug('Tube: Added participants: %r', added) logger.debug('Tube: Removed participants: %r', removed) for handle, bus_name in added: buddy = self._get_buddy(handle) if buddy is not None: logger.debug('Tube: Handle %u (Buddy %s) was added', handle, buddy.props.nick) for handle in removed: buddy = self._get_buddy(handle) if buddy is not None: logger.debug('Buddy %s was removed' % buddy.props.nick) if not self.entered: if self.is_initiator: logger.debug("I'm initiating the tube, will " "watch for hellos.") self.add_hello_handler() else: logger.debug('Hello, everyone! What did I miss?') self.Hello() self.entered = True
def __init__(self, handle): # Initialize the parent Activity.__init__(self, handle) logger.debug('Initiating PlayGo') self.size = DEFAULT_SIZE self.komi = DEFAULT_KOMI # Set the activity toolbox toolbox = ActivityToolbox(self) self.set_toolbox(toolbox) self.gameToolbar = GameToolbar(self) toolbox.add_toolbar(_('Game'), self.gameToolbar) self.gameToolbar.connect('game-restart', self.restart_game) self.gameToolbar.connect('game-board-size', self.board_size_change) self.gameToolbar.connect('ai-activated', self.ai_activated_cb) self.gameToolbar.connect('ai-deactivated', self.ai_deactivated_cb) self.gameToolbar.show() # Initialize the game self.game = GoGame(self.size) self.CurrentColor = 'B' self.PlayerColor = 'B' self.pass_count = 0 self.ai_activated = False self.set_up_ui() if not handle.object_id: self.infopanel.show(_('Welcome to PlayGo!')) else: self.show_score() self.lastX = -1 self.lastY = -1 # Set keypad actions self._key_actions = { 'KP_Up' : 'move_up', 'KP_Right' : 'move_right', 'KP_Down' : 'move_down', 'KP_Left' : 'move_left', 'KP_Home' : 'place_stone', 'KP_Next' : 'undo', 'KP_End' : 'pass' } self._key_grabber = KeyGrabber() self._key_grabber.connect('key-pressed', self._key_pressed_cb) # New KeyGrabber API change (ticket #7999) try: self._key_grabber.grab_keys(self._key_actions.keys()) except: for key in self._key_actions.keys(): self._key_grabber.grab(key) #Set up collaboration self.collaboration = CollaborationWrapper(self, self.buddy_joined, self.buddy_left, self.Play, self.game.undostack, self.bootstrap) self.connect('shared', self.collaboration._shared_cb) if self._shared_activity: # We are joining the activity self.connect('joined', self.collaboration._joined_cb) if self.get_shared(): # We've already joined self.collaboration._joined_cb()
def __init__(self, handle): # Initialize the parent Activity.__init__(self, handle) logger.debug('Initiating Tuxmath') # Set the activity toolbox toolbox = ActivityToolbox(self) self.set_toolbox(toolbox) self.ceibaljam_icon_path = os.getenv("SUGAR_BUNDLE_PATH") + "/images/ceibaljam.png" # # There's a good explanation of the use of boxes in PyGTK here: # http://www.pygtk.org/pygtk2tutorial/sec-DetailsOfBoxes.html # box_canvas = gtk.VBox(False, 0) self.set_canvas(box_canvas) # Title box_title = gtk.VBox(False, 0) label_title = gtk.Label(_("Tuxmath")) label_title.set_justify(gtk.JUSTIFY_CENTER) label_title.modify_font(pango.FontDescription("Arial 22")) box_title.add(gtk.Label("\n\n\n")) box_title.add(label_title) box_title.add(gtk.Label("\n")) # Author box_author = gtk.VBox(False, 0) box_author.add(gtk.Label("")) box_author.add(gtk.Label(_("Created by Tux4kids"))) label_author_url = gtk.Label('<b>http://tux4kids.alioth.debian.org</b>') label_author_url.set_use_markup(True) box_author.add(label_author_url) # Options box box_options = gtk.VBox(False, 0) label_options = gtk.Label(_("Options:")) label_options.set_justify(gtk.JUSTIFY_LEFT) self.checkbtn_sound = gtk.CheckButton(label=_("No sound")) self.checkbtn_sound.set_active(True) self.checkbtn_negatives = gtk.CheckButton(label=_("Include negative numbers")) self.checkbtn_negatives.set_active(False) # Pack the checkboxes in HBoxes to center them hbox1 = gtk.HBox(False, 0) hbox1.add(gtk.Label("")) hbox1.add(gtk.Label("")) hbox1.add(gtk.Label("")) hbox1.add(gtk.Label("")) hbox1.add(gtk.Label("")) hbox1.add(gtk.Label("")) hbox1.add(gtk.Label("")) hbox1.add(self.checkbtn_sound) hbox1.add(gtk.Label("")) hbox1.add(gtk.Label("")) hbox1.add(gtk.Label("")) hbox1.add(gtk.Label("")) hbox1.add(gtk.Label("")) hbox1.add(gtk.Label("")) box_options.add(hbox1) #box_options.add(gtk.Label("")) #box_options.add(label_options) #box_options.add(self.checkbtn_sound) #box_options.add(self.checkbtn_negatives) # Credits box_credits = gtk.VBox(False, 0) box_credits.add(gtk.Label("")) box_credits.add(gtk.Label(_('Spanish translation and pedagogical evaluation by %(TEACHER)s') % { 'TEACHER': 'Ana Cichero' })) label_teacher_email= gtk.Label('<b>[email protected]</b>') label_teacher_email.set_use_markup(True) box_credits.add(label_teacher_email) box_credits.add(gtk.Label(_('Sugarized by %(SUGARIZER)s') % { 'SUGARIZER': 'Marcos Orfila' })) label_sugarizer_website = gtk.Label('<b>http://www.marcosorfila.com</b>') label_sugarizer_website.set_use_markup(True) box_credits.add(label_sugarizer_website) box_credits.add(gtk.Label("")) # Footer box (Activities on CeibalJAM! website) box_footer = gtk.VBox(False, 0) box_footer.add(gtk.Label("")) box_footer.add(gtk.Label(_('Find more activities on %(CEIBALJAM)s website:') % { 'CEIBALJAM': 'CeibalJAM!'})) label_ceibaljam_website = gtk.Label('<b>http://activities.ceibaljam.org</b>') label_ceibaljam_website.set_use_markup(True) box_footer.add(label_ceibaljam_website) box_footer.add(gtk.Label("")) # CeibalJAM! image box_ceibaljam_image = gtk.VBox(False, 0) image_ceibaljam = gtk.Image() image_ceibaljam.set_from_file(self.ceibaljam_icon_path) box_ceibaljam_image.pack_end(image_ceibaljam, False, False, 0) # Buttons box box_buttons = gtk.HBox(False, 0) self.button_play = gtk.Button(_("Play")) self.button_play.connect("clicked", self._button_play_clicked_cb) self.button_exit = gtk.Button(_("Exit")) self.button_exit.connect("clicked", self._button_exit_clicked_cb) box_buttons.add(gtk.VBox()) box_buttons.add(self.button_play) box_buttons.add(gtk.VBox()) box_buttons.add(self.button_exit) box_buttons.add(gtk.VBox()) # Get all the boxes together box_canvas.pack_start(box_title, False, False, 0) box_canvas.pack_start(box_options, False, False, 0) box_canvas.pack_end(gtk.Label("\n\n"), False, False, 0) box_canvas.pack_end(box_buttons, False, False, 0) box_canvas.pack_end(gtk.Label("\n"), False, False, 0) box_canvas.pack_end(box_footer, False, False, 0) box_canvas.pack_end(box_ceibaljam_image, False, False, 0) box_canvas.pack_end(box_credits, False, False, 0) box_canvas.pack_end(box_author, False, False, 0) self.button_play.grab_focus() self.show_all()
def __init__(self, handle): # Initialize the parent Activity.__init__(self, handle) logger.debug('Initiating PlayGo') self.size = DEFAULT_SIZE self.komi = DEFAULT_KOMI # Set the activity toolbox toolbox = ActivityToolbox(self) self.set_toolbox(toolbox) self.gameToolbar = GameToolbar(self) toolbox.add_toolbar(_('Game'), self.gameToolbar) self.gameToolbar.connect('game-restart', self.restart_game) self.gameToolbar.connect('game-board-size', self.board_size_change) self.gameToolbar.connect('ai-activated', self.ai_activated_cb) self.gameToolbar.connect('ai-deactivated', self.ai_deactivated_cb) self.gameToolbar.show() # Initialize the game self.game = GoGame(self.size) self.CurrentColor = 'B' self.PlayerColor = 'B' self.pass_count = 0 self.ai_activated = False self.set_up_ui() if not handle.object_id: self.infopanel.show(_('Welcome to PlayGo!')) else: self.show_score() self.lastX = -1 self.lastY = -1 # Set keypad actions self._key_actions = { 'KP_Up': 'move_up', 'KP_Right': 'move_right', 'KP_Down': 'move_down', 'KP_Left': 'move_left', 'KP_Home': 'place_stone', 'KP_Next': 'undo', 'KP_End': 'pass' } self._key_grabber = KeyGrabber() self._key_grabber.connect('key-pressed', self._key_pressed_cb) # New KeyGrabber API change (ticket #7999) try: self._key_grabber.grab_keys(self._key_actions.keys()) except: for key in self._key_actions.keys(): self._key_grabber.grab(key) #Set up collaboration self.collaboration = CollaborationWrapper(self, self.buddy_joined, self.buddy_left, self.Play, self.game.undostack, self.bootstrap) self.connect('shared', self.collaboration._shared_cb) if self._shared_activity: # We are joining the activity self.connect('joined', self.collaboration._joined_cb) if self.get_shared(): # We've already joined self.collaboration._joined_cb()