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")
68 acctsLabel = gtk.Label("Accounts:")
69 acctsLabel.set_justify(gtk.JUSTIFY_LEFT)
71 vbox.pack_start(acctsLabel, False, False, 1)
73 self.accounts_model = models.AccountsModel(self.controller)
75 accounts_treeview = gtk.TreeView(model = self.accounts_model)
76 self.add_columns_to_accounts(accounts_treeview)
77 vbox.pack_start(accounts_treeview, False, False, 1)
79 # all stock responses are negative, so we can use any positive value
80 new_button = dialog.add_button("New", RESPONSE_NEW)
81 #TODO: get edit button working
82 #edit_button = dialog.add_button("Edit", RESPONSE_EDIT)
83 delete_button = dialog.add_button("Delete", RESPONSE_DELETE)
84 ok_button = dialog.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
85 cancel_button = dialog.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
87 #TODO: for some reason the scrollbar shows up in the middle of the
89 #scrollbar = gtk.VScrollbar()
95 while(result != gtk.RESPONSE_CANCEL):
96 if result == RESPONSE_NEW:
97 self.new_account_clicked(window)
98 #elif result == RESPONSE_EDIT:
99 # # get the selected treeview item and pop up the account_box
100 # self.edit_account(accounts_treeview)
101 elif result == RESPONSE_DELETE:
102 # get the selected treeview item, and delete the gconf keys
103 self.delete_account(accounts_treeview)
104 elif result == gtk.RESPONSE_OK:
105 self.char_model.get_characters()
108 result = dialog.run()
114 def get_selected_item(self, treeview, column):
115 selection = treeview.get_selection()
116 model, miter = selection.get_selected()
118 value = model.get_value(miter, column)
122 def edit_account(self, treeview):
123 uid = self.get_selected_item(treeview, 0)
124 # pop up the account dialog
126 self.accounts_model.get_accounts()
128 def delete_account(self, treeview):
129 uid = self.get_selected_item(treeview, 0)
130 self.controller.remove_account(uid)
132 self.accounts_model.get_accounts()
135 def add_columns_to_accounts(self, treeview):
136 #Column 0 for the treeview
137 renderer = gtk.CellRendererText()
138 column = gtk.TreeViewColumn('User ID', renderer,
139 text=models.AccountsModel.C_UID)
140 column.set_property("expand", True)
141 treeview.append_column(column)
143 #Column 2 (characters) for the treeview
144 column = gtk.TreeViewColumn('Characters', renderer,
145 markup=models.AccountsModel.C_CHARS)
146 column.set_property("expand", True)
147 treeview.append_column(column)
150 def new_account_clicked(self, window):
151 dialog = gtk.Dialog()
153 #get the vbox to pack all the settings into
156 dialog.set_transient_for(window)
157 dialog.set_title("New Account")
159 uidLabel = gtk.Label("User ID:")
160 uidLabel.set_justify(gtk.JUSTIFY_LEFT)
163 uidEntry = gtk.Entry()
164 uidEntry.set_property('is_focus', False)
168 apiLabel = gtk.Label("API key:")
169 apiLabel.set_justify(gtk.JUSTIFY_LEFT)
172 apiEntry = gtk.Entry()
173 apiEntry.set_property('is_focus', False)
177 ok_button = dialog.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
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.connect('row-activated', character_win.build_window)
255 treeview.set_model(self.char_model)
256 self.add_columns_to_treeview(treeview)
258 # add the treeview with scrollbar --danny
259 self.win.add_with_scrollbar(treeview)
262 progress_bar.set_fraction(1)
263 progress_bar.destroy()
265 def add_columns_to_treeview(self, treeview):
266 #Column 0 for the treeview
267 renderer = gtk.CellRendererPixbuf()
268 column = gtk.TreeViewColumn()
269 column.pack_start(renderer, True)
270 column.add_attribute(renderer, "pixbuf",
271 models.CharacterListModel.C_PORTRAIT)
272 treeview.append_column(column)
274 #Column 1 for the treeview
275 renderer = gtk.CellRendererText()
276 column = gtk.TreeViewColumn('Character Name', renderer,
277 text=models.CharacterListModel.C_NAME)
278 column.set_property("expand", True)
279 treeview.append_column(column)
281 def refresh_clicked(self, button):
282 progress_bar = hildon.hildon_banner_show_progress(self.win, None, "Loading characters...")
283 progress_bar.set_fraction(1)
284 self.char_model.get_characters()
285 progress_bar.destroy()
287 class CharacterSheetUI(BaseUI):
290 def __init__(self, controller):
291 self.controller = controller
294 self.skills_model = None
297 def build_window(self, treeview, path, view_column):
298 # TODO: this is a really long and ugly function, split it up somehow
300 self.win = hildon.Window()
303 progress_bar = hildon.hildon_banner_show_progress(self.win, None, "Loading character sheet...")
304 progress_bar.set_fraction(0.4)
307 # NOTE: we probably want a window-specific menu for this page, but the
308 # main appmenu works for now
309 menu = self.create_menu(self.win)
310 # Attach menu to the window
311 self.win.set_menu(menu)
313 model = treeview.get_model()
314 miter = model.get_iter(path)
316 # column 0 is the portrait, column 1 is name
317 char_name = model.get_value(miter, 1)
318 self.uid = model.get_value(miter, 2)
319 self.char_id = self.controller.char_name2id(char_name)
321 self.sheet = self.controller.get_char_sheet(self.uid, self.char_id)
323 self.win.set_title(char_name)
326 hbox = gtk.HBox(False, 0)
327 info_vbox = gtk.VBox(False, 0)
329 portrait = gtk.Image()
330 portrait.set_from_file(self.controller.get_portrait(char_name, 256))
333 hbox.pack_start(portrait, False, False, 10)
334 hbox.pack_start(info_vbox, False, False, 5)
336 vbox = gtk.VBox(False, 0)
338 vbox.pack_start(hbox, False, False, 0)
340 self.fill_info(info_vbox)
341 self.fill_stats(info_vbox)
343 separator = gtk.HSeparator()
344 vbox.pack_start(separator, False, False, 5)
348 self.add_label("<big>Skill in Training:</big>", vbox, align="normal")
350 self.display_skill_in_training(vbox)
352 separator = gtk.HSeparator()
353 vbox.pack_start(separator, False, False, 0)
356 self.add_label("<big>Skills:</big>", vbox, align="normal")
359 self.skills_model = models.CharacterSkillsModel(self.controller, self.char_id)
360 skills_treeview = gtk.TreeView(model = skills_model)
361 skills_treeview.set_model(self.skills_model)
362 self.add_columns_to_skills_view(skills_treeview)
364 vbox.pack_start(skills_treeview, False, False, 0)
366 self.win.add_with_scrollbar(vbox)
369 progress_bar.set_fraction(1)
370 progress_bar.destroy()
372 def display_skill_in_training(self, vbox):
373 skill = self.controller.get_skill_in_training(self.uid, self.char_id)
375 if skill.skillInTraining:
377 skilltree = self.controller.get_skill_tree()
379 # I'm assuming that we will always find a skill with the skill ID
380 for group in skilltree.skillGroups:
381 found_skill = group.skills.Get(skill.trainingTypeID, False)
383 skill_name = found_skill.typeName
386 self.add_label("%s <small>(Level %d)</small>" % (skill_name, skill.trainingToLevel),
387 vbox, align="normal")
388 self.add_label("<small>start time: %s\t\tend time: %s</small>"
389 %(time.ctime(skill.trainingStartTime),
390 time.ctime(skill.trainingEndTime)), vbox, align="normal")
392 progressbar = gtk.ProgressBar()
393 fraction_completed = (time.time() - skill.trainingStartTime) / \
394 (skill.trainingEndTime - skill.trainingStartTime)
396 progressbar.set_fraction(fraction_completed)
397 align = gtk.Alignment(0.5, 0.5, 0.5, 0)
398 vbox.pack_start(align, False, False, 5)
400 align.add(progressbar)
403 self.add_label("<small>No skills are currently being trained</small>",
404 vbox, align="normal")
408 def fill_info(self, box):
409 self.add_label("<big><big>%s</big></big>" % self.sheet.name, box)
410 self.add_label("<small>%s %s %s</small>" % (self.sheet.gender,
411 self.sheet.race, self.sheet.bloodLine), box)
412 self.add_label("", box, markup=False)
413 self.add_label("<small><b>Corp:</b> %s</small>" % self.sheet.corporationName, box)
414 self.add_label("<small><b>Balance:</b> %s ISK</small>" % self.sheet.balance, box)
416 self.live_sp_val = self.controller.get_sp(self.uid, self.char_id)
417 self.live_sp = self.add_label("<small><b>Total SP:</b> %s</small>" %
418 self.live_sp_val, box)
420 self.spps = self.controller.get_spps(self.uid, self.char_id)[0]
422 glib.timeout_add_seconds(self.UPDATE_INTERVAL, self.update_live_sp)
424 def fill_stats(self, box):
426 atr = self.sheet.attributes
428 self.add_label("<small><b>I: </b>%d <b>M: </b>%d <b>C: </b>%d " \
429 "<b>P: </b>%d <b>W: </b>%d</small>" % (atr.intelligence,
430 atr.memory, atr.charisma, atr.perception, atr.willpower), box)
433 def add_columns_to_skills_view(self, treeview):
434 #Column 0 for the treeview
435 renderer = gtk.CellRendererText()
436 column = gtk.TreeViewColumn('Skill Name', renderer,
437 markup=models.CharacterSkillsModel.C_NAME)
438 column.set_property("expand", True)
439 treeview.append_column(column)
441 #Column 1 for the treeview
442 column = gtk.TreeViewColumn('Rank', renderer,
443 markup=models.CharacterSkillsModel.C_RANK)
444 column.set_property("expand", True)
445 treeview.append_column(column)
448 column = gtk.TreeViewColumn('Points', renderer,
449 markup=models.CharacterSkillsModel.C_SKILLPOINTS)
450 column.set_property("expand", True)
451 treeview.append_column(column)
454 column = gtk.TreeViewColumn('Level', renderer,
455 markup=models.CharacterSkillsModel.C_LEVEL)
456 column.set_property("expand", True)
457 treeview.append_column(column)
460 def refresh_clicked(self, button):
461 progress_bar = hildon.hildon_banner_show_progress(self.win, None, "Loading overview...")
462 progress_bar.set_fraction(1)
463 self.skills_model.get_skills()
464 progress_bar.destroy()
467 def update_live_sp(self):
468 # we don't want to keep the timer running in the background
469 # when this callback returns False, the timer destorys itself
470 if not self.win.get_is_topmost():
473 self.live_sp_val = self.live_sp_val + self.spps * self.UPDATE_INTERVAL
474 self.live_sp.set_label("<small><b>Total SP:</b> %d</small>" %
480 if __name__ == "__main__":