Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Simmons <jim@simmons.olpc>2009-11-22 20:52:52 (GMT)
committer James Simmons <jim@simmons.olpc>2009-11-22 20:52:52 (GMT)
commitf9cd8557dadb1ce754cebccc3f2909ef03a162c2 (patch)
treefab5084fecdccd72c580bebce561f8c23d42be97
parent91e102086f0ad60fd15ab7e6d3f0fcba37a3bcf5 (diff)
modified: ReadEtextsActivity.py
modified: activity/activity.info modified: help.txt new file: pgconvert.py Add word wrapping conversion for text files.
-rw-r--r--ReadEtextsActivity.py29
-rw-r--r--activity/activity.info2
-rw-r--r--help.txt25
-rwxr-xr-xpgconvert.py63
4 files changed, 96 insertions, 23 deletions
diff --git a/ReadEtextsActivity.py b/ReadEtextsActivity.py
index f77184d..b4a5008 100644
--- a/ReadEtextsActivity.py
+++ b/ReadEtextsActivity.py
@@ -42,6 +42,7 @@ import cPickle as pickle
import speech
import xopower
import rtfconvert
+import pgconvert
PAGE_SIZE = 38
TOOLBAR_READ = 2
@@ -244,9 +245,16 @@ class ReadEtextsActivity(activity.Activity):
self.annotation_textview.set_right_margin(50)
self.annotation_textview.set_wrap_mode(gtk.WRAP_WORD)
+ if os.path.exists(os.path.join(self.get_activity_root(), 'instance', 'fontsize.txt')):
+ f = open(os.path.join(self.get_activity_root(), 'instance', 'fontsize.txt'), 'r')
+ line = f.readline()
+ fontsize = int(line.strip())
+ self.font_desc = pango.FontDescription("sans %d" % style.zoom(fontsize))
+ f.close()
+ else:
+ self.font_desc = pango.FontDescription("sans %d" % style.zoom(10))
buffer = self.textview.get_buffer()
self.markset_id = buffer.connect("mark-set", self.mark_set_cb)
- self.font_desc = pango.FontDescription("sans %d" % style.zoom(10))
self.textview.modify_font(self.font_desc)
self.annotation_textview.modify_font(self.font_desc)
self.scrolled.add(self.textview)
@@ -595,6 +603,11 @@ class ReadEtextsActivity(activity.Activity):
self.font_desc.set_size(font_size * 1024)
self.textview.modify_font(self.font_desc)
self.annotation_textview.modify_font(self.font_desc)
+ f = open(os.path.join(self.get_activity_root(), 'instance', 'fontsize.txt'), 'w')
+ try:
+ f.write(str(font_size))
+ finally:
+ f.close
def font_increase(self):
font_size = self.font_desc.get_size() / 1024
@@ -602,6 +615,11 @@ class ReadEtextsActivity(activity.Activity):
self.font_desc.set_size(font_size * 1024)
self.textview.modify_font(self.font_desc)
self.annotation_textview.modify_font(self.font_desc)
+ f = open(os.path.join(self.get_activity_root(), 'instance', 'fontsize.txt'), 'w')
+ try:
+ f.write(str(font_size))
+ finally:
+ f.close
def scroll_down(self):
v_adjustment = self.scrolled.get_vadjustment()
@@ -805,7 +823,14 @@ class ReadEtextsActivity(activity.Activity):
os.remove(current_file_name)
current_file_name = converted_file_name
self.tempfile = converted_file_name
-
+ else:
+ converted_file_name = os.path.join(self.get_activity_root(), 'instance',
+ 'convert%i' % time.time())
+ pgconvert.convert(current_file_name, converted_file_name)
+ os.remove(current_file_name)
+ current_file_name = converted_file_name
+ self.tempfile = converted_file_name
+
self.etext_file = open(current_file_name,"r")
self.page_index = [ 0 ]
diff --git a/activity/activity.info b/activity/activity.info
index 8d70e18..8d8fd45 100644
--- a/activity/activity.info
+++ b/activity/activity.info
@@ -4,6 +4,6 @@ service_name = org.laptop.sugar.ReadEtextsActivity
icon = read-etexts
exec = sugar-activity ReadEtextsActivity.ReadEtextsActivity
show_launcher = yes
-activity_version = 17
+activity_version = 18
mime_types = text/plain;application/zip;application/rtf
license = GPLv2+
diff --git a/help.txt b/help.txt
index 37a311b..dd70404 100644
--- a/help.txt
+++ b/help.txt
@@ -1,26 +1,11 @@
-"Outside of a dog, a book is man's best friend. Inside of a dog it's too
-dark to read." -- Groucho Marx
+"Outside of a dog, a book is man's best friend. Inside of a dog it's too dark to read." -- Groucho Marx
-The Books tab above will let you search through the offline catalog
-of Project Gutenberg, an Internet repository of free etexts featuring
-books in many languages. The catalog used contains 28,595 titles
-from Project Gutenberg and Project Gutenberg Australia. The catalog
-is current as of January 29, 2009. For titles added after that date you
-should visit http://www.gutenberg.org.
+The Books tab above will let you search through the offline catalog of Project Gutenberg, an Internet repository of free etexts featuring books in many languages. The catalog used contains 28,595 titles from Project Gutenberg and Project Gutenberg Australia. The catalog is current as of January 29, 2009. For titles added after that date you should visit http://www.gutenberg.org.
-To find a book, type one or more words that would be in the author's
-name or the title, then press Enter. The list will only include books
-that match all the words, so use fewer words to make the list longer
-and more words to shorten the list. If an author goes by his initials
-(like H.G. Wells, P.G. Wodehouse, or E.E. Smith) you may need to try
-both the initials and the complete first name to get every title
-available. If you use a well known author's name like "Shakespeare"
-you will get titles both by and about him.
+To find a book, type one or more words that would be in the author's name or the title, then press Enter. The list will only include books that match all the words, so use fewer words to make the list longer and more words to shorten the list. If an author goes by his initials (like H.G. Wells, P.G. Wodehouse, or E.E. Smith) you may need to try both the initials and the complete first name to get every title available. If you use a well known author's name like "Shakespeare" you will get titles both by and about him.
-To download the book select it in the list and press the download button
-next to the search box.
+To download the book select it in the list and press the download button next to the search box.
-Press the Escape key or click the 'X' button to hide the search results table
-and start reading.
+Press the Escape key or click the 'X' button to hide the search results table and start reading.
diff --git a/pgconvert.py b/pgconvert.py
new file mode 100755
index 0000000..b9e6c4d
--- /dev/null
+++ b/pgconvert.py
@@ -0,0 +1,63 @@
+#! /usr/bin/env python
+
+# Copyright (C) 2009 James D. Simmons
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+import getopt
+import sys
+
+# This is a script to take the a file in PG format and convert it to a text file readable by Read Etexts that does
+# not have newlines at the end of each line.
+
+def convert(file_path, output_path):
+
+ pg_file = open(file_path,"r")
+ out = open(output_path, 'w')
+ previous_line_length = 0
+
+ while pg_file:
+ line = pg_file.readline()
+ outline = ''
+ if not line:
+ break
+ # print line
+ if len(line) == 2 and not previous_line_length == 2:
+ # Blank line separates paragraphs
+ outline = line + '\r\n'
+ # print 'first blank line'''
+ elif len(line) == 2 and previous_line_length == 2:
+ outline = line
+ # print 'multiple blank lines'
+ elif line[0] == ' ' or (line[0] >= '0' and line[0] <= '9'):
+ outline = '\r\n' + line[0:len(line)-2]
+ # print 'non-wrapped line;'
+ else:
+ outline = line[0:len(line)-2] + ' '
+ # print 'wrapped line'
+ out.write(outline)
+ previous_line_length = len(line)
+ pg_file.close()
+ out.close()
+ print "All done!"
+
+if __name__ == "__main__":
+ try:
+ opts, args = getopt.getopt(sys.argv[1:], "")
+ convert(args[0], args[1])
+ except getopt.error, msg:
+ print msg
+ print "This program has no options"
+ sys.exit(2)