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/>.
31 menu_items = ("Settings", "About", "Refresh")
33 def create_menu(self, window):
36 for command in self.menu_items:
38 button = gtk.MenuItem(command)
40 if command == "About":
41 button.connect("activate", self.about_clicked)
42 elif command == "Settings":
43 button.connect("activate", self.settings_clicked, window)
44 elif command == "Refresh":
45 button.connect("activate", self.refresh_clicked, window)
49 # Add entry to the view menu
56 def settings_clicked(self, button, window):
58 RESPONSE_NEW, RESPONSE_EDIT, RESPONSE_DELETE = range(3)
61 dialog.set_transient_for(window)
62 dialog.set_title("Settings")
66 acctsLabel = gtk.Label("Accounts:")
67 acctsLabel.set_justify(gtk.JUSTIFY_LEFT)
69 vbox.pack_start(acctsLabel, False, False, 1)
71 self.accounts_model = models.AccountsModel(self.controller)
73 accounts_treeview = gtk.TreeView(model = self.accounts_model)
74 self.add_columns_to_accounts(accounts_treeview)
75 vbox.pack_start(accounts_treeview, False, False, 1)
77 clear_button = gtk.Button("Clear Cache")
78 clear_button.connect("clicked", self.on_clear_cache_clicked)
79 vbox.pack_start(clear_button, False, False, 1)
81 # all stock responses are negative, so we can use any positive value
82 new_button = dialog.add_button("New", RESPONSE_NEW)
83 #TODO: get edit button working
84 #edit_button = dialog.add_button("Edit", RESPONSE_EDIT)
85 delete_button = dialog.add_button("Delete", RESPONSE_DELETE)
86 ok_button = dialog.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
87 cancel_button = dialog.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
89 #TODO: for some reason the scrollbar shows up in the middle of the
91 #scrollbar = gtk.VScrollbar()
97 while(result != gtk.RESPONSE_CANCEL):
98 if result == RESPONSE_NEW:
99 self.new_account_clicked(window)
100 #elif result == RESPONSE_EDIT:
101 # # get the selected treeview item and pop up the account_box
102 # self.edit_account(accounts_treeview)
103 elif result == RESPONSE_DELETE:
104 # get the selected treeview item, and delete the gconf keys
105 self.delete_account(accounts_treeview)
106 elif result == gtk.RESPONSE_OK:
107 self.char_model.get_characters()
110 result = dialog.run()
114 def on_clear_cache_clicked(self, button):
115 self.controller.clear_cache()
118 def get_selected_item(self, treeview, column):
119 selection = treeview.get_selection()
120 model, miter = selection.get_selected()
122 value = model.get_value(miter, column)
126 def edit_account(self, treeview):
127 uid = self.get_selected_item(treeview, 0)
128 # pop up the account dialog
130 self.accounts_model.get_accounts()
132 def delete_account(self, treeview):
133 uid = self.get_selected_item(treeview, 0)
134 self.controller.settings.remove_account(uid)
136 self.accounts_model.get_accounts()
139 def add_columns_to_accounts(self, treeview):
140 #Column 0 for the treeview
141 renderer = gtk.CellRendererText()
142 column = gtk.TreeViewColumn('User ID', renderer,
143 text=models.AccountsModel.C_UID)
144 column.set_property("expand", True)
145 treeview.append_column(column)
147 #Column 2 (characters) for the treeview
148 column = gtk.TreeViewColumn('Characters', renderer,
149 markup=models.AccountsModel.C_CHARS)
150 column.set_property("expand", True)
151 treeview.append_column(column)
154 def new_account_clicked(self, window):
155 dialog = gtk.Dialog()
157 #get the vbox to pack all the settings into
160 dialog.set_transient_for(window)
161 dialog.set_title("New Account")
163 uidLabel = gtk.Label("User ID:")
164 uidLabel.set_justify(gtk.JUSTIFY_LEFT)
167 uidEntry = gtk.Entry()
168 uidEntry.set_property('is_focus', False)
172 apiLabel = gtk.Label("API key:")
173 apiLabel.set_justify(gtk.JUSTIFY_LEFT)
176 apiEntry = gtk.Entry()
177 apiEntry.set_property('is_focus', False)
181 ok_button = dialog.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
182 cancel_button = dialog.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
185 result = dialog.run()
187 valid_credentials = False
189 while not valid_credentials:
190 if result == gtk.RESPONSE_OK:
191 uid = uidEntry.get_text()
192 api_key = apiEntry.get_text()
195 validation.validate_uid(uid)
196 validation.validate_api_key(api_key)
197 except validation.ValidationError, e:
198 self.report_error(e.message)
199 result = dialog.run()
201 valid_credentials = True
202 self.controller.settings.add_account(uid, api_key)
203 self.accounts_model.get_accounts()
210 def report_error(self, error):
211 hildon.hildon_banner_show_information(self.win, '', error)
213 def about_clicked(self, button):
214 dialog = gtk.AboutDialog()
215 dialog.set_website(constants.ABOUT_WEBSITE)
216 dialog.set_website_label(constants.ABOUT_WEBSITE)
217 dialog.set_name(constants.ABOUT_NAME)
218 dialog.set_authors(constants.ABOUT_AUTHORS)
219 dialog.set_comments(constants.ABOUT_TEXT)
220 dialog.set_version(constants.APP_VERSION)
224 def add_label(self, text, box, markup=True, align="left", padding=1):
225 label = gtk.Label(text)
227 label.set_use_markup(True)
229 label.set_alignment(0, 0.5)
231 box.pack_start(label, False, False, padding)
235 class mEveMonUI(BaseUI):
237 def __init__(self, controller):
238 self.controller = controller
239 gtk.set_application_name("mEveMon")
242 # create the main window
243 self.win = hildon.Window()
244 self.win.connect("destroy", self.controller.quit)
247 # wait notification start --danny
250 menu = self.create_menu(self.win)
252 # Attach menu to the window
253 self.win.set_menu(menu)
256 # create the treeview --danny
257 self.char_model = models.CharacterListModel(self.controller)
258 treeview = gtk.TreeView(model = self.char_model)
259 treeview.set_grid_lines(gtk.TREE_VIEW_GRID_LINES_HORIZONTAL)
260 treeview.connect('row-activated', self.do_charactersheet)
261 treeview.set_model(self.char_model)
262 self.add_columns_to_treeview(treeview)
264 # add the treeview with scrollbar --danny
265 self.win.add_with_scrollbar(treeview)
268 # wait notification end --danny
270 def add_columns_to_treeview(self, treeview):
271 #Column 0 for the treeview
272 renderer = gtk.CellRendererPixbuf()
273 column = gtk.TreeViewColumn()
274 column.pack_start(renderer, True)
275 column.add_attribute(renderer, "pixbuf",
276 models.CharacterListModel.C_PORTRAIT)
277 treeview.append_column(column)
279 #Column 1 for the treeview
280 renderer = gtk.CellRendererText()
281 column = gtk.TreeViewColumn('Character Name', renderer,
282 text=models.CharacterListModel.C_NAME)
283 column.set_property("expand", True)
284 treeview.append_column(column)
286 def refresh_clicked(self, button):
287 self.char_model.get_characters()
288 # wait notification end --danny
290 def do_charactersheet(self, treeview, path, view_column):
292 model = treeview.get_model()
293 miter = model.get_iter(path)
295 # column 0 is the portrait, column 1 is name
296 char_name = model.get_value(miter, 1)
297 uid = model.get_value(miter, 2)
300 CharacterSheetUI(self.controller, char_name, uid)
304 class CharacterSheetUI(BaseUI):
305 #time between live sp updates (in milliseconds)
306 UPDATE_INTERVAL = 1000
308 def __init__(self, controller, char_name, uid):
309 self.controller = controller
310 self.char_name = char_name
314 self.skills_model = None
318 def build_window(self):
319 # TODO: this is a really long and ugly function, split it up somehow
321 self.win = hildon.Window()
325 # wait notification start --danny
328 # NOTE: we probably want a window-specific menu for this page, but the
329 # main appmenu works for now
330 menu = self.create_menu(self.win)
331 # Attach menu to the window
332 self.win.set_menu(menu)
334 self.char_id = self.controller.char_name2id(self.char_name)
336 self.sheet = self.controller.get_char_sheet(self.uid, self.char_id)
338 self.win.set_title(self.char_name)
341 hbox = gtk.HBox(False, 0)
342 info_vbox = gtk.VBox(False, 0)
344 portrait = gtk.Image()
345 portrait.set_from_file(self.controller.get_portrait(self.char_name, 256))
348 hbox.pack_start(portrait, False, False, 10)
349 hbox.pack_start(info_vbox, False, False, 5)
351 vbox = gtk.VBox(False, 0)
353 vbox.pack_start(hbox, False, False, 0)
355 self.fill_info(info_vbox)
356 self.fill_stats(info_vbox)
358 separator = gtk.HSeparator()
359 vbox.pack_start(separator, False, False, 5)
363 self.add_label("<big>Skill in Training:</big>", vbox, align="normal")
365 self.display_skill_in_training(vbox)
367 separator = gtk.HSeparator()
368 vbox.pack_start(separator, False, False, 0)
371 self.add_label("<big>Skills:</big>", vbox, align="normal")
374 self.skills_model = models.CharacterSkillsModel(self.controller, self.char_id)
375 skills_treeview = gtk.TreeView(model=self.skills_model)
376 self.add_columns_to_skills_view(skills_treeview)
378 vbox.pack_start(skills_treeview, False, False, 0)
380 self.win.add_with_scrollbar(vbox)
383 # wait notification end --danny
385 # diablo doesnt have a glib module, but gobject module seems to have
386 # the same functions...
387 self.timer = gobject.timeout_add(self.UPDATE_INTERVAL, self.update_live_sp)
388 self.win.connect("destroy", self.back)
390 def back(self, widget):
391 gobject.source_remove(self.timer)
392 gtk.Window.destroy(self.win)
394 def display_skill_in_training(self, vbox):
395 skill = self.controller.get_skill_in_training(self.uid, self.char_id)
397 if skill.skillInTraining:
399 skilltree = self.controller.get_skill_tree()
401 # I'm assuming that we will always find a skill with the skill ID
402 for group in skilltree.skillGroups:
403 found_skill = group.skills.Get(skill.trainingTypeID, False)
405 skill_name = found_skill.typeName
408 self.add_label("%s <small>(Level %d)</small>" % (skill_name, skill.trainingToLevel),
409 vbox, align="normal")
410 self.add_label("<small>start time: %s\t\tend time: %s</small>"
411 %(time.ctime(skill.trainingStartTime),
412 time.ctime(skill.trainingEndTime)), vbox, align="normal")
414 progressbar = gtk.ProgressBar()
415 fraction_completed = (time.time() - skill.trainingStartTime) / \
416 (skill.trainingEndTime - skill.trainingStartTime)
418 progressbar.set_fraction(fraction_completed)
419 align = gtk.Alignment(0.5, 0.5, 0.5, 0)
420 vbox.pack_start(align, False, False, 5)
422 align.add(progressbar)
425 self.add_label("<small>No skills are currently being trained</small>",
426 vbox, align="normal")
430 def fill_info(self, box):
431 self.add_label("<big><big>%s</big></big>" % self.sheet.name, box)
432 self.add_label("<small>%s %s %s</small>" % (self.sheet.gender,
433 self.sheet.race, self.sheet.bloodLine), box)
434 self.add_label("", box, markup=False)
435 self.add_label("<small><b>Corp:</b> %s</small>" % self.sheet.corporationName, box)
436 self.add_label("<small><b>Balance:</b> %s ISK</small>" %
437 util.comma(self.sheet.balance), box)
439 self.live_sp_val = self.controller.get_sp(self.uid, self.char_id)
440 self.live_sp = self.add_label("<small><b>Total SP:</b> %s</small>" %
441 util.comma(int(self.live_sp_val)), box)
443 self.spps = self.controller.get_spps(self.uid, self.char_id)[0]
446 def fill_stats(self, box):
448 atr = self.sheet.attributes
450 self.add_label("<small><b>I: </b>%d <b>M: </b>%d <b>C: </b>%d " \
451 "<b>P: </b>%d <b>W: </b>%d</small>" % (atr.intelligence,
452 atr.memory, atr.charisma, atr.perception, atr.willpower), box)
455 def add_columns_to_skills_view(self, treeview):
456 #Column 0 for the treeview
457 renderer = gtk.CellRendererText()
458 column = gtk.TreeViewColumn('Skill Name', renderer,
459 markup=models.CharacterSkillsModel.C_NAME)
460 column.set_property("expand", True)
461 treeview.append_column(column)
463 #Column 1 for the treeview
464 column = gtk.TreeViewColumn('Rank', renderer,
465 markup=models.CharacterSkillsModel.C_RANK)
466 column.set_property("expand", True)
467 treeview.append_column(column)
470 column = gtk.TreeViewColumn('Points', renderer,
471 markup=models.CharacterSkillsModel.C_SKILLPOINTS)
472 column.set_property("expand", True)
473 treeview.append_column(column)
476 column = gtk.TreeViewColumn('Level', renderer,
477 markup=models.CharacterSkillsModel.C_LEVEL)
478 column.set_property("expand", True)
479 treeview.append_column(column)
482 def refresh_clicked(self, button):
483 self.skills_model.get_skills()
484 # wait notification end --danny
486 def update_live_sp(self):
487 self.live_sp_val = self.live_sp_val + self.spps * (self.UPDATE_INTERVAL / 1000)
488 self.live_sp.set_label("<small><b>Total SP:</b> %s</small>" %
489 util.comma(int(self.live_sp_val)))
494 if __name__ == "__main__":