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/>.
27 about_name = 'mEveMon'
28 about_text = ('Mobile character monitor for EVE Online')
29 about_authors = ['Ryan Campbell', 'Danny Campbell']
30 about_website = 'http://example.site.org'
33 menu_items = ("Settings", "About", "Refresh")
35 def __init__(self, controller):
36 self.controller = controller
37 gtk.set_application_name("mEveMon")
39 #create the main window
40 win = hildon.StackableWindow()
41 win.connect("destroy", self.controller.quit)
43 hildon.hildon_gtk_window_set_progress_indicator(win, 1)
46 menu = self.create_menu(win)
47 # Attach menu to the window
48 win.set_app_menu(menu)
50 pannable_area = hildon.PannableArea()
52 # gtk.HILDON_UI_MODE_NORMAL -> not selection in the treeview
53 # gtk.HILDON_UI_MODE_EDIT -> selection in the treeview
54 treeview = hildon.GtkTreeView(gtk.HILDON_UI_MODE_NORMAL)
55 treeview.connect('row-activated', self.build_window)
57 self.char_model = self.create_char_model()
58 treeview.set_model(self.char_model)
60 self.add_columns_to_treeview(treeview)
62 pannable_area.add(treeview)
64 win.add(pannable_area);
68 hildon.hildon_gtk_window_set_progress_indicator(win, 0)
70 def build_window(self, treeview, path, view_column):
71 win = hildon.StackableWindow()
73 hildon.hildon_gtk_window_set_progress_indicator(win, 1)
76 # NOTE: we probably want a window-specific menu for this page, but the
77 # main appmenu works for now
78 menu = self.create_menu(win)
79 # Attach menu to the window
80 win.set_app_menu(menu)
82 pannable_area = hildon.PannableArea()
84 model = treeview.get_model()
85 miter = model.get_iter(path)
87 # column 0 is the portrait, column 1 is name
89 char_name = model.get_value(miter, 1)
90 char_id = self.controller.char_name2id(char_name)
91 sheet = self.controller.get_char_sheet(char_id)
93 win.set_title(char_name)
95 skillLabel = gtk.Label("Skills")
97 name = gtk.Label("%s" % char_name)
98 name.set_alignment(0, 0.5)
100 race = gtk.Label("%s %s %s" % (sheet.gender, sheet.race,
102 race.set_alignment(0, 0.5)
104 corp = gtk.Label("Corp: %s" % sheet.corporationName)
105 corp.set_alignment(0, 0.5)
107 balance = gtk.Label("Balance: %s ISK" % sheet.balance)
108 balance.set_alignment(0, 0.5)
110 portrait = gtk.Image()
111 portrait.set_from_file(self.controller.get_portrait(char_name, 256))
114 hbox = gtk.HBox(False, 0)
116 info_vbox = gtk.VBox(False, 0)
117 info_vbox.pack_start(name, False, False, 1)
118 info_vbox.pack_start(race, False, False, 1)
119 info_vbox.pack_start(corp, False, False, 1)
120 info_vbox.pack_start(balance, False, False, 1)
122 hbox.pack_start(portrait, False, False, 10)
123 hbox.pack_start(info_vbox, False, False, 5)
124 #hbox.pack_start(stats_vbox, False, False, 5)
126 vbox = gtk.VBox(False, 0)
127 pannable_area.add_with_viewport(vbox)
129 vbox.pack_start(hbox, False, False, 0)
130 vbox.pack_start(skillLabel, False, False, 5)
132 win.add(pannable_area)
135 hildon.hildon_gtk_window_set_progress_indicator(win, 0)
137 def create_char_model(self):
138 lstore = gtk.ListStore(gtk.gdk.Pixbuf, gobject.TYPE_STRING)
140 #get icon and name and put in a liststore
141 self.fill_char_model(lstore)
146 def fill_char_model(self, lstore):
147 char_list = self.controller.get_characters()
149 for name, icon in char_list:
150 liter = lstore.append()
151 lstore.set(liter, 1, name, 0, self.set_pix(icon))
154 def update_model(self, lstore):
156 self.fill_char_model(lstore)
159 def set_pix(self, filename):
160 pixbuf = gtk.gdk.pixbuf_new_from_file(filename)
164 def add_columns_to_treeview(self, treeview):
165 #Column 0 for the treeview
166 renderer = gtk.CellRendererPixbuf()
167 column = gtk.TreeViewColumn()
168 column.pack_start(renderer, True)
169 column.add_attribute(renderer, "pixbuf", 0)
170 treeview.append_column(column)
172 #Column 1 for the treeview
173 renderer = gtk.CellRendererText()
174 column = gtk.TreeViewColumn('title', renderer, text=1)
175 column.set_property("expand", True)
176 treeview.append_column(column)
179 def settings_clicked(self, button, window):
180 dialog = gtk.Dialog()
182 #get the vbox to pack all the settings into
185 dialog.set_transient_for(window)
186 dialog.set_title("Settings")
188 uidLabel = gtk.Label("User ID:")
189 uidLabel.set_justify(gtk.JUSTIFY_LEFT)
192 uidEntry = hildon.Entry(gtk.HILDON_SIZE_FINGER_HEIGHT)
193 uidEntry.set_placeholder("User ID")
194 uidEntry.set_text(self.controller.get_uid())
195 uidEntry.set_property('is_focus', False)
199 apiLabel = gtk.Label("API key:")
200 apiLabel.set_justify(gtk.JUSTIFY_LEFT)
203 apiEntry = hildon.Entry(gtk.HILDON_SIZE_FINGER_HEIGHT)
204 apiEntry.set_placeholder("API Key")
205 apiEntry.set_text(self.controller.get_api_key())
206 apiEntry.set_property('is_focus', False)
210 ok_button = dialog.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
211 help_button = dialog.add_button(gtk.STOCK_HELP, gtk.RESPONSE_HELP)
214 result = dialog.run()
215 if result == gtk.RESPONSE_OK:
216 self.controller.set_api_key(apiEntry.get_text())
217 self.controller.set_uid(uidEntry.get_text())
218 self.controller.set_auth()
219 self.update_model(self.char_model)
227 def about_clicked(self, button):
228 dialog = gtk.AboutDialog()
229 dialog.set_website(self.about_website)
230 dialog.set_website_label(self.about_website)
231 dialog.set_name(self.about_name)
232 dialog.set_authors(self.about_authors)
233 dialog.set_comments(self.about_text)
234 dialog.set_version(self.app_version)
239 def refresh_clicked(self, button, window):
240 self.update_model(self.char_model)
243 def create_menu(self, window):
244 menu = hildon.AppMenu()
246 for command in self.menu_items:
247 # Create menu entries
248 button = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
249 button.set_label(command)
251 if command == "About":
252 button.connect("clicked", self.about_clicked)
253 elif command == "Settings":
254 button.connect("clicked", self.settings_clicked, window)
255 elif command == "Refresh":
256 button.connect("clicked", self.refresh_clicked, window)
258 assert False, command
260 # Add entry to the view menu
268 if __name__ == "__main__":