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/>.
19 # Based on Ry's Fremantle Python code. --danny
29 about_name = 'mEveMon'
30 about_text = ('Mobile character monitor for EVE Online')
31 about_authors = ['Ryan Campbell','Danny Campbell']
32 about_website = 'http://mevemon.garage.maemo.org'
35 menu_items = ("Settings", "About", "Refresh")
37 def __init__(self, controller):
38 self.controller = controller
40 gtk.set_application_name("mEveMon")
42 # create the main window
44 win.connect("destroy", self.controller.quit)
46 progress_bar = hildon.hildon_banner_show_progress(win, None, "Loading overview...")
47 progress_bar.set_fraction( 0.4 )
50 menu = self.create_menu(win)
51 # Attach menu to the window
54 self.char_model = self.create_char_model()
55 treeview = gtk.TreeView( model = self.char_model )
56 treeview.connect( 'row-activated', self.build_window )
57 treeview.set_model(self.char_model)
58 self.add_columns_to_treeview(treeview)
60 win.add_with_scrollbar(treeview)
63 progress_bar.set_fraction( 1 )
64 progress_bar.destroy()
66 def build_window(self, treeview, path, view_column):
70 progress_bar = hildon.hildon_banner_show_progress(win, None, "Loading character sheet...")
71 progress_bar.set_fraction( 0.4 )
74 # NOTE: we probably want a window-specific menu for this page, but the
75 # main appmenu works for now
76 menu = self.create_menu(win)
77 # Attach menu to the window
80 #pannable_area = hildon.PannableArea()
82 model = treeview.get_model()
83 miter = model.get_iter(path)
85 # column 0 is the portrait, column 1 is name
87 char_name = model.get_value(miter, 1)
88 char_id = self.controller.char_name2id(char_name)
89 sheet = self.controller.get_char_sheet(char_id)
91 win.set_title(char_name)
93 skillLabel = gtk.Label("Skills")
95 name = gtk.Label("Name: %s" % char_name)
96 name.set_alignment(0, 0.5)
98 race = gtk.Label("%s %s %s" % (sheet.gender, sheet.race,
100 race.set_alignment(0, 0.5)
102 corp = gtk.Label("Corp: %s" % sheet.corporationName)
103 corp.set_alignment(0, 0.5)
105 balance = gtk.Label("Balance: %s ISK" % sheet.balance)
106 balance.set_alignment(0, 0.5)
108 intel = gtk.Label("Intelligence: %d" % sheet.attributes.intelligence)
109 intel.set_alignment(0, 0.5)
110 mem = gtk.Label("Memory: %d" % sheet.attributes.memory)
111 mem.set_alignment(0, 0.5)
112 char = gtk.Label("Charisma: %d" % sheet.attributes.charisma)
113 char.set_alignment(0, 0.5)
114 percep = gtk.Label("Perception: %d" % sheet.attributes.perception)
115 percep.set_alignment(0, 0.5)
116 wp = gtk.Label("Willpower: %d" % sheet.attributes.willpower)
117 wp.set_alignment(0, 0.5)
118 blank_label = gtk.Label('')
119 blank_label.set_alignment(0, 0.5)
121 portrait = gtk.Image()
122 portrait.set_from_file(self.controller.get_portrait(char_name, 256))
125 hbox = gtk.HBox(False, 0)
127 info_vbox = gtk.VBox(False, 0)
128 info_vbox.pack_start(name, False, False, 1)
129 info_vbox.pack_start(race, False, False, 1)
130 info_vbox.pack_start(corp, False, False, 1)
131 info_vbox.pack_start(balance, False, False, 1)
133 info_vbox.pack_start(blank_label, False, False, 1)
135 info_vbox.pack_start(intel, False, False, 1)
136 info_vbox.pack_start(mem, False, False, 1)
137 info_vbox.pack_start(char, False, False, 1)
138 info_vbox.pack_start(percep, False, False, 1)
139 info_vbox.pack_start(wp, False, False, 1)
141 hbox.pack_start(portrait, False, False, 10)
142 hbox.pack_start(info_vbox, False, False, 5)
144 vbox = gtk.VBox(False, 0)
146 vbox.pack_start(hbox, False, False, 0)
147 vbox.pack_start(skillLabel, False, False, 5)
149 skills_model = self.create_skills_model(sheet)
150 skills_treeview = gtk.TreeView( model = skills_model )
151 skills_treeview.set_model(skills_model)
152 self.add_columns_to_skills_view(skills_treeview)
154 vbox.pack_start(skills_treeview, False, False, 0)
156 win.add_with_scrollbar(vbox)
159 progress_bar.set_fraction( 1 )
160 progress_bar.destroy()
162 def add_columns_to_skills_view(self, treeview):
163 #Column 0 for the treeview
164 renderer = gtk.CellRendererText()
165 column = gtk.TreeViewColumn('Skill Name', renderer, text=0)
166 column.set_property("expand", True)
167 treeview.append_column(column)
169 #Column 1 for the treeview
170 renderer = gtk.CellRendererText()
171 column = gtk.TreeViewColumn('Skill Info', renderer, text=1)
172 column.set_property("expand", True)
173 treeview.append_column(column)
175 def create_skills_model(self, sheet):
177 lstore = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING)
179 skilltree = self.controller.get_skill_tree()
181 sp = [0, 250, 1414, 8000, 45255, 256000]
183 for g in skilltree.skillGroups:
185 skills_trained_in_this_group = False
187 for skill in g.skills:
189 trained = sheet.skills.Get(skill.typeID, False)
193 if not skills_trained_in_this_group:
195 #TODO: add as a heading/category
196 skills_trained_in_this_group = True
198 # add row for this skill
199 liter = lstore.append()
200 lstore.set(liter, 0, "%s (Rank %d)" % (skill.typeName, skill.rank), 1, "SP: %d Level %d" % (trained.skillpoints, trained.level))
204 def create_char_model(self):
205 lstore = gtk.ListStore(gtk.gdk.Pixbuf, gobject.TYPE_STRING)
206 #get icon and name and put in a liststore
207 self.fill_char_model(lstore)
210 def fill_char_model(self, lstore):
211 char_list = self.controller.get_characters()
212 for name, icon in char_list:
213 liter = lstore.append()
214 lstore.set(liter, 1, name, 0, self.set_pix(icon))
216 def update_model(self, lstore):
218 self.fill_char_model(lstore)
220 def set_pix(self, filename):
221 pixbuf = gtk.gdk.pixbuf_new_from_file(filename)
224 def add_columns_to_treeview(self, treeview):
225 #Column 0 for the treeview
226 renderer = gtk.CellRendererPixbuf()
227 column = gtk.TreeViewColumn()
228 column.pack_start(renderer, True)
229 column.add_attribute(renderer, "pixbuf", 0)
230 treeview.append_column(column)
232 #Column 1 for the treeview
233 renderer = gtk.CellRendererText()
234 column = gtk.TreeViewColumn('Character Name', renderer, text=1)
235 column.set_property("expand", True)
236 treeview.append_column(column)
239 def settings_clicked(self, button, window):
241 dialog = gtk.Dialog()
243 #get the vbox to pack all the settings into
246 dialog.set_transient_for(window)
247 dialog.set_title("Settings")
249 uidLabel = gtk.Label("User ID:")
250 uidLabel.set_justify(gtk.JUSTIFY_LEFT)
253 uidEntry = gtk.Entry()
254 uidEntry.set_text(self.controller.get_uid())
255 uidEntry.set_property('is_focus', False)
259 apiLabel = gtk.Label("API key:")
260 apiLabel.set_justify(gtk.JUSTIFY_LEFT)
263 apiEntry = gtk.Entry()
264 apiEntry.set_text(self.controller.get_api_key())
265 apiEntry.set_property('is_focus', False)
269 ok_button = dialog.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
270 help_button = dialog.add_button(gtk.STOCK_HELP, gtk.RESPONSE_HELP)
274 result = dialog.run()
276 if result == gtk.RESPONSE_OK:
277 self.controller.set_api_key(apiEntry.get_text())
278 self.controller.set_uid(uidEntry.get_text())
279 self.update_model(self.char_model)
285 def about_clicked(self, button):
287 dialog = gtk.AboutDialog()
288 dialog.set_website(self.about_website)
289 dialog.set_website_label(self.about_website)
290 dialog.set_name(self.about_name)
291 dialog.set_authors(self.about_authors)
292 dialog.set_comments(self.about_text)
293 dialog.set_version(self.app_version)
297 def refresh_clicked(self, button, window):
298 self.update_model(self.char_model)
300 def create_menu(self, window):
302 for command in self.menu_items:
303 button = gtk.MenuItem( command )
304 if command == "About":
305 button.connect("activate", self.about_clicked)
306 elif command == "Settings":
307 button.connect("activate", self.settings_clicked, window)
308 elif command == "Refresh":
309 button.connect("activate", self.refresh_clicked, window)
311 assert False, command
312 # Add entry to the view menu
317 if __name__ == "__main__":