Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/Lessons.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lessons.py')
-rw-r--r--Lessons.py76
1 files changed, 76 insertions, 0 deletions
diff --git a/Lessons.py b/Lessons.py
new file mode 100644
index 0000000..060db1e
--- /dev/null
+++ b/Lessons.py
@@ -0,0 +1,76 @@
+# 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 os
+import gtk
+import locale
+import logging
+from glob import glob
+
+import Theme
+
+THEMES = []
+
+class Lesson:
+ def __init__(self, index, filename):
+ self.index = index
+ self.name = os.path.splitext(os.path.basename(filename).lstrip(
+ '.-_1234567890').replace('_', ' '))[0]
+ self.text = file(filename, 'r').read()
+
+ def change(self):
+ View.notebook.set_current_page(self.index)
+
+class View(gtk.EventBox):
+ notebook = None
+
+ def __init__(self):
+ gtk.EventBox.__init__(self)
+
+ View.notebook = gtk.Notebook()
+ View.notebook.props.show_border = False
+ View.notebook.props.show_tabs = False
+ self.add(View.notebook)
+
+ for i in THEMES:
+ view = gtk.TextView()
+ view.get_buffer().set_text(i.text)
+ view.set_wrap_mode(gtk.WRAP_WORD)
+ view.set_editable(False)
+
+ view_box = gtk.EventBox()
+ view_box.add(view)
+ view_box.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(Theme.WHITE))
+ view_box.props.border_width = 10
+
+ border_box = gtk.EventBox()
+ border_box.add(view_box)
+ border_box.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(Theme.WHITE))
+
+ scrolled_window = gtk.ScrolledWindow()
+ scrolled_window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
+ scrolled_window.add_with_viewport(border_box)
+
+ View.notebook.append_page(scrolled_window)
+
+ self.show_all()
+
+_lang = locale.getdefaultlocale()[0].split('_')[0]
+
+if not os.path.isdir(Theme.path('lessons', _lang)):
+ logging.info('Cannot find lessons for language %s, thus use en' % _lang)
+ _lang = 'en'
+
+for i, filename in enumerate(sorted(glob(Theme.path('lessons', _lang, '*')))):
+ THEMES.append(Lesson(i, filename))