Refactor Fremantule UI code and implement logging
[mevemon] / package / src / ui / fremantle / menu.py
1 import hildon
2 import gtk
3
4 import ui.models as models
5 import ui.fremantle.dialogs as dialogs
6
7 class Menu(hildon.AppMenu):
8     MENU_ITEMS = { "Settings": 'on_settings_clicked', 
9                    "About": 'on_about_clicked', 
10                    "Refresh": 'on_refresh_clicked' }
11     def __init__(self, win, controller):
12         hildon.AppMenu.__init__(self)
13         self.win = win
14         self.controller = controller
15         self.build_buttons()
16
17     def build_buttons(self):
18         for button_name in self.MENU_ITEMS:
19             self.create_menu_button(button_name)
20         self.show_all()
21
22     def create_menu_button(self, name):
23         button = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
24         button.set_label(name)
25         button.connect("clicked", getattr(self, self.MENU_ITEMS[name]))
26         self.append(button)
27
28     def on_refresh_clicked(self, button):
29         pass
30
31     def on_settings_clicked(self, button):
32         setting_dialog = dialogs.SettingsDialog(self.win, self.controller)
33
34     
35     def on_about_clicked(self, button):
36         dialog = gtk.AboutDialog()
37         dialog.set_website(self.controller.about_website)
38         dialog.set_website_label(self.controller.about_website)
39         dialog.set_name(self.controller.about_name)
40         dialog.set_authors(self.controller.about_authors)
41         dialog.set_comments(self.controller.about_text)
42         dialog.set_version(self.controller.app_version)
43         dialog.run()
44         dialog.destroy()
45
46     def report_error(self, error):
47         hildon.hildon_banner_show_information(self.win, '', error)