Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/pages
diff options
context:
space:
mode:
Diffstat (limited to 'pages')
-rw-r--r--pages/__init__.py0
-rw-r--r--pages/choose.py127
-rw-r--r--pages/cover.py60
-rw-r--r--pages/edit.py303
-rw-r--r--pages/joke.py164
-rw-r--r--pages/preview.py56
-rw-r--r--pages/submit.py137
7 files changed, 847 insertions, 0 deletions
diff --git a/pages/__init__.py b/pages/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/pages/__init__.py
diff --git a/pages/choose.py b/pages/choose.py
new file mode 100644
index 0000000..c115f94
--- /dev/null
+++ b/pages/choose.py
@@ -0,0 +1,127 @@
+# 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 os
+import gtk
+import hippo
+import pango
+import logging
+from gettext import gettext as _
+
+from gui.canvaslistbox import CanvasListBox
+
+from globals import Globals
+from gui.page import Page
+from gui import theme
+
+import pages.cover
+import pages.edit
+
+#from persistence.jokemachinestate import JokeMachineState
+#from persistence.jokebook import Jokebook
+
+class Choose(Page):
+
+ def __init__(self):
+ Page.__init__(self)
+
+ # page title
+ self.append(hippo.CanvasText(
+ text= 'Choose a Jokebook to read:',
+ xalign=hippo.ALIGNMENT_START,
+ padding=10,
+ font_desc=theme.FONT_BODY.get_pango_desc()))
+
+ # list of Jokebooks
+ allow_edit = Globals.JokeMachineActivity.is_initiator
+ #jokebooks_div = CanvasListBox(1050, 500)
+ jokebooks_div = CanvasListBox(1050, theme.zoom(500)) # TODO -> This should be sizing relative to parent
+ for jokebook in Globals.JokeMachineState.jokebooks:
+ jokebooks_div.append(self.__make_jokebook_div(jokebook, allow_edit))
+ self.append(jokebooks_div)
+
+
+ def __do_clicked_title(self, control, event, jokebook):
+ Globals.JokeMachineActivity.set_page(pages.cover.Cover, jokebook)
+
+
+ def __do_clicked_edit(self, button, jokebook):
+ Globals.JokeMachineActivity.set_page(pages.edit.Edit, jokebook)
+
+
+ def __do_clicked_delete(self, button, jokebook):
+ confirm = gtk.MessageDialog(Globals.JokeMachineActivity,
+ gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
+ gtk.MESSAGE_QUESTION,
+ gtk.BUTTONS_YES_NO,
+ _('Are you sure you want to delete your') + \
+ ' \'' + jokebook.title + '\' ' + _('jokebook ?'))
+ response = confirm.run()
+ confirm.hide()
+ confirm.destroy()
+ del confirm
+ if response == gtk.RESPONSE_YES:
+ logging.debug('Deleting jokebook: %s' % jokebook.title)
+ Globals.JokeMachineState.jokebooks.remove(jokebook)
+ Globals.JokeMachineActivity.set_page(pages.choose.Choose)
+
+
+ def __make_jokebook_div(self, jokebook, edit = False):
+ list_row = self.make_listrow()
+
+ # thumbnail
+ thumbnail = self.make_imagebox(jokebook, 'image', 80, 60, False, 10)
+ list_row.append(self.__make_column_div(100, thumbnail))
+
+ # title
+ title = hippo.CanvasText(text=jokebook.title,
+ padding_left = 20,
+ xalign=hippo.ALIGNMENT_START,
+ font_desc=theme.FONT_LARGE.get_pango_desc(),
+ color=theme.COLOR_LINK.get_int())
+ title.set_clickable(True)
+ title.connect('button-press-event', self.__do_clicked_title, jokebook)
+ list_row.append(self.__make_column_div(330, title))
+
+ list_row.append(hippo.CanvasBox(box_width=theme.SPACER_HORIZONTAL)) # TODO spacer
+
+ # owner
+ list_row.append(self.__make_column_div(330, hippo.CanvasText(text= jokebook.owner,
+ xalign=hippo.ALIGNMENT_START,
+ font_desc=theme.FONT_LARGE.get_pango_desc())))
+
+ # buttons
+ if edit:
+ button = gtk.Button(_('Edit'))
+ button.connect('clicked', self.__do_clicked_edit, jokebook)
+ list_row.append(self.__make_column_div(100, hippo.CanvasWidget(widget=theme.theme_widget(button))))
+ list_row.append(hippo.CanvasBox(box_width=theme.SPACER_HORIZONTAL)) # TODO spacer
+ button = gtk.Button(_('Delete'))
+ button.connect('clicked', self.__do_clicked_delete, jokebook)
+ list_row.append(self.__make_column_div(100, hippo.CanvasWidget(widget=theme.theme_widget(button))))
+
+ return list_row
+
+
+ def __make_column_div(self, width, content):
+ ret = hippo.CanvasBox(
+ box_width=width,
+ yalign=hippo.ALIGNMENT_CENTER)
+ ret.append(content)
+ return ret
+
+
+
diff --git a/pages/cover.py b/pages/cover.py
new file mode 100644
index 0000000..23a2da0
--- /dev/null
+++ b/pages/cover.py
@@ -0,0 +1,60 @@
+# 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 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
+
+import pages.joke
+
+
+class Cover(Page):
+
+ def __init__(self, jokebook):
+ Page.__init__(self)
+
+ # title
+ self.append(hippo.CanvasText(text='"' + jokebook.title + '" ' + _('started by') + ' ' + jokebook.owner,
+ xalign=hippo.ALIGNMENT_CENTER,
+ padding_top=10,
+ font_desc=theme.FONT_BODY_BOLD.get_pango_desc()))
+ self.append(hippo.CanvasBox(box_height=theme.SPACER_VERTICAL))
+
+ # cover picture
+ cover_picture = self.make_imagebox(jokebook, 'image', 640, 480, False)
+ self.append(cover_picture)
+ self.append(hippo.CanvasBox(box_height=theme.SPACER_VERTICAL))
+
+ # open button
+ button = gtk.Button(_('Open'))
+ button.connect('clicked', self.__do_clicked_open, jokebook)
+ button.set_size_request(50, -1)
+ self.append(hippo.CanvasWidget(widget=theme.theme_widget(button),
+ box_width=50))
+
+
+ def __do_clicked_open(self, button, jokebook):
+ Globals.JokeMachineActivity.set_page(pages.joke.Joke, jokebook)
+
+
+ \ No newline at end of file
diff --git a/pages/edit.py b/pages/edit.py
new file mode 100644
index 0000000..b213655
--- /dev/null
+++ b/pages/edit.py
@@ -0,0 +1,303 @@
+# 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 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 gui.canvaslistbox import CanvasListBox
+
+from util.decorators import Property
+
+from pages.submit import JokeEditor
+from pages.joke import JokeViewer
+
+import pages.preview
+import persistence.joke
+
+
+
+class PageSelector(hippo.CanvasBox):
+
+ def __init__(self, parent, **kwargs):
+ hippo.CanvasBox.__init__(self, **kwargs)
+ self.__parent = parent
+
+ control_width = 1024 # TODO -> Figure this out from parent size
+ self.props.border = 1
+ self.props.border_color=theme.COLOR_TAB_ACTIVE.get_int()
+ self.props.background_color=theme.COLOR_PAGE.get_int()
+ self.props.orientation=hippo.ORIENTATION_VERTICAL
+
+ # button box -> # TODO -> Make into generic control
+ tab_width = control_width / 3.0
+ tab_box = hippo.CanvasBox(background_color=theme.COLOR_TAB_SEPERATOR.get_int(),
+ spacing=2,
+ orientation=hippo.ORIENTATION_HORIZONTAL)
+ self.__tab_1 = hippo.CanvasText(text=_('Edit Jokebook Cover'),
+ box_width=tab_width,
+ padding=theme.PADDING_TAB,
+ xalign=hippo.ALIGNMENT_START,
+ background_color=theme.COLOR_TAB_ACTIVE.get_int(),
+ color=theme.COLOR_TAB_TEXT.get_int(),
+ font_desc=theme.FONT_TABS.get_pango_desc())
+ self.__tab_1.page = EditInfo
+ self.__tab_1.connect('button-press-event', self.__do_clicked_tab)
+ tab_box.append(self.__tab_1)
+ self.__tab_2 = hippo.CanvasText(text=_('Edit My Jokes'),
+ box_width=tab_width,
+ padding=theme.PADDING_TAB,
+ xalign=hippo.ALIGNMENT_START,
+ background_color=theme.COLOR_TAB_INACTIVE.get_int(),
+ color=theme.COLOR_TAB_TEXT.get_int(),
+ font_desc=theme.FONT_TABS.get_pango_desc())
+ self.__tab_2.page = EditJokes
+ self.__tab_2.connect('button-press-event', self.__do_clicked_tab)
+ tab_box.append(self.__tab_2)
+ self.__tab_3 = hippo.CanvasText(text=_('Review Submitted Jokes'),
+ box_width=tab_width,
+ padding=theme.PADDING_TAB,
+ xalign=hippo.ALIGNMENT_START,
+ background_color=theme.COLOR_TAB_INACTIVE.get_int(),
+ color=theme.COLOR_TAB_TEXT.get_int(),
+ font_desc=theme.FONT_TABS.get_pango_desc())
+ self.__tab_3.page = EditReview
+ self.__tab_3.connect('button-press-event', self.__do_clicked_tab)
+ tab_box.append(self.__tab_3)
+ self.append(tab_box)
+
+ self.__page = hippo.CanvasBox(background_color=theme.COLOR_PAGE.get_int(),
+ orientation=hippo.ORIENTATION_VERTICAL)
+ self.append(self.__page)
+
+
+ @Property
+ def page():
+ def get(self): return self.__page.the_page
+ def set(self, value):
+ self.__page.clear()
+ self.__page.append(value)
+ self.__page.the_page = value
+
+
+ def __do_clicked_tab(self, control, event):
+ self.__tab_1.props.background_color=theme.COLOR_TAB_INACTIVE.get_int()
+ self.__tab_2.props.background_color=theme.COLOR_TAB_INACTIVE.get_int()
+ self.__tab_3.props.background_color=theme.COLOR_TAB_INACTIVE.get_int()
+ control.props.background_color=theme.COLOR_TAB_ACTIVE.get_int()
+ self.__parent.do_tab_clicked(control.page)
+
+
+
+class Edit(Page):
+
+ def __init__(self, jokebook):
+ Page.__init__(self, xalign=hippo.ALIGNMENT_CENTER)
+
+ self.__jokebook = jokebook
+
+ self.__page_selector = PageSelector(self)
+ self.append(self.__page_selector)
+ self.__page_selector.page = EditInfo(jokebook, self)
+
+ button = gtk.Button(_('Preview'))
+ button.connect('clicked', self.__do_clicked_preview, jokebook)
+ self.append(hippo.CanvasWidget(widget=theme.theme_widget(button), padding_top=theme.SPACER_VERTICAL))
+
+
+ def __do_clicked_preview(self, button, jokebook):
+ Globals.JokeMachineActivity.set_page(pages.preview.Preview, jokebook)
+
+
+ def do_tab_clicked(self, page_class):
+ print page_class
+ self.__page_selector.page = page_class(self.__jokebook, self)
+
+
+
+class EditInfo(Page): # TODO -> gui.Page should follow this pattern rather
+ def __init__(self, jokebook, parent):
+ Page.__init__(self, xalign=hippo.ALIGNMENT_CENTER,
+ orientation=hippo.ORIENTATION_VERTICAL,
+ padding=20,
+ spacing=20,
+ box_height=theme.TABS_HEIGHT)
+
+ # page title
+ self.append(self.make_field(_('Title of Jokebook:'), 250, jokebook, 'title', 300, True))
+ #field = self.make_field(_('Sound Effect:'), 250, None, '', 300, False)
+
+ sound_effect = hippo.CanvasBox(orientation=hippo.ORIENTATION_HORIZONTAL, spacing=10)
+ sound_effect.append(self.make_bodytext(_('Sound Effect:'), 250, hippo.ALIGNMENT_START, theme.COLOR_DARK_GREEN))
+ sound_effect.append(self.make_audiobox(jokebook, 'sound', 316))
+ self.append(sound_effect)
+
+
+ # cover picture
+ cover_image = self.make_imagebox(jokebook, 'image', 320, 240, True)
+ self.append(cover_image)
+
+ # punchline sound
+ #self.append(self.make_audiobox(jokebook, 'sound'))
+
+
+
+class EditJokes(Page):
+
+ def __init__(self, jokebook, parent):
+ Page.__init__(self)
+
+ # list of jokes
+ jokes_div = CanvasListBox(800, theme.TABS_HEIGHT)
+ jokes_div.props.border=0
+ for joke in jokebook.jokes:
+ list_row = self.make_listrow(JokeEditor(joke))
+ button = gtk.Button(' ' + _('Delete') + ' ')
+ button.connect('clicked', self.__do_clicked_delete, jokebook, joke, parent)
+ list_row.append(hippo.CanvasWidget(widget=theme.theme_widget(button),
+ border_color=theme.COLOR_RED.get_int(),
+ border=0,
+ padding_top=10,
+ padding_bottom=10,
+ padding_left=85))
+ #xalign=hippo.ALIGNMENT_END))
+ jokes_div.append(list_row)
+ self.append(jokes_div)
+
+ # new joke button
+ buttons = hippo.CanvasBox(orientation=hippo.ORIENTATION_HORIZONTAL,
+ xalign=hippo.ALIGNMENT_START)
+
+ button = gtk.Button(_('Add New Joke'))
+ button.connect('clicked', self.__do_clicked_add_joke, jokebook, parent)
+ buttons.append(hippo.CanvasWidget(widget=theme.theme_widget(button)))
+ jokes_div.append(buttons)
+
+
+ def __do_clicked_delete(self, button, jokebook, joke, parent):
+ confirm = gtk.MessageDialog(Globals.JokeMachineActivity,
+ gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
+ gtk.MESSAGE_QUESTION,
+ gtk.BUTTONS_YES_NO,
+ _('Are you sure you want to delete this joke ?'))
+ response = confirm.run()
+ confirm.hide()
+ confirm.destroy()
+ del confirm
+ if response == gtk.RESPONSE_YES:
+ logging.debug('Deleting joke: %s' % joke.id)
+ jokebook.jokes.remove(joke)
+ parent.do_tab_clicked(EditJokes)
+
+
+ def __do_clicked_add_joke(self, button, jokebook, parent):
+ # create a new joke
+ joke = persistence.joke.Joke()
+ joke.id = jokebook.next_joke_id
+ logging.info('Created new joke with id: %d' % joke.id)
+ joke.joker = Globals.nickname
+ jokebook.jokes.append(joke)
+
+ # reload tab
+ parent.do_tab_clicked(EditJokes)
+
+
+
+class EditReview(Page):
+ def __init__(self, jokebook, parent):
+ Page.__init__(self)
+
+ jokes_div = CanvasListBox(800, theme.TABS_HEIGHT)
+ jokes_div.props.border=0
+ for joke in jokebook.submissions:
+ list_row = self.make_listrow(JokeViewer(joke, jokebook.title))
+ list_row.props.orientation=hippo.ORIENTATION_VERTICAL
+
+ buttons = hippo.CanvasBox(orientation=hippo.ORIENTATION_HORIZONTAL,
+ xalign=hippo.ALIGNMENT_END,
+ spacing=10,
+ padding=10)
+
+ button = gtk.Button(' ' + _('Reject') + ' ')
+ button.connect('clicked', self.__do_clicked_reject, jokebook, joke, parent)
+ buttons.append(hippo.CanvasWidget(widget=theme.theme_widget(button),
+ border_color=theme.COLOR_RED.get_int(),
+ border=0,
+ xalign=hippo.ALIGNMENT_CENTER))
+
+ button = gtk.Button(' ' + _('Accept') + ' ')
+ button.connect('clicked', self.__do_clicked_accept, jokebook, joke, parent)
+ buttons.append(hippo.CanvasWidget(widget=theme.theme_widget(button),
+ border_color=theme.COLOR_RED.get_int(),
+ border=0,
+ xalign=hippo.ALIGNMENT_CENTER))
+
+ list_row.append(buttons)
+
+ #list_row.props.orientation=hippo.ORIENTATION_VERTICAL
+ #status_box = hippo.CanvasBox(orientation=hippo.ORIENTATION_HORIZONTAL,
+ #padding_top=4,
+ #padding_left=4)
+ #status_box.append(hippo.CanvasText(text=_('Status:'),
+ #color=theme.COLOR_DARK_GREEN.get_int(),
+ #box_width=100,
+ #xalign=hippo.ALIGNMENT_START,
+ #font_desc=theme.FONT_BODY.get_pango_desc()))
+ ##button = None
+ #button = gtk.RadioButton()
+ #button = gtk.RadioButton(button, _('Approved'))
+ #button.set_size_request(200, -1)
+ #status_box.append(hippo.CanvasWidget(widget = button))
+ #button = gtk.RadioButton(button, _('Rejected'))
+ #button.set_size_request(200, -1)
+ #status_box.append(hippo.CanvasWidget(widget = button))
+ #button = gtk.RadioButton(button, _('Not Reviewed'))
+ #button.set_size_request(200, -1)
+ #button.set_active(True)
+ #status_box.append(hippo.CanvasWidget(widget = button))
+ #list_row.append(status_box)
+
+ jokes_div.append(list_row)
+
+ self.append(jokes_div)
+
+
+ def __do_clicked_accept(self, button, jokebook, joke, parent):
+ jokebook.jokes.append(joke)
+ jokebook.submissions.remove(joke)
+ parent.do_tab_clicked(EditReview)
+
+ if not Globals.JokeMachineActivity.is_shared:
+ return
+
+ # broadcast submission onto the mesh
+ logging.debug('Broadcasting joke to mesh')
+ pickle = joke.dumps()
+ Globals.JokeMachineActivity.tube.BroadcastJoke(jokebook.id, pickle)
+ logging.debug('Broadcasted joke to mesh')
+
+
+
+ def __do_clicked_reject(self, button, jokebook, joke, parent):
+ jokebook.submissions.remove(joke)
+ parent.do_tab_clicked(EditReview)
diff --git a/pages/joke.py b/pages/joke.py
new file mode 100644
index 0000000..fedd50e
--- /dev/null
+++ b/pages/joke.py
@@ -0,0 +1,164 @@
+# 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 os
+import gtk
+import hippo
+import pango
+from gettext import gettext as _
+
+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(),
+ font_desc=theme.FONT_BODY_BOLD.get_pango_desc()))
+ self.left.append(hippo.CanvasText(text=_('Joke') + ' ' + str(joke.id),
+ xalign=hippo.ALIGNMENT_START,
+ font_desc=theme.FONT_BODY.get_pango_desc()))
+ self.left.append(hippo.CanvasText(text=_('By') + ' ' + str(joke.joker),
+ xalign=hippo.ALIGNMENT_START,
+ font_desc=theme.FONT_BODY.get_pango_desc()))
+
+ # 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(),
+ font_desc=theme.FONT_BODY.get_pango_desc()))
+ 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(),
+ font_desc=theme.FONT_BODY.get_pango_desc()))
+ 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))
+ 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
+ if jokebook.sound_blob != None:
+ player = AudioPlayer()
+ player.raw = jokebook.sound_blob
+ 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_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)
+
+
diff --git a/pages/preview.py b/pages/preview.py
new file mode 100644
index 0000000..de5bc3a
--- /dev/null
+++ b/pages/preview.py
@@ -0,0 +1,56 @@
+# 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 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 gui.canvaslistbox import CanvasListBox
+
+from pages.joke import JokeViewer
+
+import pages.edit
+
+
+class Preview(Page):
+
+ def __init__(self, jokebook):
+ Page.__init__(self, xalign=hippo.ALIGNMENT_CENTER)
+
+ preview_box = CanvasListBox(1028, theme.PREVIEW_HEIGHT) # TODO - really shouldn't be hardcoded
+ for joke in jokebook.jokes:
+ list_row = self.make_listrow(JokeViewer(joke, jokebook.title))
+ preview_box.append(list_row)
+ self.append(preview_box)
+
+ self.append(hippo.CanvasBox(box_height=theme.SPACER_VERTICAL))
+
+ button = gtk.Button(_('Edit'))
+ button.connect('clicked', self.__do_clicked_edit, jokebook)
+ self.append(hippo.CanvasWidget(widget=theme.theme_widget(button)))
+
+
+ def __do_clicked_edit(self, button, jokebook):
+ Globals.JokeMachineActivity.set_page(pages.edit.Edit, jokebook)
+
+
+ \ No newline at end of file
diff --git a/pages/submit.py b/pages/submit.py
new file mode 100644
index 0000000..77f230d
--- /dev/null
+++ b/pages/submit.py
@@ -0,0 +1,137 @@
+# 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 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,
+ 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,
+ 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(),
+ box_width=350,
+ xalign=hippo.ALIGNMENT_START,
+ 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(),
+ font_desc=theme.FONT_BODY.get_pango_desc()))
+ 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(),
+ font_desc=theme.FONT_BODY.get_pango_desc()))
+ self.right.append(self.make_textbox(joke, 'answer'))
+
+ self.append(self.left)
+ self.append(self.right)
+
+
+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')
+
+
+
+
+