diff options
author | Gonzalo Odiard <godiard@gmail.com> | 2012-09-13 13:23:23 (GMT) |
---|---|---|
committer | Gonzalo Odiard <godiard@gmail.com> | 2012-09-13 13:45:45 (GMT) |
commit | ea74dc6efa616922b20f131d5594842056eb8b3e (patch) | |
tree | dc20cc7547b6bcb234d612bc67f7a03b64193d39 | |
parent | 76a25cf799938394b85fbdb97c346268e3fc92cb (diff) |
Improve display of text files
Clean hard line breaks and justify fill.
Signed-off-by: Gonzalo Odiard <gonzalo@laptop.org>
-rw-r--r-- | textadapter.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/textadapter.py b/textadapter.py index fe6b75f..2ff02dc 100644 --- a/textadapter.py +++ b/textadapter.py @@ -14,6 +14,13 @@ import speech PAGE_SIZE = 38 +# remove hard line breaks, apply a simple logic to try identify +# the unneeded +def _clean_text(line): + if line != '\r\n': + if line[-3] not in ('.', ',', '-', ';') and len(line) > 60: + line = line[:-2] + return line class TextViewer(GObject.GObject): @@ -37,6 +44,7 @@ class TextViewer(GObject.GObject): self.textview.set_cursor_visible(False) self.textview.set_left_margin(50) self.textview.set_right_margin(50) + self.textview.set_justification(Gtk.Justification.FILL) self.textview.set_wrap_mode(Gtk.WrapMode.WORD) self.textview.connect('button-release-event', \ self._view_buttonrelease_event_cb) @@ -140,6 +148,7 @@ class TextViewer(GObject.GObject): if not line: break else: + line = _clean_text(line) label_text = label_text + unicode(line, "iso-8859-1") line_increment = (len(line) / 80) + 1 linecount = linecount + line_increment @@ -547,6 +556,7 @@ class _SearchThread(threading.Thread): self.obj._text_file.seek(0) while self.obj._text_file: line = unicode(self.obj._text_file.readline(), "iso-8859-1") + line = _clean_text(line) line_length = len(line) if not line: break |