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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
# 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 gobject
import gtk
import hippo
import logging
from i18n import LanguageComboBox
from gettext import gettext as _
from globals import Globals
from util.decorators import Property
from gui import theme
import pages.choose
import pages.edit
from persistence.jokebook import Jokebook
class Frame(hippo.Canvas):
def __init__(self):
hippo.Canvas.__init__(self)
# Root Frame ###############################################################
# Holds: Everything
self.__root = hippo.CanvasBox(
orientation=hippo.ORIENTATION_VERTICAL)
self.set_root(self.__root)
# Application Header #######################################################
# Holds: App logo, language box, lessons plan box
self.__header = self.__make_header()
self.__root.append(self.__header)
# Page Container ###########################################################
# Holds: The currently open UI page
self.__container = hippo.CanvasBox(
border=theme.BORDER_WIDTH,
border_color=theme.COLOR_FRAME.get_int(),
background_color=theme.COLOR_BACKGROUND.get_int(),
spacing=4,
padding_top=20,
padding_left=40,
padding_right=40,
padding_bottom=20,
orientation=hippo.ORIENTATION_VERTICAL)
self.__root.append(self.__container, hippo.PACK_EXPAND)
self.__page = hippo.CanvasBox(
box_height=theme.PAGE_HEIGHT, # TODO -> Pull width/height from theme - and make sure all
# children pull their sizes relative to this box
background_color=theme.COLOR_PAGE.get_int(),
border=4,
border_color=theme.COLOR_PAGE_BORDER.get_int(),
spacing=8,
padding=20,
xalign=hippo.ALIGNMENT_CENTER,
orientation=hippo.ORIENTATION_VERTICAL)
self.__container.append(self.__page)
self.__page_class = None
# Application Footer #######################################################
# Holds: Task buttons
self.__footer = self.__make_footer()
self.__container.append(self.__footer)
def __make_header(self):
ret = hippo.CanvasBox(
orientation=hippo.ORIENTATION_HORIZONTAL)
# logo
logo = gtk.Image()
logo.set_from_file(Globals.logo)
ret.append(hippo.CanvasWidget(widget=logo))
# language selection box
language = hippo.CanvasWidget(
background_color=theme.COLOR_BACKGROUND.get_int(),
border_top=theme.BORDER_WIDTH,
border_left=theme.BORDER_WIDTH,
border_color=theme.COLOR_FRAME.get_int(),
padding_top=12,
padding_bottom=12,
padding_left=100,
padding_right=100,
yalign=hippo.ALIGNMENT_CENTER,
orientation=hippo.ORIENTATION_VERTICAL)
button = LanguageComboBox()
button.install()
language.props.widget = button
button.set_name('Fubar')
ret.append(language, hippo.PACK_EXPAND)
# lesson plans
lesson_plans = hippo.CanvasWidget(
background_color=theme.COLOR_BACKGROUND.get_int(),
border_top=theme.BORDER_WIDTH,
border_left=theme.BORDER_WIDTH,
border_right=theme.BORDER_WIDTH,
border_color=theme.COLOR_FRAME.get_int(),
padding_top=12,
padding_bottom=12,
padding_left=30,
padding_right=30,
yalign=hippo.ALIGNMENT_CENTER,
orientation=hippo.ORIENTATION_VERTICAL)
button = gtk.Button(_('Lesson Plans'))
lesson_plans.props.widget = theme.theme_widget(button)
ret.append(lesson_plans, hippo.PACK_EXPAND)
return ret
def __make_footer(self):
ret = hippo.CanvasBox(
padding_right=8,
padding_top=8,
padding_bottom=0,
spacing=8,
orientation=hippo.ORIENTATION_HORIZONTAL)
button = gtk.Button(_('Read Jokebooks'))
button.connect('clicked', self.__do_clicked_read)
self.__button_read = hippo.CanvasWidget(widget=theme.theme_widget(button))
ret.append(self.__button_read)
button = gtk.Button(_('Make Jokebook'))
button.connect('clicked', self.__do_clicked_make)
self.__button_make = hippo.CanvasWidget(widget=theme.theme_widget(button))
ret.append(self.__button_make)
return ret
@property
def page_class(self):
if self.__page_class is None:
# say, for e.g. we're connecting to another activity and we haven't set a
# default page yet
self.__page_class = pages.choose.Choose
return self.__page_class
@Property
def page():
def get(self): return self.__page
def set(self, value):
self.__page_class = type(value)
self.__page.clear()
self.__page.append(value)
# some rules for the buttons in the footer
if not Globals.JokeMachineActivity.is_initiator \
and type(value) is pages.choose.Choose:
self.__button_read.set_visible(False)
self.__button_make.set_visible(False)
elif not Globals.JokeMachineActivity.is_initiator:
self.__button_read.set_visible(True)
self.__button_make.set_visible(False)
elif type(value) is pages.choose.Choose:
self.__button_read.set_visible(False)
self.__button_make.set_visible(True)
elif type(value) is pages.edit.Edit:
self.__button_read.set_visible(True)
self.__button_make.set_visible(False)
elif type(value) is pages.preview.Preview:
self.__button_read.set_visible(True)
self.__button_make.set_visible(False)
else:
self.__button_read.set_visible(True)
self.__button_make.set_visible(False)
def __do_clicked_read(self, button):
Globals.JokeMachineActivity.set_page(pages.choose.Choose)
def __do_clicked_make(self, button):
# create a new jokebook
jokebook = Jokebook()
jokebook.id = Globals.JokeMachineState.next_jokebook_id
logging.info('Created new jokebook with id: %d' % jokebook.id)
jokebook.owner = Globals.nickname
Globals.JokeMachineState.jokebooks.append(jokebook)
Globals.JokeMachineActivity.set_page(pages.edit.Edit, jokebook)
|