Added characters to settings dialog
authorRyan Campbell <campbellr@gmail.com>
Sat, 1 May 2010 05:22:27 +0000 (23:22 -0600)
committerRyan Campbell <campbellr@gmail.com>
Sat, 1 May 2010 05:22:27 +0000 (23:22 -0600)
Also, some clean-up in mevemon.py and remove some 'magic numbers'
in fremantle GUI. Still should be done for Diablo GUI.

package/src/mevemon.py
package/src/ui/diablo/gui.py
package/src/ui/fremantle/gui.py
package/src/ui/models.py

index 29cde5d..2fdc4b1 100755 (executable)
@@ -178,15 +178,31 @@ class mEveMon():
         try:
             chars = self.cached_api.eve.CharacterID(names=name).characters
             char_id = chars[0].characterID
+            char_name = chars[0].name
         except eveapi.Error:
             return None
 
         return char_id
 
-    
+    def get_chars_from_acct(self, uid):
+        """
+        Returns a list of characters associated with the provided user ID.
+        """
+        auth = self.get_auth(uid)
+        if not auth:
+            return None
+        else:
+            try:
+                api_char_list = auth.account.Characters()
+                char_list = [char.name for char in api_char_list.characters]
+            except eveapi.Error:
+                return None
+
+        return char_list
+
     def get_characters(self):
         """
-        Returns a list of (character_name, image_path) pairs from all the
+        Returns a list of (character_name, image_path, uid) tuples from all the
         accounts that are registered to mEveMon.
         
         If there is an authentication issue, then instead of adding a valid
@@ -202,24 +218,25 @@ class mEveMon():
         if not acct_dict:
             return [placeholder_chars]
 
-        for uid, api_key in acct_dict.items():
-            auth = self.cached_api.auth(userID=uid, apiKey=api_key)
-            try:
-                api_char_list = auth.account.Characters()
+        for uid in acct_dict.keys():
+            char_names = self.get_chars_from_acct(uid)
+            
+            if not char_names:
+                ui_char_list.append(placeholder_chars)
+            else:
                 # 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 ), uid) )
-            except eveapi.Error:
-                ui_char_list.append(placeholder_chars)
-
+                for char_name in char_names:
+                    ui_char_list.append((char_name, self.get_portrait(char_name, 64) , uid) )
+        
         return ui_char_list
 
     def get_portrait(self, char_name, size):
         """
