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)
30 hildon.hildon_gtk_window_set_progress_indicator(win, 1)
33 menu = self.create_menu(win)
34 # Attach menu to the window
35 win.set_app_menu(menu)
37 pannable_area = hildon.PannableArea()
39 # gtk.HILDON_UI_MODE_NORMAL -> not selection in the treeview
40 # gtk.HILDON_UI_MODE_EDIT -> selection in the treeview
41 treeview = hildon.GtkTreeView(gtk.HILDON_UI_MODE_NORMAL)
42 treeview.connect('row-activated', self.build_window)
44 self.char_model = self.create_char_model()
45 treeview.set_model(self.char_model)
47 self.add_columns_to_treeview(treeview)
49 pannable_area.add(treeview)
51 win.add(pannable_area);
55 hildon.hildon_gtk_window_set_progress_indicator(win, 0)
57 def build_window(self, treeview, path, view_column):
58 win = hildon.StackableWindow()
60 hildon.hildon_gtk_window_set_progress_indicator(win, 1)
63 # NOTE: we probably want a window-specific menu for this page, but the
64 # main appmenu works for now
65 menu = self.create_menu(win)
66 # Attach menu to the window
67 win.set_app_menu(menu)
69 pannable_area = hildon.PannableArea()
71 model = treeview.get_model()
72 miter = model.get_iter(path)
74 # column 0 is the portrait, column 1 is name
76 char_name = model.get_value(miter, 1)
77 char_id = self.controller.char_name2id(char_name)
78 sheet = self.controller.get_char_sheet(char_id)
80 win.set_title(char_name)
82 skillLabel = gtk.Label("Skills")
84 name = gtk.Label("%s" % char_name)
85 name.set_alignment(0, 0.5)
87 race = gtk.Label("%s %s %s" % (sheet.gender, sheet.race,
89 race.set_alignment(0, 0.5)
91 corp = gtk.Label("Corp: %s" % sheet.corporationName)
92 corp.set_alignment(0, 0.5)
94 balance = gtk.Label("Balance: %s ISK" % sheet.balance)
95 balance.set_alignment(0, 0.5)
97 portrait = gtk.Image()
98 portrait.set_from_file(self.controller.get_portrait(char_name, 256))
101 hbox = gtk.HBox(False, 0)
103 info_vbox = gtk.VBox(False, 0)
104 info_vbox.pack_start(name, False, False, 1)
105 info_vbox.pack_start(race, False, False, 1)
106 info_vbox.pack_start(corp, False, False, 1)
107 info_vbox.pack_start(balance, False, False, 1)
109 hbox.pack_start(portrait, False, False, 10)
110 hbox.pack_start(info_vbox, False, False, 5)
111 #hbox.pack_start(stats_vbox, False, False, 5)
113 vbox = gtk.VBox(False, 0)
114 pannable_area.add_with_viewport(vbox)
116 vbox.pack_start(hbox, False, False, 0)
117 vbox.pack_start(skillLabel, False, False, 5)
119 win.add(pannable_area)
122 hildon.hildon_gtk_window_set_progress_indicator(win, 0)
124 def create_char_model(self):
125 lstore = gtk.ListStore(gtk.gdk.Pixbuf, gobject.TYPE_STRING)
127 #get icon and name and put in a liststore
128 self.fill_char_model(lstore)
133 def fill_char_model(self, lstore):
134 char_list = self.controller.get_characters()
136 for name, icon in char_list:
137 liter = lstore.append()
138 lstore.set(liter, 1, name, 0, self.set_pix(icon))
141 def update_model(self, lstore):
143 self.fill_char_model(lstore)
146 def set_pix(self, filename):
147 pixbuf = gtk.gdk.pixbuf_new_from_file(filename)
151 def add_columns_to_treeview(self, treeview):
152 #Column 0 for the treeview
153 renderer = gtk.CellRendererPixbuf()
154 column = gtk.TreeViewColumn()
155 column.pack_start(renderer, True)
156 column.add_attribute(renderer, "pixbuf", 0)
157 treeview.append_column(column)
159 #Column 1 for the treeview
160 renderer = gtk.CellRendererText()
161 column = gtk.TreeViewColumn('title', renderer, text=1)
162 column.set_property("expand", True)
163 treeview.append_column(column)
166 def settings_clicked(self, button, window):
167 dialog = gtk.Dialog()
169 #get the vbox to pack all the settings into
172 dialog.set_transient_for(window)
173 dialog.set_title("Settings")
175 uidLabel = gtk.Label("User ID:")
176 uidLabel.set_justify(gtk.JUSTIFY_LEFT)
179 uidEntry = hildon.Entry(gtk.HILDON_SIZE_FINGER_HEIGHT)
180 uidEntry.set_placeholder("User ID")
181 uidEntry.set_text(self.controller.get_uid())
182 uidEntry.set_property('is_focus', False)
186 apiLabel = gtk.Label("API key:")
187 apiLabel.set_justify(gtk.JUSTIFY_LEFT)
190 apiEntry = hildon.Entry(gtk.HILDON_SIZE_FINGER_HEIGHT)
191 apiEntry.set_placeholder("API Key")
192 apiEntry.set_text(self.controller.get_api_key())
193 apiEntry.set_property('is_focus', False)
197 ok_button = dialog.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
198 help_button = dialog.add_button(gtk.STOCK_HELP, gtk.RESPONSE_HELP)
201 result = dialog.run()
202 if result == gtk.RESPONSE_OK:
203 self.controller.set_api_key(apiEntry.get_text())
204 self.controller.set_uid(uidEntry.get_text())
205 self.controller.set_auth()
206 self.update_model(self.char_model)
214 def about_clicked(self, button):
215 dialog = gtk.AboutDialog()
216 dialog.set_website(self.about_website)
217 dialog.set_website_label(self.about_website)
218 dialog.set_name(self.about_name)
219 dialog.set_authors(self.about_authors)
220 dialog.set_comments(self.about_text)
221 dialog.set_version(self.app_version)
226 def refresh_clicked(self, button, window):
227 self.update_model(self.char_model)
230 def create_menu(self, window):
231 menu = hildon.AppMenu()
233 for command in self.menu_items:
234 # Create menu entries
235 button = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
236 button.set_label(command)
238 if command == "About":
239 button.connect("clicked", self.about_clicked)
240 elif command == "Settings":
241 button.connect("clicked", self.settings_clicked, window)
242 elif command == "Refresh":
243 button.connect("clicked", self.refresh_clicked, window)
245 assert False, command
247 # Add entry to the view menu
255 if __name__ == "__main__":