Improve display of text files
Clean hard line breaks and justify fill.
Signed-off-by: Gonzalo Odiard <gonzalo@laptop.org>
Gonzalo Odiard
11 years ago
13 | 13 | |
14 | 14 | PAGE_SIZE = 38 |
15 | 15 | |
16 | # remove hard line breaks, apply a simple logic to try identify | |
17 | # the unneeded | |
18 | def _clean_text(line): | |
19 | if line != '\r\n': | |
20 | if line[-3] not in ('.', ',', '-', ';') and len(line) > 60: | |
21 | line = line[:-2] | |
22 | return line | |
16 | 23 | |
17 | 24 | class TextViewer(GObject.GObject): |
18 | 25 | |
36 | 43 | self.textview.set_cursor_visible(False) |
37 | 44 | self.textview.set_left_margin(50) |
38 | 45 | self.textview.set_right_margin(50) |
46 | self.textview.set_justification(Gtk.Justification.FILL) | |
39 | 47 | self.textview.set_wrap_mode(Gtk.WrapMode.WORD) |
40 | 48 | self.textview.connect('button-release-event', \ |
41 | 49 | self._view_buttonrelease_event_cb) |
139 | 147 | if not line: |
140 | 148 | break |
141 | 149 | else: |
150 | line = _clean_text(line) | |
142 | 151 | label_text = label_text + unicode(line, "iso-8859-1") |
143 | 152 | line_increment = (len(line) / 80) + 1 |
144 | 153 | linecount = linecount + line_increment |
546 | 555 | self.obj._text_file.seek(0) |
547 | 556 | while self.obj._text_file: |
548 | 557 | line = unicode(self.obj._text_file.readline(), "iso-8859-1") |
558 | line = _clean_text(line) | |
549 | 559 | line_length = len(line) |
550 | 560 | if not line: |
551 | 561 | break |