From 2e8cec2c65f19632d99e635ac94b650dec70d10d Mon Sep 17 00:00:00 2001 From: Ryan Campbell Date: Wed, 19 May 2010 19:31:29 -0600 Subject: [PATCH] Stop the SP counter when window not on top Previously our timer that increments the 'total sp' label kept ticking away even when the window for the character sheet wasn't visibile. The timer callback now checks if the window is visible (with get_is_topmost()), and if not, stops the timer. The Diablo GUI may need to try something different, not sure. --- package/src/mevemon.py | 27 +++++++++++++++------------ package/src/ui/fremantle/gui.py | 30 +++++++++++++++++------------- 2 files changed, 32 insertions(+), 25 deletions(-) diff --git a/package/src/mevemon.py b/package/src/mevemon.py index c0e4361..f45b831 100755 --- a/package/src/mevemon.py +++ b/package/src/mevemon.py @@ -268,7 +268,6 @@ class mEveMon(): """ Returns an object from eveapi containing information about the current skill in training - """ try: skill = self.get_auth(uid).character(char_id).SkillInTraining() @@ -279,10 +278,20 @@ class mEveMon(): return skill def connection_cb(self, connection, event, mgc): + """ + I'm not sure why we need this, but connection.connect() won't work + without it, even empty. + """ pass def connect_to_network(self): + """ + This will connect to the default network if avaliable, or pop up the + connection dialog to select a connection. + Running this when we start the program ensures we are connected to a + network. + """ connection = conic.Connection() #why 0xAA55? connection.connect("connection-event", self.connection_cb, 0xAA55) @@ -290,13 +299,13 @@ class mEveMon(): 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 - + """ + Adds up the SP for all known skills, then calculates the SP gained + from an in-training skill. + """ actual_sp = 0 + sheet = self.get_char_sheet(uid, char_id) for skill in sheet.skills: actual_sp += skill.skillpoints @@ -324,18 +333,12 @@ class mEveMon(): """ 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) diff --git a/package/src/ui/fremantle/gui.py b/package/src/ui/fremantle/gui.py index 2d53968..f01d8e4 100644 --- a/package/src/ui/fremantle/gui.py +++ b/package/src/ui/fremantle/gui.py @@ -295,16 +295,16 @@ class CharacterSheetUI(BaseUI): def build_window(self, treeview, path, view_column): # TODO: this is a really long and ugly function, split it up somehow - win = hildon.StackableWindow() - win.show_all() - hildon.hildon_gtk_window_set_progress_indicator(win, 1) + self.win = hildon.StackableWindow() + #win.show_all() + hildon.hildon_gtk_window_set_progress_indicator(self.win, 1) # Create menu # NOTE: we probably want a window-specific menu for this page, but the # main appmenu works for now - menu = self.create_menu(win) + menu = self.create_menu(self.win) # Attach menu to the window - win.set_app_menu(menu) + self.win.set_app_menu(menu) pannable_area = hildon.PannableArea() @@ -318,7 +318,7 @@ class CharacterSheetUI(BaseUI): self.sheet = self.controller.get_char_sheet(self.uid, self.char_id) - win.set_title(char_name) + self.win.set_title(char_name) hbox = gtk.HBox(False, 0) @@ -357,10 +357,10 @@ class CharacterSheetUI(BaseUI): self.add_columns_to_skills_view(skills_treeview) vbox.pack_start(skills_treeview, False, False, 1) - win.add(pannable_area) - win.show_all() + self.win.add(pannable_area) + self.win.show_all() - hildon.hildon_gtk_window_set_progress_indicator(win, 0) + hildon.hildon_gtk_window_set_progress_indicator(self.win, 0) def display_skill_in_training(self, vbox): skill = self.controller.get_skill_in_training(self.uid, self.char_id) @@ -402,7 +402,6 @@ class CharacterSheetUI(BaseUI): 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) @@ -445,13 +444,18 @@ class CharacterSheetUI(BaseUI): treeview.append_column(column) - def refresh_clicked(self, button, window): - hildon.hildon_gtk_window_set_progress_indicator(window, 1) + def refresh_clicked(self, button): + hildon.hildon_gtk_window_set_progress_indicator(self.win, 1) self.skills_model.get_skills() - hildon.hildon_gtk_window_set_progress_indicator(window, 0) + hildon.hildon_gtk_window_set_progress_indicator(self.win, 0) def update_live_sp(self): + # we don't want to keep the timer running in the background + # when this callback returns False, the timer destorys itself + if not self.win.get_is_topmost(): + return False + 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) -- 1.7.9.5