Index: /pykoticon/trunk/bin/pykoticon
===================================================================
--- /pykoticon/trunk/bin/pykoticon (revision 64)
+++ /pykoticon/trunk/bin/pykoticon (revision 65)
@@ -27,13 +27,18 @@
 import urllib
 import urllib2
-
-try :
-    import win32api
-    import win32net
-    import win32netcon
-    hasWindowsExtensions = 1
-except ImportError :    
-    hasWindowsExtensions = 0
-    raise ImportError, "Mark Hammond's Win32 Extensions are missing. Please install them."
+import locale
+import gettext
+
+if sys.platform == "win32" :
+    isWindows = 1
+    try :
+        import win32api
+        import win32net
+        import win32netcon
+    except ImportError :    
+        raise ImportError, "Mark Hammond's Win32 Extensions are missing. Please install them."
+else :        
+    isWindows = 0
+    import pwd
     
 try :    
@@ -48,4 +53,28 @@
 DUMPYKOTA_URL = "http://cgi.librelogiciel.com/cgi-bin/dumpykota.cgi"
 
+def getCurrentUserName() :
+    """Retrieves the current user's name."""
+    if isWindows :
+        return win32api.GetUserName()
+    else :    
+        try :
+            return pwd.getpwuid(os.geteuid())[0]
+        except :
+            return "** Unknown **"
+        
+class Printer :
+    """A class for PyKota Printers."""
+    def __init__(self, printername, priceperpage, priceperjob):
+        """Initialize printer datas."""
+        self.PrinterName = printername
+        try :
+            self.PricePerPage = float(priceperpage)
+        except (ValueError, TypeError) :
+            self.PricePerPage = 0.0
+        try :
+            self.PricePerJob = float(priceperjob)
+        except (ValueError, TypeError) :
+            self.PricePerJob = 0.0
+
 class UserQuota :
     """A class for PyKota User Print Quota entries."""
@@ -71,5 +100,5 @@
     def __init__(self, username, userinfo, userquotas) :
         """Initialize user datas."""
-        self.Name = username
+        self.UserName = username
         self.LimitBy = userinfo["limitby"][0].lower()
         try :
@@ -111,5 +140,5 @@
             lines = u.readlines()
         except IOError, msg :    
-            raise IOError, "Unable to retrieve %s : %s" % (url, msg)
+            raise IOError, _("Unable to retrieve %s : %s") % (url, msg)
         else :    
             u.close()
@@ -123,5 +152,5 @@
                                 for fieldname in fieldnames ])
             except :    
-                raise ValueError, "Invalid datas retrieved from %s" % url
+                raise ValueError, _("Invalid datas retrieved from %s") % url
         return answer
         
@@ -162,10 +191,11 @@
     def __init__(self, parent, quotas) :
         gridlib.Grid.__init__(self, parent, -1)
+        sys.stderr.write("%s\n" % dir(self))
         self.CreateGrid(len(quotas), 4)
         self.EnableEditing(False)
-        self.SetColLabelValue(0, "Page Counter")
-        self.SetColLabelValue(1, "Soft Limit")
-        self.SetColLabelValue(2, "Hard Limit")
-        self.SetColLabelValue(3, "Date Limit")
+        self.SetColLabelValue(0, _("Page Counter"))
+        self.SetColLabelValue(1, _("Soft Limit"))
+        self.SetColLabelValue(2, _("Hard Limit"))
+        self.SetColLabelValue(3, _("Date Limit"))
         attr = gridlib.GridCellAttr()
         attr.SetAlignment(wx.ALIGN_RIGHT, wx.ALIGN_RIGHT)
@@ -195,4 +225,5 @@
             attr.SetBackgroundColour(colour)        
             self.SetRowAttr(i, attr)
+        self.AutoSize()
             
 class PyKotIcon(wxPython.wx.wxFrame):
@@ -200,6 +231,6 @@
     def __init__(self, parent, id):
         wxPython.wx.wxFrame.__init__(self, parent, -1, \
-               "PyKota Print Quota for user %s" % self.getCurrentUserName(), \
-               # size=(640, 480), \
+               _("PyKota Print Quota for user %s") % getCurrentUserName(), \
+               size = (460, -1), \
                style = wxPython.wx.wxDEFAULT_FRAME_STYLE | wxPython.wx.wxNO_FULL_REPAINT_ON_RESIZE)
         self.greenicon = wxPython.wx.wxIcon(os.path.join("..", "icons", "pykoticon-green.ico"), \
@@ -223,6 +254,6 @@
                                           self.OnTaskBarClose)
         self.menu = wxPython.wx.wxMenu()
-        self.menu.Append(self.TBMENU_RESTORE, "Show Print Quota")
-        self.menu.Append(self.TBMENU_CLOSE, "Quit")
+        self.menu.Append(self.TBMENU_RESTORE, _("Show Print Quota"))
+        self.menu.Append(self.TBMENU_CLOSE, _("Quit"))
         
         wxPython.wx.EVT_CLOSE(self, self.OnClose)
@@ -235,10 +266,6 @@
         self.networkInterface = CGINetworkInterface(DUMPYKOTA_URL)
         self.inTimer = False
-        self.chrono.Start(200) # first time in 0.25 second
-
-    def getCurrentUserName(self) :
-        """Returns the name of the current user."""
-        return win32api.GetUserName()
-        
+        self.chrono.Start(250) # first time in 0.25 second
+
     def OnChronoTimer(self, event) :
         """Retrieves user's data quota information."""
@@ -248,5 +275,5 @@
         if self.inTimer is False : # avoids re-entrance
             self.inTimer = True
-            self.User = self.networkInterface.getUser(self.getCurrentUserName())
+            self.User = self.networkInterface.getUser(getCurrentUserName())
             if self.User.LimitBy == "balance" :
                 if self.User.Balance <= 0.0 :
@@ -269,16 +296,9 @@
                 else :    
                     self.tbicon.SetIcon(self.greenicon, "PyKotIcon")
-                if not self.IsIconized() :    
-                    self.Iconize(True)
-                if self.IsShown():    
-                    self.Hide()
                 if hasattr(self, "quotasgrid") :    
+                    self.quotasgrid.Close()
                     self.quotasgrid.Destroy()
                     del self.quotasgrid
                 self.quotasgrid = PyKotIconGrid(self, self.User.Quotas)    
-                if self.IsIconized() :
-                    self.Iconize(False)
-                if not self.IsShown() :
-                    self.Show(True)
             self.inTimer = False
         # Now we want it every 3 minutes    
@@ -327,4 +347,12 @@
 def main():
     """Program's entry point."""
+    try :
+        locale.setlocale(locale.LC_ALL, "")
+    except (locale.Error, IOError) :
+        sys.stderr.write("Problem while setting locale.\n")
+    try :
+        gettext.install("pykoticon")
+    except :
+        gettext.NullTranslations().install()
     app = PyKotIconApp()
     app.MainLoop()
@@ -345,8 +373,8 @@
         username = sys.argv[2] 
     else :    
-        username = win32api.GetUserName()
+        username = getCurrentUserName()
     net = CGINetworkInterface(DUMPYKOTA_URL)
     user = net.getUser(username)
-    print "UserName : ", user.Name
+    print "UserName : ", user.UserName
     print "LimitBy : ", user.LimitBy
     print "Balance : ", user.Balance
