Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/book.py
diff options
context:
space:
mode:
authorAleksey Lim <alsroot@member.fsf.org>2009-02-26 04:58:43 (GMT)
committer Walter Bender <walter@walter-laptop.(none)>2009-03-02 14:45:11 (GMT)
commit39bfabdfd281c509e0e48580fbdda436423f022b (patch)
treecf4724acdab9caf78d969c5dc8f3b29a30a971d4 /book.py
parent02efd5d922f337c40f019432b79bcd2497861599 (diff)
Add bookview widget
Diffstat (limited to 'book.py')
-rw-r--r--book.py34
1 files changed, 32 insertions, 2 deletions
diff --git a/book.py b/book.py
index f65b493..9b94716 100644
--- a/book.py
+++ b/book.py
@@ -15,6 +15,8 @@
import os
import gtk
import logging
+import gobject
+from gobject import SIGNAL_RUN_FIRST, TYPE_PYOBJECT
from gettext import gettext as _
from sugar.activity.activity import get_bundle_path, get_activity_root
@@ -27,6 +29,28 @@ wiki = None
custom = None
class Book(IO_Manager):
+ __gsignals__ = {
+ 'article-changed' : (SIGNAL_RUN_FIRST, None, [TYPE_PYOBJECT]) }
+
+ def get_article(self):
+ return self._article
+
+ def set_article(self, name):
+ if self._article.article_title == name:
+ return
+
+ new_name = [i for i in self.get_pages() if i == name]
+
+ if not new_name:
+ logger.debug('cannot find article %s' % name)
+ return
+
+ self._article = self.load_article(new_name)
+ self.emit('article-changed', self._article)
+
+ article = gobject.property(type=object,
+ getter=get_article, setter=set_article)
+
def __init__(self, preinstalled, dirname):
IO_Manager.__init__(self, 0)
self.workingDir = os.path.join(get_activity_root(), dirname)
@@ -49,9 +73,15 @@ class Book(IO_Manager):
pages = self.get_pages()
if pages:
- self.article = self.load_article(pages[0])
+ self._article = self.load_article(pages[0])
else:
- self.article = Article()
+ self._article = None
+
+ def rename(self, new_name):
+ old_name = self._article.article_title
+ self.rename_page(old_name, new_name)
+ logger.debug('article %s was renamed to %s' % (old_name, new_name))
+ self._article.article_title = new_name
class WikiBook(Book):
def __init__(self):