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()
302 progress_bar = hildon.hildon_banner_show_progress(self.win, None, "Loading character sheet...")
305 progress_bar.set_fraction(0.4)
308 # NOTE: we probably want a window-specific menu for this page, but the
309 # main appmenu works for now
310 menu = self.create_menu(self.win)
311 # Attach menu to the window
312 self.win.set_menu(menu)
314 model = treeview.get_model()
315 miter = model.get_iter(path)
317 # column 0 is the portrait, column 1 is name
318 char_name = model.get_value(miter, 1)
319 self.uid = model.get_value(miter, 2)
320 self.char_id = self.controller.char_name2id(char_name)
322 self.sheet = self.controller.get_char_sheet(self.uid, self.char_id)
324 self.win.set_title(char_name)
327 hbox = gtk.HBox(False, 0)
328 info_vbox = gtk.VBox(False, 0)
330 portrait = gtk.Image()
331 portrait.set_from_file(self.controller.get_portrait(char_name, 256))
334 hbox.pack_start(portrait, False, False, 10)
335 hbox.pack_start(info_vbox, False, False, 5)
337 vbox = gtk.VBox(False, 0)
339 vbox.pack_start(hbox, False, False, 0)
341 self.fill_info(info_vbox)
342 self.fill_stats(info_vbox)
344 separator = gtk.HSeparator()
345 vbox.pack_start(separator, False, False, 5)
349 self.add_label("<big>Skill in Training:</big>", vbox, align="normal")
351 self.display_skill_in_training(vbox)
353 separator = gtk.HSeparator()
354 vbox.pack_start(separator, False, False, 0)
357 self.add_label("<big>Skills:</big>", vbox, align="normal")
360 self.skills_model = models.CharacterSkillsModel(self.controller, self.char_id)
361 skills_treeview = gtk.TreeView(model = skills_model)
362 skills_treeview.set_model(self.skills_model)
363 self.add_columns_to_skills_view(skills_treeview)
365 vbox.pack_start(skills_treeview, False, False, 0)
367 self.win.add_with_scrollbar(vbox)
370 progress_bar.set_fraction(1)
371 progress_bar.destroy()
373 def display_skill_in_training(self, vbox):
374 skill = self.controller.get_skill_in_training(self.uid, self.char_id)
376 if skill.skillInTraining:
378 skilltree = self.controller.get_skill_tree()
380 # I'm assuming that we will always find a skill with the skill ID
381 for group in skilltree.skillGroups:
382 found_skill = group.skills.Get(skill.trainingTypeID, False)
384 skill_name = found_skill.typeName
387 self.add_label("%s <small>(Level %d)</small>" % (skill_name, skill.trainingToLevel),
388 vbox, align="normal")
389 self.add_label("<small>start time: %s\t\tend time: %s</small>"
390 %(time.ctime(skill.trainingStartTime),
391 time.ctime(skill.trainingEndTime)), vbox, align="normal")
393 progressbar = gtk.ProgressBar()
394 fraction_completed = (time.time() - skill.trainingStartTime) / \
395 (skill.trainingEndTime - skill.trainingStartTime)
397 progressbar.set_fraction(fraction_completed)
398 align = gtk.Alignment(0.5, 0.5, 0.5, 0)
399 vbox.pack_start(align, False, False, 5)
401 align.add(progressbar)
404 self.add_label("<small>No skills are currently being trained</small>",
405 vbox, align="normal")
409 def fill_info(self, box):
410 self.add_label("<big><big>%s</big></big>" % self.sheet.name, box)
411 self.add_label("<small>%s %s %s</small>" % (self.sheet.gender,
412 self.sheet.race, self.sheet.bloodLine), box)
413 self.add_label("", box, markup=False)
414 self.add_label("<small><b>Corp:</b> %s</small>" % self.sheet.corporationName, box)
415 self.add_label("<small><b>Balance:</b> %s ISK</small>" % self.sheet.balance, box)
417 self.live_sp_val = self.controller.get_sp(self.uid, self.char_id)
418 self.live_sp = self.add_label("<small><b>Total SP:</b> %d</small>" %
419 self.live_sp_val, box)
421 self.spps = self.controller.get_spps(self.uid, self.char_id)[0]
423 glib.timeout_add_seconds(self.UPDATE_INTERVAL, self.update_live_sp)
425 def fill_stats(self, box):
427 atr = self.sheet.attributes
429 self.add_label("<small><b>I: </b>%d <b>M: </b>%d <b>C: </b>%d " \
430 "<b>P: </b>%d <b>W: </b>%d</small>" % (atr.intelligence,
431 atr.memory, atr.charisma, atr.perception, atr.willpower), box)
434 def add_columns_to_skills_view(self, treeview):
435 #Column 0 for the treeview
436 renderer = gtk.CellRendererText()
437 column = gtk.TreeViewColumn('Skill Name', renderer,
438 markup=models.CharacterSkillsModel.C_NAME)
439 column.set_property("expand", True)
440 treeview.append_column(column)
442 #Column 1 for the treeview
443 column = gtk.TreeViewColumn('Rank', renderer,
444 markup=models.CharacterSkillsModel.C_RANK)
445 column.set_property("expand", True)
446 treeview.append_column(column)
449 column = gtk.TreeViewColumn('Points', renderer,
450 markup=models.CharacterSkillsModel.C_SKILLPOINTS)
451 column.set_property("expand", True)
452 treeview.append_column(column)
455 column = gtk.TreeViewColumn('Level', renderer,
456 markup=models.CharacterSkillsModel.C_LEVEL)
457 column.set_property("expand", True)
458 treeview.append_column(column)
461 def refresh_clicked(self, button):
462 progress_bar = hildon.hildon_banner_show_progress(self.win, None, "Loading overview...")
463 progress_bar.set_fraction(1)
464 self.skills_model.get_skills()
465 progress_bar.destroy()
468 def update_live_sp(self):
469 # we don't want to keep the timer running in the background
470 # when this callback returns False, the timer destorys itself
472 # TODO: figure out why this doesn't work on the real device
474 #if not self.win.get_is_topmost():
477 self.live_sp_val = self.live_sp_val + self.spps * self.UPDATE_INTERVAL
478 self.live_sp.set_label("<small><b>Total SP:</b> %d</small>" %
484 if __name__ == "__main__":