From: Ryan Campbell Date: Tue, 18 May 2010 23:05:05 +0000 (-0600) Subject: Added live 'total sp' counter in fremantle X-Git-Tag: v0.4-1~6 X-Git-Url: https://vcs.maemo.org/git/?p=mevemon;a=commitdiff_plain;h=e47bec2e992f5e83e85da0d54deb34d360ab85e5 Added live 'total sp' counter in fremantle We now display the total sp (actual sp + sp gained from skill-in-training). This has only been enabled in fremantle, so diablo gui will need to be adapted to take advantage of it. The total sp is also 'live', meaning that it increments every second based on the calculated SP/hour. --- diff --git a/package/src/mevemon.py b/package/src/mevemon.py index 00ebe20..c0e4361 100755 --- a/package/src/mevemon.py +++ b/package/src/mevemon.py @@ -25,6 +25,7 @@ import fetchimg import apicache import os.path import traceback +import time #conic is used for connection handling import conic @@ -55,7 +56,7 @@ class mEveMon(): self.gconf = gnome.gconf.client_get_default() #NOTE: remove this after a few releases self.update_settings() - self.connect() + self.connect_to_network() self.cached_api = eveapi.EVEAPIConnection( cacheHandler = \ apicache.cache_handler(debug=False)) self.gui = gui.mEveMonUI(self) @@ -281,13 +282,65 @@ class mEveMon(): pass - def connect(self): + def connect_to_network(self): connection = conic.Connection() #why 0xAA55? connection.connect("connection-event", self.connection_cb, 0xAA55) assert(connection.request_connection(conic.CONNECT_FLAG_NONE)) + def get_sp(self, uid, char_id): + sheet = self.get_char_sheet(uid, char_id) + + # TODO: we also have to calculate how much we earned from a + # currently training skill + + actual_sp = 0 + + for skill in sheet.skills: + actual_sp += skill.skillpoints + + live_sp = actual_sp + self.get_training_sp(uid, char_id) + + return live_sp + + def get_spps(self, uid, char_id): + """ + Calculate and returns the skill points per hour for the given character. + """ + skill = self.get_skill_in_training(uid, char_id) + + if not skill.skillInTraining: + return (0, 0) + + total_sp = skill.trainingDestinationSP - skill.trainingStartSP + total_time = skill.trainingEndTime - skill.trainingStartTime + + spps = float(total_sp) / total_time + + return (spps, skill.trainingStartTime) + + def get_training_sp(self, uid, char_id): + """ + returns the additional SP that the in-training skill has acquired + """ + + spps_tuple = self.get_spps(uid, char_id) + + print spps_tuple + + if not spps_tuple: + return 0 + + spps, start_time = spps_tuple + + eve_time = time.time() #evetime is utc, right? + + time_diff = eve_time - start_time + + return (spps * time_diff) + + if __name__ == "__main__": app = mEveMon() app.run() diff --git a/package/src/ui/fremantle/gui.py b/package/src/ui/fremantle/gui.py index 70aebb5..2d53968 100644 --- a/package/src/ui/fremantle/gui.py +++ b/package/src/ui/fremantle/gui.py @@ -22,6 +22,8 @@ import gtk import hildon import gobject +import glib + from ui import models class BaseUI(): @@ -214,6 +216,8 @@ class BaseUI(): box.pack_start(label, False, False, padding) + return label + class mEveMonUI(BaseUI): @@ -279,7 +283,8 @@ class mEveMonUI(BaseUI): class CharacterSheetUI(BaseUI): - + UPDATE_INTERVAL = 1 + def __init__(self, controller): self.controller = controller self.sheet = None @@ -308,10 +313,10 @@ class CharacterSheetUI(BaseUI): # column 0 is the portrait, column 1 is name char_name = model.get_value(miter, 1) - uid = model.get_value(miter, 2) + self.uid = model.get_value(miter, 2) self.char_id = self.controller.char_name2id(char_name) - self.sheet = self.controller.get_char_sheet(uid, self.char_id) + self.sheet = self.controller.get_char_sheet(self.uid, self.char_id) win.set_title(char_name) @@ -338,7 +343,27 @@ class CharacterSheetUI(BaseUI): vbox.pack_start(separator, False, False, 5) self.add_label("Skill in Training:", vbox, align="normal") - skill = self.controller.get_skill_in_training(uid, self.char_id) + + self.display_skill_in_training(vbox) + + separator = gtk.HSeparator() + vbox.pack_start(separator, False, False, 0) + + self.add_label("Skills:", vbox, align="normal") + + skills_treeview = hildon.GtkTreeView(gtk.HILDON_UI_MODE_NORMAL) + self.skills_model = models.CharacterSkillsModel(self.controller, self.char_id) + skills_treeview.set_model(self.skills_model) + self.add_columns_to_skills_view(skills_treeview) + vbox.pack_start(skills_treeview, False, False, 1) + + win.add(pannable_area) + win.show_all() + + hildon.hildon_gtk_window_set_progress_indicator(win, 0) + + def display_skill_in_training(self, vbox): + skill = self.controller.get_skill_in_training(self.uid, self.char_id) if skill.skillInTraining: @@ -367,21 +392,7 @@ class CharacterSheetUI(BaseUI): self.add_label("No skills are currently being trained", vbox, align="normal") - separator = gtk.HSeparator() - vbox.pack_start(separator, False, False, 0) - - self.add_label("Skills:", vbox, align="normal") - - skills_treeview = hildon.GtkTreeView(gtk.HILDON_UI_MODE_NORMAL) - self.skills_model = models.CharacterSkillsModel(self.controller, self.char_id) - skills_treeview.set_model(self.skills_model) - self.add_columns_to_skills_view(skills_treeview) - vbox.pack_start(skills_treeview, False, False, 1) - - win.add(pannable_area) - win.show_all() - hildon.hildon_gtk_window_set_progress_indicator(win, 0) def fill_info(self, box): self.add_label("%s" % self.sheet.name, box) @@ -390,7 +401,14 @@ class CharacterSheetUI(BaseUI): self.add_label("", box, markup=False) self.add_label("Corp: %s" % self.sheet.corporationName, box) self.add_label("Balance: %s ISK" % self.sheet.balance, box) + self.live_sp_val = self.controller.get_sp(self.uid, self.char_id) + print self.live_sp_val + self.live_sp = self.add_label("Total SP: %s" % + self.live_sp_val, box) + + self.spps = self.controller.get_spps(self.uid, self.char_id)[0] + glib.timeout_add_seconds(self.UPDATE_INTERVAL, self.update_live_sp) def fill_stats(self, box): @@ -432,6 +450,15 @@ class CharacterSheetUI(BaseUI): self.skills_model.get_skills() hildon.hildon_gtk_window_set_progress_indicator(window, 0) + + def update_live_sp(self): + self.live_sp_val = self.live_sp_val + self.spps * self.UPDATE_INTERVAL + self.live_sp.set_label("Total SP: %d" % + self.live_sp_val) + + return True + + if __name__ == "__main__": main()