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://example.site.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 # will probably need to refer to http://maemo.org/community/maemo-developers/gtktreeview_issue/ for sample code again when we make these clickable --danny
55 self.char_model = self.create_char_model()
56 treeview = gtk.TreeView( model = self.char_model )
57 treeview.connect( 'row-activated', self.build_window )
58 treeview.set_model(self.char_model)
59 self.add_columns_to_treeview(treeview)
64 progress_bar.set_fraction( 1 )
65 progress_bar.destroy()
67 def build_window(self, treeview, path, view_column):
71 progress_bar = hildon.hildon_banner_show_progress(win, None, "Loading character sheet...")
72 progress_bar.set_fraction( 0.4 )
75 # NOTE: we probably want a window-specific menu for this page, but the
76 # main appmenu works for now
77 menu = self.create_menu(win)
78 # Attach menu to the window
81 #pannable_area = hildon.PannableArea()
83 model = treeview.get_model()
84 miter = model.get_iter(path)
86 # column 0 is the portrait, column 1 is name
88 char_name = model.get_value(miter, 1)
89 char_id = self.controller.char_name2id(char_name)
90 sheet = self.controller.get_char_sheet(char_id)
92 win.set_title(char_name)
94 skillLabel = gtk.Label("Skills")
96 # TODO: replace these with api calls
100 name = gtk.Label("Name: %s" % char_name)
101 name.set_alignment(0, 0.5)
103 corp = gtk.Label("Corp: %s" % corp_name)
104 corp.set_alignment(0, 0.5)
106 balance = gtk.Label("Balance: %s ISK" % sheet.balance )
107 balance.set_alignment(0, 0.5)
109 sp = gtk.Label("Skill points: %s" % skill_points)
110 sp.set_alignment(0, 0.5)
112 portrait = gtk.Image()
113 portrait.set_from_file(self.controller.get_portrait(char_name, 256))
116 hbox = gtk.HBox(False, 0)
118 info_vbox = gtk.VBox(False, 0)
119 info_vbox.pack_start(name, False, False, 1)
120 info_vbox.pack_start(corp, False, False, 1)
121 info_vbox.pack_start(balance, False, False, 1)
122 info_vbox.pack_start(sp, False, False, 1)
124 hbox.pack_start(portrait, False, False, 10)
125 hbox.pack_start(info_vbox, False, False, 5)
126 #hbox.pack_start(stats_vbox, False, False, 5)
128 vbox = gtk.VBox(False, 0)
129 #pannable_area.add(vbox)
131 vbox.pack_start(hbox, False, False, 0)
132 vbox.pack_start(skillLabel, False, False, 5)
134 # need to make scrollable --danny
135 skills_model = self.create_skills_model(sheet)
136 skills_treeview = gtk.TreeView( model = skills_model )
137 skills_treeview.set_model(skills_model)
138 self.add_columns_to_skills_view(skills_treeview)
140 vbox.pack_start(skills_treeview, False, False, 0)
145 progress_bar.set_fraction( 1 )
146 progress_bar.destroy()
148 def add_columns_to_skills_view(self, treeview):
149 #Column 0 for the treeview
150 renderer = gtk.CellRendererText()
151 column = gtk.TreeViewColumn('Skill Name', renderer, text=0)
152 column.set_property("expand", True)
153 treeview.append_column(column)
155 #Column 1 for the treeview
156 renderer = gtk.CellRendererText()
157 column = gtk.TreeViewColumn('Skill Info', renderer, text=1)
158 column.set_property("expand", True)
159 treeview.append_column(column)
161 def create_skills_model(self, sheet):
163 lstore = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING)
165 skilltree = self.controller.get_skill_tree()
167 sp = [0, 250, 1414, 8000, 45255, 256000]
169 for g in skilltree.skillGroups:
171 skills_trained_in_this_group = False
173 for skill in g.skills:
175 trained = sheet.skills.Get(skill.typeID, False)
179 if not skills_trained_in_this_group:
181 #TODO: add as a heading/category
182 skills_trained_in_this_group = True
184 # add row for this skill
185 liter = lstore.append()
186 lstore.set(liter, 0, "%s (Rank %d)" % (skill.typeName, skill.rank), 1, "SP: %d Level %d" % (trained.skillpoints, trained.level))
190 def create_char_model(self):
191 lstore = gtk.ListStore(gtk.gdk.Pixbuf, gobject.TYPE_STRING)
192 #get icon and name and put in a liststore
193 self.fill_char_model(lstore)
196 def fill_char_model(self, lstore):
197 char_list = self.controller.get_characters()
198 for name, icon in char_list:
199 liter = lstore.append()
200 lstore.set(liter, 1, name, 0, self.set_pix(icon))
202 def update_model(self, lstore):
204 self.fill_char_model(lstore)
206 def set_pix(self, filename):
207 pixbuf = gtk.gdk.pixbuf_new_from_file(filename)
210 def add_columns_to_treeview(self, treeview):
211 #Column 0 for the treeview
212 renderer = gtk.CellRendererPixbuf()
213 column = gtk.TreeViewColumn()
214 column.pack_start(renderer, True)
215 column.add_attribute(renderer, "pixbuf", 0)
216 treeview.append_column(column)
218 #Column 1 for the treeview
219 renderer = gtk.CellRendererText()
220 column = gtk.TreeViewColumn('Character Name', renderer, text=1)
221 column.set_property("expand", True)
222 treeview.append_column(column)
225 def settings_clicked(self, button, window):
227 dialog = gtk.Dialog()
229 #get the vbox to pack all the settings into
232 dialog.set_transient_for(window)
233 dialog.set_title("Settings")
235 uidLabel = gtk.Label("User ID:")
236 uidLabel.set_justify(gtk.JUSTIFY_LEFT)
239 uidEntry = gtk.Entry()
240 uidEntry.set_text(self.controller.get_uid())
241 uidEntry.set_property('is_focus', False)
245 apiLabel = gtk.Label("API key:")
246 apiLabel.set_justify(gtk.JUSTIFY_LEFT)
249 apiEntry = gtk.Entry()
250 apiEntry.set_text(self.controller.get_api_key())
251 apiEntry.set_property('is_focus', False)
255 ok_button = dialog.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
256 help_button = dialog.add_button(gtk.STOCK_HELP, gtk.RESPONSE_HELP)
260 result = dialog.run()
262 if result == gtk.RESPONSE_OK:
263 self.controller.set_api_key(apiEntry.get_text())
264 self.controller.set_uid(uidEntry.get_text())
265 self.update_model(self.char_model)
271 def about_clicked(self, button):
273 dialog = gtk.AboutDialog()
274 dialog.set_website(self.about_website)
275 dialog.set_website_label(self.about_website)
276 dialog.set_name(self.about_name)
277 dialog.set_authors(self.about_authors)
278 dialog.set_comments(self.about_text)
279 dialog.set_version(self.app_version)
283 def refresh_clicked(self, button, window):
284 self.update_model(self.char_model)
286 def create_menu(self, window):
288 for command in self.menu_items:
289 button = gtk.MenuItem( command )
290 if command == "About":
291 button.connect("activate", self.about_clicked)
292 elif command == "Settings":
293 button.connect("activate", self.settings_clicked, window)
294 elif command == "Refresh":
295 button.connect("activate", self.refresh_clicked, window)
297 assert False, command
298 # Add entry to the view menu
303 if __name__ == "__main__":