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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# coding: UTF-8
# Copyright 2009, 2010 Thomas Jourdan
#
# 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 3 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 sys
import traceback
import ka_extensionpoint
import ka_debug
try:
from sugar import env
# HACK: Needed by http://dev.sugarlabs.org/ticket/456
import gnome
gnome.init('Hulahop', '1.0')
import hulahop
hulahop.set_app_version(os.environ['SUGAR_BUNDLE_VERSION'])
hulahop.startup(os.path.join(env.get_profile_path(), 'gecko'))
from hulahop.webview import WebView
except:
ka_debug.err('failed importing hulahop [%s] [%s]' % \
(sys.exc_info()[0], sys.exc_info()[1]))
traceback.print_exc(file=sys.__stderr__)
class HtmlPage(object):
"""
inv: self._widget_tree is not None
"""
def __init__(self, page_number, on_switch_page, parent_widget, widget_tree):
"""
pre: on_switch_page is not None and callable(on_switch_page)
pre: parent_widget is not None
pre: widget_tree is not None
"""
self._widget_tree = widget_tree
self._parent_widget = parent_widget
self._page_number = page_number
self._on_switch_page = on_switch_page
self._my_page = False
self._empty = True
self._htmlview = None
try:
# The XOCom object helps us communicate with the browser
# This uses web/index.html as the default page to load
#!! from XOCom import XOCom
#!! self.xocom = XOCom(self.control_sending_text) #REMEMBER THAT I HAVE STILL TO SEND THE ARGUMENT IN THE XOCOM CLASS
#!! self._htmlview = self.xocom.create_webview()
self._htmlview = WebView()
except:
ka_debug.err('failed creating hulahop [%s] [%s]' % \
(sys.exc_info()[0], sys.exc_info()[1]))
traceback.print_exc(file=sys.__stderr__)
def autoconnect_events(self):
"""Auto connect introduction view."""
events = {
'on_notebook_switch_page' : self.on_notebook_switch_page,
}
self._widget_tree.signal_autoconnect(events)
def localize(self):
"""A dummy"""
pass
def show(self):
"""Insert HTML view."""
if self._htmlview is not None:
intro_scrolled = self._widget_tree.get_widget(self._parent_widget)
intro_scrolled.add(self._htmlview)
@staticmethod
def get_localized_path(locale, territory):
"""Try to read intro.html from LOCALE folder.
Default input file is locale/en/intro.html"""
bundle_path = ka_extensionpoint.get_bundle_path()
file_path = os.path.join(bundle_path,
'locale',
locale + '_' + territory,
'intro.html')
if not os.path.isfile(file_path):
file_path = os.path.join(bundle_path,
'locale',
locale,
'intro.html')
if not os.path.isfile(file_path):
file_path = os.path.join(bundle_path,
'locale',
'en',
'intro.html')
return file_path
def on_notebook_switch_page(self, *args):
"""Test if introduction page will be displayed.
Lazy evaluation to fill the page with text.
pre: len(args) >= 3
"""
ka_debug.info('on_notebook_switch_page %s' % (args[2]))
self._my_page = args[2] == self._page_number
if self._my_page and self._empty:
try:
self._on_switch_page()
# self._empty = False
except:
ka_debug.err('switching to %s failed [%s] [%s]' %
(str(self.__class__),
sys.exc_info()[0], sys.exc_info()[1]))
traceback.print_exc(file=sys.__stderr__)
|