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)
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("Settings")
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)
177 result = dialog.run()
179 if result == gtk.RESPONSE_OK:
180 self.controller.add_account(uidEntry.get_text(), apiEntry.get_text())
181 self.accounts_model.get_accounts()
187 def about_clicked(self, button):
188 dialog = gtk.AboutDialog()
189 dialog.set_website(self.about_website)
190 dialog.set_website_label(self.about_website)
191 dialog.set_name(self.about_name)
192 dialog.set_authors(self.about_authors)
193 dialog.set_comments(self.about_text)
194 dialog.set_version(self.app_version)
198 def add_label(self, text, box, markup=True, align="left", padding=1):
199 label = gtk.Label(text)
201 label.set_use_markup(True)
203 label.set_alignment(0, 0.5)
204 box.pack_start(label, False, False, padding)
206 class mEveMonUI(BaseUI):
208 def __init__(self, controller):
209 self.controller = controller
210 gtk.set_application_name("mEveMon")
212 # create the main window
213 win = hildon.Window()
214 win.connect("destroy", self.controller.quit)
216 progress_bar = hildon.hildon_banner_show_progress(win, None, "Loading overview...")
217 progress_bar.set_fraction(0.4)
220 menu = self.create_menu(win)
222 # Attach menu to the window
225 character_win = CharacterSheetUI(self.controller)
227 # create the treeview --danny
228 self.char_model = models.CharacterListModel(self.controller)
229 treeview = gtk.TreeView(model = self.char_model)
230 treeview.connect('row-activated', character_win.build_window)
231 treeview.set_model(self.char_model)
232 self.add_columns_to_treeview(treeview)
234 # add the treeview with scrollbar --danny
235 win.add_with_scrollbar(treeview)
238 progress_bar.set_fraction(1)
239 progress_bar.destroy()
241 def add_columns_to_treeview(self, treeview):
242 #Column 0 for the treeview
243 renderer = gtk.CellRendererPixbuf()
244 column = gtk.TreeViewColumn()
245 column.pack_start(renderer, True)
246 column.add_attribute(renderer, "pixbuf", 0)
247 treeview.append_column(column)
249 #Column 1 for the treeview
250 renderer = gtk.CellRendererText()
251 column = gtk.TreeViewColumn('Character Name', renderer, text=1)
252 column.set_property("expand", True)
253 treeview.append_column(column)
255 def refresh_clicked(self, button, window):
256 progress_bar = hildon.hildon_banner_show_progress(win, None, "Loading characters...")
257 progress_bar.set_fraction(1)
258 self.char_model.get_characters()
259 progress_bar.destroy()
261 class CharacterSheetUI(BaseUI):
263 def __init__(self, controller):
264 self.controller = controller
267 self.skills_model = None
269 def build_window(self, treeview, path, view_column):
270 # TODO: this is a really long and ugly function, split it up somehow
272 win = hildon.Window()
275 progress_bar = hildon.hildon_banner_show_progress(win, None, "Loading character sheet...")
276 progress_bar.set_fraction(0.4)
279 # NOTE: we probably want a window-specific menu for this page, but the
280 # main appmenu works for now
281 menu = self.create_menu(win)
282 # Attach menu to the window
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)
291 self.char_id = self.controller.char_name2id(char_name)
293 self.sheet = self.controller.get_char_sheet(uid, self.char_id)
295 win.set_title(char_name)
297 hbox = gtk.HBox(False, 0)
298 info_vbox = gtk.VBox(False, 1)
300 portrait = gtk.Image()
301 portrait.set_from_file(self.controller.get_portrait(char_name, 256))
304 hbox.pack_start(portrait, False, False, 10)
305 hbox.pack_start(info_vbox, False, False, 5)
307 vbox = gtk.VBox(False, 0)
309 vbox.pack_start(hbox, False, False, 0)
312 self.fill_info(info_vbox)
313 self.fill_stats(info_vbox)
315 separator = gtk.HSeparator()
316 vbox.pack_start(separator, False, False, 5)
320 self.add_label("<big>Skill in Training:</big>", vbox, align="normal")
321 skill = self.controller.get_skill_in_training(uid, self.char_id)
323 if skill.skillInTraining:
325 skilltree = self.controller.get_skill_tree()
327 # I'm assuming that we will always find a skill with the skill ID
328 for group in skilltree.skillGroups:
329 found_skill = group.skills.Get(skill.trainingTypeID, False)
331 skill_name = found_skill.typeName
334 self.add_label("%s <small>(Level %d)</small>" % (skill_name, skill.trainingToLevel),
335 vbox, align="normal")
336 self.add_label("<small>start time: %s\t\tend time: %s</small>" %(time.ctime(skill.trainingStartTime),
337 time.ctime(skill.trainingEndTime)), vbox, align="normal")
339 progressbar = gtk.ProgressBar()
340 fraction_completed = (time.time() - skill.trainingStartTime) / \
341 (skill.trainingEndTime - skill.trainingStartTime)
343 progressbar.set_fraction(fraction_completed)
344 align = gtk.Alignment(0.5, 0.5, 0.5, 0)
345 vbox.pack_start(align, False, False, 5)
347 align.add(progressbar)
351 self.add_label("<small>No skills are currently being trained</small>", vbox, align="normal")
353 separator = gtk.HSeparator()
354 vbox.pack_start(separator, False, False, 0)
357 self.add_label("<big>Skills:</big>", vbox, align="normal")
360 skills_model = models.CharacterSkillsModel(self.controller, self.char_id)
361 skills_treeview = gtk.TreeView(model = skills_model)
362 skills_treeview.set_model(skills_model)
363 self.add_columns_to_skills_view(skills_treeview)
365 vbox.pack_start(skills_treeview, False, False, 0)
367 win.add_with_scrollbar(vbox)
370 progress_bar.set_fraction(1)
371 progress_bar.destroy()
373 def fill_info(self, box):
374 self.add_label("<big><big>%s</big></big>" % self.sheet.name, box)
375 self.add_label("<small>%s %s %s</small>" % (self.sheet.gender, self.sheet.race, self.sheet.bloodLine), box)
376 self.add_label("", box, markup=False)
377 self.add_label("<small><b>Corp:</b> %s</small>" % self.sheet.corporationName, box)
378 self.add_label("<small><b>Balance:</b> %s ISK</small>" % self.sheet.balance, box)
380 def fill_stats(self, box):
382 atr = self.sheet.attributes
384 self.add_label("<small><b>I: </b>%d <b>M: </b>%d <b>C: </b>%d " \
385 "<b>P: </b>%d <b>W: </b>%d</small>" % (atr.intelligence,
386 atr.memory, atr.charisma, atr.perception, atr.willpower), box)
389 def add_columns_to_skills_view(self, treeview):
390 #Column 0 for the treeview
391 renderer = gtk.CellRendererText()
392 column = gtk.TreeViewColumn('Skill Name', renderer, markup=0)
393 column.set_property("expand", True)
394 treeview.append_column(column)
396 #Column 1 for the treeview
397 column = gtk.TreeViewColumn('Rank', renderer, markup=1)
398 column.set_property("expand", True)
399 treeview.append_column(column)
402 renderer = gtk.CellRendererText()
403 renderer = gtk.CellRendererText()
404 column = gtk.TreeViewColumn('Points', renderer, markup=2)
405 column.set_property("expand", True)
406 treeview.append_column(column)
409 column = gtk.TreeViewColumn('Level', renderer, markup=3)
410 column.set_property("expand", True)
411 treeview.append_column(column)
413 def refresh_clicked(self, button, window):
414 progress_bar = hildon.hildon_banner_show_progress(win, None, "Loading overview...")
415 progress_bar.set_fraction(1)
416 self.skills_model.get_skills()
417 progress_bar.destroy()
419 if __name__ == "__main__":