2 # Based on Ry's Fremantle Python code. --danny
12 about_name = 'mEveMon'
13 about_text = ('Mobile character monitor for EVE Online')
14 about_authors = ['Ryan Campbell','Danny Campbell']
15 about_website = 'http://example.site.org'
18 menu_items = ("Settings", "About", "Refresh")
20 def __init__(self, controller):
21 self.controller = controller
23 gtk.set_application_name("mEveMon")
25 # create the main window
27 win.connect("destroy", self.controller.quit)
29 progress_bar = hildon.hildon_banner_show_progress(win, None, "Loading overview...")
30 progress_bar.set_fraction( 0.4 )
33 menu = self.create_menu(win)
34 # Attach menu to the window
37 # will probably need to refer to http://maemo.org/community/maemo-developers/gtktreeview_issue/ for sample code again when we make these clickable --danny
38 self.char_model = self.create_char_model()
39 treeview = gtk.TreeView( model = self.char_model )
40 treeview.connect( 'row-activated', self.build_window )
41 treeview.set_model(self.char_model)
42 self.add_columns_to_treeview(treeview)
47 progress_bar.set_fraction( 1 )
48 progress_bar.destroy()
50 def build_window(self, treeview, path, view_column):
54 progress_bar = hildon.hildon_banner_show_progress(win, None, "Loading character sheet...")
55 progress_bar.set_fraction( 0.4 )
58 # NOTE: we probably want a window-specific menu for this page, but the
59 # main appmenu works for now
60 menu = self.create_menu(win)
61 # Attach menu to the window
64 #pannable_area = hildon.PannableArea()
66 model = treeview.get_model()
67 miter = model.get_iter(path)
69 # column 0 is the portrait, column 1 is name
71 char_name = model.get_value(miter, 1)
72 char_id = self.controller.char_name2id(char_name)
74 win.set_title(char_name)
76 skillLabel = gtk.Label("Skills")
78 # TODO: replace these with api calls
82 name = gtk.Label("Name: %s" % char_name)
83 name.set_alignment(0, 0.5)
85 corp = gtk.Label("Corp: %s" % corp_name)
86 corp.set_alignment(0, 0.5)
88 balance = gtk.Label("Balance: %s ISK" %
89 self.controller.get_account_balance(char_id))
90 balance.set_alignment(0, 0.5)
92 sp = gtk.Label("Skill points: %s" % skill_points)
93 sp.set_alignment(0, 0.5)
95 portrait = gtk.Image()
96 portrait.set_from_file(self.controller.get_portrait(char_name, 256))
99 hbox = gtk.HBox(False, 0)
101 info_vbox = gtk.VBox(False, 0)
102 info_vbox.pack_start(name, False, False, 1)
103 info_vbox.pack_start(corp, False, False, 1)
104 info_vbox.pack_start(balance, False, False, 1)
105 info_vbox.pack_start(sp, False, False, 1)
107 hbox.pack_start(portrait, False, False, 10)
108 hbox.pack_start(info_vbox, False, False, 5)
109 #hbox.pack_start(stats_vbox, False, False, 5)
111 vbox = gtk.VBox(False, 0)
112 #pannable_area.add(vbox)
114 vbox.pack_start(hbox, False, False, 0)
115 vbox.pack_start(skillLabel, False, False, 5)
120 progress_bar.set_fraction( 1 )
121 progress_bar.destroy()
123 def create_char_model(self):
124 lstore = gtk.ListStore(gtk.gdk.Pixbuf, gobject.TYPE_STRING)
125 #get icon and name and put in a liststore
126 self.fill_char_model(lstore)
129 def fill_char_model(self, lstore):
130 char_list = self.controller.get_characters()
131 for name, icon in char_list:
132 liter = lstore.append()
133 lstore.set(liter, 1, name, 0, self.set_pix(icon))
135 def update_model(self, lstore):
137 self.fill_char_model(lstore)
139 def set_pix(self, filename):
140 pixbuf = gtk.gdk.pixbuf_new_from_file(filename)
143 def add_columns_to_treeview(self, treeview):
144 #Column 0 for the treeview
145 renderer = gtk.CellRendererPixbuf()
146 column = gtk.TreeViewColumn()
147 column.pack_start(renderer, True)
148 column.add_attribute(renderer, "pixbuf", 0)
149 treeview.append_column(column)
151 #Column 1 for the treeview
152 renderer = gtk.CellRendererText()
153 column = gtk.TreeViewColumn('title', renderer, text=1)
154 column.set_property("expand", True)
155 treeview.append_column(column)
158 def settings_clicked(self, button, window):
160 dialog = gtk.Dialog()
162 #get the vbox to pack all the settings into
165 dialog.set_transient_for(window)
166 dialog.set_title("Settings")
168 uidLabel = gtk.Label("User ID:")
169 uidLabel.set_justify(gtk.JUSTIFY_LEFT)
172 uidEntry = gtk.Entry()
173 uidEntry.set_text(self.controller.get_uid())
174 uidEntry.set_property('is_focus', False)
178 apiLabel = gtk.Label("API key:")
179 apiLabel.set_justify(gtk.JUSTIFY_LEFT)
182 apiEntry = gtk.Entry()
183 apiEntry.set_text(self.controller.get_api_key())
184 apiEntry.set_property('is_focus', False)
188 ok_button = dialog.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
189 help_button = dialog.add_button(gtk.STOCK_HELP, gtk.RESPONSE_HELP)
193 result = dialog.run()
195 if result == gtk.RESPONSE_OK:
196 self.controller.set_api_key(apiEntry.get_text())
197 self.controller.set_uid(uidEntry.get_text())
198 self.update_model(self.char_model)
204 def about_clicked(self, button):
206 dialog = gtk.AboutDialog()
207 dialog.set_website(self.about_website)
208 dialog.set_website_label(self.about_website)
209 dialog.set_name(self.about_name)
210 dialog.set_authors(self.about_authors)
211 dialog.set_comments(self.about_text)
212 dialog.set_version(self.app_version)
216 def refresh_clicked(self, button, window):
217 self.update_model(self.char_model)
219 def create_menu(self, window):
221 for command in self.menu_items:
222 button = gtk.MenuItem( command )
223 if command == "About":
224 button.connect("activate", self.about_clicked)
225 elif command == "Settings":
226 button.connect("activate", self.settings_clicked, window)
227 elif command == "Refresh":
228 button.connect("activate", self.refresh_clicked, window)
230 assert False, command
231 # Add entry to the view menu
236 if __name__ == "__main__":