diff options
-rw-r--r-- | AbiWordActivity.py | 137 | ||||
-rw-r--r-- | port/chooser.py | 7 | ||||
-rw-r--r-- | toolbar.py | 34 | ||||
-rw-r--r-- | widgets.py | 37 |
4 files changed, 140 insertions, 75 deletions
diff --git a/AbiWordActivity.py b/AbiWordActivity.py index 4f585af..0f62523 100644 --- a/AbiWordActivity.py +++ b/AbiWordActivity.py @@ -53,10 +53,11 @@ from widgets import ExportButton logger = logging.getLogger('write-activity') -class AbiWordActivity (activity.Activity): - def __init__ (self, handle): - activity.Activity.__init__ (self, handle) +class AbiWordActivity(activity.Activity): + + def __init__(self, handle): + activity.Activity.__init__(self, handle) # abiword uses the current directory for all its file dialogs os.chdir(os.path.expanduser('~')) @@ -108,7 +109,7 @@ class AbiWordActivity (activity.Activity): list_toolbar.props.icon_name = 'toolbar-bulletlist' list_toolbar.props.label = _('Bullet List') toolbar_box.toolbar.insert(list_toolbar, -1) - + insert_toolbar = ToolbarButton() insert_toolbar.props.page = InsertToolbar(self.abiword_canvas) insert_toolbar.props.icon_name = 'insert-table' @@ -169,7 +170,8 @@ class AbiWordActivity (activity.Activity): self.abiword_canvas.connect_after('map-event', self.__map_event_cb) self.abiword_canvas.show() - self._zoom_handler = self.abiword_canvas.connect("zoom", self.__zoom_cb) + self._zoom_handler = self.abiword_canvas.connect("zoom", + self.__zoom_cb) def _text_color_cb(self, button, abiword_canvas): newcolor = button.get_color() @@ -188,7 +190,9 @@ class AbiWordActivity (activity.Activity): # XXX workarond code to redraw abi document on every resize, see #1121 # looks like original #1121 issue is already not reproducible in # environments like fc13 but we still need it for older ones + def size_allocate_cb(abi, alloc): + def idle_cb(): zoom = abi.get_zoom_percentage() abi.set_zoom_percentage(zoom) @@ -199,8 +203,8 @@ class AbiWordActivity (activity.Activity): logger.debug('__map_event_cb') # set custom keybindings for Write - logger.debug("Loading keybindings") - keybindings_file = os.path.join( get_bundle_path(), "keybindings.xml" ) + logger.debug('Loading keybindings') + keybindings_file = os.path.join(get_bundle_path(), 'keybindings.xml') self.abiword_canvas.invoke_cmd( 'com.abisource.abiword.loadbindings.fromURI', keybindings_file, 0, 0) @@ -228,9 +232,10 @@ class AbiWordActivity (activity.Activity): if self._shared_activity: # we are joining the activity - logger.debug("We are joining an activity") + logger.debug('We are joining an activity') self.connect('joined', self._joined_cb) - self._shared_activity.connect('buddy-joined', self._buddy_joined_cb) + self._shared_activity.connect('buddy-joined', + self._buddy_joined_cb) self._shared_activity.connect('buddy-left', self._buddy_left_cb) if self.get_shared(): # # oh, OK, we've already joined @@ -250,6 +255,7 @@ class AbiWordActivity (activity.Activity): gtk.gdk.INTERP_BILINEAR) preview_data = [] + def save_func(buf, data): data.append(buf) @@ -266,11 +272,10 @@ class AbiWordActivity (activity.Activity): self._shared_activity.connect('buddy-joined', self._buddy_joined_cb) self._shared_activity.connect('buddy-left', self._buddy_left_cb) + channel = self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES] logger.debug('This is my activity: offering a tube...') - id = self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].OfferDBusTube( - "com.abisource.abiword.abicollab", {}) - logger.debug('Tube address: %s', self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].GetDBusTubeAddress(id)) - + id = channel.OfferDBusTube('com.abisource.abiword.abicollab', {}) + logger.debug('Tube address: %s', channel.GetDBusTubeAddress(id)) def _setup(self): logger.debug("_setup()") @@ -279,7 +284,8 @@ class AbiWordActivity (activity.Activity): logger.error('Failed to share or join activity') return - bus_name, conn_path, channel_paths = self._shared_activity.get_channels() + bus_name, conn_path, channel_paths = \ + self._shared_activity.get_channels() # Work out what our room is called and whether we have Tubes already room = None @@ -309,10 +315,12 @@ class AbiWordActivity (activity.Activity): # Make sure we have a Tubes channel - PS doesn't yet provide one if tubes_chan is None: - logger.debug("Didn't find our Tubes negotation channel, requesting one...") - tubes_chan = self.conn.request_channel(telepathy.CHANNEL_TYPE_TUBES, - telepathy.HANDLE_TYPE_ROOM, room, True) - logger.debug("Got our tubes negotiation channel") + logger.debug('Didn''t find our Tubes negotation channel, ' + + 'requesting one...') + tubes_chan = self.conn.request_channel( \ + telepathy.CHANNEL_TYPE_TUBES, \ + telepathy.HANDLE_TYPE_ROOM, room, True) + logger.debug('Got our tubes negotiation channel') self.tubes_chan = tubes_chan self.text_chan = text_chan @@ -348,12 +356,13 @@ class AbiWordActivity (activity.Activity): if (type == telepathy.TUBE_TYPE_DBUS and service == "com.abisource.abiword.abicollab"): + channel = self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES] if state == telepathy.TUBE_STATE_LOCAL_PENDING: - self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].AcceptDBusTube(id) + channel.AcceptDBusTube(id) initiator_path = None - contacts = self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].GetDBusNames(id) - #print 'dbus contact mapping',self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].GetDBusNames(id) + contacts = channel.GetDBusNames(id) + #print 'dbus contact mapping',channel.GetDBusNames(id) for i, struct in enumerate(contacts): #print 'mapping i',i handle, path = struct @@ -363,33 +372,48 @@ class AbiWordActivity (activity.Activity): break if initiator_path is None: - logger.error('Unable to get the dbus path of the tube initiator') + logger.error('Unable to get the dbus path ' + + 'of the tube initiator') else: # pass this tube to abicollab - address = self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].GetDBusTubeAddress(id) + address = channel.GetDBusTubeAddress(id) + cmd_prefix = 'com.abisource.abiword.abicollab.olpc' if self.joined: - logger.debug('Passing tube address to abicollab (join): %s', address) - self.abiword_canvas.invoke_cmd('com.abisource.abiword.abicollab.olpc.joinTube', address, 0, 0) + logger.debug( \ + 'Passing tube address to abicollab (join): %s', + address) + self.abiword_canvas.invoke_cmd(cmd_prefix + '.joinTube', + address, 0, 0) if initiator_path is not None: - logger.debug('Adding the initiator to the session: %s', initiator_path) - self.abiword_canvas.invoke_cmd('com.abisource.abiword.abicollab.olpc.buddyJoined', initiator_path, 0, 0) + logger.debug('Adding the initiator to session: %s', + initiator_path) + self.abiword_canvas.invoke_cmd( \ + cmd_prefix + '.buddyJoined', + initiator_path, 0, 0) else: - logger.debug('Passing tube address to abicollab (offer): %s', address) - self.abiword_canvas.invoke_cmd('com.abisource.abiword.abicollab.olpc.offerTube', address, 0, 0) + logger.debug( \ + 'Passing tube address to abicollab (offer): %s', + address) + self.abiword_canvas.invoke_cmd(cmd_prefix + '.offerTube', + address, 0, 0) - self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].connect_to_signal('DBusNamesChanged', + channel.connect_to_signal('DBusNamesChanged', self._on_dbus_names_changed) # HACK, as DBusNamesChanged doesn't fire on buddies leaving - self.tubes_chan[telepathy.CHANNEL_INTERFACE_GROUP].connect_to_signal('MembersChanged', - self._on_members_changed) + channel_group = self.tubes_chan[telepathy.CHANNEL_INTERFACE_GROUP] + channel_group.connect_to_signal('MembersChanged', + self._on_members_changed) def _on_dbus_names_changed(self, tube_id, added, removed): logger.debug('_on_dbus_names_changed') # if tube_id == self.tube_id: + cmd_prefix = 'com.abisource.abiword.abicollab.olpc' for handle, bus_name in added: - logger.debug('added handle: %s, with dbus_name: %s', handle, bus_name) - self.abiword_canvas.invoke_cmd('com.abisource.abiword.abicollab.olpc.buddyJoined', bus_name, 0, 0) + logger.debug('added handle: %s, with dbus_name: %s', + handle, bus_name) + self.abiword_canvas.invoke_cmd(cmd_prefix + '.buddyJoined', + bus_name, 0, 0) self.participants[handle] = bus_name # if handle == self.self_handle: @@ -401,10 +425,12 @@ class AbiWordActivity (activity.Activity): # HACK: doesn't work yet, bad morgs! # for handle in removed: -# logger.debug('removed handle: %s, with dbus name: %s', handle, bus_name) +# logger.debug('removed handle: %s, with dbus name: %s', +# handle, bus_name) # bus_name = self.participants.pop(handle, None) - def _on_members_changed(self, message, added, removed, local_pending, remote_pending, actor, reason): + def _on_members_changed(self, message, added, removed, local_pending, + remote_pending, actor, reason): logger.debug("_on_members_changed") for handle in removed: bus_name = self.participants.pop(handle, None) @@ -413,41 +439,54 @@ class AbiWordActivity (activity.Activity): # Should be investigated continue + cmd_prefix = 'com.abisource.abiword.abicollab.olpc' logger.debug('removed handle: %d, with dbus name: %s', handle, bus_name) - self.abiword_canvas.invoke_cmd('com.abisource.abiword.abicollab.olpc.buddyLeft', bus_name, 0, 0) + self.abiword_canvas.invoke_cmd(cmd_prefix + '.buddyLeft', + bus_name, 0, 0) - def _buddy_joined_cb (self, activity, buddy): + def _buddy_joined_cb(self, activity, buddy): logger.debug('buddy joined with object path: %s', buddy.object_path()) -# self.abiword_canvas.invoke_cmd('com.abisource.abiword.abicollab.olpc.buddyJoined', buddy.object_path(), 0, 0) +# self.abiword_canvas.invoke_cmd( +# 'com.abisource.abiword.abicollab.olpc.buddyJoined', +# buddy.object_path(), 0, 0) - def _buddy_left_cb (self, activity, buddy): + def _buddy_left_cb(self, activity, buddy): logger.debug('buddy left with object path: %s', buddy.object_path()) - #self.abiword_canvas.invoke_cmd('com.abisource.abiword.abicollab.olpc.buddyLeft', self.participants[buddy.object_path()], 0, 0) +#self.abiword_canvas.invoke_cmd('com.abisource.abiword.abicollab.olpc.' + +#'buddyLeft', self.participants[buddy.object_path()], 0, 0) def read_file(self, file_path): - logging.debug('AbiWordActivity.read_file: %s, mimetype: %s', file_path, self.metadata['mime_type']) + logging.debug('AbiWordActivity.read_file: %s, mimetype: %s', + file_path, self.metadata['mime_type']) if 'source' in self.metadata and self.metadata['source'] == '1': logger.debug('Opening file in view source mode') - self.abiword_canvas.load_file('file://' + file_path, 'text/plain') + self.abiword_canvas.load_file('file://' + file_path, 'text/plain') else: - self.abiword_canvas.load_file('file://' + file_path, '') # we pass no mime/file type, let libabiword autodetect it, so we can handle multiple file formats + # we pass no mime/file type, let libabiword autodetect it, + # so we can handle multiple file formats + self.abiword_canvas.load_file('file://' + file_path, '') def write_file(self, file_path): logging.debug('AbiWordActivity.write_file') - # check if we have a default mimetype; if not, fall back to OpenDocument + # check if we have a default mimetype; if not, + # fall back to OpenDocument # also fallback if we know we cannot export in that format - if 'mime_type' not in self.metadata or self.metadata['mime_type'] == '' or \ + if 'mime_type' not in self.metadata or \ + self.metadata['mime_type'] == '' or \ self.metadata['mime_type'] == 'application/msword': - self.metadata['mime_type'] = 'application/vnd.oasis.opendocument.text' + self.metadata['mime_type'] = \ + 'application/vnd.oasis.opendocument.text' - # if we were viewing the source of a file, + # if we were viewing the source of a file, # then always save as plain text actual_mimetype = self.metadata['mime_type'] if 'source' in self.metadata and self.metadata['source'] == '1': logger.debug('Writing file as type source (text/plain)') actual_mimetype = 'text/plain' - self.metadata['fulltext'] = self.abiword_canvas.get_content(extension_or_mimetype=".txt")[:3000] + self.metadata['fulltext'] = \ + self.abiword_canvas.get_content(extension_or_mimetype=".txt") \ + [:3000] self.abiword_canvas.save('file://' + file_path, actual_mimetype, '') diff --git a/port/chooser.py b/port/chooser.py index e2df259..c56d19f 100644 --- a/port/chooser.py +++ b/port/chooser.py @@ -20,16 +20,17 @@ import logging from sugar import mime from sugar.graphics.objectchooser import ObjectChooser -TEXT = hasattr(mime, 'GENERIC_TYPE_TEXT') and mime.GENERIC_TYPE_TEXT or None +TEXT = hasattr(mime, 'GENERIC_TYPE_TEXT') and mime.GENERIC_TYPE_TEXT or None IMAGE = hasattr(mime, 'GENERIC_TYPE_IMAGE') and mime.GENERIC_TYPE_IMAGE or None AUDIO = hasattr(mime, 'GENERIC_TYPE_AUDIO') and mime.GENERIC_TYPE_AUDIO or None VIDEO = hasattr(mime, 'GENERIC_TYPE_VIDEO') and mime.GENERIC_TYPE_VIDEO or None -LINK = hasattr(mime, 'GENERIC_TYPE_LINK') and mime.GENERIC_TYPE_LINK or None +LINK = hasattr(mime, 'GENERIC_TYPE_LINK') and mime.GENERIC_TYPE_LINK or None + def pick(cb=None, default=None, parent=None, what=None): """ Opens object chooser. - + Method returns: * cb(jobject), if object was choosen and cb is not None @@ -41,9 +41,11 @@ from widgets import FontSizeCombo logger = logging.getLogger('write-activity') + class EditToolbar(gtk.Toolbar): + def __init__(self, pc, toolbar_box): - + gtk.Toolbar.__init__(self) self._abiword_canvas = pc.abiword_canvas @@ -126,10 +128,10 @@ class EditToolbar(gtk.Toolbar): self._findnext.set_sensitive(False) def __paste_button_cb(self, button): - clipBoard = gtk.Clipboard() + clipboard = gtk.Clipboard() - if clipBoard.wait_is_image_available(): - pixbuf_sel = clipBoard.wait_for_image() + if clipboard.wait_is_image_available(): + pixbuf_sel = clipboard.wait_for_image() size = int(pixbuf_sel.get_width()), int(pixbuf_sel.get_height()) activity = self._abiword_canvas.get_toplevel() temp_path = os.path.join(activity.get_activity_root(), 'instance') @@ -141,8 +143,8 @@ class EditToolbar(gtk.Toolbar): pixbuf_sel.save(file_path, 'jpeg') self._abiword_canvas.insert_image(file_path, False) - elif clipBoard.wait_is_uris_available(): - selection = clipBoard.wait_for_contents('text/uri-list') + elif clipboard.wait_is_uris_available(): + selection = clipboard.wait_for_contents('text/uri-list') if selection != None: for uri in selection.get_uris(): self._abiword_canvas.insert_image(urlparse(uri).path, @@ -203,7 +205,9 @@ class EditToolbar(gtk.Toolbar): self.insert(tool_item, -1) tool_item.show() + class InsertToolbar(gtk.Toolbar): + def __init__(self, abiword_canvas): gtk.Toolbar.__init__(self) @@ -256,13 +260,16 @@ class InsertToolbar(gtk.Toolbar): self.show_all() self._abiword_canvas.connect('table-state', self._isTable_cb) - #self._abiword_canvas.connect('image-selected', self._image_selected_cb) + #self._abiword_canvas.connect('image-selected', + # self._image_selected_cb) def _image_cb(self, button): + def cb(object): logging.debug('ObjectChooser: %r' % object) self._abiword_canvas.insert_image(object.file_path, True) - chooser.pick(parent=self._abiword_canvas.get_toplevel(), what=chooser.IMAGE, cb=cb) + chooser.pick(parent=self._abiword_canvas.get_toplevel(), + what=chooser.IMAGE, cb=cb) def _table_cb(self, abi, rows, cols): self._abiword_canvas.insert_table(rows, cols) @@ -285,7 +292,9 @@ class InsertToolbar(gtk.Toolbar): self._table_cols_after.set_sensitive(b) self._table_delete_cols.set_sensitive(b) + class ViewToolbar(gtk.Toolbar): + def __init__(self, abiword_canvas): gtk.Toolbar.__init__(self) @@ -294,7 +303,8 @@ class ViewToolbar(gtk.Toolbar): self._zoom_out = ToolButton('zoom-out') self._zoom_out.set_tooltip(_('Zoom Out')) - self._zoom_out_id = self._zoom_out.connect('clicked', self._zoom_out_cb) + self._zoom_out_id = self._zoom_out.connect('clicked', + self._zoom_out_cb) self.insert(self._zoom_out, -1) self._zoom_out.show() @@ -401,7 +411,9 @@ class ViewToolbar(gtk.Toolbar): finally: self._page_spin.handler_unblock(self._page_spin_id) + class TextToolbar(gtk.Toolbar): + def __init__(self, abiword_canvas): gtk.Toolbar.__init__(self) @@ -416,7 +428,9 @@ class TextToolbar(gtk.Toolbar): self.show_all() + class ParagraphToolbar(gtk.Toolbar): + def __init__(self, abi): gtk.Toolbar.__init__(self) @@ -491,7 +505,9 @@ class ParagraphToolbar(gtk.Toolbar): self.show_all() + class ListToolbar(gtk.Toolbar): + def __init__(self, abi): gtk.Toolbar.__init__(self) @@ -27,7 +27,9 @@ from sugar.datastore import datastore logger = logging.getLogger('write-activity') + class FontCombo(ComboBox): + def __init__(self, abi): ComboBox.__init__(self) @@ -85,7 +87,9 @@ class FontCombo(ComboBox): self.set_active(font_index) self.handler_unblock(self._fonts_changed_id) + class FontSizeCombo(ComboBox): + def __init__(self, abi): ComboBox.__init__(self) @@ -120,7 +124,9 @@ class FontSizeCombo(ComboBox): self.handler_unblock(self._changed_id) break + class AbiButton(RadioToolButton): + def __init__(self, abi, abi_signal, do_abi_cb, on_abi_cb=None, **kwargs): RadioToolButton.__init__(self, **kwargs) @@ -152,22 +158,24 @@ class AbiButton(RadioToolButton): finally: self.handler_unblock(self._toggled_handler) + class ExportButton(ToolButton): - _EXPORT_FORMATS = [{'mime_type' : 'application/rtf', - 'title' : _('Rich Text (RTF)'), - 'jpostfix' : _('RTF'), - 'exp_props' : ''}, - - {'mime_type' : 'text/html', - 'title' : _('Hypertext (HTML)'), - 'jpostfix' : _('HTML'), - 'exp_props' : 'html4:yes; declare-xml:no; ' \ + + _EXPORT_FORMATS = [{'mime_type': 'application/rtf', + 'title': _('Rich Text (RTF)'), + 'jpostfix': _('RTF'), + 'exp_props': ''}, + + {'mime_type': 'text/html', + 'title': _('Hypertext (HTML)'), + 'jpostfix': _('HTML'), + 'exp_props': 'html4:yes; declare-xml:no; ' \ 'embed-css:yes; embed-images:yes;'}, - {'mime_type' : 'text/plain', - 'title' : _('Plain Text (TXT)'), - 'jpostfix' : _('TXT'), - 'exp_props' : ''}, + {'mime_type': 'text/plain', + 'title': _('Plain Text (TXT)'), + 'jpostfix': _('TXT'), + 'exp_props': ''}, {'mime_type': 'application/pdf', 'title': _('Portable Document Format (PDF)'), @@ -205,7 +213,8 @@ class ExportButton(ToolButton): act_meta = activity.metadata fileObject.metadata['title'] = \ act_meta['title'] + ' (' + format['jpostfix'] + ')' - fileObject.metadata['title_set_by_user'] = act_meta['title_set_by_user'] + fileObject.metadata['title_set_by_user'] = \ + act_meta['title_set_by_user'] fileObject.metadata['mime_type'] = format['mime_type'] fileObject.metadata['fulltext'] = abi.get_content( extension_or_mimetype=".txt")[:3000] |