Fixing issue with back button
[watersofshiloah] / src / windows / scriptures.py
1 import logging
2
3 import gobject
4 import gtk
5
6 import hildonize
7 import util.go_utils as go_utils
8 import util.misc as misc_utils
9
10 import windows
11
12
13 _moduleLogger = logging.getLogger(__name__)
14
15
16 class ScripturesWindow(windows._base.ListWindow):
17
18         def __init__(self, app, player, store, node):
19                 windows._base.ListWindow.__init__(self, app, player, store, node)
20                 self._window.set_title(self._node.title)
21
22         @classmethod
23         def _get_columns(cls):
24                 yield gobject.TYPE_PYOBJECT, None
25
26                 textrenderer = gtk.CellRendererText()
27                 hildonize.set_cell_thumb_selectable(textrenderer)
28                 column = gtk.TreeViewColumn("Scripture")
29                 column.set_property("sizing", gtk.TREE_VIEW_COLUMN_FIXED)
30                 column.pack_start(textrenderer, expand=True)
31                 column.add_attribute(textrenderer, "text", 1)
32                 yield gobject.TYPE_STRING, column
33
34         def _refresh(self):
35                 windows._base.ListWindow._refresh(self)
36                 self._node.get_children(
37                         self._on_scriptures,
38                         self._on_error,
39                 )
40
41         @misc_utils.log_exception(_moduleLogger)
42         def _on_scriptures(self, programs):
43                 if self._isDestroyed:
44                         _moduleLogger.info("Download complete but window destroyed")
45                         return
46
47                 self._hide_loading()
48                 for programNode in programs:
49                         program = programNode.get_properties()
50                         row = programNode, program["title"]
51                         self._model.append(row)
52
53                 self._select_row()
54                 go_utils.Async(self._on_delay_scroll).start()
55
56         @misc_utils.log_exception(_moduleLogger)
57         def _on_error(self, exception):
58                 self._hide_loading()
59                 self._errorBanner.push_message(str(exception))
60
61         def _window_from_node(self, node):
62                 booksWindow = ScriptureBooksWindow(self._app, self._player, self._store, node)
63                 if not hildonize.IS_FREMANTLE_SUPPORTED:
64                         booksWindow.window.set_modal(True)
65                         booksWindow.window.set_transient_for(self._window)
66                 if self._windowInFullscreen:
67                         booksWindow.window.fullscreen()
68                 else:
69                         booksWindow.window.unfullscreen()
70                 booksWindow.connect_auto(booksWindow, "quit", self._on_quit)
71                 booksWindow.connect_auto(booksWindow, "home", self._on_home)
72                 booksWindow.connect_auto(booksWindow, "jump-to", self._on_jump)
73                 booksWindow.connect_auto(booksWindow, "fullscreen", self._on_child_fullscreen)
74                 booksWindow.show()
75                 return booksWindow
76
77
78 gobject.type_register(ScripturesWindow)
79
80
81 class ScriptureBooksWindow(windows._base.ListWindow):
82
83         def __init__(self, app, player, store, node):
84                 windows._base.ListWindow.__init__(self, app, player, store, node)
85                 self._window.set_title(self._node.title)
86
87         @classmethod
88         def _get_columns(cls):
89                 yield gobject.TYPE_PYOBJECT, None
90
91                 textrenderer = gtk.CellRendererText()
92                 hildonize.set_cell_thumb_selectable(textrenderer)
93                 column = gtk.TreeViewColumn("Book")
94                 column.set_property("sizing", gtk.TREE_VIEW_COLUMN_FIXED)
95                 column.pack_start(textrenderer, expand=True)
96                 column.add_attribute(textrenderer, "text", 1)
97                 yield gobject.TYPE_STRING, column
98
99         def _refresh(self):
100                 windows._base.ListWindow._refresh(self)
101                 self._node.get_children(
102                         self._on_scripture_books,
103                         self._on_error,
104                 )
105
106         @misc_utils.log_exception(_moduleLogger)
107         def _on_scripture_books(self, programs):
108                 if self._isDestroyed:
109                         _moduleLogger.info("Download complete but window destroyed")
110                         return
111
112                 self._hide_loading()
113                 for programNode in programs:
114                         program = programNode.get_properties()
115                         row = programNode, program["title"]
116                         self._model.append(row)
117
118                 self._select_row()
119                 go_utils.Async(self._on_delay_scroll).start()
120
121         @misc_utils.log_exception(_moduleLogger)
122         def _on_error(self, exception):
123                 self._hide_loading()
124                 self._errorBanner.push_message(str(exception))
125
126         def _window_from_node(self, node):
127                 booksWindow = ScriptureChaptersWindow(self._app, self._player, self._store, node)
128                 if not hildonize.IS_FREMANTLE_SUPPORTED:
129                         booksWindow.window.set_modal(True)
130                         booksWindow.window.set_transient_for(self._window)
131                 if self._windowInFullscreen:
132                         booksWindow.window.fullscreen()
133                 else:
134                         booksWindow.window.unfullscreen()
135                 booksWindow.connect_auto(booksWindow, "quit", self._on_quit)
136                 booksWindow.connect_auto(booksWindow, "home", self._on_home)
137                 booksWindow.connect_auto(booksWindow, "jump-to", self._on_jump)
138                 booksWindow.connect_auto(booksWindow, "fullscreen", self._on_child_fullscreen)
139                 booksWindow.show()
140                 return booksWindow
141
142
143 gobject.type_register(ScriptureBooksWindow)
144
145
146 class ScriptureChaptersWindow(windows._base.ListWindow):
147
148         def __init__(self, app, player, store, node):
149                 windows._base.ListWindow.__init__(self, app, player, store, node)
150                 self._window.set_title(self._node.title)
151
152         @classmethod
153         def _get_columns(cls):
154                 yield gobject.TYPE_PYOBJECT, None
155
156                 textrenderer = gtk.CellRendererText()
157                 hildonize.set_cell_thumb_selectable(textrenderer)
158                 column = gtk.TreeViewColumn("Chapter")
159                 column.set_property("sizing", gtk.TREE_VIEW_COLUMN_FIXED)
160                 column.pack_start(textrenderer, expand=True)
161                 column.add_attribute(textrenderer, "text", 1)
162                 yield gobject.TYPE_STRING, column
163
164         def _refresh(self):
165                 windows._base.ListWindow._refresh(self)
166                 self._node.get_children(
167                         self._on_scripture_chapters,
168                         self._on_error,
169                 )
170
171         @misc_utils.log_exception(_moduleLogger)
172         def _on_scripture_chapters(self, programs):
173                 if self._isDestroyed:
174                         _moduleLogger.info("Download complete but window destroyed")
175                         return
176
177                 self._hide_loading()
178                 for programNode in programs:
179                         program = programNode.get_properties()
180                         row = programNode, program["title"]
181                         self._model.append(row)
182
183                 self._select_row()
184                 go_utils.Async(self._on_delay_scroll).start()
185
186         @misc_utils.log_exception(_moduleLogger)
187         def _on_error(self, exception):
188                 self._hide_loading()
189                 self._errorBanner.push_message(str(exception))
190
191         def _window_from_node(self, node):
192                 booksWindow = ScriptureChapterWindow(self._app, self._player, self._store, node)
193                 if not hildonize.IS_FREMANTLE_SUPPORTED:
194                         booksWindow.window.set_modal(True)
195                         booksWindow.window.set_transient_for(self._window)
196                 if self._windowInFullscreen:
197                         booksWindow.window.fullscreen()
198                 else:
199                         booksWindow.window.unfullscreen()
200                 booksWindow.connect_auto(booksWindow, "quit", self._on_quit)
201                 booksWindow.connect_auto(booksWindow, "home", self._on_home)
202                 booksWindow.connect_auto(booksWindow, "jump-to", self._on_jump)
203                 booksWindow.connect_auto(booksWindow, "fullscreen", self._on_child_fullscreen)
204                 booksWindow.show()
205                 return booksWindow
206
207
208 gobject.type_register(ScriptureChaptersWindow)
209
210
211 class ScriptureChapterWindow(windows._base.PresenterWindow):
212
213         def __init__(self, app, player, store, node):
214                 windows._base.PresenterWindow.__init__(self, app, player, store, node)
215
216         def _get_background(self):
217                 return self._store.STORE_LOOKUP["scripture_background"]
218
219
220 gobject.type_register(ScriptureChapterWindow)