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
|
# 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 gtk
from gettext import gettext as _
from sugar.graphics.toolbutton import ToolButton
from sugar.graphics.toggletoolbutton import ToggleToolButton
from sugar.activity.activity import ActivityToolbox
from shared import SharedActivity
import library
import edit
import book
gtk.gdk.threads_init()
gtk.gdk.threads_enter()
class InfoslicerActivity(SharedActivity):
def __init__(self, handle):
self.notebook = gtk.Notebook()
self.notebook.show()
self.notebook.props.show_border = False
self.notebook.props.show_tabs = False
SharedActivity.__init__(self, self.notebook, 'SERVICE', handle)
self.connect('init', self._init_cb)
self.connect('tube', self._tube_cb)
def read_file(self, filepath):
pass
def write_file(self, filepath):
# XXX this method will be invoked on every props.status changing
# thus ignore it and use can_close() instead to save data on exit
pass
def can_close(self):
book.teardown()
return True
def _init_cb(self, sender):
book.init()
self.edit_page = 1
self.edit = edit.View()
self.edit_bar = edit.Toolbar(self.edit)
self.library = library.View(self)
library_bar = library.Toolbar(self.library)
toolbox = ActivityToolbox(self)
toolbox.connect('current-toolbar-changed', self._toolbar_changed_cb)
self.set_toolbox(toolbox)
toolbox.add_toolbar(_('Library'), library_bar)
toolbox.add_toolbar(_('Edit'), self.edit_bar)
edit_fake = gtk.EventBox()
self.notebook.append_page(self.library)
self.notebook.append_page(self.edit)
self.notebook.append_page(edit_fake)
toolbox.set_current_toolbar(1)
self.show_all()
def set_edit_sensitive(self, enable):
self.edit_bar.props.sensitive = enable
self.edit_page = (enable and 1 or 2)
def _tube_cb(self, activity, tube_conn, initiating):
pass
def _toolbar_changed_cb(self, widget, index):
if index > 0:
if index == 1:
index = 0
else:
self.library.sync()
index = self.edit_page
self.notebook.set_current_page(index)
|