1 # -*- coding: utf-8 -*-
3 ###########################################################################
5 # Copyright (C) 2010 Simón Pena <spenap@gmail.com>
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 ###########################################################################
21 from maeviesui.util import constants
27 from random import randint
32 class Maevies(hildon.StackableWindow):
40 super(Maevies, self).__init__()
41 self.set_title("Maevies - 0.1")
42 self.connect('delete-event',
43 lambda widget, event: gtk.main_quit())
45 self.add(self._create_contents())
46 self.set_app_menu(self._create_app_menu())
50 def _create_box(self, title, action):
52 box.set_border_width(20)
55 button.connect("clicked", self._button_clicked, action)
56 foot_label = gtk.Label()
57 foot_label.set_text(title)
59 box.pack_start(button,
60 expand = True, fill = True)
61 box.pack_start(foot_label,
62 expand = False, fill = False)
66 def _create_contents(self):
68 contents.set_border_width(60)
69 contents.set_homogeneous(True)
70 contents.pack_start(self._create_box(title = "On Theaters",
71 action = self.ACTION_THEATERS),
72 expand = True, fill = True)
73 contents.pack_start(self._create_box(title = "Favorites",
74 action = self.ACTION_FAVORITES),
75 expand = True, fill = True)
76 contents.pack_start(self._create_box(title = "Search",
77 action = self.ACTION_SEARCH),
78 expand = True, fill = True)
82 def _button_clicked(self, button, action):
83 if action == self.ACTION_SEARCH:
84 search_dialog = SearchDialog(self)
85 if search_dialog.run() == gtk.RESPONSE_ACCEPT:
86 ResultsWindow(search_term = search_dialog.get_search_term(),
87 search_category = search_dialog.get_search_category())
88 search_dialog.destroy()
89 elif action == self.ACTION_ABOUT:
90 about_dialog = AboutDialog(self)
92 about_dialog.destroy()
94 def _create_app_menu(self):
95 menu = hildon.AppMenu()
97 about = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
98 about.set_label("About")
99 about.connect("clicked", self._button_clicked, self.ACTION_ABOUT)
110 class SearchDialog(gtk.Dialog):
117 def __init__(self, parent):
118 super(SearchDialog, self).__init__(parent = parent,
119 flags = gtk.DIALOG_DESTROY_WITH_PARENT)
120 self.set_title("Enter search terms")
122 self.vbox.pack_start(self._create_contents(), True, False, 0)
123 self.add_button(gtk.STOCK_OK, gtk.RESPONSE_ACCEPT)
127 def _create_contents(self):
128 self._search_entry = hildon.Entry(gtk.HILDON_SIZE_FINGER_HEIGHT)
129 search_button = self._create_picker_button()
131 search_contents = gtk.VBox()
133 search_contents.pack_start(self._search_entry,
134 expand = True, fill = True)
135 search_contents.pack_start(search_button,
136 expand = True, fill = True)
138 return search_contents
140 def _create_picker_button(self):
141 self._picker_button = hildon.PickerButton(gtk.HILDON_SIZE_FINGER_HEIGHT,
142 hildon.BUTTON_ARRANGEMENT_VERTICAL)
143 self._picker_button.set_title("Search for")
145 selector = hildon.TouchSelector(text = True)
146 selector.set_column_selection_mode(hildon.TOUCH_SELECTOR_SELECTION_MODE_SINGLE)
148 for field in self._search_fields:
149 selector.append_text(field)
151 self._picker_button.set_selector(selector)
152 self._picker_button.set_active(0)
154 return self._picker_button
156 def get_search_term(self):
157 return self._search_entry.get_text()
159 def get_search_category(self):
160 return self._search_fields[self._picker_button.get_active()]
162 class ResultsWindow(hildon.StackableWindow):
164 def __init__(self, search_term, search_category):
165 super(ResultsWindow, self).__init__()
166 self.set_title("Search results")
168 self.search_term = search_term
169 self.search_category = search_category
171 self._simulate_search()
172 content_area = hildon.PannableArea()
173 self._movies_view = MoviesView()
175 content_area.add(self._movies_view)
176 self.add(content_area)
180 def _simulate_search(self):
182 hildon.hildon_gtk_window_set_progress_indicator(self, True)
183 gobject.timeout_add(constants.TIMEOUT_TIME_MILLIS, self._populate_view)
185 def _populate_view(self):
186 self._movies_view.add_movies([MovieDecorator("The Lord of the Rings"),
187 MovieDecorator("The Lord of the flies"),
188 MovieDecorator("Gone by the wind"),
189 MovieDecorator("Madagascar"),
190 MovieDecorator("Madagascar 2"),
191 MovieDecorator("2 Fast 2 Furious"),
192 MovieDecorator("Fast & Furious"),
193 MovieDecorator("Pitch Black"),
195 hildon.hildon_gtk_window_set_progress_indicator(self, False)
198 def _show_banner(self):
199 message = "Searching <i>%(category)s</i> for <i>%(term)s</i>" % {'category': self.search_category,
200 'term' : self.search_term}
201 banner = hildon.hildon_banner_show_information_with_markup(self,
204 banner.set_timeout(constants.TIMEOUT_TIME_MILLIS)
207 class MoviesView(gtk.TreeView):
210 super(MoviesView, self).__init__()
211 model = MoviesListStore()
212 self.set_model(model)
214 movie_image_renderer = gtk.CellRendererPixbuf()
215 column = gtk.TreeViewColumn('Image', movie_image_renderer, pixbuf = model.IMAGE_COLUMN)
216 self.append_column(column)
218 movie_text_renderer = gtk.CellRendererText()
219 movie_text_renderer.set_property('ellipsize', pango.ELLIPSIZE_END)
220 column = gtk.TreeViewColumn('Name', movie_text_renderer, markup = model.INFO_COLUMN)
221 self.append_column(column)
225 def add_movies(self, movie_list):
226 model = self.get_model()
227 model.add(movie_list)
229 class MoviesListStore(gtk.ListStore):
236 super(MoviesListStore, self).__init__(gtk.gdk.Pixbuf,
238 gobject.TYPE_PYOBJECT)
240 def add(self, movies_found):
242 for movie in movies_found:
243 row = {self.IMAGE_COLUMN: movie.get_image(),
244 self.INFO_COLUMN: movie.get_info(),
245 self.MOVIE_COLUMN: movie,
247 self.append(row.values())
249 if __name__ == "__main__":
253 class AboutDialog(gtk.Dialog):
255 def __init__(self, parent):
256 super(AboutDialog, self).__init__(parent = parent,
257 flags = gtk.DIALOG_DESTROY_WITH_PARENT)
258 self.set_title("About Maevies")
261 class MovieDecorator:
263 def __init__(self, name):
270 def get_length(self):
271 return "%sh:%sm" % (random.randrange(1, 2), random.randrange(0, 59))
274 return "%s" % (random.randrange(6, 9))
277 return "<b>%s</b>\n<small><i>Length: </i>%s || <i>Score: </i>%s</small>" % (
283 return self._get_placeholder_pixbuf()
285 def _get_placeholder_pixbuf(self):
286 pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(constants.PLACEHOLDER_IMAGE,
287 constants.IMAGE_WIDTH,
288 constants.IMAGE_HEIGHT)