Changeset 65 for pykoticon/trunk
- Timestamp:
- 01/16/05 12:37:47 (20 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykoticon/trunk/bin/pykoticon
r64 r65 27 27 import urllib 28 28 import urllib2 29 30 try : 31 import win32api 32 import win32net 33 import win32netcon 34 hasWindowsExtensions = 1 35 except ImportError : 36 hasWindowsExtensions = 0 37 raise ImportError, "Mark Hammond's Win32 Extensions are missing. Please install them." 29 import locale 30 import gettext 31 32 if sys.platform == "win32" : 33 isWindows = 1 34 try : 35 import win32api 36 import win32net 37 import win32netcon 38 except ImportError : 39 raise ImportError, "Mark Hammond's Win32 Extensions are missing. Please install them." 40 else : 41 isWindows = 0 42 import pwd 38 43 39 44 try : … … 48 53 DUMPYKOTA_URL = "http://cgi.librelogiciel.com/cgi-bin/dumpykota.cgi" 49 54 55 def getCurrentUserName() : 56 """Retrieves the current user's name.""" 57 if isWindows : 58 return win32api.GetUserName() 59 else : 60 try : 61 return pwd.getpwuid(os.geteuid())[0] 62 except : 63 return "** Unknown **" 64 65 class Printer : 66 """A class for PyKota Printers.""" 67 def __init__(self, printername, priceperpage, priceperjob): 68 """Initialize printer datas.""" 69 self.PrinterName = printername 70 try : 71 self.PricePerPage = float(priceperpage) 72 except (ValueError, TypeError) : 73 self.PricePerPage = 0.0 74 try : 75 self.PricePerJob = float(priceperjob) 76 except (ValueError, TypeError) : 77 self.PricePerJob = 0.0 78 50 79 class UserQuota : 51 80 """A class for PyKota User Print Quota entries.""" … … 71 100 def __init__(self, username, userinfo, userquotas) : 72 101 """Initialize user datas.""" 73 self. Name = username102 self.UserName = username 74 103 self.LimitBy = userinfo["limitby"][0].lower() 75 104 try : … … 111 140 lines = u.readlines() 112 141 except IOError, msg : 113 raise IOError, "Unable to retrieve %s : %s"% (url, msg)142 raise IOError, _("Unable to retrieve %s : %s") % (url, msg) 114 143 else : 115 144 u.close() … … 123 152 for fieldname in fieldnames ]) 124 153 except : 125 raise ValueError, "Invalid datas retrieved from %s"% url154 raise ValueError, _("Invalid datas retrieved from %s") % url 126 155 return answer 127 156 … … 162 191 def __init__(self, parent, quotas) : 163 192 gridlib.Grid.__init__(self, parent, -1) 193 sys.stderr.write("%s\n" % dir(self)) 164 194 self.CreateGrid(len(quotas), 4) 165 195 self.EnableEditing(False) 166 self.SetColLabelValue(0, "Page Counter")167 self.SetColLabelValue(1, "Soft Limit")168 self.SetColLabelValue(2, "Hard Limit")169 self.SetColLabelValue(3, "Date Limit")196 self.SetColLabelValue(0, _("Page Counter")) 197 self.SetColLabelValue(1, _("Soft Limit")) 198 self.SetColLabelValue(2, _("Hard Limit")) 199 self.SetColLabelValue(3, _("Date Limit")) 170 200 attr = gridlib.GridCellAttr() 171 201 attr.SetAlignment(wx.ALIGN_RIGHT, wx.ALIGN_RIGHT) … … 195 225 attr.SetBackgroundColour(colour) 196 226 self.SetRowAttr(i, attr) 227 self.AutoSize() 197 228 198 229 class PyKotIcon(wxPython.wx.wxFrame): … … 200 231 def __init__(self, parent, id): 201 232 wxPython.wx.wxFrame.__init__(self, parent, -1, \ 202 "PyKota Print Quota for user %s" % self.getCurrentUserName(), \203 # size=(640, 480), \233 _("PyKota Print Quota for user %s") % getCurrentUserName(), \ 234 size = (460, -1), \ 204 235 style = wxPython.wx.wxDEFAULT_FRAME_STYLE | wxPython.wx.wxNO_FULL_REPAINT_ON_RESIZE) 205 236 self.greenicon = wxPython.wx.wxIcon(os.path.join("..", "icons", "pykoticon-green.ico"), \ … … 223 254 self.OnTaskBarClose) 224 255 self.menu = wxPython.wx.wxMenu() 225 self.menu.Append(self.TBMENU_RESTORE, "Show Print Quota")226 self.menu.Append(self.TBMENU_CLOSE, "Quit")256 self.menu.Append(self.TBMENU_RESTORE, _("Show Print Quota")) 257 self.menu.Append(self.TBMENU_CLOSE, _("Quit")) 227 258 228 259 wxPython.wx.EVT_CLOSE(self, self.OnClose) … … 235 266 self.networkInterface = CGINetworkInterface(DUMPYKOTA_URL) 236 267 self.inTimer = False 237 self.chrono.Start(200) # first time in 0.25 second 238 239 def getCurrentUserName(self) : 240 """Returns the name of the current user.""" 241 return win32api.GetUserName() 242 268 self.chrono.Start(250) # first time in 0.25 second 269 243 270 def OnChronoTimer(self, event) : 244 271 """Retrieves user's data quota information.""" … … 248 275 if self.inTimer is False : # avoids re-entrance 249 276 self.inTimer = True 250 self.User = self.networkInterface.getUser( self.getCurrentUserName())277 self.User = self.networkInterface.getUser(getCurrentUserName()) 251 278 if self.User.LimitBy == "balance" : 252 279 if self.User.Balance <= 0.0 : … … 269 296 else : 270 297 self.tbicon.SetIcon(self.greenicon, "PyKotIcon") 271 if not self.IsIconized() :272 self.Iconize(True)273 if self.IsShown():274 self.Hide()275 298 if hasattr(self, "quotasgrid") : 299 self.quotasgrid.Close() 276 300 self.quotasgrid.Destroy() 277 301 del self.quotasgrid 278 302 self.quotasgrid = PyKotIconGrid(self, self.User.Quotas) 279 if self.IsIconized() :280 self.Iconize(False)281 if not self.IsShown() :282 self.Show(True)283 303 self.inTimer = False 284 304 # Now we want it every 3 minutes … … 327 347 def main(): 328 348 """Program's entry point.""" 349 try : 350 locale.setlocale(locale.LC_ALL, "") 351 except (locale.Error, IOError) : 352 sys.stderr.write("Problem while setting locale.\n") 353 try : 354 gettext.install("pykoticon") 355 except : 356 gettext.NullTranslations().install() 329 357 app = PyKotIconApp() 330 358 app.MainLoop() … … 345 373 username = sys.argv[2] 346 374 else : 347 username = win32api.GetUserName()375 username = getCurrentUserName() 348 376 net = CGINetworkInterface(DUMPYKOTA_URL) 349 377 user = net.getUser(username) 350 print "UserName : ", user. Name378 print "UserName : ", user.UserName 351 379 print "LimitBy : ", user.LimitBy 352 380 print "Balance : ", user.Balance