3f164d27928bfe806808a67a5c5fae89d4021c22
[mevemon] / ui / fremantle / 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         #get the vbox to pack all the settings into
49         vbox = dialog.vbox
50     
51         dialog.set_transient_for(window)
52         dialog.set_title("Settings")
53
54         uidLabel = gtk.Label("User ID:")
55         uidLabel.set_justify(gtk.JUSTIFY_LEFT)
56         vbox.add(uidLabel)
57         
58         uidEntry = hildon.Entry(gtk.HILDON_SIZE_FINGER_HEIGHT)
59         uidEntry.set_placeholder("User ID")
60         uidEntry.set_text(self.controller.get_uid())
61         uidEntry.set_property('is_focus', False)
62         
63         vbox.add(uidEntry)
64
65         apiLabel = gtk.Label("API key:")
66         apiLabel.set_justify(gtk.JUSTIFY_LEFT)
67         vbox.add(apiLabel)
68         
69         apiEntry = hildon.Entry(gtk.HILDON_SIZE_FINGER_HEIGHT)
70         apiEntry.set_placeholder("API Key")
71         apiEntry.set_text(self.controller.get_api_key())
72         apiEntry.set_property('is_focus', False)
73
74         vbox.add(apiEntry)
75     
76        
77         ok_button = dialog.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
78         help_button = dialog.add_button(gtk.STOCK_HELP, gtk.RESPONSE_HELP)
79
80
81         dialog.show_all()
82         result = dialog.run()
83         if result == gtk.RESPONSE_OK:
84             self.controller.set_api_key(apiEntry.get_text())
85             self.controller.set_uid(uidEntry.get_text())
86         
87         dialog.destroy()
88
89         return result
90
91     def about_clicked(self, button):
92     
93         dialog = gtk.AboutDialog()
94         dialog.set_website(self.about_website)
95         dialog.set_website_label(self.about_website)
96         dialog.set_name(self.about_name)
97         dialog.set_authors(self.about_authors)
98         dialog.set_comments(self.about_text)
99         dialog.set_version(self.app_version)
100         dialog.run()
101         dialog.destroy()
102
103     def refresh_clicked(self, button, window):
104         pass
105   
106
107     def create_menu(self, window):
108     
109         menu = hildon.AppMenu()
110
111         for command in self.menu_items:
112             # Create menu entries
113             button = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
114             button.set_label(command)
115
116             if command == "About":
117                 button.connect("clicked", self.about_clicked)
118             elif command == "Settings":
119                 button.connect("clicked", self.settings_clicked, window)
120             elif command == "Refresh":
121                 button.connect("clicked", self.refresh_clicked, window)
122             else:
123                 assert False, command
124
125             # Add entry to the view menu
126             menu.append(button)
127         
128         menu.show_all()
129
130         return menu
131
132     def create_table(self, window):
133     
134         # create a table of 10 by 10 squares. 
135         table = gtk.Table (1, 10, False)
136         table.show()
137
138         # this simply creates a grid of toggle buttons on the table
139         # to demonstrate the scrolled window. 
140         for i in range(10):
141             data_buffer = "button %d\n" % i
142             button = gtk.ToggleButton(data_buffer)
143             table.attach(button, 0, 1 , i, i+1)
144
145         return table
146
147
148 if __name__ == "__main__":
149     main()
150