2 # mEveMon - A character monitor for EVE Online
3 # Copyright (c) 2010 Ryan and Danny Campbell, and the mEveMon Team
5 # mEveMon is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # mEveMon is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
27 about_name = 'mEveMon'
28 about_text = ('Mobile character monitor for EVE Online')
29 about_authors = ['Ryan Campbell', 'Danny Campbell']
30 about_website = 'http://mevemon.garage.maemo.org'
33 menu_items = ("Settings", "About", "Refresh")
35 def __init__(self, controller):
36 self.controller = controller
37 gtk.set_application_name("mEveMon")
39 #create the main window
40 win = hildon.StackableWindow()
41 win.connect("destroy", self.controller.quit)
43 hildon.hildon_gtk_window_set_progress_indicator(win, 1)
46 menu = self.create_menu(win)
47 # Attach menu to the window
48 win.set_app_menu(menu)
50 pannable_area = hildon.PannableArea()
52 # gtk.HILDON_UI_MODE_NORMAL -> not selection in the treeview
53 # gtk.HILDON_UI_MODE_EDIT -> selection in the treeview
54 treeview = hildon.GtkTreeView(gtk.HILDON_UI_MODE_NORMAL)
55 treeview.connect('row-activated', self.build_window)
57 self.char_model = self.create_char_model()
58 treeview.set_model(self.char_model)
60 self.add_columns_to_treeview(treeview)
62 pannable_area.add(treeview)
64 win.add(pannable_area);
68 hildon.hildon_gtk_window_set_progress_indicator(win, 0)
70 def build_window(self, treeview, path, view_column):
71 # TODO: this is a really long and ugly function, split it up somehow
73 win = hildon.StackableWindow()
75 hildon.hildon_gtk_window_set_progress_indicator(win, 1)
78 # NOTE: we probably want a window-specific menu for this page, but the
79 # main appmenu works for now
80 menu = self.create_menu(win)
81 # Attach menu to the window
82 win.set_app_menu(menu)
84 pannable_area = hildon.PannableArea()
86 model = treeview.get_model()
87 miter = model.get_iter(path)
89 # column 0 is the portrait, column 1 is name
91 char_name = model.get_value(miter, 1)
92 char_id = self.controller.char_name2id(char_name)
93 sheet = self.controller.get_char_sheet(char_id)
95 win.set_title(char_name)
97 skillLabel = gtk.Label("Skills")
99 name = gtk.Label("%s" % char_name)
100 name.set_alignment(0, 0.5)
102 race = gtk.Label("%s %s %s" % (sheet.gender, sheet.race,
104 race.set_alignment(0, 0.5)
106 corp = gtk.Label("Corp: %s" % sheet.corporationName)
107 corp.set_alignment(0, 0.5)
109 balance = gtk.Label("Balance: %s ISK" % sheet.balance)
110 balance.set_alignment(0, 0.5)
112 portrait = gtk.Image()
113 portrait.set_from_file(self.controller.get_portrait(char_name, 256))
116 hbox = gtk.HBox(False, 0)
118 info_vbox = gtk.VBox(False, 0)
119 info_vbox.pack_start(name, False, False, 1)
120 info_vbox.pack_start(race, False, False, 1)
121 info_vbox.pack_start(corp, False, False, 1)
122 info_vbox.pack_start(balance, False, False, 1)
124 hbox.pack_start(portrait, False, False, 10)
125 hbox.pack_start(info_vbox, False, False, 5)
126 #hbox.pack_start(stats_vbox, False, False, 5)
128 vbox = gtk.VBox(False, 0)
129 pannable_area.add_with_viewport(vbox)
131 vbox.pack_start(hbox, False, False, 0)
132 vbox.pack_start(skillLabel, False, False, 5)
134 skills_treeview = hildon.GtkTreeView(gtk.HILDON_UI_MODE_NORMAL)
136 skills_model = self.create_skills_model(sheet)
137 skills_treeview.set_model(skills_model)
139 self.add_columns_to_skills_view(skills_treeview)
141 vbox.pack_start(skills_treeview, False, False, 0)
143 win.add(pannable_area)
146 hildon.hildon_gtk_window_set_progress_indicator(win, 0)
148 def add_columns_to_skills_view(self, treeview):
149 #Column 0 for the treeview
150 renderer = gtk.CellRendererText()
151 column = gtk.TreeViewColumn('Skill Name', renderer, text=0)
152 column.set_property("expand", True)
153 treeview.append_column(column)
155 #Column 1 for the treeview
156 renderer = gtk.CellRendererText()
157 column = gtk.TreeViewColumn('Skill Info', renderer, text=1)
158 column.set_property("expand", True)
159 treeview.append_column(column)
161 def create_skills_model(self, sheet):
163 lstore = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING)
165 skilltree = self.controller.get_skill_tree()
167 sp = [0, 250, 1414, 8000, 45255, 256000]
169 for g in skilltree.skillGroups:
171 skills_trained_in_this_group = False
173 for skill in g.skills:
175 trained = sheet.skills.Get(skill.typeID, False)
179 if not skills_trained_in_this_group:
181 #TODO: add as a heading/category
182 skills_trained_in_this_group = True
184 # add row for this skill
185 liter = lstore.append()
186 lstore.set(liter, 0, "%s (Rank %d)" % (skill.typeName, skill.rank),
187 1, "SP: %d Level %d" %
188 (trained.skillpoints,
195 def create_char_model(self):
196 lstore = gtk.ListStore(gtk.gdk.Pixbuf, gobject.TYPE_STRING)
198 #get icon and name and put in a liststore
199 self.fill_char_model(lstore)
204 def fill_char_model(self, lstore):
205 char_list = self.controller.get_characters()
207 for name, icon in char_list:
208 liter = lstore.append()
209 lstore.set(liter, 1, name, 0, self.set_pix(icon))
212 def update_model(self, lstore):
214 self.fill_char_model(lstore)
217 def set_pix(self, filename):
218 pixbuf = gtk.gdk.pixbuf_new_from_file(filename)
222 def add_columns_to_treeview(self, treeview):
223 #Column 0 for the treeview
224 renderer = gtk.CellRendererPixbuf()
225 column = gtk.TreeViewColumn()
226 column.pack_start(renderer, True)
227 column.add_attribute(renderer, "pixbuf", 0)
228 treeview.append_column(column)
230 #Column 1 for the treeview
231 renderer = gtk.CellRendererText()
232 column = gtk.TreeViewColumn('Character Name', renderer, text=1)
233 column.set_property("expand", True)
234 treeview.append_column(column)
237 def settings_clicked(self, button, window):
238 dialog = gtk.Dialog()
240 #get the vbox to pack all the settings into
243 dialog.set_transient_for(window)
244 dialog.set_title("Settings")
246 uidLabel = gtk.Label("User ID:")
247 uidLabel.set_justify(gtk.JUSTIFY_LEFT)
250 uidEntry = hildon.Entry(gtk.HILDON_SIZE_FINGER_HEIGHT)
251 uidEntry.set_placeholder("User ID")
252 uidEntry.set_text(self.controller.get_uid())
253 uidEntry.set_property('is_focus', False)
257 apiLabel = gtk.Label("API key:")
258 apiLabel.set_justify(gtk.JUSTIFY_LEFT)
261 apiEntry = hildon.Entry(gtk.HILDON_SIZE_FINGER_HEIGHT)
262 apiEntry.set_placeholder("API Key")
263 apiEntry.set_text(self.controller.get_api_key())
264 apiEntry.set_property('is_focus', False)
268 ok_button = dialog.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
269 help_button = dialog.add_button(gtk.STOCK_HELP, gtk.RESPONSE_HELP)
272 result = dialog.run()
273 if result == gtk.RESPONSE_OK:
274 self.controller.set_api_key(apiEntry.get_text())
275 self.controller.set_uid(uidEntry.get_text())
276 self.controller.set_auth()
277 self.update_model(self.char_model)
285 def about_clicked(self, button):
286 dialog = gtk.AboutDialog()
287 dialog.set_website(self.about_website)
288 dialog.set_website_label(self.about_website)
289 dialog.set_name(self.about_name)
290 dialog.set_authors(self.about_authors)
291 dialog.set_comments(self.about_text)
292 dialog.set_version(self.app_version)
297 def refresh_clicked(self, button, window):
298 self.update_model(self.char_model)
301 def create_menu(self, window):
302 menu = hildon.AppMenu()
304 for command in self.menu_items:
305 # Create menu entries
306 button = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
307 button.set_label(command)
309 if command == "About":
310 button.connect("clicked", self.about_clicked)
311 elif command == "Settings":
312 button.connect("clicked", self.settings_clicked, window)
313 elif command == "Refresh":
314 button.connect("clicked", self.refresh_clicked, window)
316 assert False, command
318 # Add entry to the view menu
326 if __name__ == "__main__":