Removed the UI's dependance on having a valid working authentication. The
authorDanny Campbell <danny.campbell@gmail.com>
Tue, 20 Apr 2010 10:56:40 +0000 (04:56 -0600)
committerDanny Campbell <danny.campbell@gmail.com>
Tue, 20 Apr 2010 11:01:33 +0000 (05:01 -0600)
solution isn't pretty, but it avoids having to modify the UI yet, until we
can discuss how we'll handle it.

Also cleaned up some of the comments in the Diablo UI code.

mevemon.py
ui/diablo/ui.py

index 422a8e1..1435fcb 100644 (file)
@@ -41,26 +41,29 @@ class mEveMon():
 
 
     def set_auth(self):
+        """
+        set self.auth to None if there was a problem. somehow later on we'll
+        have to pass the error to the UI, but for now I just want the program
+        to not be broken. --danny
+        """
         uid = self.get_uid()
         api_key = self.get_api_key()
         self.cached_api = eveapi.EVEAPIConnection( cacheHandler = \
                 apicache.cache_handler( debug = False ) )
-
         try:
             self.auth = self.cached_api.auth( userID = uid, apiKey = api_key )
         except eveapi.Error, e:
-            # if we can't, return the error message/pic --danny
-            return None
-        except Exception, e:
-            # unknown exception, dunno if this needs to be here if I just
-            # ignore it... probably a bad idea, but it was in the 
-            # apitest.py example... --danny
+            # we need to deal with this, so raise --danny
             raise
+        except ValueError, e:
+            self.auth = None
+            #raise
 
     def get_auth(self):
         return self.auth
 
     def get_char_sheet(self, charID):
+        if not self.auth: return None
         try:
             sheet = self.auth.character(charID).CharacterSheet()
         except eveapi.Error, e:
@@ -92,6 +95,7 @@ class mEveMon():
         return char_id
 
     def get_account_balance(self, charID):
+        if not self.auth: return None
         try:
             wallet = self.auth.char.AccountBalance(CharacterID=charID)
             isk = wallet.accounts[0].balance  # do we always want the first one??
@@ -101,24 +105,23 @@ class mEveMon():
 
         return isk
 
-    # really quick hack to get character list. doesn't handle errors well, and
-    # if it can't get the gconf settings it just returns the placeholders, when
-    # in reality it should tell the UI or something. basically half finished,
-    # just uploading to show ry... FIXME --danny
     def get_characters( self ):
+        """
+        returns a list containing a single character with an error message for a
+        name, if there's a problem. FIXME --danny
+        """
         ui_char_list = []
-        # error message --danny
         placeholder_chars = [("Please check your API settings.", "imgs/error.jpg")]
-        
+        if not self.auth: return placeholder_chars
         try:
             api_char_list = self.auth.account.Characters()
-            # append each char we get to the list we'll return to the UI --danny
+            # append each char we get to the list we'll return to the
+            # UI --danny
             for character in api_char_list.characters:
-                ui_char_list.append( ( character.name, 
-                    fetchimg.portrait_filename( character.characterID, 64 ) ) )
-        # if not entered into gconf, error message --danny
+                ui_char_list.append( ( character.name, fetchimg.portrait_filename( character.characterID, 64 ) ) )
         except eveapi.Error, e:
-            return placeholder_chars
+            # again, we need to handle this... --danny
+            raise
 
         return ui_char_list
 
index 904c8fc..6c98310 100644 (file)
@@ -22,13 +22,13 @@ class mEveMonUI():
    
         gtk.set_application_name("mEveMon")
     
-        # create the main window, changing from StackableWindow() --danny
+        # create the main window
         win = hildon.Window()
         win.connect("destroy", self.controller.quit)
 
         # Create menu
         menu = self.create_menu(win)
-        # Attach menu to the window, changed from set_app_menu() --danny
+        # Attach menu to the window
         win.set_menu(menu)
 
         # will probably need to refer to http://maemo.org/community/maemo-developers/gtktreeview_issue/ for sample code again when we make these clickable --danny
@@ -113,11 +113,8 @@ class mEveMonUI():
 
     def create_char_model(self):
         lstore = gtk.ListStore(gtk.gdk.Pixbuf, gobject.TYPE_STRING)
-
         #get icon and name and put in a liststore
-
         self.fill_char_model(lstore)
-
         return lstore
 
     def fill_char_model(self, lstore):
@@ -165,7 +162,6 @@ class mEveMonUI():
         uidLabel.set_justify(gtk.JUSTIFY_LEFT)
         vbox.add(uidLabel)
         
-        # had to remove placeholder stuff --danny
         uidEntry = gtk.Entry()
         uidEntry.set_text(self.controller.get_uid())
         uidEntry.set_property('is_focus', False)
@@ -176,7 +172,6 @@ class mEveMonUI():
         apiLabel.set_justify(gtk.JUSTIFY_LEFT)
         vbox.add(apiLabel)
         
-        # had to remove placeholder stuff --danny
         apiEntry = gtk.Entry()
         apiEntry.set_text(self.controller.get_api_key())
         apiEntry.set_property('is_focus', False)
@@ -215,14 +210,9 @@ class mEveMonUI():
         self.update_model(self.char_model)
   
     def create_menu(self, window):
-    
-        # changed from hildon.AppMenu --danny
         menu = gtk.Menu()
-
         for command in self.menu_items:
-            # Create menu entries, changed from hildon.GtkButton() --danny
             button = gtk.MenuItem( command )
-
             if command == "About":
                 button.connect("activate", self.about_clicked)
             elif command == "Settings":
@@ -231,12 +221,9 @@ class mEveMonUI():
                 button.connect("activate", self.refresh_clicked, window)
             else:
                 assert False, command
-
             # Add entry to the view menu
             menu.append(button)
-        
         menu.show_all()
-
         return menu
 
 if __name__ == "__main__":