Codebase list sugar-read-activity / ea74dc6
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
1 changed file(s) with 10 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
1313
1414 PAGE_SIZE = 38
1515
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
1623
1724 class TextViewer(GObject.GObject):
1825
3643 self.textview.set_cursor_visible(False)
3744 self.textview.set_left_margin(50)
3845 self.textview.set_right_margin(50)
46 self.textview.set_justification(Gtk.Justification.FILL)
3947 self.textview.set_wrap_mode(Gtk.WrapMode.WORD)
4048 self.textview.connect('button-release-event', \
4149 self._view_buttonrelease_event_cb)
139147 if not line:
140148 break
141149 else:
150 line = _clean_text(line)
142151 label_text = label_text + unicode(line, "iso-8859-1")
143152 line_increment = (len(line) / 80) + 1
144153 linecount = linecount + line_increment
546555 self.obj._text_file.seek(0)
547556 while self.obj._text_file:
548557 line = unicode(self.obj._text_file.readline(), "iso-8859-1")
558 line = _clean_text(line)
549559 line_length = len(line)
550560 if not line:
551561 break