Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomeu Vizoso <tomeu@tomeuvizoso.net>2007-03-04 21:25:55 (GMT)
committer Tomeu Vizoso <tomeu@tomeuvizoso.net>2007-03-04 21:25:55 (GMT)
commit23fb24b4b0dadbe2129e9d45b2fb020ffbdf946e (patch)
tree5d7aca41acd5593a6fea796f2a4ffc1ef1277db8
parent2bbf396d78e254be56c855837b026bba880a9c73 (diff)
Added support for saving to and opening from the journal.
-rw-r--r--AbiWordActivity.py100
-rw-r--r--toolbar.py229
2 files changed, 180 insertions, 149 deletions
diff --git a/AbiWordActivity.py b/AbiWordActivity.py
index f8a05db..bd70193 100644
--- a/AbiWordActivity.py
+++ b/AbiWordActivity.py
@@ -18,42 +18,90 @@
import logging
import os
import time
-import gtk
+
+import gobject
import hippo
+
+from sugar.activity import activity
+from sugar.datastore import datastore
+from sugar.datastore.datastore import Text
+from sugar import profile
from abiword import Canvas
+
from toolbar import AbiToolbar
-from sugar.activity import activity
class AbiWordActivity (activity.Activity):
- def __init__ (self, handle):
- activity.Activity.__init__ (self, handle)
- self.set_title ("Write")
+ def __init__ (self, handle):
+ activity.Activity.__init__ (self, handle)
+ self.set_title ("Write")
+
+ self._journal_handle = None
+ self._last_saved_text = None
+
+ hippoCanvasBox = hippo.CanvasBox()
+ self.set_root(hippoCanvasBox)
+
+ # create our main abiword canvas
+ self.abiword_canvas = Canvas()
+
+ # create and add a toolbar for our window, which listens to our canvas
+ abiToolbar = AbiToolbar(hippoCanvasBox, self.abiword_canvas)
+
+ # create a hippo container to embed our canvas in
+ abiwordCanvasContainer = hippo.CanvasWidget()
+ abiwordCanvasContainer.props.widget = self.abiword_canvas
- hippoCanvasBox = hippo.CanvasBox()
- self.set_root(hippoCanvasBox)
+ # add the controls to our window
+ hippoCanvasBox.append(abiwordCanvasContainer, hippo.PACK_EXPAND)
- # create our main abiword canvas
- self.abiword_canvas = Canvas()
+ if handle.object_id:
+ obj = datastore.read(handle.object_id)
+ self.abiword_canvas.load_file('file://' + obj.get_file_path())
+ else:
+ # open a blank file
+ self.abiword_canvas.load_file("")
- # create and add a toolbar for our window, which listens to our canvas
- abiToolbar = AbiToolbar(hippoCanvasBox, self.abiword_canvas)
+ self.abiword_canvas.show()
- # create a hippo container to embed our canvas in
- abiwordCanvasContainer = hippo.CanvasWidget()
- abiwordCanvasContainer.props.widget = self.abiword_canvas
+ self.connect('focus-out-event', self._focus_out_event_cb)
+ self.connect('delete-event', self._delete_event_cb)
- # add the controls to our window
- hippoCanvasBox.append(abiwordCanvasContainer, hippo.PACK_EXPAND)
+ def _focus_out_event_cb(self, widget, event):
+ self._autosave()
- # show the abiword canvas and have it open a blank file
- self.abiword_canvas.load_file("")
- self.abiword_canvas.show()
+ def _delete_event_cb(self, widget, event):
+ self._autosave()
+
+ def _autosave(self):
+ text_content = self.abiword_canvas.get_content(".txt")[0]
+ if not self._journal_handle:
+ home_dir = os.path.expanduser('~')
+ journal_dir = os.path.join(home_dir, "Journal")
+ text = Text({'preview' : text_content[0:30],
+ 'date' : str(time.time()),
+ 'title' : 'A text document',
+ 'icon' : 'theme:object-text',
+ 'keep' : '0',
+ 'buddies' : str([ { 'name' : profile.get_nick_name(),
+ 'color': profile.get_color().to_string() }]),
+ 'icon-color' : profile.get_color().to_string()})
+ f = open(os.path.join(journal_dir, '%i.abw' % time.time()), 'w')
+ try:
+ f.write(self.abiword_canvas.get_content(".abw")[0])
+ finally:
+ f.close()
+ text.set_file_path(f.name)
+ self._journal_handle = datastore.write(text)
+ elif text_content != self._last_saved_text:
+ text = datastore.read(self._journal_handle)
+ text.get_metadata()['preview'] = text_content[0:30]
+ text.get_metadata()['date'] = str(time.time())
+ f = open(text.get_file_path(), 'w')
+ try:
+ f.write(self.abiword_canvas.get_content(".abw")[0])
+ finally:
+ f.close()
+ datastore.write(text)
- def execute(self, command, args):
- if(command == 'open_document'):
- self.abiword_canvas.load_file('file://' + args[0])
-
- return True
- else:
- return False
+ self._last_saved_text = text_content
diff --git a/toolbar.py b/toolbar.py
index 1664375..4260ebb 100644
--- a/toolbar.py
+++ b/toolbar.py
@@ -16,8 +16,6 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import logging
-import gtk
-import pango
import abiword
import hippo
@@ -25,143 +23,128 @@ from sugar.graphics.toolbar import Toolbar
from sugar.graphics.iconbutton import IconButton
class AbiToolbar(object):
- def __init__(self, hippoCanvasBox, abiword_canvas):
- toolbar = Toolbar()
- hippoCanvasBox.append(toolbar)
-
- self._abiword_canvas = abiword_canvas
-
- self._open = IconButton(icon_name='theme:stock-open')
- self._open.connect("activated", self._open_cb)
- toolbar.append(self._open)
-
- self._save = IconButton(icon_name='theme:stock-save')
- self._save.connect("activated", self._save_cb)
- self._abiword_canvas.connect("is-dirty", self._isDirty_cb)
- toolbar.append(self._save)
-
-# self._insert_separator()
-
- self._undo = IconButton(icon_name='theme:stock-undo')
- self._undo.connect("activated", self._undo_cb)
- self._abiword_canvas.connect("can_undo", self._canUndo_cb)
- toolbar.append(self._undo)
-
- self._redo = IconButton(icon_name='theme:stock-redo')
- self._redo.connect("activated", self._redo_cb)
- self._abiword_canvas.connect("can_redo", self._canRedo_cb)
- toolbar.append(self._redo)
-
-# self._insert_separator()
-
- self._underline = IconButton(icon_name='theme:stock-underline')
- self._underline_id = self._underline.connect("activated", self._underline_cb)
- self._abiword_canvas.connect("underline", self._isUnderline_cb)
- toolbar.append(self._underline)
-
- self._bold = IconButton(icon_name='theme:stock-bold')
- self._bold_id = self._bold.connect("activated", self._bold_cb)
- self._abiword_canvas.connect("bold", self._isBold_cb)
- toolbar.append(self._bold)
-
-# self._insert_separator()
-
- self._align_left = IconButton(icon_name='theme:stock-justify-left')
- self._align_left_id = self._align_left.connect("activated", self._align_left_cb)
- self._abiword_canvas.connect("left-align", self._isLeftAlign_cb)
- toolbar.append(self._align_left)
-
- self._align_center = IconButton(icon_name='theme:stock-justify-center')
- self._align_center_id = self._align_center.connect("activated", self._align_center_cb)
- self._abiword_canvas.connect("center-align", self._isCenterAlign_cb)
- toolbar.append(self._align_center)
-
- self._align_right = IconButton(icon_name='theme:stock-justify-right')
- self._align_right_id = self._align_right.connect("activated", self._align_right_cb)
- self._abiword_canvas.connect("right-align", self._isRightAlign_cb)
- toolbar.append(self._align_right)
+ def __init__(self, hippoCanvasBox, abiword_canvas):
+ toolbar = Toolbar()
+ hippoCanvasBox.append(toolbar)
+
+ self._abiword_canvas = abiword_canvas
+
+# self._insert_separator()
+
+ self._undo = IconButton(icon_name='theme:stock-undo')
+ self._undo.connect("activated", self._undo_cb)
+ self._abiword_canvas.connect("can_undo", self._canUndo_cb)
+ toolbar.append(self._undo)
+
+ self._redo = IconButton(icon_name='theme:stock-redo')
+ self._redo.connect("activated", self._redo_cb)
+ self._abiword_canvas.connect("can_redo", self._canRedo_cb)
+ toolbar.append(self._redo)
+
+# self._insert_separator()
+
+ self._underline = IconButton(icon_name='theme:stock-underline')
+ self._underline_id = self._underline.connect("activated", self._underline_cb)
+ self._abiword_canvas.connect("underline", self._isUnderline_cb)
+ toolbar.append(self._underline)
+
+ self._bold = IconButton(icon_name='theme:stock-bold')
+ self._bold_id = self._bold.connect("activated", self._bold_cb)
+ self._abiword_canvas.connect("bold", self._isBold_cb)
+ toolbar.append(self._bold)
+
+# self._insert_separator()
+
+ self._align_left = IconButton(icon_name='theme:stock-justify-left')
+ self._align_left_id = self._align_left.connect("activated", self._align_left_cb)
+ self._abiword_canvas.connect("left-align", self._isLeftAlign_cb)
+ toolbar.append(self._align_left)
+
+ self._align_center = IconButton(icon_name='theme:stock-justify-center')
+ self._align_center_id = self._align_center.connect("activated", self._align_center_cb)
+ self._abiword_canvas.connect("center-align", self._isCenterAlign_cb)
+ toolbar.append(self._align_center)
+
+ self._align_right = IconButton(icon_name='theme:stock-justify-right')
+ self._align_right_id = self._align_right.connect("activated", self._align_right_cb)
+ self._abiword_canvas.connect("right-align", self._isRightAlign_cb)
+ toolbar.append(self._align_right)
# reenable this after march 6th
-# self._table = abiword.TableCreator()
-# self._table.set_labels("Table", "Cancel")
-# self._table.show()
-# #self._tableCreate.label().hide()
-
-# tableContainer = hippo.CanvasWidget()
-# tableContainer.props.widget = self._table;
-# self._table_id = self._table.connect("selected", self._table_cb)
- #self._table_id = self._abiword_canvas.connect("table-state", self._tableState)
-# toolbar.append(tableContainer)
-
-# def _insert_separator(self):
-# separator = gtk.SeparatorToolItem()
-# separator.set_draw(True)
-# self.insert(separator, -1)
-# separator.show()
+# self._table = abiword.TableCreator()
+# self._table.set_labels("Table", "Cancel")
+# self._table.show()
+# #self._tableCreate.label().hide()
+
+# tableContainer = hippo.CanvasWidget()
+# tableContainer.props.widget = self._table;
+# self._table_id = self._table.connect("selected", self._table_cb)
+ #self._table_id = self._abiword_canvas.connect("table-state", self._tableState)
+# toolbar.append(tableContainer)
+
+# def _insert_separator(self):
+# separator = gtk.SeparatorToolItem()
+# separator.set_draw(True)
+# self.insert(separator, -1)
+# separator.show()
#
-# def setToggleButtonState(self, button, b, id):
-# button.handler_block(id)
-# button.set_active(b)
-# button.handler_unblock(id)
-
- def _open_cb(self, button):
- self._abiword_canvas.file_open()
+# def setToggleButtonState(self, button, b, id):
+# button.handler_block(id)
+# button.set_active(b)
+# button.handler_unblock(id)
- def _save_cb(self, button):
- self._abiword_canvas.file_save()
+ def _isDirty_cb(self, abi, b):
+ print "isDirty",b
+# self._save.set_sensitive(b)
- def _isDirty_cb(self, abi, b):
- print "isDirty",b
-# self._save.set_sensitive(b)
+ def _undo_cb(self, button):
+ self._abiword_canvas.undo()
- def _undo_cb(self, button):
- self._abiword_canvas.undo()
+ def _canUndo_cb(self, abi, b):
+ print "canUndo",b
+# self._undo.set_sensitive(b)
- def _canUndo_cb(self, abi, b):
- print "canUndo",b
-# self._undo.set_sensitive(b)
+ def _redo_cb(self, button):
+ self._abiword_canvas.redo()
- def _redo_cb(self, button):
- self._abiword_canvas.redo()
+ def _canRedo_cb(self, abi ,b):
+ print "canRedo",b
+# self._redo.set_sensitive(b)
- def _canRedo_cb(self, abi ,b):
- print "canRedo",b
-# self._redo.set_sensitive(b)
+ def _underline_cb(self, button):
+ self._abiword_canvas.toggle_underline()
- def _underline_cb(self, button):
- self._abiword_canvas.toggle_underline()
+ def _isUnderline_cb(self, abi, b):
+ print "isUnderline",b
+# self.setToggleButtonState(self._underline, b, self._underline_id)
- def _isUnderline_cb(self, abi, b):
- print "isUnderline",b
-# self.setToggleButtonState(self._underline, b, self._underline_id)
+ def _bold_cb(self, button):
+ self._abiword_canvas.toggle_bold()
- def _bold_cb(self, button):
- self._abiword_canvas.toggle_bold()
+ def _isBold_cb(self, abi, b):
+ print "isBold",b
+# self.setToggleButtonState(self._bold,b,self._bold_id)
- def _isBold_cb(self, abi, b):
- print "isBold",b
-# self.setToggleButtonState(self._bold,b,self._bold_id)
+ def _align_left_cb(self, button):
+ self._abiword_canvas.align_left()
- def _align_left_cb(self, button):
- self._abiword_canvas.align_left()
+ def _isLeftAlign_cb(self, abi, b):
+ print "isLeftAlign",b
+# self.setToggleButtonState(self._align_left,b,self._align_left_id)
- def _isLeftAlign_cb(self, abi, b):
- print "isLeftAlign",b
-# self.setToggleButtonState(self._align_left,b,self._align_left_id)
+ def _align_center_cb(self, button):
+ self._abiword_canvas.align_center()
- def _align_center_cb(self, button):
- self._abiword_canvas.align_center()
+ def _isCenterAlign_cb(self, abi, b):
+ print "isCenterAlign",b
+# self.setToggleButtonState(self._align_center,b,self._align_center_id)
- def _isCenterAlign_cb(self, abi, b):
- print "isCenterAlign",b
-# self.setToggleButtonState(self._align_center,b,self._align_center_id)
+ def _align_right_cb(self, button):
+ self._abiword_canvas.align_right()
- def _align_right_cb(self, button):
- self._abiword_canvas.align_right()
+ def _isRightAlign_cb(self, abi, b):
+ print "isRightAlign",b
+# self.setToggleButtonState(self._align_right,b,self._align_right_id)
- def _isRightAlign_cb(self, abi, b):
- print "isRightAlign",b
-# self.setToggleButtonState(self._align_right,b,self._align_right_id)
-
-# def _table_cb(self, abi, rows, cols):
-# self._abiword_canvas.insert_table(rows,cols)
+# def _table_cb(self, abi, rows, cols):
+# self._abiword_canvas.insert_table(rows,cols)