From: Ryan Campbell Date: Mon, 19 Apr 2010 16:13:26 +0000 (-0600) Subject: only call auth() once, and make it a member of mevemon class. X-Git-Tag: v0.1~39 X-Git-Url: http://git.maemo.org/git/?p=mevemon;a=commitdiff_plain;h=ac50ed43a8c3a28344a0070eeda09e32477f22b6 only call auth() once, and make it a member of mevemon class. refresh self.auth when the settings are changed. I'm not sure if this makes any REAL difference, but it seems a bit redundant to call auth() every time we want to do something with the eveapi. --- diff --git a/mevemon.py b/mevemon.py index d39e708..16a3954 100644 --- a/mevemon.py +++ b/mevemon.py @@ -17,8 +17,8 @@ class mEveMon(): def __init__(self): self.program = hildon.Program() self.program.__init__() - self.config = None self.gconf = gnome.gconf.client_get_default() + self.set_auth() self.ui = ui.mEveMonUI(self) def run(self): @@ -39,13 +39,14 @@ class mEveMon(): def set_uid(self, uid): self.gconf.set_string("/apps/maemo/mevemon/eve_uid", uid) - def eveapi_connect(self): + + def set_auth(self): uid = self.get_uid() api_key = self.get_api_key() cached_api = eveapi.EVEAPIConnection( cacheHandler = apicache.cache_handler( debug = False ) ) try: - auth = cached_api.auth( userID = uid, apiKey = api_key ) + self.auth = cached_api.auth( userID = uid, apiKey = api_key ) except eveapi.Error, e: # if we can't, return the error message/pic --danny return None @@ -55,17 +56,8 @@ class mEveMon(): # apitest.py example... --danny raise - return auth - - def get_alliances(self, charID): - auth = eveapi_connect() - - if auth: - alliance_list = auth.character(charID) - - - - + def get_auth(self): + return self.auth # really quick hack to get character list. doesn't handle errors well, and # if it can't get the gconf settings it just returns the placeholders, when @@ -76,10 +68,8 @@ class mEveMon(): # error message --danny placeholder_chars = [("Please check your API settings.", "imgs/error.jpg")] - auth = self.eveapi_connect() - try: - api_char_list = auth.account.Characters() + api_char_list = self.auth.account.Characters() # append each char we get to the list we'll return to the UI --danny for character in api_char_list.characters: ui_char_list.append( ( character.name, diff --git a/ui/fremantle/ui.py b/ui/fremantle/ui.py index f4aab76..a155a2b 100644 --- a/ui/fremantle/ui.py +++ b/ui/fremantle/ui.py @@ -21,7 +21,6 @@ class mEveMonUI(): def __init__(self, controller): self.controller = controller - gtk.set_application_name("mEveMon") #create the main window @@ -52,12 +51,15 @@ class mEveMonUI(): win.show_all() def build_window(self, treeview, path, view_column): - print "triggered treeview" - print treeview - print path - print view_column win = hildon.StackableWindow() + # Create menu + # 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 + win.set_app_menu(menu) + model = treeview.get_model() miter = model.get_iter(path) @@ -157,7 +159,9 @@ class mEveMonUI(): 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()