Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/textadapter.py
diff options
context:
space:
mode:
authorGonzalo Odiard <godiard@sugarlabs.org>2011-02-18 17:27:29 (GMT)
committer Gonzalo Odiard <godiard@sugarlabs.org>2011-02-18 17:33:12 (GMT)
commitaa5534a95735df60c9cf619b6d463d2ec21abd95 (patch)
treecfcb4008b9333a7336eb97772ff48343d9050ef6 /textadapter.py
parent76cacfad48af182b1edefbdaf202b7edb4f43c81 (diff)
Add highlight support to thetext backend
- The highlights are saved in the same db we save the bookmarks. - The highlights can be removed selecting again the same tex, or a subportion of the text or puting the cursos inside the highlighted area.
Diffstat (limited to 'textadapter.py')
-rw-r--r--textadapter.py31
1 files changed, 30 insertions, 1 deletions
diff --git a/textadapter.py b/textadapter.py
index c3709e5..a82c153 100644
--- a/textadapter.py
+++ b/textadapter.py
@@ -51,6 +51,11 @@ class TextViewer(gobject.GObject):
self.font_zoom_relation = self._zoom / self._font_size
self._current_page = 0
+ self.highlight_tag = self.textview.get_buffer().create_tag()
+ self.highlight_tag.set_property('underline', 'single')
+ self.highlight_tag.set_property('foreground', 'black')
+ self.highlight_tag.set_property('background', 'yellow')
+
def load_document(self, file_path):
self._etext_file = open(file_path.replace('file://', ''), 'r')
@@ -88,6 +93,30 @@ class TextViewer(gobject.GObject):
label_text = label_text + '\n\n\n'
textbuffer.set_text(label_text)
+ def can_highlight(self):
+ return True
+
+ def get_selection_bounds(self):
+ if self.textview.get_buffer().get_selection_bounds():
+ begin, end = self.textview.get_buffer().get_selection_bounds()
+ return [begin.get_offset(), end.get_offset()]
+ else:
+ return []
+
+ def get_cursor_position(self):
+ insert_mark = self.textview.get_buffer().get_insert()
+ return self.textview.get_buffer().get_iter_at_mark( \
+ insert_mark).get_offset()
+
+ def show_highlights(self, tuples_list):
+ textbuffer = self.textview.get_buffer()
+ bounds = textbuffer.get_bounds()
+ textbuffer.remove_all_tags(bounds[0], bounds[1])
+ for highlight_tuple in tuples_list:
+ iterStart = textbuffer.get_iter_at_offset(highlight_tuple[0])
+ iterEnd = textbuffer.get_iter_at_offset(highlight_tuple[1])
+ textbuffer.apply_tag(self.highlight_tag, iterStart, iterEnd)
+
def connect_page_changed_handler(self, handler):
self.connect('page-changed', handler)
@@ -148,7 +177,7 @@ class TextViewer(gobject.GObject):
def get_current_file(self):
pass
- def update_metadata(self):
+ def update_metadata(self, activity):
pass
def copy(self):