2 # Based on C code from:
3 # "Hildon Tutorial" version 2009-04-28
4 # Example 3.1, "Example of a Hildon application menu"
14 about_name = 'mEveMon'
15 about_text = ('Mobile character monitor for EVE Online')
16 about_authors = ['Ryan Campbell', 'Danny Campbell']
17 about_website = 'http://example.site.org'
20 menu_items = ("Settings", "About", "Refresh")
22 def __init__(self, controller):
23 self.controller = controller
25 gtk.set_application_name("mEveMon")
27 #create the main window
28 win = hildon.StackableWindow()
29 win.connect("destroy", self.controller.quit)
32 menu = self.create_menu(win)
33 # Attach menu to the window
34 win.set_app_menu(menu)
36 pannable_area = hildon.PannableArea()
38 # gtk.HILDON_UI_MODE_NORMAL -> not selection in the treeview
39 # gtk.HILDON_UI_MODE_EDIT -> selection in the treeview
40 treeview = hildon.GtkTreeView(gtk.HILDON_UI_MODE_NORMAL)
42 model = self.create_model()
43 treeview.set_model(model)
45 self.add_columns_to_treeview(treeview)
47 pannable_area.add(treeview)
49 win.add(pannable_area);
53 def create_model(self):
54 lstore = gtk.ListStore(gtk.gdk.Pixbuf, gobject.TYPE_STRING)
56 #get icon and name and put in a liststore
58 char_list = self.controller.get_characters()
60 for name, icon in char_list:
61 liter = lstore.append()
62 lstore.set(liter, 1, name, 0, self.set_pix(icon))
66 def set_pix(self, filename):
67 pixbuf = gtk.gdk.pixbuf_new_from_file(filename)
70 def add_columns_to_treeview(self, treeview):
71 #Column 0 for the treeview
72 renderer = gtk.CellRendererPixbuf()
73 column = gtk.TreeViewColumn()
74 column.pack_start(renderer, True)
75 column.add_attribute(renderer, "pixbuf", 0)
76 treeview.append_column(column)
78 #Column 1 for the treeview
79 renderer = gtk.CellRendererText()
80 column = gtk.TreeViewColumn('title', renderer, text=1)
81 column.set_property("expand", True)
82 treeview.append_column(column)
85 def settings_clicked(self, button, window):
89 #get the vbox to pack all the settings into
92 dialog.set_transient_for(window)
93 dialog.set_title("Settings")
95 uidLabel = gtk.Label("User ID:")
96 uidLabel.set_justify(gtk.JUSTIFY_LEFT)
99 uidEntry = hildon.Entry(gtk.HILDON_SIZE_FINGER_HEIGHT)
100 uidEntry.set_placeholder("User ID")
101 uidEntry.set_text(self.controller.get_uid())
102 uidEntry.set_property('is_focus', False)
106 apiLabel = gtk.Label("API key:")
107 apiLabel.set_justify(gtk.JUSTIFY_LEFT)
110 apiEntry = hildon.Entry(gtk.HILDON_SIZE_FINGER_HEIGHT)
111 apiEntry.set_placeholder("API Key")
112 apiEntry.set_text(self.controller.get_api_key())
113 apiEntry.set_property('is_focus', False)
117 ok_button = dialog.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
118 help_button = dialog.add_button(gtk.STOCK_HELP, gtk.RESPONSE_HELP)
122 result = dialog.run()
123 if result == gtk.RESPONSE_OK:
124 self.controller.set_api_key(apiEntry.get_text())
125 self.controller.set_uid(uidEntry.get_text())
131 def about_clicked(self, button):
133 dialog = gtk.AboutDialog()
134 dialog.set_website(self.about_website)
135 dialog.set_website_label(self.about_website)
136 dialog.set_name(self.about_name)
137 dialog.set_authors(self.about_authors)
138 dialog.set_comments(self.about_text)
139 dialog.set_version(self.app_version)
143 def refresh_clicked(self, button, window):
146 def create_menu(self, window):
148 menu = hildon.AppMenu()
150 for command in self.menu_items:
151 # Create menu entries
152 button = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
153 button.set_label(command)
155 if command == "About":
156 button.connect("clicked", self.about_clicked)
157 elif command == "Settings":
158 button.connect("clicked", self.settings_clicked, window)
159 elif command == "Refresh":
160 button.connect("clicked", self.refresh_clicked, window)
162 assert False, command
164 # Add entry to the view menu
171 if __name__ == "__main__":