add a 'clear cache' button in the settings
[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 import constants
7
8 class Menu(hildon.AppMenu):
9     MENU_ITEMS = { "Settings": 'on_settings_clicked', 
10                    "About": 'on_about_clicked', 
11                    "Refresh": 'on_refresh_clicked' }
12     def __init__(self, win, controller):
13         hildon.AppMenu.__init__(self)
14         self.win = win
15         self.controller = controller
16         self.callback = lambda *args: None
17         self.build_buttons()
18
19     def set_refresh_cb(self, callback):
20         self.callback = callback
21
22     def build_buttons(self):
23         for button_name in self.MENU_ITEMS:
24             self.create_menu_button(button_name)
25         self.show_all()
26
27     def create_menu_button(self, name):
28         button = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
29         button.set_label(name)
30         button.connect("clicked", getattr(self, self.MENU_ITEMS[name]))
31         self.append(button)
32
33     def on_refresh_clicked(self, button):
34         self.callback(button)
35
36     def on_settings_clicked(self, button):
37         setting_dialog = dialogs.SettingsDialog(self.win, self.controller)
38
39     
40     def on_about_clicked(self, button):
41         dialog = gtk.AboutDialog()
42         dialog.set_website(constants.ABOUT_WEBSITE)
43         dialog.set_website_label(constants.ABOUT_WEBSITE)
44         dialog.set_name(constants.ABOUT_NAME)
45         dialog.set_authors(constants.ABOUT_AUTHORS)
46         dialog.set_comments(constants.ABOUT_TEXT)
47         dialog.set_version(constants.APP_VERSION)
48         dialog.run()
49         dialog.destroy()
50
51     def report_error(self, error):
52         hildon.hildon_banner_show_information(self.win, '', error)