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/>.
19 # DIABLO UI: Heavily based on Ry's Fremantle Python code. --danny
31 menu_items = ("Settings", "About", "Refresh")
33 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()
93 while(result != gtk.RESPONSE_CANCEL):
94 if result == RESPONSE_NEW:
95 self.new_account_clicked(window)
96 elif result == RESPONSE_EDIT:
97 # get the selected treeview item and pop up the account_box
98 self.edit_account(accounts_treeview)
99 elif result == RESPONSE_DELETE:
100 # get the selected treeview item, and delete the gconf keys
101 self.delete_account(accounts_treeview)
102 elif result == gtk.RESPONSE_OK:
103 self.char_model.get_characters()
106 result = dialog.run()
112 def get_selected_item(self, treeview, column):
113 selection = treeview.get_selection()
114 model, miter = selection.get_selected()
116 value = model.get_value(miter, column)
120 def edit_account(self, treeview):
121 uid = self.get_selected_item(treeview, 0)
122 # pop up the account dialog
124 self.accounts_model.get_accounts()
126 def delete_account(self, treeview):
127 uid = self.get_selected_item(treeview, 0)
128 self.controller.remove_account(uid)
130 self.accounts_model.get_accounts()
133 def add_columns_to_accounts(self, treeview):
134 #Column 0 for the treeview
135 renderer = gtk.CellRendererText()
136 column = gtk.TreeViewColumn('Account ID', renderer, text=0)
137 column.set_property("expand", True)
138 treeview.append_column(column)
139 #Column 2 (characters) for the treeview
140 column = gtk.TreeViewColumn('Characters', renderer,
141 markup=models.AccountsModel.C_CHARS)
142 column.set_property("expand", True)
143 treeview.append_column(column)
146 def new_account_clicked(self, window):
147 dialog = gtk.Dialog()
149 #get the vbox to pack all the settings into
152 dialog.set_transient_for(window)
153 dialog.set_title("Settings")
155 uidLabel = gtk.Label("User ID:")
156 uidLabel.set_justify(gtk.JUSTIFY_LEFT)
159 uidEntry = gtk.Entry()
160 uidEntry.set_property('is_focus', False)
164 apiLabel = gtk.Label("API key:")
165 apiLabel.set_justify(gtk.JUSTIFY_LEFT)
168 apiEntry = gtk.Entry()
169 apiEntry.set_property('is_focus', False)
173 ok_button = dialog.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
176 result = dialog.run()
178 if result == gtk.RESPONSE_OK:
179 self.controller.add_account(uidEntry.get_text(), apiEntry.get_text())
180 self.accounts_model.get_accounts()
186 def about_clicked(self, button):
187 dialog = gtk.AboutDialog()
188 dialog.set_website(self.controller.about_website)
189 dialog.set_website_label(self.controller.about_website)
190 dialog.set_name(self.controller.about_name)
191 dialog.set_authors(self.controller.about_authors)
192 dialog.set_comments(self.controller.about_text)
193 dialog.set_version(self.controller.app_version)
197 def add_label(self, text, box, markup=True, align="left", padding=1):
198 label = gtk.Label(text)
200 label.set_use_markup(True)
202 label.set_alignment(0, 0.5)
203 box.pack_start(label, False, False, padding)
205 class mEveMonUI(BaseUI):
207 def __init__(self, controller):
208 self.controller = controller
209 gtk.set_application_name("mEveMon")
211 # create the main window
212 win = hildon.Window()
213 win.connect("destroy", self.controller.quit)
215 progress_bar = hildon.hildon_banner_show_progress(win, None, "Loading overview...")
216 progress_bar.set_fraction(0.4)
219 menu = self.create_menu(win)
221 # Attach menu to the window
224 character_win = CharacterSheetUI(self.controller)
226 # create the treeview --danny
227 self.char_model = models.CharacterListModel(self.controller)
228 treeview = gtk.TreeView(model = self.char_model)
229 treeview.connect('row-activated', character_win.build_window)
230 treeview.set_model(self.char_model)
231 self.add_columns_to_treeview(treeview)
233 # add the treeview with scrollbar --danny
234 win.add_with_scrollbar(treeview)
237 progress_bar.set_fraction(1)
238 progress_bar.destroy()
240 def add_columns_to_treeview(self, treeview):
241 #Column 0 for the treeview
242 renderer = gtk.CellRendererPixbuf()
243 column = gtk.TreeViewColumn()
244 column.pack_start(renderer, True)
245 column.add_attribute(renderer, "pixbuf", 0)
246 treeview.append_column(column)
248 #Column 1 for the treeview
249 renderer = gtk.CellRendererText()
250 column = gtk.TreeViewColumn('Character Name', renderer, text=1)
251 column.set_property("expand", True)
252 treeview.append_column(column)
254 def refresh_clicked(self, button, window):
255 progress_bar = hildon.hildon_banner_show_progress(win, None, "Loading characters...")
256 progress_bar.set_fraction(1)
257 self.char_model.get_characters()
258 progress_bar.destroy()
260 class CharacterSheetUI(BaseUI):
262 def __init__(self, controller):
263 self.controller = controller
266 self.skills_model = None
268 def build_window(self, treeview, path, view_column):
269 # TODO: this is a really long and ugly function, split it up somehow
271 win = hildon.Window()
274 progress_bar = hildon.hildon_banner_show_progress(win, None, "Loading character sheet...")
275 progress_bar.set_fraction(0.4)
278 # NOTE: we probably want a window-specific menu for this page, but the
279 # main appmenu works for now
280 menu = self.create_menu(win)
281 # Attach menu to the window
284 model = treeview.get_model()
285 miter = model.get_iter(path)
287 # column 0 is the portrait, column 1 is name
288 char_name = model.get_value(miter, 1)
289 uid = model.get_value(miter, 2)
290 self.char_id = self.controller.char_name2id(char_name)
292 self.sheet = self.controller.get_char_sheet(uid, self.char_id)
294 win.set_title(char_name)
296 hbox = gtk.HBox(False, 0)
297 info_vbox = gtk.VBox(False, 1)
299 portrait = gtk.Image()
300 portrait.set_from_file(self.controller.get_portrait(char_name, 256))
303 hbox.pack_start(portrait, False, False, 10)
304 hbox.pack_start(info_vbox, False, False, 5)
306 vbox = gtk.VBox(False, 0)
308 vbox.pack_start(hbox, False, False, 0)
311 self.fill_info(info_vbox)
312 self.fill_stats(info_vbox)
314 separator = gtk.HSeparator()
315 vbox.pack_start(separator, False, False, 5)
319 self.add_label("<big>Skill in Training:</big>", vbox, align="normal")
320 skill = self.controller.get_skill_in_training(uid, self.char_id)
322 if skill.skillInTraining:
324 skilltree = self.controller.get_skill_tree()
326 # I'm assuming that we will always find a skill with the skill ID
327 for group in skilltree.skillGroups:
328 found_skill = group.skills.Get(skill.trainingTypeID, False)
330 skill_name = found_skill.typeName
333 self.add_label("%s <small>(Level %d)</small>" % (skill_name, skill.trainingToLevel),
334 vbox, align="normal")
335 self.add_label("<small>start time: %s\t\tend time: %s</small>" %(time.ctime(skill.trainingStartTime),
336 time.ctime(skill.trainingEndTime)), vbox, align="normal")
338 progressbar = gtk.ProgressBar()
339 fraction_completed = (time.time() - skill.trainingStartTime) / \
340 (skill.trainingEndTime - skill.trainingStartTime)
342 progressbar.set_fraction(fraction_completed)
343 align = gtk.Alignment(0.5, 0.5, 0.5, 0)
344 vbox.pack_start(align, False, False, 5)
346 align.add(progressbar)
350 self.add_label("<small>No skills are currently being trained</small>", vbox, align="normal")
352 separator = gtk.HSeparator()
353 vbox.pack_start(separator, False, False, 0)
356 self.add_label("<big>Skills:</big>", vbox, align="normal")
359 skills_model = models.CharacterSkillsModel(self.controller, self.char_id)
360 skills_treeview = gtk.TreeView(model = skills_model)
361 skills_treeview.set_model(skills_model)
362 self.add_columns_to_skills_view(skills_treeview)
364 vbox.pack_start(skills_treeview, False, False, 0)
366 win.add_with_scrollbar(vbox)
369 progress_bar.set_fraction(1)
370 progress_bar.destroy()
372 def fill_info(self, box):
373 self.add_label("<big><big>%s</big></big>" % self.sheet.name, box)
374 self.add_label("<small>%s %s %s</small>" % (self.sheet.gender, self.sheet.race, self.sheet.bloodLine), box)
375 self.add_label("", box, markup=False)
376 self.add_label("<small><b>Corp:</b> %s</small>" % self.sheet.corporationName, box)
377 self.add_label("<small><b>Balance:</b> %s ISK</small>" % self.sheet.balance, box)
379 def fill_stats(self, box):
381 atr = self.sheet.attributes
383 self.add_label("<small><b>I: </b>%d <b>M: </b>%d <b>C: </b>%d " \
384 "<b>P: </b>%d <b>W: </b>%d</small>" % (atr.intelligence,
385 atr.memory, atr.charisma, atr.perception, atr.willpower), box)
388 def add_columns_to_skills_view(self, treeview):
389 #Column 0 for the treeview
390 renderer = gtk.CellRendererText()
391 column = gtk.TreeViewColumn('Skill Name', renderer, markup=0)
392 column.set_property("expand", True)
393 treeview.append_column(column)
395 #Column 1 for the treeview
396 column = gtk.TreeViewColumn('Rank', renderer, markup=1)
397 column.set_property("expand", True)
398 treeview.append_column(column)
401 renderer = gtk.CellRendererText()
402 renderer = gtk.CellRendererText()
403 column = gtk.TreeViewColumn('Points', renderer, markup=2)
404 column.set_property("expand", True)
405 treeview.append_column(column)
408 column = gtk.TreeViewColumn('Level', renderer, markup=3)
409 column.set_property("expand", True)
410 treeview.append_column(column)
412 def refresh_clicked(self, button, window):
413 progress_bar = hildon.hildon_banner_show_progress(win, None, "Loading overview...")
414 progress_bar.set_fraction(1)
415 self.skills_model.get_skills()
416 progress_bar.destroy()
418 if __name__ == "__main__":