1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# Copyright 2007 World Wide Workshop Foundation
#
# 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
#
# If you find this activity useful or end up using parts of it in one of your
# own creations we would love to hear from you at info@WorldWideWorkshop.org !
#
import os
import locale
import gtk
import logging
from abiword import Canvas as AbiCanvas
class LessonPlanWidget(gtk.Notebook):
def __init__ (self, basepath):
"""Create a Notebook widget for displaying lesson plans in tabs.
basepath -- string, path of directory containing lesson plans.
"""
super(LessonPlanWidget, self).__init__()
lessons = filter(lambda x: os.path.isdir(os.path.join(basepath, 'lessons', x)),
os.listdir(os.path.join(basepath, 'lessons')))
lessons.sort()
for lesson in lessons:
self._load_lesson(os.path.join(basepath, 'lessons', lesson),
_(lesson))
def _load_lesson (self, path, name):
"""Load the lesson content from a .abw, taking l10n into account.
path -- string, path of lesson plan file, e.g. lessons/Introduction
lesson -- string, name of lesson
"""
code, encoding = locale.getdefaultlocale()
logging.debug('Locale code: %r' % code)
if code is None or encoding is None:
locale.setlocale(locale.LC_ALL, 'en_US')
code, encoding = locale.getlocale()
canvas = AbiCanvas()
canvas.show()
files = map(lambda x: os.path.join(path, '%s.abw' % x),
('_'+code.lower(), '_'+code.split('_')[0].lower(),
'default'))
files = filter(lambda x: os.path.exists(x), files)
# On jhbuild, the first works, on XO image 432 the second works:
try:
canvas.load_file('file://%s' % files[0], 'application/x-abiword')
except:
canvas.load_file('file://%s' % files[0])
canvas.view_online_layout()
canvas.zoom_width()
canvas.set_show_margin(False)
self.append_page(canvas, gtk.Label(name))
|