fixed some bugs created when splitting into gui and controller
[mevemon] / ui.py
1
2 # Based on C code from:
3 # "Hildon Tutorial" version 2009-04-28
4 # Example 3.1, "Example of a Hildon application menu"
5
6 import sys
7
8 import gtk
9 import hildon
10
11 class mEveMonUI():
12
13     about_name = 'mEveMon'
14     about_text = ('Mobile character monitor for EVE Online')
15     about_authors = ['Ryan Campbell']
16     about_website = 'http://example.site.org'
17     app_version = '0.1'
18
19     menu_items = ("Settings", "About", "Refresh")
20
21     def __init__(self, controller):
22         self.controller = controller
23    
24         gtk.set_application_name("mEveMon")
25     
26         #create the main window
27         win = hildon.StackableWindow()
28         win.connect("destroy", self.controller.quit)
29
30         # Create menu
31         menu = self.create_menu(win)
32         # Attach menu to the window
33         win.set_app_menu(menu)
34
35         pannable_area = hildon.PannableArea()
36         table = self.create_table(win)
37
38         pannable_area.add_with_viewport(table)
39         
40         win.add(pannable_area);
41         
42         win.show_all()
43   
44     def settings_clicked(self, button, window):
45    
46         dialog = gtk.Dialog()
47    
48         dialog.set_transient_for(window)
49         dialog.set_title("Settings")
50         dialog.show_all()
51         dialog.run()
52         dialog.destroy()
53
54
55     def about_clicked(self, button):
56     
57         dialog = gtk.AboutDialog()
58         dialog.set_website(self.about_website)
59         dialog.set_website_label(self.about_website)
60         dialog.set_name(self.about_name)
61         dialog.set_authors(self.about_authors)
62         dialog.set_comments(self.about_text)
63         dialog.set_version(self.app_version)
64         dialog.run()
65         dialog.destroy()
66
67     def refresh_clicked(self, button, window):
68         pass
69   
70
71     def create_menu(self, window):
72     
73         menu = hildon.AppMenu()
74
75         for command in self.menu_items:
76             # Create menu entries
77             button = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
78             button.set_label(command)
79
80             if command == "About":
81                     button.connect("clicked", self.about_clicked)
82             elif command == "Settings":
83                 button.connect("clicked", self.settings_clicked, window)
84             elif command == "Refresh":
85                 button.connect("clicked", self.refresh_clicked, window)
86             else:
87                 assert False, command
88
89             # Add entry to the view menu
90             menu.append(button)
91         
92         menu.show_all()
93
94         return menu
95
96     def create_table(self, window):
97     
98         # create a table of 10 by 10 squares. 
99         table = gtk.Table (1, 10, False)
100         table.show()
101
102         # this simply creates a grid of toggle buttons on the table
103         # to demonstrate the scrolled window. 
104         for i in range(10):
105             data_buffer = "button %d\n" % i
106             button = gtk.ToggleButton(data_buffer)
107             table.attach(button, 0, 1 , i, i+1)
108
109         return table
110
111
112 if __name__ == "__main__":
113     main()
114