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 about_name = 'mEveMon'
32 about_text = ('Mobile character monitor for EVE Online')
33 about_authors = ['Ryan Campbell', 'Danny Campbell']
34 about_website = 'http://mevemon.garage.maemo.org'
37 menu_items = ("Settings", "About", "Refresh")
39 def create_menu(self, window):
41 for command in self.menu_items:
43 button = gtk.MenuItem(command)
45 if command == "About":
46 button.connect("activate", self.about_clicked)
47 elif command == "Settings":
48 button.connect("activate", self.settings_clicked, window)
49 elif command == "Refresh":
50 button.connect("activate", self.refresh_clicked, window)
54 # Add entry to the view menu
61 def settings_clicked(self, button, window):
63 RESPONSE_NEW, RESPONSE_EDIT, RESPONSE_DELETE = range(3)
66 dialog.set_transient_for(window)
67 dialog.set_title("Settings")
71 acctsLabel = gtk.Label("Accounts:")
72 acctsLabel.set_justify(gtk.JUSTIFY_LEFT)
74 vbox.pack_start(acctsLabel, False, False, 1)
76 self.accounts_model = models.AccountsModel(self.controller)
78 accounts_treeview = gtk.TreeView(model = self.accounts_model)
79 self.add_columns_to_accounts(accounts_treeview)
80 vbox.pack_start(accounts_treeview, False, False, 1)
82 # all stock responses are negative, so we can use any positive value
83 new_button = dialog.add_button("New", RESPONSE_NEW)
84 #TODO: get edit button working
85 #edit_button = dialog.add_button("Edit", RESPONSE_EDIT)
86 delete_button = dialog.add_button("Delete", RESPONSE_DELETE)
87 ok_button = dialog.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
88 cancel_button = dialog.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
90 #TODO: for some reason the scrollbar shows up in the middle of the
92 #scrollbar = gtk.VScrollbar()
99 while(result != gtk.RESPONSE_CANCEL):
100 if result == RESPONSE_NEW:
101 self.new_account_clicked(window)
102 elif result == RESPONSE_EDIT:
103 # get the selected treeview item and pop up the account_box
104 self.edit_account(accounts_treeview)
105 elif result == RESPONSE_DELETE:
106 # get the selected treeview item, and delete the gconf keys
107 self.delete_account(accounts_treeview)
108 elif result == gtk.RESPONSE_OK:
109 self.char_model.get_characters()
112 result = dialog.run()
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.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('Account ID', renderer, text=0)
143 column.set_property("expand", True)
144 treeview.append_column(column)
145 #Column 2 (characters) for the treeview
146 column = gtk.TreeViewColumn('Characters', renderer,
147 markup=models.AccountsModel.C_CHARS)
148 column.set_property("expand", True)
149 treeview.append_column(column)
152 def new_account_clicked(self, window):
153 dialog = gtk.Dialog()
155 #get the vbox to pack all the settings into
158 dialog.set_transient_for(window)
159 dialog.set_title("Settings")
161 uidLabel = gtk.Label("User ID:")
162 uidLabel.set_justify(gtk.JUSTIFY_LEFT)
165 uidEntry = gtk.Entry()
166 uidEntry.set_property('is_focus', False)
170 apiLabel = gtk.Label("API key:")
171 apiLabel.set_justify(gtk.JUSTIFY_LEFT)
174 apiEntry = gtk.Entry()
175 apiEntry.set_property('is_focus', False)
179 ok_button = dialog.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
182 result = dialog.run()
184 if result == gtk.RESPONSE_OK:
185 self.controller.add_account(uidEntry.get_text(), apiEntry.get_text())
186 self.accounts_model.get_accounts()
192 def about_clicked(self, button):
193 dialog = gtk.AboutDialog()
194 dialog.set_website(self.about_website)
195 dialog.set_website_label(self.about_website)
196 dialog.set_name(self.about_name)
197 dialog.set_authors(self.about_authors)
198 dialog.set_comments(self.about_text)
199 dialog.set_version(self.app_version)
203 def add_label(self, text, box, markup=True, align="left", padding=1):
204 label = gtk.Label(text)
206 label.set_use_markup(True)
208 label.set_alignment(0, 0.5)
209 box.pack_start(label, False, False, padding)
211 class mEveMonUI(BaseUI):
213 def __init__(self, controller):
214 self.controller = controller
215 gtk.set_application_name("mEveMon")
217 # create the main window
218 win = hildon.Window()
219 win.connect("destroy", self.controller.quit)
221 progress_bar = hildon.hildon_banner_show_progress(win, None, "Loading overview...")
222 progress_bar.set_fraction(0.4)
225 menu = self.create_menu(win)
227 # Attach menu to the window
230 character_win = CharacterSheetUI(self.controller)
232 # create the treeview --danny
233 self.char_model = models.CharacterListModel(self.controller)
234 treeview = gtk.TreeView(model = self.char_model)
235 treeview.connect('row-activated', character_win.build_window)
236 treeview.set_model(self.char_model)
237 self.add_columns_to_treeview(treeview)
239 # add the treeview with scrollbar --danny
240 win.add_with_scrollbar(treeview)
243 progress_bar.set_fraction(1)
244 progress_bar.destroy()
246 def add_columns_to_treeview(self, treeview):
247 #Column 0 for the treeview
248 renderer = gtk.CellRendererPixbuf()
249 column = gtk.TreeViewColumn()
250 column.pack_start(renderer, True)
251 column.add_attribute(renderer, "pixbuf", 0)
252 treeview.append_column(column)
254 #Column 1 for the treeview
255 renderer = gtk.CellRendererText()
256 column = gtk.TreeViewColumn('Character Name', renderer, text=1)
257 column.set_property("expand", True)
258 treeview.append_column(column)
260 def refresh_clicked(self, button, window):
261 progress_bar = hildon.hildon_banner_show_progress(win, None, "Loading characters...")
262 progress_bar.set_fraction(1)
263 self.char_model.get_characters()
264 progress_bar.destroy()
266 class CharacterSheetUI(BaseUI):
268 def __init__(self, controller):
269 self.controller = controller
272 self.skills_model = None
274 def build_window(self, treeview, path, view_column):
275 # TODO: this is a really long and ugly function, split it up somehow
277 win = hildon.Window()
280 progress_bar = hildon.hildon_banner_show_progress(win, None, "Loading character sheet...")
281 progress_bar.set_fraction(0.4)
284 # NOTE: we probably want a window-specific menu for this page, but the
285 # main appmenu works for now
286 menu = self.create_menu(win)
287 # Attach menu to the window
290 model = treeview.get_model()
291 miter = model.get_iter(path)
293 # column 0 is the portrait, column 1 is name
294 char_name = model.get_value(miter, 1)
295 uid = model.get_value(miter, 2)
296 self.char_id = self.controller.char_name2id(char_name)
298 self.sheet = self.controller.get_char_sheet(uid, self.char_id)
300 win.set_title(char_name)
302 hbox = gtk.HBox(False, 0)
303 info_vbox = gtk.VBox(False, 1)
305 portrait = gtk.Image()
306 portrait.set_from_file(self.controller.get_portrait(char_name, 256))
309 hbox.pack_start(portrait, False, False, 10)
310 hbox.pack_start(info_vbox, False, False, 5)
312 vbox = gtk.VBox(False, 0)
314 vbox.pack_start(hbox, False, False, 0)
317 self.fill_info(info_vbox)
318 self.fill_stats(info_vbox)
320 separator = gtk.HSeparator()
321 vbox.pack_start(separator, False, False, 5)
325 self.add_label("<big>Skill in Training:</big>", vbox, align="normal")
326 skill = self.controller.get_skill_in_training(uid, self.char_id)
328 if skill.skillInTraining:
330 skilltree = self.controller.get_skill_tree()
332 # I'm assuming that we will always find a skill with the skill ID
333 for group in skilltree.skillGroups:
334 found_skill = group.skills.Get(skill.trainingTypeID, False)
336 skill_name = found_skill.typeName
339 self.add_label("%s <small>(Level %d)</small>" % (skill_name, skill.trainingToLevel),
340 vbox, align="normal")
341 self.add_label("<small>start time: %s\t\tend time: %s</small>" %(time.ctime(skill.trainingStartTime),
342 time.ctime(skill.trainingEndTime)), vbox, align="normal")
344 progressbar = gtk.ProgressBar()
345 fraction_completed = (time.time() - skill.trainingStartTime) / \
346 (skill.trainingEndTime - skill.trainingStartTime)
348 progressbar.set_fraction(fraction_completed)
349 align = gtk.Alignment(0.5, 0.5, 0.5, 0)
350 vbox.pack_start(align, False, False, 5)
352 align.add(progressbar)
356 self.add_label("<small>No skills are currently being trained</small>", vbox, align="normal")
358 separator = gtk.HSeparator()
359 vbox.pack_start(separator, False, False, 0)
362 self.add_label("<big>Skills:</big>", vbox, align="normal")
365 skills_model = models.CharacterSkillsModel(self.controller, self.char_id)
366 skills_treeview = gtk.TreeView(model = skills_model)
367 skills_treeview.set_model(skills_model)
368 self.add_columns_to_skills_view(skills_treeview)
370 vbox.pack_start(skills_treeview, False, False, 0)
372 win.add_with_scrollbar(vbox)
375 progress_bar.set_fraction(1)
376 progress_bar.destroy()
378 def fill_info(self, box):
379 self.add_label("<big><big>%s</big></big>" % self.sheet.name, box)
380 self.add_label("<small>%s %s %s</small>" % (self.sheet.gender, self.sheet.race, self.sheet.bloodLine), box)
381 self.add_label("", box, markup=False)
382 self.add_label("<small><b>Corp:</b> %s</small>" % self.sheet.corporationName, box)
383 self.add_label("<small><b>Balance:</b> %s ISK</small>" % self.sheet.balance, box)
385 def fill_stats(self, box):
387 atr = self.sheet.attributes
389 self.add_label("<small><b>I: </b>%d <b>M: </b>%d <b>C: </b>%d " \
390 "<b>P: </b>%d <b>W: </b>%d</small>" % (atr.intelligence,
391 atr.memory, atr.charisma, atr.perception, atr.willpower), box)
394 def add_columns_to_skills_view(self, treeview):
395 #Column 0 for the treeview
396 renderer = gtk.CellRendererText()
397 column = gtk.TreeViewColumn('Skill Name', renderer, markup=0)
398 column.set_property("expand", True)
399 treeview.append_column(column)
401 #Column 1 for the treeview
402 column = gtk.TreeViewColumn('Rank', renderer, markup=1)
403 column.set_property("expand", True)
404 treeview.append_column(column)
407 renderer = gtk.CellRendererText()
408 renderer = gtk.CellRendererText()
409 column = gtk.TreeViewColumn('Points', renderer, markup=2)
410 column.set_property("expand", True)
411 treeview.append_column(column)
414 column = gtk.TreeViewColumn('Level', renderer, markup=3)
415 column.set_property("expand", True)
416 treeview.append_column(column)
418 def refresh_clicked(self, button, window):
419 progress_bar = hildon.hildon_banner_show_progress(win, None, "Loading overview...")
420 progress_bar.set_fraction(1)
421 self.skills_model.get_skills()
422 progress_bar.destroy()
424 if __name__ == "__main__":