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/>.
30 menu_items = ("Settings", "About", "Refresh")
32 def create_menu(self, window):
35 for command in self.menu_items:
37 button = gtk.MenuItem(command)
39 if command == "About":
40 button.connect("activate", self.about_clicked)
41 elif command == "Settings":
42 button.connect("activate", self.settings_clicked, window)
43 elif command == "Refresh":
44 button.connect("activate", self.refresh_clicked, window)
48 # Add entry to the view menu
55 def settings_clicked(self, button, window):
57 RESPONSE_NEW, RESPONSE_EDIT, RESPONSE_DELETE = range(3)
60 dialog.set_transient_for(window)
61 dialog.set_title("Settings")
67 acctsLabel = gtk.Label("Accounts:")
68 acctsLabel.set_justify(gtk.JUSTIFY_LEFT)
70 vbox.pack_start(acctsLabel, False, False, 1)
72 self.accounts_model = models.AccountsModel(self.controller)
74 accounts_treeview = gtk.TreeView(model = self.accounts_model)
75 self.add_columns_to_accounts(accounts_treeview)
76 vbox.pack_start(accounts_treeview, False, False, 1)
78 # all stock responses are negative, so we can use any positive value
79 new_button = dialog.add_button("New", RESPONSE_NEW)
80 #TODO: get edit button working
81 #edit_button = dialog.add_button("Edit", RESPONSE_EDIT)
82 delete_button = dialog.add_button("Delete", RESPONSE_DELETE)
83 ok_button = dialog.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
84 cancel_button = dialog.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
86 #TODO: for some reason the scrollbar shows up in the middle of the
88 #scrollbar = gtk.VScrollbar()
94 while(result != gtk.RESPONSE_CANCEL):
95 if result == RESPONSE_NEW:
96 self.new_account_clicked(window)
97 #elif result == RESPONSE_EDIT:
98 # # get the selected treeview item and pop up the account_box
99 # self.edit_account(accounts_treeview)
100 elif result == RESPONSE_DELETE:
101 # get the selected treeview item, and delete the gconf keys
102 self.delete_account(accounts_treeview)
103 elif result == gtk.RESPONSE_OK:
104 self.char_model.get_characters()
107 result = dialog.run()
113 def get_selected_item(self, treeview, column):
114 selection = treeview.get_selection()
115 model, miter = selection.get_selected()
117 value = model.get_value(miter, column)
121 def edit_account(self, treeview):
122 uid = self.get_selected_item(treeview, 0)
123 # pop up the account dialog
125 self.accounts_model.get_accounts()
127 def delete_account(self, treeview):
128 uid = self.get_selected_item(treeview, 0)
129 self.controller.remove_account(uid)
131 self.accounts_model.get_accounts()
134 def add_columns_to_accounts(self, treeview):
135 #Column 0 for the treeview
136 renderer = gtk.CellRendererText()
137 column = gtk.TreeViewColumn('User ID', renderer,
138 text=models.AccountsModel.C_UID)
139 column.set_property("expand", True)
140 treeview.append_column(column)
142 #Column 2 (characters) for the treeview
143 column = gtk.TreeViewColumn('Characters', renderer,
144 markup=models.AccountsModel.C_CHARS)
145 column.set_property("expand", True)
146 treeview.append_column(column)
149 def new_account_clicked(self, window):
150 dialog = gtk.Dialog()
152 #get the vbox to pack all the settings into
155 dialog.set_transient_for(window)
156 dialog.set_title("New Account")
158 uidLabel = gtk.Label("User ID:")
159 uidLabel.set_justify(gtk.JUSTIFY_LEFT)
162 uidEntry = gtk.Entry()
163 uidEntry.set_property('is_focus', False)
167 apiLabel = gtk.Label("API key:")
168 apiLabel.set_justify(gtk.JUSTIFY_LEFT)
171 apiEntry = gtk.Entry()
172 apiEntry.set_property('is_focus', False)
176 ok_button = dialog.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
177 cancel_button = dialog.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
180 result = dialog.run()
182 valid_credentials = False
184 while not valid_credentials:
185 if result == gtk.RESPONSE_OK:
186 uid = uidEntry.get_text()
187 api_key = apiEntry.get_text()
191 validation.api_key(api_key)
192 except validation.ValidationError, e:
193 self.report_error(e.message)
194 result = dialog.run()
196 valid_credentials = True
197 self.controller.add_account(uid, api_key)
198 self.accounts_model.get_accounts()
205 def report_error(self, error):
206 hildon.hildon_banner_show_information(self.win, '', error)
208 def about_clicked(self, button):
209 dialog = gtk.AboutDialog()
210 dialog.set_website(self.controller.about_website)
211 dialog.set_website_label(self.controller.about_website)
212 dialog.set_name(self.controller.about_name)
213 dialog.set_authors(self.controller.about_authors)
214 dialog.set_comments(self.controller.about_text)
215 dialog.set_version(self.controller.app_version)
219 def add_label(self, text, box, markup=True, align="left", padding=1):
220 label = gtk.Label(text)
222 label.set_use_markup(True)
224 label.set_alignment(0, 0.5)
226 box.pack_start(label, False, False, padding)
230 class mEveMonUI(BaseUI):
232 def __init__(self, controller):
233 self.controller = controller
234 gtk.set_application_name("mEveMon")
236 # create the main window
237 self.win = hildon.Window()
238 self.win.connect("destroy", self.controller.quit)
240 progress_bar = hildon.hildon_banner_show_progress(self.win, None, "Loading overview...")
241 progress_bar.set_fraction(0.4)
244 menu = self.create_menu(self.win)
246 # Attach menu to the window
247 self.win.set_menu(menu)
249 character_win = CharacterSheetUI(self.controller)
251 # create the treeview --danny
252 self.char_model = models.CharacterListModel(self.controller)
253 treeview = gtk.TreeView(model = self.char_model)
254 treeview.set_grid_lines(gtk.TREE_VIEW_GRID_LINES_HORIZONTAL)
255 treeview.connect('row-activated', character_win.build_window)
256 treeview.set_model(self.char_model)
257 self.add_columns_to_treeview(treeview)
259 # add the treeview with scrollbar --danny
260 self.win.add_with_scrollbar(treeview)
263 progress_bar.set_fraction(1)
264 progress_bar.destroy()
266 def add_columns_to_treeview(self, treeview):
267 #Column 0 for the treeview
268 renderer = gtk.CellRendererPixbuf()
269 column = gtk.TreeViewColumn()
270 column.pack_start(renderer, True)
271 column.add_attribute(renderer, "pixbuf",
272 models.CharacterListModel.C_PORTRAIT)
273 treeview.append_column(column)
275 #Column 1 for the treeview
276 renderer = gtk.CellRendererText()
277 column = gtk.TreeViewColumn('Character Name', renderer,
278 text=models.CharacterListModel.C_NAME)
279 column.set_property("expand", True)
280 treeview.append_column(column)
282 def refresh_clicked(self, button):
283 progress_bar = hildon.hildon_banner_show_progress(self.win, None, "Loading characters...")
284 progress_bar.set_fraction(1)
285 self.char_model.get_characters()
286 progress_bar.destroy()
288 class CharacterSheetUI(BaseUI):
289 #time between live sp updates (in milliseconds)
290 UPDATE_INTERVAL = 1000
292 def __init__(self, controller):
293 self.controller = controller
296 self.skills_model = None
299 def build_window(self, treeview, path, view_column):
300 # TODO: this is a really long and ugly function, split it up somehow
302 self.win = hildon.Window()
304 progress_bar = hildon.hildon_banner_show_progress(self.win, None, "Loading character sheet...")
307 progress_bar.set_fraction(0.4)
310 # NOTE: we probably want a window-specific menu for this page, but the
311 # main appmenu works for now
312 menu = self.create_menu(self.win)
313 # Attach menu to the window
314 self.win.set_menu(menu)
316 model = treeview.get_model()
317 miter = model.get_iter(path)
319 # column 0 is the portrait, column 1 is name
320 char_name = model.get_value(miter, 1)
321 self.uid = model.get_value(miter, 2)
322 self.char_id = self.controller.char_name2id(char_name)
324 self.sheet = self.controller.get_char_sheet(self.uid, self.char_id)
326 self.win.set_title(char_name)
329 hbox = gtk.HBox(False, 0)
330 info_vbox = gtk.VBox(False, 0)
332 portrait = gtk.Image()
333 portrait.set_from_file(self.controller.get_portrait(char_name, 256))
336 hbox.pack_start(portrait, False, False, 10)
337 hbox.pack_start(info_vbox, False, False, 5)
339 vbox = gtk.VBox(False, 0)
341 vbox.pack_start(hbox, False, False, 0)
343 self.fill_info(info_vbox)
344 self.fill_stats(info_vbox)
346 separator = gtk.HSeparator()
347 vbox.pack_start(separator, False, False, 5)
351 self.add_label("<big>Skill in Training:</big>", vbox, align="normal")
353 self.display_skill_in_training(vbox)
355 separator = gtk.HSeparator()
356 vbox.pack_start(separator, False, False, 0)
359 self.add_label("<big>Skills:</big>", vbox, align="normal")
362 self.skills_model = models.CharacterSkillsModel(self.controller, self.char_id)
363 skills_treeview = gtk.TreeView(model=self.skills_model)
364 self.add_columns_to_skills_view(skills_treeview)
366 vbox.pack_start(skills_treeview, False, False, 0)
368 self.win.add_with_scrollbar(vbox)
371 progress_bar.set_fraction(1)
372 progress_bar.destroy()
374 # diablo doesnt have a glib module, but gobject module seems to have
375 # the same functions...
376 self.timer = gobject.timeout_add(self.UPDATE_INTERVAL, self.update_live_sp)
377 self.win.connect("destroy", self.back)
379 def back(self, widget):
380 gobject.source_remove(self.timer)
381 gtk.Window.destroy(self.win)
383 def display_skill_in_training(self, vbox):
384 skill = self.controller.get_skill_in_training(self.uid, self.char_id)
386 if skill.skillInTraining:
388 skilltree = self.controller.get_skill_tree()
390 # I'm assuming that we will always find a skill with the skill ID
391 for group in skilltree.skillGroups:
392 found_skill = group.skills.Get(skill.trainingTypeID, False)
394 skill_name = found_skill.typeName
397 self.add_label("%s <small>(Level %d)</small>" % (skill_name, skill.trainingToLevel),
398 vbox, align="normal")
399 self.add_label("<small>start time: %s\t\tend time: %s</small>"
400 %(time.ctime(skill.trainingStartTime),
401 time.ctime(skill.trainingEndTime)), vbox, align="normal")
403 progressbar = gtk.ProgressBar()
404 fraction_completed = (time.time() - skill.trainingStartTime) / \
405 (skill.trainingEndTime - skill.trainingStartTime)
407 progressbar.set_fraction(fraction_completed)
408 align = gtk.Alignment(0.5, 0.5, 0.5, 0)
409 vbox.pack_start(align, False, False, 5)
411 align.add(progressbar)
414 self.add_label("<small>No skills are currently being trained</small>",
415 vbox, align="normal")
419 def fill_info(self, box):
420 self.add_label("<big><big>%s</big></big>" % self.sheet.name, box)
421 self.add_label("<small>%s %s %s</small>" % (self.sheet.gender,
422 self.sheet.race, self.sheet.bloodLine), box)
423 self.add_label("", box, markup=False)
424 self.add_label("<small><b>Corp:</b> %s</small>" % self.sheet.corporationName, box)
425 self.add_label("<small><b>Balance:</b> %s ISK</small>" %
426 util.comma(self.sheet.balance), box)
428 self.live_sp_val = self.controller.get_sp(self.uid, self.char_id)
429 self.live_sp = self.add_label("<small><b>Total SP:</b> %s</small>" %
430 util.comma(int(self.live_sp_val)), box)
432 self.spps = self.controller.get_spps(self.uid, self.char_id)[0]
435 def fill_stats(self, box):
437 atr = self.sheet.attributes
439 self.add_label("<small><b>I: </b>%d <b>M: </b>%d <b>C: </b>%d " \
440 "<b>P: </b>%d <b>W: </b>%d</small>" % (atr.intelligence,
441 atr.memory, atr.charisma, atr.perception, atr.willpower), box)
444 def add_columns_to_skills_view(self, treeview):
445 #Column 0 for the treeview
446 renderer = gtk.CellRendererText()
447 column = gtk.TreeViewColumn('Skill Name', renderer,
448 markup=models.CharacterSkillsModel.C_NAME)
449 column.set_property("expand", True)
450 treeview.append_column(column)
452 #Column 1 for the treeview
453 column = gtk.TreeViewColumn('Rank', renderer,
454 markup=models.CharacterSkillsModel.C_RANK)
455 column.set_property("expand", True)
456 treeview.append_column(column)
459 column = gtk.TreeViewColumn('Points', renderer,
460 markup=models.CharacterSkillsModel.C_SKILLPOINTS)
461 column.set_property("expand", True)
462 treeview.append_column(column)
465 column = gtk.TreeViewColumn('Level', renderer,
466 markup=models.CharacterSkillsModel.C_LEVEL)
467 column.set_property("expand", True)
468 treeview.append_column(column)
471 def refresh_clicked(self, button):
472 progress_bar = hildon.hildon_banner_show_progress(self.win, None, "Loading overview...")
473 progress_bar.set_fraction(1)
474 self.skills_model.get_skills()
475 progress_bar.destroy()
478 def update_live_sp(self):
479 self.live_sp_val = self.live_sp_val + self.spps * (self.UPDATE_INTERVAL / 1000)
480 self.live_sp.set_label("<small><b>Total SP:</b> %s</small>" %
481 util.comma(int(self.live_sp_val)))
486 if __name__ == "__main__":