diff options
author | Walter Bender <walter.bender@gmail.com> | 2012-07-30 21:29:34 (GMT) |
---|---|---|
committer | Walter Bender <walter.bender@gmail.com> | 2012-07-30 21:29:34 (GMT) |
commit | 8963df6cedfc17b98a7792fe78954e9e045ba87c (patch) | |
tree | 74abf4cc87dbe9001ef9f5370dffac910eb3f8ed | |
parent | fb8e121ece1b26fe8b9ed614a5a18df1898f5a88 (diff) |
fix bug in image file chooser preventing opening files from ~/Documents
-rw-r--r-- | GNUChessActivity.py | 47 |
1 files changed, 43 insertions, 4 deletions
diff --git a/GNUChessActivity.py b/GNUChessActivity.py index 73ddf42..794a1e5 100644 --- a/GNUChessActivity.py +++ b/GNUChessActivity.py @@ -33,7 +33,8 @@ from sugar.graphics.xocolor import XoColor from toolbar_utils import button_factory, label_factory, separator_factory, \ radio_factory, entry_factory -from utils import json_load, json_dump, get_hardware +from utils import json_load, json_dump, get_hardware, \ + pixbuf_to_base64, base64_to_pixbuf import telepathy import dbus @@ -482,14 +483,23 @@ class GNUChessActivity(activity.Activity): id = self.metadata[piece] jobject = datastore.get(id) if jobject is not None and jobject.file_path is not None: - self._gnuchess.reskin_from_file(piece, jobject.file_path) + if self._gnuchess.we_are_sharing and self.buddy is not None: + pixbuf = self._gnuchess.reskin_from_file( + piece, jobject.file_path, return_pixbuf= True) + if 'white' in piece and self.playing_white: + self.send_piece(piece, pixbuf) + elif 'black' in piece and not self.playing_white: + self.send_piece(piece, pixbuf) + else: + self._gnuchess.reskin_from_file(piece, + jobject.file_path) return def _reskin_cb(self, button, piece): - id, file_path = self._choose_skin() + object_id, file_path = self._choose_skin() if file_path is not None: self._gnuchess.reskin_from_file(piece, file_path) - self.metadata[piece] = str(id) + self.metadata[piece] = str(object_id) def do_fullscreen_cb(self, button): ''' Hide the Sugar toolbars. ''' @@ -697,9 +707,11 @@ class GNUChessActivity(activity.Activity): name = jobject.metadata['title'] mime_type = jobject.metadata['mime_type'] finally: + jobject.destroy() 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 @@ -865,6 +877,7 @@ params=%r state=%d' % (id, initiator, type, service, params, state)) 'N': [self._receive_nick, 'receive nick from opponent'], 'C': [self._receive_colors, 'receive colors from opponent'], 'j': [self._receive_join, 'receive new joiner'], + 'p': [self._receive_piece, 'receive new piece'], } def event_received_cb(self, event_message): @@ -974,6 +987,32 @@ params=%r state=%d' % (id, initiator, type, service, params, state)) if hasattr(self, 'chattube') and self.chattube is not None: self.chattube.SendText(entry) + # sharing pieces + + def send_piece(self, piece, pixbuf): + _logger.debug('send_piece %s' % (piece)) + self.send_event('p|%s' % (self._dump(peice, pixbuf))) + + def _receive_piece(self, payload): + piece, pixbuf = self._load(payload) + _logger.debug('received_piece %s' % (piece)) + self._gnuchess.reskin(piece, pixbuf) + + def _dump(self, piece, pixbuf): + ''' Dump data for sharing.''' + _logger.debug('dumping %s' % (piece)) + data = [piece, pixbuf_to_base64(activity, pixbuf)] + return json_dump(data) + + def _load(self, data): + ''' Load game data from the journal. ''' + piece, pixbuf_data = json_load(data) + pixbuf = base64_to_pixbuf(activity, + pixbuf_data, + width=self._gnuchess.scale, + height=self._gnuchess.scale) + return piece, pixbuf + class ChatTube(ExportedGObject): ''' Class for setting up tube for sharing ''' |