2 # mEveMon - A character monitor for EVE Online
3 # Copyright (c) 2010 Ryan and Danny Campbell, and the mEveMon Team
5 # mEveMon is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # mEveMon is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 import ui.models as models
28 class CharacterSheetUI:
31 def __init__(self, controller, char_name, uid):
32 self.controller = controller
33 self.char_name = char_name
37 self.skills_model = None
42 def build_window(self):
43 # TODO: this is a really long and ugly function, split it up somehow
45 self.win = hildon.StackableWindow()
46 hildon.hildon_gtk_window_set_progress_indicator(self.win, 1)
50 # NOTE: we probably want a window-specific menu for this page, but the
51 # main appmenu works for now
52 menu = Menu(self.win, self.controller)
53 # Attach menu to the window
54 self.win.set_app_menu(menu)
56 pannable_area = hildon.PannableArea()
58 self.char_id = self.controller.char_name2id(self.char_name)
60 self.sheet = self.controller.get_char_sheet(self.uid, self.char_id)
62 self.win.set_title(self.char_name)
65 hbox = gtk.HBox(False, 0)
66 info_vbox = gtk.VBox(False, 0)
68 portrait = gtk.Image()
69 portrait.set_from_file(self.controller.get_portrait(self.char_name, 256))
72 hbox.pack_start(portrait, False, False, 10)
73 hbox.pack_start(info_vbox, False, False, 5)
75 vbox = gtk.VBox(False, 0)
76 pannable_area.add_with_viewport(vbox)
78 vbox.pack_start(hbox, False, False, 0)
80 self.fill_info(info_vbox)
81 self.fill_stats(info_vbox)
83 separator = gtk.HSeparator()
84 vbox.pack_start(separator, False, False, 5)
88 self.add_label("<big>Skill in Training:</big>", vbox, align='normal')
90 self.display_skill_in_training(vbox)
92 separator = gtk.HSeparator()
93 vbox.pack_start(separator, False, False, 0)
96 self.add_label("<big>Skills:</big>", vbox, align='normal')
98 skills_treeview = hildon.GtkTreeView(gtk.HILDON_UI_MODE_NORMAL)
99 self.skills_model = models.CharacterSkillsModel(self.controller, self.char_id)
100 skills_treeview.set_model(self.skills_model)
101 self.add_columns_to_skills_view(skills_treeview)
102 vbox.pack_start(skills_treeview, False, False, 1)
104 self.win.add(pannable_area)
107 hildon.hildon_gtk_window_set_progress_indicator(self.win, 0)
109 # if we start the timer too early, get_is_topmost() returns False
110 self.timer = gobject.timeout_add_seconds(self.UPDATE_INTERVAL, self.update_live_sp)
112 self.win.connect("destroy", self.back)
114 def back(self, widget):
115 gobject.source_remove(self.timer)
116 gtk.Window.destroy(self.win)
119 def display_skill_in_training(self, vbox):
120 skill = self.controller.get_skill_in_training(self.uid, self.char_id)
122 if skill.skillInTraining:
124 skilltree = self.controller.get_skill_tree()
126 # I'm assuming that we will always find a skill with the skill ID
127 for group in skilltree.skillGroups:
128 found_skill = group.skills.Get(skill.trainingTypeID, False)
130 skill_name = found_skill.typeName
133 self.add_label("%s <small>(Level %d)</small>" % (skill_name, skill.trainingToLevel),
134 vbox, align='normal')
135 self.add_label("<small>start time: %s\t\tend time: %s</small>"
136 %(time.ctime(skill.trainingStartTime),
137 time.ctime(skill.trainingEndTime)), vbox, align='normal')
139 progressbar = gtk.ProgressBar()
140 fraction_completed = (time.time() - skill.trainingStartTime) / \
141 (skill.trainingEndTime - skill.trainingStartTime)
143 progressbar.set_fraction(fraction_completed)
144 align = gtk.Alignment(0.5, 0.5, 0.5, 0)
145 vbox.pack_start(align, False, False, 5)
147 align.add(progressbar)
150 self.add_label("<small>No skills are currently being trained</small>",
151 vbox, align='normal')
155 def fill_info(self, box):
156 self.add_label("<big><big>%s</big></big>" % self.sheet.name, box)
157 self.add_label("<small>%s %s %s</small>" % (self.sheet.gender,
158 self.sheet.race, self.sheet.bloodLine), box)
159 self.add_label("", box, markup=False)
160 self.add_label("<small><b>Corp:</b> %s</small>" % self.sheet.corporationName, box)
161 self.add_label("<small><b>Balance:</b> %s ISK</small>" %
162 util.comma(self.sheet.balance), box)
164 self.live_sp_val = self.controller.get_sp(self.uid, self.char_id)
165 self.live_sp = self.add_label("<small><b>Total SP:</b> %s</small>" %
166 util.comma(int(self.live_sp_val)), box)
168 self.spps = self.controller.get_spps(self.uid, self.char_id)[0]
171 def fill_stats(self, box):
173 atr = self.sheet.attributes
175 self.add_label("<small><b>I: </b>%d <b>M: </b>%d <b>C: </b>%d " \
176 "<b>P: </b>%d <b>W: </b>%d</small>" % (atr.intelligence,
177 atr.memory, atr.charisma, atr.perception, atr.willpower), box)
180 def add_columns_to_skills_view(self, treeview):
181 #Column 0 for the treeview
182 renderer = gtk.CellRendererText()
183 column = gtk.TreeViewColumn('Skill Name', renderer,
184 markup=models.CharacterSkillsModel.C_NAME)
185 column.set_property("expand", True)
186 treeview.append_column(column)
188 #Column 1 for the treeview
189 column = gtk.TreeViewColumn('Rank', renderer,
190 markup=models.CharacterSkillsModel.C_RANK)
191 column.set_property("expand", True)
192 treeview.append_column(column)
195 column = gtk.TreeViewColumn('Points', renderer,
196 markup=models.CharacterSkillsModel.C_SKILLPOINTS)
197 column.set_property("expand", True)
198 treeview.append_column(column)
201 column = gtk.TreeViewColumn('Level', renderer,
202 markup=models.CharacterSkillsModel.C_LEVEL)
203 column.set_property("expand", True)
204 treeview.append_column(column)
207 def refresh_clicked(self, button):
208 hildon.hildon_gtk_window_set_progress_indicator(self.win, 1)
209 self.skills_model.get_skills()
210 hildon.hildon_gtk_window_set_progress_indicator(self.win, 0)
213 def update_live_sp(self):
214 self.live_sp_val = self.live_sp_val + self.spps * self.UPDATE_INTERVAL
215 self.live_sp.set_label("<small><b>Total SP:</b> %s</small>" %
216 util.comma(int(self.live_sp_val)))
220 def add_label(self, text, box, markup=True, align='left'):
221 label = gtk.Label(text)
223 label.set_use_markup(True)
225 label.set_alignment(0, 0.5)
227 box.pack_start(label, False, False)