Convert API key to uppercase on input
[mevemon] / package / src / ui / diablo / gui.py
index 2fe9e56..3038f4b 100644 (file)
@@ -22,10 +22,9 @@ import gtk
 import hildon
 import gobject
 
-import glib
-
 from ui import models
 import validation
+import util
 
 class BaseUI():
     menu_items = ("Settings", "About", "Refresh")
@@ -175,6 +174,7 @@ class BaseUI():
         vbox.add(apiEntry)
        
         ok_button = dialog.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
+        cancel_button = dialog.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
 
         dialog.show_all()
         result = dialog.run()
@@ -184,7 +184,8 @@ class BaseUI():
         while not valid_credentials:
             if result == gtk.RESPONSE_OK:
                 uid = uidEntry.get_text()
-                api_key = apiEntry.get_text()
+                # auth() fails if api_key has lower-case characters
+                api_key = apiEntry.get_text().upper()
             
                 try:
                     validation.uid(uid)
@@ -251,6 +252,7 @@ class mEveMonUI(BaseUI):
         # create the treeview --danny
         self.char_model = models.CharacterListModel(self.controller)
         treeview = gtk.TreeView(model = self.char_model)
+        treeview.set_grid_lines(gtk.TREE_VIEW_GRID_LINES_HORIZONTAL)
         treeview.connect('row-activated', character_win.build_window)
         treeview.set_model(self.char_model)
         self.add_columns_to_treeview(treeview)
@@ -285,7 +287,8 @@ class mEveMonUI(BaseUI):
         progress_bar.destroy()
 
 class CharacterSheetUI(BaseUI):
-    UPDATE_INTERVAL = 1
+    #time between live sp updates (in milliseconds)
+    UPDATE_INTERVAL = 1000
 
     def __init__(self, controller):
         self.controller = controller
@@ -358,8 +361,7 @@ class CharacterSheetUI(BaseUI):
 
 
         self.skills_model = models.CharacterSkillsModel(self.controller, self.char_id)
-        skills_treeview = gtk.TreeView(model = skills_model)
-        skills_treeview.set_model(self.skills_model)
+        skills_treeview = gtk.TreeView(model=self.skills_model)
         self.add_columns_to_skills_view(skills_treeview)
 
         vbox.pack_start(skills_treeview, False, False, 0)
@@ -369,6 +371,15 @@ class CharacterSheetUI(BaseUI):
 
         progress_bar.set_fraction(1)
         progress_bar.destroy()
+        
+        # diablo doesnt have a glib module, but gobject module seems to have
+        # the same functions...
+        self.timer = gobject.timeout_add(self.UPDATE_INTERVAL, self.update_live_sp)
+        self.win.connect("destroy", self.back)
+
+    def back(self, widget):
+        gobject.source_remove(self.timer)
+        gtk.Window.destroy(self.win)
 
     def display_skill_in_training(self, vbox):
         skill = self.controller.get_skill_in_training(self.uid, self.char_id)
@@ -412,15 +423,15 @@ class CharacterSheetUI(BaseUI):
             self.sheet.race, self.sheet.bloodLine), box)
         self.add_label("", box, markup=False)
         self.add_label("<small><b>Corp:</b> %s</small>" % self.sheet.corporationName, box)
-        self.add_label("<small><b>Balance:</b> %s ISK</small>" % self.sheet.balance, box)
+        self.add_label("<small><b>Balance:</b> %s ISK</small>" % 
+                util.comma(self.sheet.balance), box)
 
         self.live_sp_val = self.controller.get_sp(self.uid, self.char_id)
-        self.live_sp = self.add_label("<small><b>Total SP:</b> %d</small>" %
-                self.live_sp_val, box)
+        self.live_sp = self.add_label("<small><b>Total SP:</b> %s</small>" %
+                util.comma(int(self.live_sp_val)), box)
         
         self.spps = self.controller.get_spps(self.uid, self.char_id)[0]
 
-        glib.timeout_add_seconds(self.UPDATE_INTERVAL, self.update_live_sp)
 
     def fill_stats(self, box):
 
@@ -466,17 +477,9 @@ class CharacterSheetUI(BaseUI):
 
 
     def update_live_sp(self):
-        # we don't want to keep the timer running in the background
-        # when this callback returns False, the timer destorys itself
-       
-        # TODO: figure out why this doesn't work on the real device
-        #
-        #if not self.win.get_is_topmost():
-        #    return False
-        
-        self.live_sp_val = self.live_sp_val + self.spps * self.UPDATE_INTERVAL
-        self.live_sp.set_label("<small><b>Total SP:</b> %d</small>" %
-                                self.live_sp_val)
+        self.live_sp_val = self.live_sp_val + self.spps * (self.UPDATE_INTERVAL / 1000)
+        self.live_sp.set_label("<small><b>Total SP:</b> %s</small>" %
+                                util.comma(int(self.live_sp_val)))
 
         return True