Removed legacy key support, added custom key support
[mevemon] / package / src / ui / models.py
1 import gtk
2 import util
3
4 class AccountsModel(gtk.ListStore):
5
6     # userID no longer exists, we want keyID
7     # api key becomes verification code... --danny
8     C_KID, C_VCODE, C_CHARS = range(3)
9
10     def __init__(self, controller):
11         gtk.ListStore.__init__(self, str, str, str)
12         self.controller = controller
13         self.get_accounts()
14
15     def get_accounts(self):
16         self.clear()
17
18         accts_dict = self.controller.settings.get_accounts()
19
20         if not accts_dict:
21             return None
22
23         for key_id, key in accts_dict.items():
24             liter = self.append()
25             chars, ids = self.controller.get_chars_from_acct(key_id)
26             if chars:
27                 char_str = ', '.join(chars)
28                 char_str = "<small>%s</small>" % char_str
29             else:
30                 char_str = ""
31
32             self.set(liter, self.C_KID, key_id, self.C_VCODE, key, self.C_CHARS, char_str)
33         
34
35
36 class CharacterListModel(gtk.ListStore):
37
38     C_PORTRAIT, C_NAME, C_KID = range(3)
39
40     def __init__(self, controller):
41         gtk.ListStore.__init__(self, gtk.gdk.Pixbuf, str, str)
42         self.controller = controller
43         # should we do this on initialization?
44         self.get_characters()
45
46     def get_characters(self):
47         self.clear()
48         
49         char_list = self.controller.get_characters()
50
51         for name, icon, key_id in char_list:
52             liter = self.append()
53             self.set(liter, self.C_PORTRAIT, self._set_pix(icon), self.C_NAME, name, self.C_KID, key_id)
54
55     def _set_pix(self, filename):
56         pixbuf = gtk.gdk.pixbuf_new_from_file(filename)
57         return pixbuf
58
59
60 class CharacterSkillsModel(gtk.ListStore):
61     C_NAME, C_RANK, C_SKILLPOINTS, C_LEVEL = range(4)
62
63     SP = [0, 250, 1414, 8000, 45255, 256000]
64
65     def __init__(self, controller, charID):
66         gtk.ListStore.__init__(self, str, str, str, str)
67         self.controller = controller
68         self.charID = charID
69         self.get_skills()
70
71     def get_skills(self):
72         self.clear()
73         
74         key_id = self.controller.charid2key_id(self.charID)
75
76         self.sheet = self.controller.get_char_sheet(key_id, self.charID)
77         
78         skilltree = self.controller.get_skill_tree()
79
80         for g in skilltree.skillGroups:
81
82             skills_trained_in_this_group = False
83
84             for skill in g.skills:
85
86                 trained = self.sheet.skills.Get(skill.typeID, False)
87                 
88                 if trained:
89
90                     if not skills_trained_in_this_group:
91
92                         #TODO: add as a heading/category
93                         skills_trained_in_this_group = True
94                     
95                     # add row for this skill
96                     liter = self.append()
97                     self.set(liter, self.C_NAME, "%s" % skill.typeName,
98                                       self.C_RANK, "<small>(Rank %d)</small>" % skill.rank,
99                                       self.C_SKILLPOINTS, "SP: %s" % util.comma(trained.skillpoints),
100                                       self.C_LEVEL, "Level %d" % trained.level)
101