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