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 ###########################################################################
26 class Maevies(hildon.StackableWindow):
34 super(Maevies, self).__init__()
35 self.set_title("Maevies - 0.1")
36 self.connect('delete-event',
37 lambda widget, event: gtk.main_quit())
39 self.add(self._create_contents())
40 self.set_app_menu(self._create_app_menu())
44 def _create_box(self, title, action):
46 box.set_border_width(20)
49 button.connect("clicked", self._button_clicked, action)
50 foot_label = gtk.Label()
51 foot_label.set_text(title)
53 box.pack_start(button,
54 expand = True, fill = True)
55 box.pack_start(foot_label,
56 expand = False, fill = False)
60 def _create_contents(self):
62 contents.set_border_width(60)
63 contents.set_homogeneous(True)
64 contents.pack_start(self._create_box(title = "On Theaters",
65 action = self.ACTION_THEATERS),
66 expand = True, fill = True)
67 contents.pack_start(self._create_box(title = "Favorites",
68 action = self.ACTION_FAVORITES),
69 expand = True, fill = True)
70 contents.pack_start(self._create_box(title = "Search",
71 action = self.ACTION_SEARCH),
72 expand = True, fill = True)
76 def _button_clicked(self, button, action):
77 if action == self.ACTION_SEARCH:
78 search_dialog = SearchDialog(self)
79 if search_dialog.run() == gtk.RESPONSE_ACCEPT:
80 ResultsWindow(search_term = search_dialog.get_search_term(),
81 search_category = search_dialog.get_search_category())
82 search_dialog.destroy()
83 elif action == self.ACTION_ABOUT:
84 about_dialog = AboutDialog(self)
86 about_dialog.destroy()
88 def _create_app_menu(self):
89 menu = hildon.AppMenu()
91 about = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
92 about.set_label("About")
93 about.connect("clicked", self._button_clicked, self.ACTION_ABOUT)
104 class SearchDialog(gtk.Dialog):
111 def __init__(self, parent):
112 super(SearchDialog, self).__init__(parent = parent,
113 flags = gtk.DIALOG_DESTROY_WITH_PARENT)
114 self.set_title("Enter search terms")
116 self.vbox.pack_start(self._create_contents(), True, False, 0)
117 self.add_button(gtk.STOCK_OK, gtk.RESPONSE_ACCEPT)
121 def _create_contents(self):
122 self._search_entry = hildon.Entry(gtk.HILDON_SIZE_FINGER_HEIGHT)
123 search_button = self._create_picker_button()
125 search_contents = gtk.VBox(False, 0)
127 search_contents.pack_start(self._search_entry, True, True, 0)
128 search_contents.pack_start(search_button, True, True, 0)
130 return search_contents
132 def _create_picker_button(self):
133 self._picker_button = hildon.PickerButton(gtk.HILDON_SIZE_FINGER_HEIGHT,
134 hildon.BUTTON_ARRANGEMENT_VERTICAL)
135 self._picker_button.set_title("Search for")
137 selector = hildon.TouchSelector(text = True)
138 selector.set_column_selection_mode(hildon.TOUCH_SELECTOR_SELECTION_MODE_SINGLE)
140 for field in self.fields:
141 selector.append_text(field)
143 self._picker_button.set_selector(selector)
144 self._picker_button.set_active(0)
146 return self._picker_button
148 def get_search_term(self):
149 return self._search_entry.get_text()
151 def get_search_category(self):
152 return self.fields[self._picker_button.get_active()]
154 class ResultsWindow(hildon.StackableWindow):
158 def __init__(self, search_term, search_category):
159 super(ResultsWindow, self).__init__()
160 self.set_title("Search results")
162 self.search_term = search_term
163 self.search_category = search_category
169 def _show_banner(self):
170 message = "Searching <i>%(category)s</i> for <i>%(term)s</i>" % {'category': self.search_category,
171 'term' : self.search_term}
172 banner = hildon.hildon_banner_show_information_with_markup(self,
175 banner.set_timeout(self.TIMEOUT_TIME)
178 if __name__ == "__main__":
182 class AboutDialog(gtk.Dialog):
184 def __init__(self, parent):
185 super(AboutDialog, self).__init__(parent = parent,
186 flags = gtk.DIALOG_DESTROY_WITH_PARENT)
187 self.set_title("About Maevies")