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