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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
# 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
OLD_TOOLBAR = False
try:
from sugar.graphics.toolbarbox import ToolbarBox, ToolbarButton
from sugar.activity.widgets import StopButton
from sugar.graphics.radiotoolbutton import RadioToolButton
from sugar.activity.widgets import ActivityToolbarButton
except ImportError:
OLD_TOOLBAR = True
from port.activity 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)
def instance(self):
book.wiki = book.WikiBook()
if not book.custom:
book.custom = book.CustomBook()
self.edit_page = 1
self.edit = edit.View()
self.library = library.View(self)
if OLD_TOOLBAR:
self.edit_toolbar = gtk.Toolbar()
self.edit_bar = edit.ToolbarBuilder(self.edit, self.edit_toolbar)
self.edit_toolbar.show_all()
self.library_toolbar = gtk.Toolbar()
self.library_bar = library.ToolbarBuilder(self.library,
self.library_toolbar)
self.library_toolbar.show_all()
toolbox = ActivityToolbox(self)
toolbox.connect('current-toolbar-changed',
self._toolbar_changed_cb)
self.set_toolbox(toolbox)
toolbox.add_toolbar(_('Library'), self.library_toolbar)
toolbox.add_toolbar(_('Edit'), self.edit_toolbar)
toolbox.set_current_toolbar(1)
else:
toolbar_box = ToolbarBox()
activity_button = ActivityToolbarButton(self)
toolbar_box.toolbar.insert(activity_button, 0)
self.set_toolbar_box(toolbar_box)
self._toolbar = toolbar_box.toolbar
tool_group = None
search_button = RadioToolButton()
search_button.props.group = tool_group
tool_group = search_button
search_button.props.icon_name = 'white-search'
search_button.set_tooltip(_('Library'))
search_button.mode = 'search'
search_button.connect('clicked', self.__mode_button_clicked)
self._toolbar.insert(search_button, -1)
edit_button = RadioToolButton()
edit_button.props.group = tool_group
edit_button.props.icon_name = 'toolbar-edit'
edit_button.set_tooltip(_('Edit'))
edit_button.mode = 'edit'
edit_button.connect('clicked', self.__mode_button_clicked)
self._toolbar.insert(edit_button, -1)
self._toolbar.insert(gtk.SeparatorToolItem(), -1)
self.edit_bar = edit.ToolbarBuilder(self.edit, self._toolbar)
self.library_bar = library.ToolbarBuilder(self.library, self._toolbar)
edit_fake = gtk.EventBox()
self.notebook.append_page(self.library)
self.notebook.append_page(self.edit)
self.notebook.append_page(edit_fake)
self.show_all()
if not OLD_TOOLBAR:
self.__mode_button_clicked(search_button)
separator = gtk.SeparatorToolItem()
separator.props.draw = False
separator.set_expand(True)
separator.show()
self._toolbar.insert(separator, -1)
stop_button = StopButton(self)
stop_button.show()
self._toolbar.insert(stop_button, -1)
def new_instance(self):
self.instance()
def resume_instance(self, filepath):
book.custom = book.CustomBook(filepath)
self.instance()
def save_instance(self, filepath):
book.wiki.sync()
book.custom.sync(filepath)
def set_edit_sensitive(self, enable):
if OLD_TOOLBAR:
#self.edit_toolbar.props.sensitive = enable
self.edit_page = (enable and 1 or 2)
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)
def __mode_button_clicked(self, button):
if button.mode == 'search':
self.edit_bar.unsensitize_all()
self.notebook.set_current_page(0)
else:
self.edit_bar.sensitize_all()
self.notebook.set_current_page(1)
|