Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/pages/choose.py
blob: fee1e4839664e750e904cb6e479219cc8eaadcf2 (plain)
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
# 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):
    message = _('Are you sure you want to delete your ') 
    if jokebook.title is not None:
      message += '\'' + jokebook.title + '\' ' 
    message += _('jokebook ?')
    confirm = gtk.MessageDialog(Globals.JokeMachineActivity, 
                                gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
                                gtk.MESSAGE_QUESTION,
                                gtk.BUTTONS_YES_NO,
                                message)
    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