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
|
# 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
import logging
from gettext import gettext as _
from globals import Globals
from gui.page import Page
from gui import theme
from persistence.joke import Joke
import pages.joke
import pages.choose
class JokeEditor(Page):
def __init__(self, joke):
Page.__init__(self,
spacing=8,
padding=4,
border_color=theme.COLOR_RED.get_int(),
border=0,
orientation=hippo.ORIENTATION_HORIZONTAL)
# left column
self.left = hippo.CanvasBox(border=0,
border_color=theme.COLOR_RED.get_int(),
xalign=hippo.ALIGNMENT_START,
orientation=hippo.ORIENTATION_VERTICAL,
padding=theme.BORDER_WIDTH_CONTROL/2)
joke_image = self.make_imagebox(joke, 'image', 320, 240, True)
self.left.append(joke_image)
# right column
self.right = hippo.CanvasBox(border=0,
border_color=theme.COLOR_RED.get_int(),
padding=theme.SPACER_HORIZONTAL,
orientation=hippo.ORIENTATION_VERTICAL,
padding_bottom=theme.BORDER_WIDTH_CONTROL/2,
spacing=theme.BORDER_WIDTH_CONTROL/2)
self.right.append(hippo.CanvasText(text=_('Question'),
xalign=hippo.ALIGNMENT_START,
color=theme.COLOR_DARK_GREEN.get_int()))
self.right.append(self.make_textbox(joke, 'text'))
self.right.append(hippo.CanvasBox(box_height=theme.SPACER_VERTICAL))
self.right.append(hippo.CanvasText(text=_('Answer'),
xalign=hippo.ALIGNMENT_START,
color=theme.COLOR_DARK_GREEN.get_int()))
self.right.append(self.make_textbox(joke, 'answer'))
self.append(self.left)
self.append(self.right, hippo.PACK_EXPAND)
class Submit(Page):
def __init__(self, jokebook, last_joke=0): # last_joke is for 'back' button
Page.__init__(self, spacing=10)
# create a new joke
joke = Joke()
joke.id = jokebook.next_joke_id
logging.info('Created new joke with id: %d' % joke.id)
joke.joker = Globals.nickname
# info
self.append(self.make_field(_('Submission For:'), 250, jokebook, 'title', 300, False))
self.append(self.make_field(_('Your Name:'), 250, joke, 'joker', 300, True))
self.append(hippo.CanvasBox(box_height=theme.SPACER_VERTICAL)) # spacer
# joke editor
jokebox = JokeEditor(joke)
nav = hippo.CanvasBox(
padding_right=8,
padding_top=8,
spacing=18,
orientation=hippo.ORIENTATION_HORIZONTAL)
button = gtk.Button(_('Submit'))
button.connect('clicked', self.__do_clicked_submit, jokebook, joke)
nav.append(hippo.CanvasWidget(widget=theme.theme_widget(button), padding_right=10, padding_top=20))
button = gtk.Button(_('Back'))
button.connect('clicked', self.__do_clicked_back, jokebook, last_joke)
nav.append(hippo.CanvasWidget(widget=theme.theme_widget(button), padding_top=20))
jokebox.right.append(nav)
self.append(jokebox)
def __do_clicked_back(self, button, jokebook, last_joke):
joke_page = Globals.JokeMachineActivity.set_page(pages.joke.Joke, jokebook, last_joke)
joke_page.force_answer(jokebook, last_joke) # force joke into answered state
def __do_clicked_submit(self, button, jokebook, joke):
Globals.JokeMachineActivity.set_page(pages.choose.Choose)
# TODO -> Factor out of the page ? Should be transparent to UI layer ?
if not Globals.JokeMachineActivity.is_shared:
logging.error('pages.submit.Submit -> CANNOT SUBMIT WITHOUT A TUBE')
return
logging.debug('Submitting joke to remote')
pickle = joke.dumps()
Globals.JokeMachineActivity.tube.Submit(jokebook.id, pickle)
logging.debug('Submitted joke to remote')
|