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
24 gtk.set_application_name("mEveMon")
26 #create the main window
27 win = hildon.StackableWindow()
28 win.connect("destroy", self.controller.quit)
31 menu = self.create_menu(win)
32 # Attach menu to the window
33 win.set_app_menu(menu)
35 pannable_area = hildon.PannableArea()
37 # gtk.HILDON_UI_MODE_NORMAL -> not selection in the treeview
38 # gtk.HILDON_UI_MODE_EDIT -> selection in the treeview
39 treeview = hildon.GtkTreeView(gtk.HILDON_UI_MODE_NORMAL)
40 treeview.connect('row-activated', self.build_window)
42 self.char_model = self.create_char_model()
43 treeview.set_model(self.char_model)
45 self.add_columns_to_treeview(treeview)
47 pannable_area.add(treeview)
49 win.add(pannable_area);
53 def build_window(self, treeview, path, view_column):
54 win = hildon.StackableWindow()
57 # NOTE: we probably want a window-specific menu for this page, but the
58 # main appmenu works for now
59 menu = self.create_menu(win)
60 # Attach menu to the window
61 win.set_app_menu(menu)
63 model = treeview.get_model()
64 miter = model.get_iter(path)
66 # column 0 is the portrait, column 1 is name
68 char_name = model.get_value(miter, 1)
70 win.set_title(char_name)
72 label = gtk.Label("This is a subview with information about %s" % char_name)
74 vbox = gtk.VBox(False, 0)
75 vbox.pack_start(label, True, True, 0)
81 def create_char_model(self):
82 lstore = gtk.ListStore(gtk.gdk.Pixbuf, gobject.TYPE_STRING)
84 #get icon and name and put in a liststore
85 self.fill_char_model(lstore)
90 def fill_char_model(self, lstore):
91 char_list = self.controller.get_characters()
93 for name, icon in char_list:
94 liter = lstore.append()
95 lstore.set(liter, 1, name, 0, self.set_pix(icon))
98 def update_model(self, lstore):
100 self.fill_char_model(lstore)
103 def set_pix(self, filename):
104 pixbuf = gtk.gdk.pixbuf_new_from_file(filename)
108 def add_columns_to_treeview(self, treeview):
109 #Column 0 for the treeview
110 renderer = gtk.CellRendererPixbuf()
111 column = gtk.TreeViewColumn()
112 column.pack_start(renderer, True)
113 column.add_attribute(renderer, "pixbuf", 0)
114 treeview.append_column(column)
116 #Column 1 for the treeview
117 renderer = gtk.CellRendererText()
118 column = gtk.TreeViewColumn('title', renderer, text=1)
119 column.set_property("expand", True)
120 treeview.append_column(column)
123 def settings_clicked(self, button, window):
124 dialog = gtk.Dialog()
126 #get the vbox to pack all the settings into
129 dialog.set_transient_for(window)
130 dialog.set_title("Settings")
132 uidLabel = gtk.Label("User ID:")
133 uidLabel.set_justify(gtk.JUSTIFY_LEFT)
136 uidEntry = hildon.Entry(gtk.HILDON_SIZE_FINGER_HEIGHT)
137 uidEntry.set_placeholder("User ID")
138 uidEntry.set_text(self.controller.get_uid())
139 uidEntry.set_property('is_focus', False)
143 apiLabel = gtk.Label("API key:")
144 apiLabel.set_justify(gtk.JUSTIFY_LEFT)
147 apiEntry = hildon.Entry(gtk.HILDON_SIZE_FINGER_HEIGHT)
148 apiEntry.set_placeholder("API Key")
149 apiEntry.set_text(self.controller.get_api_key())
150 apiEntry.set_property('is_focus', False)
154 ok_button = dialog.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
155 help_button = dialog.add_button(gtk.STOCK_HELP, gtk.RESPONSE_HELP)
158 result = dialog.run()
159 if result == gtk.RESPONSE_OK:
160 self.controller.set_api_key(apiEntry.get_text())
161 self.controller.set_uid(uidEntry.get_text())
162 self.controller.set_auth()
163 self.update_model(self.char_model)
171 def about_clicked(self, button):
172 dialog = gtk.AboutDialog()
173 dialog.set_website(self.about_website)
174 dialog.set_website_label(self.about_website)
175 dialog.set_name(self.about_name)
176 dialog.set_authors(self.about_authors)
177 dialog.set_comments(self.about_text)
178 dialog.set_version(self.app_version)
183 def refresh_clicked(self, button, window):
184 self.update_model(self.char_model)
187 def create_menu(self, window):
188 menu = hildon.AppMenu()
190 for command in self.menu_items:
191 # Create menu entries
192 button = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
193 button.set_label(command)
195 if command == "About":
196 button.connect("clicked", self.about_clicked)
197 elif command == "Settings":
198 button.connect("clicked", self.settings_clicked, window)
199 elif command == "Refresh":
200 button.connect("clicked", self.refresh_clicked, window)
202 assert False, command
204 # Add entry to the view menu
212 if __name__ == "__main__":