Fix bug #5645, and other minor bug
[mevemon] / package / src / mevemon.py
index c0e4361..eb10a49 100755 (executable)
@@ -48,6 +48,15 @@ class mEveMon():
 
     """
 
+    about_name = 'mEveMon'
+    about_text = ('Mobile character monitor for EVE Online')
+    about_authors = ['Ryan Campbell <campbellr@gmail.com>',
+                     'Danny Campbell <danny.campbell@gmail.com>']
+
+    about_website = 'http://mevemon.garage.maemo.org'
+    app_version = '0.4'
+
+
     GCONF_DIR = "/apps/maemo/mevemon"
 
     def __init__(self):
@@ -60,6 +69,7 @@ class mEveMon():
         self.cached_api = eveapi.EVEAPIConnection( cacheHandler = \
                 apicache.cache_handler(debug=False))
         self.gui = gui.mEveMonUI(self)
+        self.gui.run()
 
     def run(self):
         gtk.main()
@@ -122,7 +132,8 @@ class mEveMon():
 
         try:
             auth = self.cached_api.auth(userID=uid, apiKey=api_key)
-        except:
+        except Exception, e:
+            self.gui.report_error(str(e))
             traceback.print_exc()
             return None
 
@@ -135,7 +146,8 @@ class mEveMon():
         """
         try:
             sheet = self.get_auth(uid).character(char_id).CharacterSheet()
-        except:
+        except Exception, e:
+            self.gui.report_error(str(e))
             # TODO: we should really have a logger that logs this error somewhere
             traceback.print_exc()
             return None
@@ -154,9 +166,13 @@ class mEveMon():
         
         for uid, api_key in acct_dict.items():
             auth = self.cached_api.auth(userID=uid, apiKey=api_key)
-            api_char_list = auth.account.Characters()
-            
-            for character in api_char_list.characters:
+            try:
+                api_char_list = auth.account.Characters()
+                characters = api_char_list.characters
+            except:
+                characters = []
+
+            for character in characters:
                 if character.characterID == char_id:
                     return uid
 
@@ -173,7 +189,8 @@ class mEveMon():
         try:
             chars = self.cached_api.eve.CharacterName(ids=char_id).characters
             name = chars[0].characterName
-        except:
+        except Exception, e:
+            self.gui.report_error(str(e))
             traceback.print_exc()
             return None
 
@@ -190,7 +207,8 @@ class mEveMon():
             chars = self.cached_api.eve.CharacterID(names=name).characters
             char_id = chars[0].characterID
             char_name = chars[0].name
-        except:
+        except Exception, e:
+            self.gui.report_error(str(e))
             traceback.print_exc()
             return None
 
@@ -207,7 +225,8 @@ class mEveMon():
             try:
                 api_char_list = auth.account.Characters()
                 char_list = [char.name for char in api_char_list.characters]
-            except:
+            except Exception, e:
+                self.gui.report_error(str(e))
                 traceback.print_exc()
                 return None
 
@@ -222,10 +241,12 @@ class mEveMon():
         pair to the list, it appends an 'error message' 
 
         """
+
         ui_char_list = []
         err_img = "/usr/share/mevemon/imgs/error.jpg"
+        err_txt = "Problem fetching info for account"
 
-        placeholder_chars = ("Please check your API settings.", err_img, "0")
+        placeholder_chars = (err_txt, err_img, None)
         
         acct_dict = self.get_accounts()
         if not acct_dict:
@@ -235,7 +256,7 @@ class mEveMon():
             char_names = self.get_chars_from_acct(uid)
             
             if not char_names:
-                ui_char_list.append(placeholder_chars)
+                ui_char_list.append((err_txt + "\t(UID: %s)" % uid, err_img, None))
             else:
                 # append each char we get to the list we'll return to the
                 # UI --danny
@@ -258,7 +279,8 @@ class mEveMon():
         """
         try:
             tree = self.cached_api.eve.SkillTree()
-        except:
+        except Exception, e:
+            self.gui.report_error(str(e))
             traceback.print_exc()
             return None
         
@@ -268,21 +290,31 @@ 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()
-        except:
+        except Exception, e:
+            self.gui.report_error(str(e))
             traceback.print_exc()
             return None
 
         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 +322,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 +356,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)