import hildon
import gobject
-class mEveMonUI():
-
+class BaseUI():
+
about_name = 'mEveMon'
about_text = ('Mobile character monitor for EVE Online')
about_authors = ['Ryan Campbell', 'Danny Campbell']
menu_items = ("Settings", "About", "Refresh")
+
+ def create_menu(self, window):
+ menu = hildon.AppMenu()
+
+ for command in self.menu_items:
+ # Create menu entries
+ button = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
+ button.set_label(command)
+
+ if command == "About":
+ button.connect("clicked", self.about_clicked)
+ elif command == "Settings":
+ button.connect("clicked", self.settings_clicked, window)
+ elif command == "Refresh":
+ button.connect("clicked", self.refresh_clicked, window)
+ else:
+ assert False, command
+
+ # Add entry to the view menu
+ menu.append(button)
+
+ menu.show_all()
+
+ return menu
+
+ def set_pix(self, filename):
+ pixbuf = gtk.gdk.pixbuf_new_from_file(filename)
+ return pixbuf
+
+ def settings_clicked(self, button, window):
+ dialog = gtk.Dialog()
+
+ #get the vbox to pack all the settings into
+ vbox = dialog.vbox
+
+ dialog.set_transient_for(window)
+ dialog.set_title("Settings")
+
+ uidLabel = gtk.Label("User ID:")
+ uidLabel.set_justify(gtk.JUSTIFY_LEFT)
+ vbox.add(uidLabel)
+
+ uidEntry = hildon.Entry(gtk.HILDON_SIZE_FINGER_HEIGHT)
+ uidEntry.set_placeholder("User ID")
+ uidEntry.set_text(self.controller.get_uid())
+ uidEntry.set_property('is_focus', False)
+
+ vbox.add(uidEntry)
+
+ apiLabel = gtk.Label("API key:")
+ apiLabel.set_justify(gtk.JUSTIFY_LEFT)
+ vbox.add(apiLabel)
+
+ apiEntry = hildon.Entry(gtk.HILDON_SIZE_FINGER_HEIGHT)
+ apiEntry.set_placeholder("API Key")
+ apiEntry.set_text(self.controller.get_api_key())
+ apiEntry.set_property('is_focus', False)
+
+ vbox.add(apiEntry)
+
+ ok_button = dialog.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
+ help_button = dialog.add_button(gtk.STOCK_HELP, gtk.RESPONSE_HELP)
+
+ dialog.show_all()
+ result = dialog.run()
+ if result == gtk.RESPONSE_OK:
+ self.controller.set_api_key(apiEntry.get_text())
+ self.controller.set_uid(uidEntry.get_text())
+ self.controller.set_auth()
+ self.update_model(self.char_model)
+
+
+ dialog.destroy()
+
+ return result
+
+
+ def about_clicked(self, button):
+ dialog = gtk.AboutDialog()
+ dialog.set_website(self.about_website)
+ dialog.set_website_label(self.about_website)
+ dialog.set_name(self.about_name)
+ dialog.set_authors(self.about_authors)
+ dialog.set_comments(self.about_text)
+ dialog.set_version(self.app_version)
+ dialog.run()
+ dialog.destroy()
+
+class mEveMonUI(BaseUI):
+
def __init__(self, controller):
self.controller = controller
gtk.set_application_name("mEveMon")
pannable_area = hildon.PannableArea()
+ character_win = CharacterSheetUI(self.controller)
+
# gtk.HILDON_UI_MODE_NORMAL -> not selection in the treeview
# gtk.HILDON_UI_MODE_EDIT -> selection in the treeview
treeview = hildon.GtkTreeView(gtk.HILDON_UI_MODE_NORMAL)
- treeview.connect('row-activated', self.build_window)
+ treeview.connect('row-activated', character_win.build_window)
self.char_model = self.create_char_model()
treeview.set_model(self.char_model)
hildon.hildon_gtk_window_set_progress_indicator(win, 0)
+
+ def create_char_model(self):
+ lstore = gtk.ListStore(gtk.gdk.Pixbuf, gobject.TYPE_STRING)
+
+ #get icon and name and put in a liststore
+ self.fill_char_model(lstore)
+
+ return lstore
+
+
+ def fill_char_model(self, lstore):
+ char_list = self.controller.get_characters()
+
+ for name, icon in char_list:
+ liter = lstore.append()
+ lstore.set(liter, 1, name, 0, self.set_pix(icon))
+
+
+ def update_model(self, lstore):
+ lstore.clear()
+ self.fill_char_model(lstore)
+
+
+ def add_columns_to_treeview(self, treeview):
+ #Column 0 for the treeview
+ renderer = gtk.CellRendererPixbuf()
+ column = gtk.TreeViewColumn()
+ column.pack_start(renderer, True)
+ column.add_attribute(renderer, "pixbuf", 0)
+ treeview.append_column(column)
+
+ #Column 1 for the treeview
+ renderer = gtk.CellRendererText()
+ column = gtk.TreeViewColumn('Character Name', renderer, text=1)
+ column.set_property("expand", True)
+ treeview.append_column(column)
+
+
+ def refresh_clicked(self, button, window):
+ self.update_model(self.char_model)
+
+
+
+class CharacterSheetUI(BaseUI):
+
+ def __init__(self, controller):
+ self.controller = controller
+
+
def build_window(self, treeview, path, view_column):
# TODO: this is a really long and ugly function, split it up somehow
# NOTE: we probably want a window-specific menu for this page, but the
# main appmenu works for now
menu = self.create_menu(win)
- # Attach menu to the window
+ # Attach menu to the window
win.set_app_menu(menu)
pannable_area = hildon.PannableArea()
return lstore
- def create_char_model(self):
- lstore = gtk.ListStore(gtk.gdk.Pixbuf, gobject.TYPE_STRING)
-
- #get icon and name and put in a liststore
- self.fill_char_model(lstore)
-
- return lstore
-
-
- def fill_char_model(self, lstore):
- char_list = self.controller.get_characters()
-
- for name, icon in char_list:
- liter = lstore.append()
- lstore.set(liter, 1, name, 0, self.set_pix(icon))
-
-
- def update_model(self, lstore):
- lstore.clear()
- self.fill_char_model(lstore)
-
-
- def set_pix(self, filename):
- pixbuf = gtk.gdk.pixbuf_new_from_file(filename)
- return pixbuf
-
-
- def add_columns_to_treeview(self, treeview):
- #Column 0 for the treeview
- renderer = gtk.CellRendererPixbuf()
- column = gtk.TreeViewColumn()
- column.pack_start(renderer, True)
- column.add_attribute(renderer, "pixbuf", 0)
- treeview.append_column(column)
-
- #Column 1 for the treeview
- renderer = gtk.CellRendererText()
- column = gtk.TreeViewColumn('Character Name', renderer, text=1)
- column.set_property("expand", True)
- treeview.append_column(column)
-
-
- def settings_clicked(self, button, window):
- dialog = gtk.Dialog()
-
- #get the vbox to pack all the settings into
- vbox = dialog.vbox
-
- dialog.set_transient_for(window)
- dialog.set_title("Settings")
-
- uidLabel = gtk.Label("User ID:")
- uidLabel.set_justify(gtk.JUSTIFY_LEFT)
- vbox.add(uidLabel)
-
- uidEntry = hildon.Entry(gtk.HILDON_SIZE_FINGER_HEIGHT)
- uidEntry.set_placeholder("User ID")
- uidEntry.set_text(self.controller.get_uid())
- uidEntry.set_property('is_focus', False)
-
- vbox.add(uidEntry)
-
- apiLabel = gtk.Label("API key:")
- apiLabel.set_justify(gtk.JUSTIFY_LEFT)
- vbox.add(apiLabel)
-
- apiEntry = hildon.Entry(gtk.HILDON_SIZE_FINGER_HEIGHT)
- apiEntry.set_placeholder("API Key")
- apiEntry.set_text(self.controller.get_api_key())
- apiEntry.set_property('is_focus', False)
-
- vbox.add(apiEntry)
-
- ok_button = dialog.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
- help_button = dialog.add_button(gtk.STOCK_HELP, gtk.RESPONSE_HELP)
-
- dialog.show_all()
- result = dialog.run()
- if result == gtk.RESPONSE_OK:
- self.controller.set_api_key(apiEntry.get_text())
- self.controller.set_uid(uidEntry.get_text())
- self.controller.set_auth()
- self.update_model(self.char_model)
-
-
- dialog.destroy()
-
- return result
-
-
- def about_clicked(self, button):
- dialog = gtk.AboutDialog()
- dialog.set_website(self.about_website)
- dialog.set_website_label(self.about_website)
- dialog.set_name(self.about_name)
- dialog.set_authors(self.about_authors)
- dialog.set_comments(self.about_text)
- dialog.set_version(self.app_version)
- dialog.run()
- dialog.destroy()
-
-
def refresh_clicked(self, button, window):
- self.update_model(self.char_model)
-
-
- def create_menu(self, window):
- menu = hildon.AppMenu()
-
- for command in self.menu_items:
- # Create menu entries
- button = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
- button.set_label(command)
-
- if command == "About":
- button.connect("clicked", self.about_clicked)
- elif command == "Settings":
- button.connect("clicked", self.settings_clicked, window)
- elif command == "Refresh":
- button.connect("clicked", self.refresh_clicked, window)
- else:
- assert False, command
-
- # Add entry to the view menu
- menu.append(button)
-
- menu.show_all()
-
- return menu
-
+ #self.update_model(self.char_model)
+ pass
if __name__ == "__main__":
main()
-