-        Returns the relative path of the retrieved portrait
+        Returns the file path of the retrieved portrait
         """
         char_id = self.char_name2id(char_name)
+        
         return fetchimg.portrait_filename(char_id, size)
 
     def get_skill_tree(self):
index f0226e9..3598479 100644 (file)
@@ -142,6 +142,11 @@ class BaseUI():
         column = gtk.TreeViewColumn('Account ID', renderer, text=0)
         column.set_property("expand", True)
         treeview.append_column(column)
+        #Column 2 (characters) for the treeview
+        column = gtk.TreeViewColumn('Characters', renderer, 
+                markup=models.AccountsModel.C_CHARS)
+        column.set_property("expand", True)
+        treeview.append_column(column)
 
 
     def new_account_clicked(self, window):
index 117e9f6..70aebb5 100644 (file)
@@ -72,15 +72,16 @@ class BaseUI():
 
         vbox = gtk.VBox(False, 1)
 
-        acctsLabel = gtk.Label("Accounts:")
-        acctsLabel.set_justify(gtk.JUSTIFY_LEFT)
+        #acctsLabel = gtk.Label("Accounts:")
+        #acctsLabel.set_justify(gtk.JUSTIFY_LEFT)
      
-        vbox.pack_start(acctsLabel, False, False, 1)
+        #vbox.pack_start(acctsLabel, False, False, 1)
        
         self.accounts_model = models.AccountsModel(self.controller)
         
         accounts_treeview = hildon.GtkTreeView(gtk.HILDON_UI_MODE_NORMAL)
         accounts_treeview.set_model(self.accounts_model)
+        accounts_treeview.set_headers_visible(True)
         self.add_columns_to_accounts(accounts_treeview)
         vbox.pack_start(accounts_treeview, False, False, 1)
 
@@ -101,9 +102,9 @@ class BaseUI():
         while(result != gtk.RESPONSE_DELETE_EVENT):
             if result == RESPONSE_NEW:
                 self.new_account_clicked(window)
-            elif result == RESPONSE_EDIT:
-                # get the selected treeview item and pop up the account_box
-                self.edit_account(accounts_treeview)
+            #elif result == RESPONSE_EDIT:
+            #    # get the selected treeview item and pop up the account_box
+            #    self.edit_account(accounts_treeview)
             elif result == RESPONSE_DELETE:
                 # get the selected treeview item, and delete the gconf keys
                 self.delete_account(accounts_treeview)
@@ -139,10 +140,16 @@ class BaseUI():
     def add_columns_to_accounts(self, treeview):
         #Column 0 for the treeview
         renderer = gtk.CellRendererText()
-        column = gtk.TreeViewColumn('Account ID', renderer, text=0)
+        column = gtk.TreeViewColumn('User ID', renderer, 
+                text=models.AccountsModel.C_UID)
         column.set_property("expand", True)
         treeview.append_column(column)
 
+        #Column 2 (characters) for the treeview
+        column = gtk.TreeViewColumn('Characters', renderer, 
+                markup=models.AccountsModel.C_CHARS)
+        column.set_property("expand", True)
+        treeview.append_column(column)
 
     def new_account_clicked(self, window):
         dialog = gtk.Dialog()
@@ -253,12 +260,14 @@ class mEveMonUI(BaseUI):
         renderer = gtk.CellRendererPixbuf()
         column = gtk.TreeViewColumn()
         column.pack_start(renderer, True)
-        column.add_attribute(renderer, "pixbuf", 0)
+        column.add_attribute(renderer, "pixbuf", 
+                models.CharacterListModel.C_PORTRAIT)
         treeview.append_column(column)
 
         #Column 1 for the treeview
         renderer = gtk.CellRendererText()
-        column = gtk.TreeViewColumn('Character Name', renderer, text=1)
+        column = gtk.TreeViewColumn('Character Name', renderer, 
+                text=models.CharacterListModel.C_NAME)
         column.set_property("expand", True)
         treeview.append_column(column)
  
@@ -312,11 +321,9 @@ class CharacterSheetUI(BaseUI):
 
         portrait = gtk.Image()
         portrait.set_from_file(self.controller.get_portrait(char_name, 256))
-        portrait.show()
 
         hbox.pack_start(portrait, False, False, 10)
         hbox.pack_start(info_vbox, False, False, 5)
-        hbox.show()
 
         vbox = gtk.VBox(False, 0)
         pannable_area.add_with_viewport(vbox)
@@ -329,7 +336,6 @@ class CharacterSheetUI(BaseUI):
 
         separator = gtk.HSeparator()
         vbox.pack_start(separator, False, False, 5)
-        separator.show()
         
         self.add_label("<big>Skill in Training:</big>", vbox, align="normal")
         skill = self.controller.get_skill_in_training(uid, self.char_id)
@@ -347,7 +353,8 @@ class CharacterSheetUI(BaseUI):
                 
             self.add_label("%s <small>(Level %d)</small>" % (skill_name, skill.trainingToLevel),
                     vbox, align="normal")
-            self.add_label("<small>start time: %s\t\tend time: %s</small>" %(time.ctime(skill.trainingStartTime),
+            self.add_label("<small>start time: %s\t\tend time: %s</small>" 
+                    %(time.ctime(skill.trainingStartTime),
                 time.ctime(skill.trainingEndTime)), vbox, align="normal")
             progressbar = gtk.ProgressBar()
             fraction_completed = (time.time() - skill.trainingStartTime) / \
@@ -355,20 +362,16 @@ class CharacterSheetUI(BaseUI):
             progressbar.set_fraction(fraction_completed)
             align = gtk.Alignment(0.5, 0.5, 0.5, 0)
             vbox.pack_start(align, False, False, 5)
-            align.show()
             align.add(progressbar)
-            progressbar.show()
         else:
-            self.add_label("<small>No skills are currently being trained</small>", vbox, align="normal")
+            self.add_label("<small>No skills are currently being trained</small>",
+                    vbox, align="normal")
 
         separator = gtk.HSeparator()
         vbox.pack_start(separator, False, False, 0)
-        separator.show()
         
         self.add_label("<big>Skills:</big>", vbox, align="normal")
 
-        win.show_all()
-
         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)
@@ -382,7 +385,8 @@ class CharacterSheetUI(BaseUI):
 
     def fill_info(self, box):
         self.add_label("<big><big>%s</big></big>" % self.sheet.name, box)
-        self.add_label("<small>%s %s %s</small>" % (self.sheet.gender, self.sheet.race, self.sheet.bloodLine), box)
+        self.add_label("<small>%s %s %s</small>" % (self.sheet.gender, 
+            self.sheet.race, self.sheet.bloodLine), box)
         self.add_label("", box, markup=False)
         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)
@@ -400,22 +404,25 @@ class CharacterSheetUI(BaseUI):
     def add_columns_to_skills_view(self, treeview):
         #Column 0 for the treeview
         renderer = gtk.CellRendererText()
-        column = gtk.TreeViewColumn('Skill Name', renderer, markup=0)
+        column = gtk.TreeViewColumn('Skill Name', renderer, 
+                markup=models.CharacterSkillsModel.C_NAME)
         column.set_property("expand", True)
         treeview.append_column(column)
         
         #Column 1 for the treeview
-        column = gtk.TreeViewColumn('Rank', renderer, markup=1)
+        column = gtk.TreeViewColumn('Rank', renderer, 
+                markup=models.CharacterSkillsModel.C_RANK)
         column.set_property("expand", True)
         treeview.append_column(column)
 
 
-        column = gtk.TreeViewColumn('Points', renderer, markup=2)
+        column = gtk.TreeViewColumn('Points', renderer,
+                markup=models.CharacterSkillsModel.C_SKILLPOINTS)
         column.set_property("expand", True)
         treeview.append_column(column)
 
-
-        column = gtk.TreeViewColumn('Level', renderer, markup=3)
+        column = gtk.TreeViewColumn('Level', renderer, 
+                markup=models.CharacterSkillsModel.C_LEVEL)
         column.set_property("expand", True)
         treeview.append_column(column)
 
index 41d3f77..c83415d 100644 (file)
@@ -1,10 +1,10 @@
 import gtk
 
 class AccountsModel(gtk.ListStore):
-    C_UID, C_APIKEY = range(2)
+    C_UID, C_APIKEY, C_CHARS = range(3)
 
     def __init__(self, controller):
-        gtk.ListStore.__init__(self, str, str)
+        gtk.ListStore.__init__(self, str, str, str)
         self.controller = controller
         self.get_accounts()
 
@@ -18,7 +18,14 @@ class AccountsModel(gtk.ListStore):
 
         for uid, key in accts_dict.items():
             liter = self.append()
-            self.set(liter, self.C_UID, uid, self.C_APIKEY, key)
+            chars = self.controller.get_chars_from_acct(uid)
+            if chars:
+                char_str = ', '.join(chars)
+                char_str = "<small>%s</small>" % char_str
+            else:
+                char_str = ""
+
+            self.set(liter, self.C_UID, uid, self.C_APIKEY, key, self.C_CHARS, char_str)
         
 
 
@@ -87,4 +94,3 @@ class CharacterSkillsModel(gtk.ListStore):
                                       self.C_SKILLPOINTS, "SP: %d" % trained.skillpoints,
                                       self.C_LEVEL, "Level %d" % trained.level)
 
-