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