Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Maurer <uwog@uwog.net>2007-10-31 18:11:08 (GMT)
committer Marc Maurer <uwog@uwog.net>2007-10-31 18:11:08 (GMT)
commit5be95aeb1158173e822a47f053240a3db36da083 (patch)
treedc75d12443e96b8039687bb75440fcc20aa63208
parent700ae4e87fd99234864aebd774c3220dd581561f (diff)
First implementation of 4165: Write must expose UI to allow specifying output format (uwog)
-rw-r--r--AbiWordActivity.py19
-rw-r--r--NEWS3
-rw-r--r--toolbar.py48
3 files changed, 60 insertions, 10 deletions
diff --git a/AbiWordActivity.py b/AbiWordActivity.py
index d68efbf..1120a35 100644
--- a/AbiWordActivity.py
+++ b/AbiWordActivity.py
@@ -32,7 +32,7 @@ from sugar.presence import presenceservice
from abiword import Canvas
import toolbar
-from toolbar import WriteEditToolbar, TextToolbar, ImageToolbar, TableToolbar, FormatToolbar, ViewToolbar
+from toolbar import WriteActivityToolbarExtension, WriteEditToolbar, TextToolbar, ImageToolbar, TableToolbar, FormatToolbar, ViewToolbar
from sugar.activity.activity import get_bundle_path
logger = logging.getLogger('write-activity')
@@ -45,10 +45,6 @@ class AbiWordActivity (Activity):
# abiword uses the current directory for all its file dialogs
os.chdir(os.path.expanduser('~'))
- toolbox = ActivityToolbox(self)
- self.set_toolbox(toolbox)
- toolbox.show()
-
self._file_opened = False
# create our main abiword canvas
@@ -58,6 +54,12 @@ class AbiWordActivity (Activity):
self.abiword_canvas.connect('selection-cleared', self._selection_cleared_cb)
# create our toolbars
+ toolbox = ActivityToolbox(self)
+ self.set_toolbox(toolbox)
+ toolbox.show()
+
+ activity_toolbar_ext = WriteActivityToolbarExtension(self, toolbox, self.abiword_canvas)
+
text_toolbar = TextToolbar(toolbox, self.abiword_canvas)
self._edit_toolbar = WriteEditToolbar(toolbox, self.abiword_canvas, text_toolbar)
@@ -314,14 +316,11 @@ class AbiWordActivity (Activity):
logging.debug('AbiWordActivity.write_file')
self.metadata['mime_type'] = 'application/vnd.oasis.opendocument.text'
- self.metadata['fulltext'] = self.abiword_canvas.get_content(".txt")[:3000]
+ self.metadata['fulltext'] = self.abiword_canvas.get_content(extension_or_mimetype=".txt")[:3000]
f = open(file_path, 'w')
try:
- logger.debug('Writing content as .odt')
- content = self.abiword_canvas.get_content(".odt")
- logger.debug('Content length: %d', len(content))
+ content = self.abiword_canvas.get_content(extension_or_mimetype=".odt")
f.write(content)
-# logger.debug('content written')
finally:
f.close()
diff --git a/NEWS b/NEWS
index e8fe5d6..32f6592 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,6 @@
+* First implementation of 4165: Write must expose UI to
+ allow specifying output format (uwog)
+
49
* Enable/disable the search functions based on the input (uwog)
diff --git a/toolbar.py b/toolbar.py
index aafe549..73aa4db 100644
--- a/toolbar.py
+++ b/toolbar.py
@@ -17,6 +17,8 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
from gettext import gettext as _
import logging
+import os
+import time
import abiword
import gtk
@@ -27,7 +29,10 @@ from sugar.graphics.toggletoolbutton import ToggleToolButton
from sugar.graphics.combobox import ComboBox
from sugar.graphics.toolcombobox import ToolComboBox
from sugar.graphics.objectchooser import ObjectChooser
+from sugar.activity.activity import ActivityToolbar
from sugar.activity.activity import EditToolbar
+from sugar.graphics.menuitem import MenuItem
+from sugar.datastore import datastore
logger = logging.getLogger('write-activity')
@@ -39,6 +44,49 @@ TOOLBAR_IMAGE = 3
TOOLBAR_TABLE = 4
TOOLBAR_VIEW = 5
+class WriteActivityToolbarExtension:
+
+ # file mime type, abiword exporter properties, drop down name, journal entry postfix
+ _EXPORT_FORMATS = [['application/rtf', _('Rich Text (RTF)'), _('RTF'), ""],
+ ['text/html', _('Hypertext (HTML)'), _('HTML'), "html4:yes; declare-xml:no; embed-css:yes; embed-images:yes;"],
+ ['text/plain', _('Plain Text (TXT)'), _('TXT'), ""]]
+
+ def __init__(self, activity, toolbox, abiword_canvas):
+
+ self._activity = activity
+ self._abiword_canvas = abiword_canvas
+ self._activity_toolbar = toolbox.get_activity_toolbar()
+ self._keep_palette = self._activity_toolbar.keep.get_palette()
+
+ # hook up the export formats to the Keep button
+ for i, f in enumerate(self._EXPORT_FORMATS):
+ menu_item = MenuItem(f[1])
+ menu_item.connect('activate', self._export_as_cb, f[0], f[2], f[3])
+ self._keep_palette.menu.append(menu_item)
+ menu_item.show()
+
+ def _export_as_cb(self, menu_item, mimetype, jpostfix, exp_props):
+ logger.debug('exporting file, mimetype: %s, exp_props: %s', mimetype, exp_props);
+
+ # special case HTML export to set the activity name as the HTML title
+ if mimetype == "text/html":
+ exp_props += " title:" + self._activity.metadata['title'] + ';';
+
+ # create a new journal item
+ fileObject = datastore.create()
+ fileObject.metadata['title'] = self._activity.metadata['title'] + ' (' + jpostfix + ')';
+ fileObject.metadata['mime_type'] = mimetype
+ fileObject.metadata['fulltext'] = self._abiword_canvas.get_content(extension_or_mimetype=".txt")[:3000]
+
+ # write out the document contents in the requested format
+ fileObject.file_path = os.path.join(self._activity.get_activity_root(), 'data', '%i' % time.time())
+ self._abiword_canvas.save('file://' + fileObject.file_path, mimetype, exp_props)
+
+ # store the journal item
+ datastore.write(fileObject, transfer_ownership=True)
+ fileObject.destroy()
+ del fileObject
+
class WriteEditToolbar(EditToolbar):
def __init__(self, toolbox, abiword_canvas, text_toolbar):