diff options
author | Pootle daemon <pootle@pootle.sugarlabs.org> | 2012-08-01 04:32:04 (GMT) |
---|---|---|
committer | Pootle daemon <pootle@pootle.sugarlabs.org> | 2012-08-01 04:32:04 (GMT) |
commit | 2d1ab436d0ca685fab5e571f6cf2b46b3d1275ed (patch) | |
tree | 9af0da56dfdaa56b7a8662aec7944f7acc011e46 | |
parent | e11abd5040add923e0ee37b85ebcdd70e8c39910 (diff) | |
parent | 5f0443961010afdc96cd6f389c8011808f848edc (diff) |
Merge branch 'master' of git.sugarlabs.org:sugarchess/sugarchess
-rw-r--r-- | GNUChessActivity.py | 27 | ||||
-rw-r--r-- | NEWS | 5 | ||||
-rw-r--r-- | activity/activity.info | 2 | ||||
-rw-r--r-- | chess.py | 30 | ||||
-rw-r--r-- | utils.py | 15 |
5 files changed, 39 insertions, 40 deletions
diff --git a/GNUChessActivity.py b/GNUChessActivity.py index a3b2701..1e8648f 100644 --- a/GNUChessActivity.py +++ b/GNUChessActivity.py @@ -159,7 +159,7 @@ class GNUChessActivity(activity.Activity): self.view_toolbar.show() toolbox.toolbar.insert(view_toolbar_button, -1) view_toolbar_button.show() - + adjust_toolbar_button = ToolbarButton(label=_('Adjust'), page=self.adjust_toolbar, icon_name=\ @@ -412,7 +412,6 @@ class GNUChessActivity(activity.Activity): cb_arg='black_king', tooltip=_('Black King')) - def do_default_skin_cb(self, button=None): self._gnuchess.reskin_from_file('black_king', '%s/icons/black-king.svg' % (activity.get_bundle_path())) @@ -474,9 +473,9 @@ class GNUChessActivity(activity.Activity): def do_custom_skin_cb(self, button=None): for piece in ['white_pawn', 'black_pawn', - 'white_rook', 'black_rook', + 'white_rook', 'black_rook', 'white_knight', 'black_knight', - 'white_bishop', 'black_bishop', + 'white_bishop', 'black_bishop', 'white_queen', 'black_queen', 'white_king', 'black_king']: if piece in self.metadata: @@ -486,18 +485,16 @@ class GNUChessActivity(activity.Activity): self._do_reskin(piece, jobject.file_path) def _do_reskin(self, piece, file_path): - _logger.debug('%s %s %s' % ( - piece, str(self._gnuchess.we_are_sharing), - str(self.buddy))) + ''' If we are sharing, only reskin pieces of your color ''' if self._gnuchess.we_are_sharing and self.buddy is not None: - pixbuf = self._gnuchess.reskin_from_file( - piece, file_path, return_pixbuf= True) if 'white' in piece and self.playing_white: + pixbuf = self._gnuchess.reskin_from_file( + piece, file_path, return_pixbuf=True) self.send_piece(piece, pixbuf) elif 'black' in piece and not self.playing_white: + pixbuf = self._gnuchess.reskin_from_file( + piece, file_path, return_pixbuf=True) self.send_piece(piece, pixbuf) - else: - _logger.debug('skipping... opponent reskin') else: self._gnuchess.reskin_from_file(piece, file_path) return @@ -536,7 +533,7 @@ class GNUChessActivity(activity.Activity): move_list = self._parse_move_list(clipboard.wait_for_text()) if move_list is not None: self._gnuchess.restore_game(move_list) - + def _parse_move_list(self, text): ''' Take a standard game description and return a move list ''' # Assuming of form ... 1. e4 e6 2. ... @@ -718,7 +715,6 @@ class GNUChessActivity(activity.Activity): chooser.destroy() del chooser if name is not None: - _logger.debug('foo: %s %s' % (str(jobject.object_id), jobject.file_path)) return jobject.object_id, jobject.file_path else: return None, None @@ -838,7 +834,6 @@ class GNUChessActivity(activity.Activity): self._gnuchess.set_sharing(True) self.restoring = True - _logger.debug('............... setting human button to active') self.playing_robot = False self.human_button.set_active(True) self.restoring = False @@ -896,8 +891,6 @@ params=%r state=%d' % (id, initiator, type, service, params, state)) except ValueError: _logger.debug('Could not split event message %s' % (event_message)) return - _logger.debug('%s: %s' % (self._processing_methods[command][1], - payload)) self._processing_methods[command][0](payload) def send_new_game(self): @@ -998,7 +991,7 @@ params=%r state=%d' % (id, initiator, type, service, params, state)) def send_piece(self, piece, pixbuf): _logger.debug('send_piece %s' % (piece)) - self.send_event('p|%s' % (self._dump(piece, pixbuf))) + gobject.idle_add(self.send_event, 'p|%s' % (self._dump(piece, pixbuf))) def _receive_piece(self, payload): piece, pixbuf = self._load(payload) @@ -1,3 +1,8 @@ +3 + +ENHANCEMENT: +* Support for ARM (e.g., XO 1.75) + 2 ENHANCEMENT: diff --git a/activity/activity.info b/activity/activity.info index f501361..2a47609 100644 --- a/activity/activity.info +++ b/activity/activity.info @@ -1,6 +1,6 @@ [Activity] name = SimpleGNUChess -activity_version = 2 +activity_version = 3 license = GPLv3 bundle_id = org.sugarlabs.GNUChessActivity exec = sugar-activity GNUChessActivity.GNUChessActivity @@ -173,7 +173,6 @@ class Gnuchess(): def _process_output(self, output, my_move=None, hint=False): ''' process output from gnuchess command ''' - # _logger.debug(output) self.check = False self.checkmate = False if 'White Black' in output: # processing show game @@ -273,7 +272,7 @@ class Gnuchess(): def restore_game(self, move_list): self.move_list = [] - + for move in move_list: self.move_list.append(str(move)) @@ -315,9 +314,9 @@ class Gnuchess(): if '31.' in self.game: j = self.game.index('31.') self.bg[1].set_label(self.game[i: j - 1]) - self.bg[2].set_label(self.game[j: ]) + self.bg[2].set_label(self.game[j:]) else: - self.bg[1].set_label(self.game[i: ]) + self.bg[1].set_label(self.game[i:]) else: self.bg[0].set_label(self.game) self._activity.showing_game_history = True @@ -349,7 +348,7 @@ class Gnuchess(): spr = self._sprites.find_sprite((x, y)) if spr == None or spr.type == None: return - + if self._thinking: # Robot is thinking or conjuring up a hint self._wait_your_turn() return @@ -388,10 +387,10 @@ class Gnuchess(): def _wait_your_turn(self): if self._activity.playing_white: self._activity.status.set_label( - _('White: please wait for your turn.')) + _('Please wait for your turn.')) else: self._activity.status.set_label( - _('Black: please wait for your turn.')) + _('Please wait for your turn.')) def _play_your_color(self): if self._activity.playing_white: @@ -479,7 +478,7 @@ class Gnuchess(): if self._activity.playing_robot and not self.checkmate: self._activity.set_thinking_cursor() - self._activity.status.set_label(_('Thinking')) + self._activity.status.set_label(_('Thinking...')) self._thinking = True gobject.timeout_add(500, self.move, ROBOT) @@ -776,7 +775,7 @@ class Gnuchess(): def _search_for_rook( self, piece, source_file, source_rank, capture_file, capture_rank): # Change rank - if len(self.move_list) % 2 == 1: # if piece in 'rq': + if len(self.move_list) % 2 == 1: for r in range(7 - RANKS.index(capture_rank)): i = self._file_and_rank_to_index('%s%s' % ( capture_file, RANKS[RANKS.index(capture_rank) + r + 1])) @@ -1411,12 +1410,8 @@ class Gnuchess(): if not self.we_are_sharing: return if self._activity.playing_white and len(self.move_list) % 2 == 0: - _logger.debug("received a remote move (%s) from Black but it is \ -White's turn." % (move)) return elif not self._activity.playing_white and len(self.move_list) % 2 == 1: - _logger.debug("received a remote move (%s) from White but it is \ -Black's turn." % (move)) return _logger.debug('Processing remote move (%s)' % (move)) self.move(move) @@ -1442,7 +1437,7 @@ Black's turn." % (move)) y = yo return ('%s%d' % (FILES[int((pos[0] - xo) / self.scale)], 8 - int((pos[1] - yo) / self.scale))) - + def _expose_cb(self, win, event): self.do_expose_event(event) @@ -1568,17 +1563,16 @@ Black's turn." % (move)) pixbuf = svg_str_to_pixbuf( svg_header(colors) + DICT[piece](bw) + svg_footer(), w=self.scale, h=self.scale) - self._reskin(piece, pixbuf) + self.reskin(piece, pixbuf) def reskin_from_file(self, piece, file_path, return_pixbuf=False): - _logger.debug('%s %s' % (piece, file_path)) pixbuf = gtk.gdk.pixbuf_new_from_file_at_size( file_path, self.scale, self.scale) - self._reskin(piece, pixbuf) + self.reskin(piece, pixbuf) if return_pixbuf: return pixbuf - def _reskin(self, piece, pixbuf): + def reskin(self, piece, pixbuf): DICT = {'white_pawn': WP, 'black_pawn': BP, 'white_rook': WR, 'black_rook': BR, 'white_knight': WN, 'black_knight': BN, @@ -10,6 +10,7 @@ # Foundation, 51 Franklin Street, Suite 500 Boston, MA 02110-1335 USA import os +import gtk import subprocess from StringIO import StringIO try: @@ -34,7 +35,7 @@ UNKNOWN = 'unknown' def get_hardware(): - """ Determine whether we are using XO 1.0, 1.5, or "unknown" hardware """ + ''' Determine whether we are using XO 1.0, 1.5, or "unknown" hardware ''' product = _get_dmi('product_name') if product is None: if os.path.exists('/sys/devices/platform/lis3lv02d/position'): @@ -66,11 +67,10 @@ def _get_dmi(node): def json_load(text): - """ Load JSON data using what ever resources are available. """ + ''' Load JSON data using what ever resources are available. ''' if OLD_SUGAR_SYSTEM is True: listdata = json.read(text) else: - # strip out leading and trailing whitespace, nulls, and newlines io = StringIO(text) try: listdata = jload(io) @@ -83,7 +83,7 @@ def json_load(text): def json_dump(data): - """ Save data using available JSON tools. """ + ''' Save data using available JSON tools. ''' if OLD_SUGAR_SYSTEM is True: return json.write(data) else: @@ -92,7 +92,13 @@ def json_dump(data): return _io.getvalue() +def get_path(activity, path): + ''' Find a Rainbow-approved place for temporary files. ''' + return(os.path.join(activity.get_activity_root(), path)) + + def file_to_base64(activity, path): + ''' Given a file, convert its contents to base64 ''' base64 = os.path.join(get_path(activity, 'instance'), 'base64tmp') cmd = 'base64 <' + path + ' >' + base64 subprocess.check_call(cmd, shell=True) @@ -114,6 +120,7 @@ def pixbuf_to_base64(activity, pixbuf): def base64_to_file(activity, data, path): + ''' Given a file, convert its contents from base64 ''' base64 = os.path.join(get_path(activity, 'instance'), 'base64tmp') file_handle = open(base64, 'w') file_handle.write(data) |