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
|
# 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 gtk
import hippo
import pango
from gettext import gettext as _
import logging
from globals import Globals
from gui.page import Page
from gui import theme
from util.audioplayer import AudioPlayer
import pages.submit
import persistence.joke
class JokeViewer(Page):
def __init__(self, joke, jokebook_title=''):
Page.__init__(self,
spacing=8,
#background_color=theme.COLOR_PAGE.get_int(),
padding=4,
border_color=theme.COLOR_RED.get_int(),
border=0,
xalign=hippo.ALIGNMENT_START,
orientation=hippo.ORIENTATION_HORIZONTAL)
# left column
self.left = hippo.CanvasBox(border=0,
border_color=theme.COLOR_RED.get_int(),
box_width=450,
xalign=hippo.ALIGNMENT_START,
orientation=hippo.ORIENTATION_VERTICAL)
joke_image = self.make_imagebox(joke, 'image', 320, 240, False)
self.left.append(joke_image)
self.left.append(hippo.CanvasText(text=jokebook_title,
xalign=hippo.ALIGNMENT_START,
color=theme.COLOR_DARK_GREEN.get_int()))
self.left.append(hippo.CanvasText(text=_('Joke') + ' ' + str(joke.id),
xalign=hippo.ALIGNMENT_START))
self.left.append(hippo.CanvasText(text=_('By') + ' ' + str(joke.joker),
xalign=hippo.ALIGNMENT_START))
# right column
self.right = hippo.CanvasBox(border=0,
border_color=theme.COLOR_RED.get_int(),
box_width=350,
xalign=hippo.ALIGNMENT_START,
orientation=hippo.ORIENTATION_VERTICAL)
self.right.append(hippo.CanvasText(text=_('Question'),
xalign=hippo.ALIGNMENT_START,
color=theme.COLOR_DARK_GREEN.get_int()))
self.right.append(self.make_bodytext(joke.text))
self.right.append(hippo.CanvasBox(box_height=30)) # spacer
self.answer_box = hippo.CanvasBox()
self.answer_box.append(hippo.CanvasText(text=_('Answer'),
xalign=hippo.ALIGNMENT_START,
color=theme.COLOR_DARK_GREEN.get_int()))
self.answer_box.append(self.make_bodytext(joke.answer))
self.right.append(self.answer_box)
self.append(self.left)
self.append(self.right)
class Joke(Page):
def __init__(self, jokebook, joke_id = 0):
Page.__init__(self)
# handle empty jokebook
if len(jokebook.jokes) <= joke_id:
self.append(self.make_bodytext(_('This Jokebook is empty')))
if not Globals.JokeMachineActivity.is_initiator:
button = gtk.Button(_('Submit a Joke'))
button.connect('clicked', self.__do_clicked_submit, jokebook, joke_id)
self.append(hippo.CanvasWidget(widget=theme.theme_widget(button),
padding_top=20))
else:
button = gtk.Button(_('Add Jokes'))
button.connect('clicked', self.__do_clicked_add, jokebook, joke_id)
self.append(hippo.CanvasWidget(widget=theme.theme_widget(button),
padding_top=20))
return
# the joke box
joke = jokebook.jokes[joke_id]
self.joke_box = JokeViewer(joke, jokebook.title)
self.joke_box.answer_box.set_visible(False)
# the navigation box
self.navigation_box = hippo.CanvasBox(
padding_right=8,
padding_top=8,
spacing=18,
orientation=hippo.ORIENTATION_HORIZONTAL)
# the answer button
button = gtk.Button(_('Answer'))
button.connect('clicked', self.__do_clicked_answer, jokebook, joke_id)
self.navigation_box.append(hippo.CanvasWidget(widget=theme.theme_widget(button), padding_top=20))
self.joke_box.right.append(self.navigation_box)
self.append(self.joke_box)
# for forcing the joke into the answered state from page.submit
def force_answer(self, jokebook, joke_id):
self.__do_clicked_answer(None, jokebook, joke_id)
def __do_clicked_answer(self, button, jokebook, joke_id):
# play a sound if the jokebook has one
player = AudioPlayer()
if jokebook.sound_blob != None:
player.raw = jokebook.sound_blob
else: # default laugh
logging.debug('Playing default sound: %s', Globals.laugh_uri)
player.uri = Globals.laugh_uri
player.play()
# show the answer
self.joke_box.answer_box.set_visible(True)
# reconfigure navigation box
self.navigation_box.clear()
# check if there are any more jokes left
if len(jokebook.jokes) > joke_id + 1:
button = gtk.Button(_('Next'))
button.connect('clicked', self.__do_clicked_next, jokebook, joke_id + 1)
self.navigation_box.append(hippo.CanvasWidget(widget=theme.theme_widget(button), padding_right=10, padding_top=20))
# only allow submitting a joke if activity is shared and you are the one joining
if not Globals.JokeMachineActivity.is_initiator:
button = gtk.Button(_('Submit a Joke'))
button.connect('clicked', self.__do_clicked_submit, jokebook, joke_id)
self.navigation_box.append(hippo.CanvasWidget(widget=theme.theme_widget(button),
padding_top=20))
def __do_clicked_add(self, button, jokebook, joke_id):
page = Globals.JokeMachineActivity.set_page(pages.edit.Edit, jokebook)
tab = page.do_tab_clicked(pages.edit.EditJokes)
tab.do_clicked_add_joke(None, jokebook)
def __do_clicked_submit(self, button, jokebook, joke_id):
Globals.JokeMachineActivity.set_page(pages.submit.Submit, jokebook, joke_id)
def __do_clicked_next(self, button, jokebook, joke_id):
Globals.JokeMachineActivity.set_page(pages.joke.Joke, jokebook, joke_id)
|