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")
65 acctsLabel = gtk.Label("Accounts:")
66 acctsLabel.set_justify(gtk.JUSTIFY_LEFT)
68 vbox.pack_start(acctsLabel, False, False, 1)
70 self.accounts_model = models.AccountsModel(self.controller)
72 accounts_treeview = gtk.TreeView(model = self.accounts_model)
73 self.add_columns_to_accounts(accounts_treeview)
74 vbox.pack_start(accounts_treeview, False, False, 1)
76 # all stock responses are negative, so we can use any positive value
77 new_button = dialog.add_button("New", RESPONSE_NEW)
78 #TODO: get edit button working
79 #edit_button = dialog.add_button("Edit", RESPONSE_EDIT)
80 delete_button = dialog.add_button("Delete", RESPONSE_DELETE)
81 ok_button = dialog.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
82 cancel_button = dialog.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
84 #TODO: for some reason the scrollbar shows up in the middle of the
86 #scrollbar = gtk.VScrollbar()
92 while(result != gtk.RESPONSE_CANCEL):
93 if result == RESPONSE_NEW:
94 self.new_account_clicked(window)
95 #elif result == RESPONSE_EDIT:
96 # # get the selected treeview item and pop up the account_box
97 # self.edit_account(accounts_treeview)
98 elif result == RESPONSE_DELETE:
99 # get the selected treeview item, and delete the gconf keys
100 self.delete_account(accounts_treeview)
101 elif result == gtk.RESPONSE_OK:
102 self.char_model.get_characters()
105 result = dialog.run()
111 def get_selected_item(self, treeview, column):
112 selection = treeview.get_selection()
113 model, miter = selection.get_selected()
115 value = model.get_value(miter, column)
119 def edit_account(self, treeview):
120 uid = self.get_selected_item(treeview, 0)
121 # pop up the account dialog
123 self.accounts_model.get_accounts()
125 def delete_account(self, treeview):
126 uid = self.get_selected_item(treeview, 0)
127 self.controller.settings.remove_account(uid)
129 self.accounts_model.get_accounts()
132 def add_columns_to_accounts(self, treeview):
133 #Column 0 for the treeview
134 renderer = gtk.CellRendererText()
135 column = gtk.TreeViewColumn('User ID', renderer,
136 text=models.AccountsModel.C_UID)
137 column.set_property("expand", True)
138 treeview.append_column(column)
140 #Column 2 (characters) for the treeview
141 column = gtk.TreeViewColumn('Characters', renderer,
142 markup=models.AccountsModel.C_CHARS)
143 column.set_property("expand", True)
144 treeview.append_column(column)
147 def new_account_clicked(self, window):
148 dialog = gtk.Dialog()
150 #get the vbox to pack all the settings into
153 dialog.set_transient_for(window)
154 dialog.set_title("New Account")
156 uidLabel = gtk.Label("User ID:")
157 uidLabel.set_justify(gtk.JUSTIFY_LEFT)
160 uidEntry = gtk.Entry()
161 uidEntry.set_property('is_focus', False)
165 apiLabel = gtk.Label("API key:")
166 apiLabel.set_justify(gtk.JUSTIFY_LEFT)
169 apiEntry = gtk.Entry()
170 apiEntry.set_property('is_focus', False)
174 ok_button = dialog.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
175 cancel_button = dialog.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
178 result = dialog.run()
180 valid_credentials = False
182 while not valid_credentials:
183 if result == gtk.RESPONSE_OK:
184 uid = uidEntry.get_text()
185 api_key = apiEntry.get_text()
188 validation.validate_uid(uid)
189 validation.validate_api_key(api_key)
190 except validation.ValidationError, e:
191 self.report_error(e.message)
192 result = dialog.run()
194 valid_credentials = True
195 self.controller.settings.add_account(uid, api_key)
196 self.accounts_model.get_accounts()
203 def report_error(self, error):
204 hildon.hildon_banner_show_information(self.win, '', error)
206 def about_clicked(self, button):
207 dialog = gtk.AboutDialog()
208 dialog.set_website(self.controller.about_website)
209 dialog.set_website_label(self.controller.about_website)
210 dialog.set_name(self.controller.about_name)
211 dialog.set_authors(self.controller.about_authors)
212 dialog.set_comments(self.controller.about_text)
213 dialog.set_version(self.controller.app_version)
217 def add_label(self, text, box, markup=True, align="left", padding=1):
218 label = gtk.Label(text)
220 label.set_use_markup(True)
222 label.set_alignment(0, 0.5)
224 box.pack_start(label, False, False, padding)
228 class mEveMonUI(BaseUI):
230 def __init__(self, controller):
231 self.controller = controller
232 gtk.set_application_name("mEveMon")
235 # create the main window
236 self.win = hildon.Window()
237 self.win.connect("destroy", self.controller.quit)
240 # wait notification start --danny
243 menu = self.create_menu(self.win)
245 # Attach menu to the window
246 self.win.set_menu(menu)
249 # create the treeview --danny
250 self.char_model = models.CharacterListModel(self.controller)
251 treeview = gtk.TreeView(model = self.char_model)
252 treeview.set_grid_lines(gtk.TREE_VIEW_GRID_LINES_HORIZONTAL)
253 treeview.connect('row-activated', self.do_charactersheet)
254 treeview.set_model(self.char_model)
255 self.add_columns_to_treeview(treeview)
257 # add the treeview with scrollbar --danny
258 self.win.add_with_scrollbar(treeview)
261 # wait notification end --danny
263 def add_columns_to_treeview(self, treeview):
264 #Column 0 for the treeview
265 renderer = gtk.CellRendererPixbuf()
266 column = gtk.TreeViewColumn()
267 column.pack_start(renderer, True)
268 column.add_attribute(renderer, "pixbuf",
269 models.CharacterListModel.C_PORTRAIT)
270 treeview.append_column(column)
272 #Column 1 for the treeview
273 renderer = gtk.CellRendererText()
274 column = gtk.TreeViewColumn('Character Name', renderer,
275 text=models.CharacterListModel.C_NAME)
276 column.set_property("expand", True)
277 treeview.append_column(column)
279 def refresh_clicked(self, button):
280 self.char_model.get_characters()
281 # wait notification end --danny
283 def do_charactersheet(self, treeview, path, view_column):
285 model = treeview.get_model()
286 miter = model.get_iter(path)
288 # column 0 is the portrait, column 1 is name
289 char_name = model.get_value(miter, 1)
290 uid = model.get_value(miter, 2)
293 CharacterSheetUI(self.controller, char_name, uid)
297 class CharacterSheetUI(BaseUI):
298 #time between live sp updates (in milliseconds)
299 UPDATE_INTERVAL = 1000
301 def __init__(self, controller, char_name, uid):
302 self.controller = controller
303 self.char_name = char_name
307 self.skills_model = None
311 def build_window(self):
312 # TODO: this is a really long and ugly function, split it up somehow
314 self.win = hildon.Window()
318 # wait notification start --danny
321 # NOTE: we probably want a window-specific menu for this page, but the
322 # main appmenu works for now
323 menu = self.create_menu(self.win)
324 # Attach menu to the window
325 self.win.set_menu(menu)
327 self.char_id = self.controller.char_name2id(self.char_name)
329 self.sheet = self.controller.get_char_sheet(self.uid, self.char_id)
331 self.win.set_title(self.char_name)
334 hbox = gtk.HBox(False, 0)
335 info_vbox = gtk.VBox(False, 0)
337 portrait = gtk.Image()
338 portrait.set_from_file(self.controller.get_portrait(self.char_name, 256))
341 hbox.pack_start(portrait, False, False, 10)
342 hbox.pack_start(info_vbox, False, False, 5)
344 vbox = gtk.VBox(False, 0)
346 vbox.pack_start(hbox, False, False, 0)
348 self.fill_info(info_vbox)
349 self.fill_stats(info_vbox)
351 separator = gtk.HSeparator()
352 vbox.pack_start(separator, False, False, 5)
356 self.add_label("<big>Skill in Training:</big>", vbox, align="normal")
358 self.display_skill_in_training(vbox)
360 separator = gtk.HSeparator()
361 vbox.pack_start(separator, False, False, 0)
364 self.add_label("<big>Skills:</big>", vbox, align="normal")
367 self.skills_model = models.CharacterSkillsModel(self.controller, self.char_id)
368 skills_treeview = gtk.TreeView(model=self.skills_model)
369 self.add_columns_to_skills_view(skills_treeview)
371 vbox.pack_start(skills_treeview, False, False, 0)
373 self.win.add_with_scrollbar(vbox)
376 # wait notification end --danny
378 # diablo doesnt have a glib module, but gobject module seems to have
379 # the same functions...
380 self.timer = gobject.timeout_add(self.UPDATE_INTERVAL, self.update_live_sp)
381 self.win.connect("destroy", self.back)
383 def back(self, widget):
384 gobject.source_remove(self.timer)
385 gtk.Window.destroy(self.win)
387 def display_skill_in_training(self, vbox):
388 skill = self.controller.get_skill_in_training(self.uid, self.char_id)
390 if skill.skillInTraining:
392 skilltree = self.controller.get_skill_tree()
394 # I'm assuming that we will always find a skill with the skill ID
395 for group in skilltree.skillGroups:
396 found_skill = group.skills.Get(skill.trainingTypeID, False)
398 skill_name = found_skill.typeName
401 self.add_label("%s <small>(Level %d)</small>" % (skill_name, skill.trainingToLevel),
402 vbox, align="normal")
403 self.add_label("<small>start time: %s\t\tend time: %s</small>"
404 %(time.ctime(skill.trainingStartTime),
405 time.ctime(skill.trainingEndTime)), vbox, align="normal")
407 progressbar = gtk.ProgressBar()
408 fraction_completed = (time.time() - skill.trainingStartTime) / \
409 (skill.trainingEndTime - skill.trainingStartTime)
411 progressbar.set_fraction(fraction_completed)
412 align = gtk.Alignment(0.5, 0.5, 0.5, 0)
413 vbox.pack_start(align, False, False, 5)
415 align.add(progressbar)
418 self.add_label("<small>No skills are currently being trained</small>",
419 vbox, align="normal")
423 def fill_info(self, box):
424 self.add_label("<big><big>%s</big></big>" % self.sheet.name, box)
425 self.add_label("<small>%s %s %s</small>" % (self.sheet.gender,
426 self.sheet.race, self.sheet.bloodLine), box)
427 self.add_label("", box, markup=False)
428 self.add_label("<small><b>Corp:</b> %s</small>" % self.sheet.corporationName, box)
429 self.add_label("<small><b>Balance:</b> %s ISK</small>" %
430 util.comma(self.sheet.balance), box)
432 self.live_sp_val = self.controller.get_sp(self.uid, self.char_id)
433 self.live_sp = self.add_label("<small><b>Total SP:</b> %s</small>" %
434 util.comma(int(self.live_sp_val)), box)
436 self.spps = self.controller.get_spps(self.uid, self.char_id)[0]
439 def fill_stats(self, box):
441 atr = self.sheet.attributes
443 self.add_label("<small><b>I: </b>%d <b>M: </b>%d <b>C: </b>%d " \
444 "<b>P: </b>%d <b>W: </b>%d</small>" % (atr.intelligence,
445 atr.memory, atr.charisma, atr.perception, atr.willpower), box)
448 def add_columns_to_skills_view(self, treeview):
449 #Column 0 for the treeview
450 renderer = gtk.CellRendererText()
451 column = gtk.TreeViewColumn('Skill Name', renderer,
452 markup=models.CharacterSkillsModel.C_NAME)
453 column.set_property("expand", True)
454 treeview.append_column(column)
456 #Column 1 for the treeview
457 column = gtk.TreeViewColumn('Rank', renderer,
458 markup=models.CharacterSkillsModel.C_RANK)
459 column.set_property("expand", True)
460 treeview.append_column(column)
463 column = gtk.TreeViewColumn('Points', renderer,
464 markup=models.CharacterSkillsModel.C_SKILLPOINTS)
465 column.set_property("expand", True)
466 treeview.append_column(column)
469 column = gtk.TreeViewColumn('Level', renderer,
470 markup=models.CharacterSkillsModel.C_LEVEL)
471 column.set_property("expand", True)
472 treeview.append_column(column)
475 def refresh_clicked(self, button):
476 self.skills_model.get_skills()
477 # wait notification end --danny
479 def update_live_sp(self):
480 self.live_sp_val = self.live_sp_val + self.spps * (self.UPDATE_INTERVAL / 1000)
481 self.live_sp.set_label("<small><b>Total SP:</b> %s</small>" %
482 util.comma(int(self.live_sp_val)))
487 if __name__ == "__main__":