Stop the SP counter when window not on top
authorRyan Campbell <campbellr@gmail.com>
Thu, 20 May 2010 01:31:29 +0000 (19:31 -0600)
committerRyan Campbell <campbellr@gmail.com>
Thu, 20 May 2010 01:31:29 +0000 (19:31 -0600)
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
package/src/ui/fremantle/gui.py

index c0e4361..f45b831 100755 (executable)
@@ -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) 
index 2d53968..f01d8e4 100644 (file)
@@ -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("<small><b>Corp:</b> %s</small>" % self.sheet.corporationName, box)
         self.add_label("<small><b>Balance:</b> %s ISK</small>" % 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("<small><b>Total SP:</b> %s</small>" %
                 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("<small><b>Total SP:</b> %d</small>" %
                                 self.live_sp_val)