Changeset 66
- Timestamp:
- 01/16/05 17:20:39 (20 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykoticon/trunk/bin/pykoticon
r65 r66 98 98 class User : 99 99 """A class for PyKota users.""" 100 def __init__(self, username, userinfo, userquotas ) :100 def __init__(self, username, userinfo, userquotas, printers) : 101 101 """Initialize user datas.""" 102 102 self.UserName = username … … 110 110 except (ValueError, TypeError) : 111 111 self.LifeTimePaid = 0.0 112 self.Quotas = [] 112 self.Printers = {} 113 self.Quotas = {} 113 114 for i in range(len(userquotas["printername"])) : 114 115 printername = userquotas["printername"][i] 116 try : 117 pindex = printers["printername"].index(printername) 118 except (ValueError, KeyError) : 119 pass 120 else : 121 self.Printers[printername] = Printer(printername, \ 122 printers["priceperpage"][pindex],\ 123 printers["priceperjob"][pindex]) 115 124 pagecounter = userquotas["pagecounter"][i] 116 125 softlimit = userquotas["softlimit"][i] 117 126 hardlimit = userquotas["hardlimit"][i] 118 127 datelimit = userquotas["datelimit"][i] 119 self.Quotas.append(UserQuota(printername, pagecounter, softlimit, \ 120 hardlimit, datelimit)) 128 self.Quotas[printername] = UserQuota(printername, pagecounter, \ 129 softlimit, hardlimit, \ 130 datelimit) 121 131 122 132 class CGINetworkInterface : … … 155 165 return answer 156 166 157 def getPrinter Names(self) :167 def getPrinters(self) : 158 168 """Retrieve the printer's names.""" 159 169 arguments = { "report" : 1, … … 161 171 "datatype" : "printers", 162 172 } 163 return self.retrieveDatas(arguments, ["printername"])["printername"] 164 165 def getUserInfo(self, username) : 173 return self.retrieveDatas(arguments, ["printername", "priceperpage", \ 174 "priceperjob"]) 175 176 def getUser(self, username) : 166 177 """Retrieve the user's information.""" 167 178 arguments = { "datatype" : "users", … … 180 191 "datelimit")) 181 192 182 def getUser (self, username) :193 def getUserInfo(self, username) : 183 194 """Retrieves the user account and quota information.""" 184 info = self.getUser Info(username)195 info = self.getUser(username) 185 196 if info : 186 197 quotas = self.getUserPQuotas(username) 187 return User(username, info, quotas) 198 return User(username, info, \ 199 self.getUserPQuotas(username), \ 200 self.getPrinters()) 188 201 189 202 class PyKotIconGrid(gridlib.Grid) : 190 203 """A class for user print quota entries.""" 191 def __init__(self, parent, quotas) :204 def __init__(self, parent, user) : 192 205 gridlib.Grid.__init__(self, parent, -1) 193 206 sys.stderr.write("%s\n" % dir(self)) 194 self.CreateGrid(len( quotas), 4)207 self.CreateGrid(len(user.Quotas.keys()), 4) 195 208 self.EnableEditing(False) 196 209 self.SetColLabelValue(0, _("Page Counter")) … … 208 221 attr.SetReadOnly(True) 209 222 self.SetColAttr(3, attr) 210 for i in range(len(quotas)) : 211 q = quotas[i] 212 self.SetRowLabelValue(i, quotas[i].PrinterName) 213 self.SetCellValue(i, 0, str(q.PageCounter)) 214 self.SetCellValue(i, 1, str(q.SoftLimit)) 215 self.SetCellValue(i, 2, str(q.HardLimit)) 216 self.SetCellValue(i, 3, str(q.DateLimit)) 223 i = 0 224 for printername in user.Quotas.keys() : 225 quota = user.Quotas[printername] 226 self.SetRowLabelValue(i, printername) 227 self.SetCellValue(i, 0, str(quota.PageCounter)) 228 self.SetCellValue(i, 1, str(quota.SoftLimit)) 229 self.SetCellValue(i, 2, str(quota.HardLimit)) 230 self.SetCellValue(i, 3, str(quota.DateLimit)) 217 231 attr = gridlib.GridCellAttr() 218 232 colour = wx.GREEN 219 if q .SoftLimit is not None :220 if q .PageCounter >= q.SoftLimit :233 if quota.SoftLimit is not None : 234 if quota.PageCounter >= quota.SoftLimit : 221 235 colour = wx.RED 222 elif q .HardLimit is not None :223 if q .PageCounter >= q.HardLimit :236 elif quota.HardLimit is not None : 237 if quota.PageCounter >= quota.HardLimit : 224 238 colour = wx.RED 225 239 attr.SetBackgroundColour(colour) 226 240 self.SetRowAttr(i, attr) 241 i += 1 227 242 self.AutoSize() 228 243 … … 233 248 _("PyKota Print Quota for user %s") % getCurrentUserName(), \ 234 249 size = (460, -1), \ 235 style = wxPython.wx.wxDEFAULT_FRAME_STYLE | wxPython.wx.wxNO_FULL_REPAINT_ON_RESIZE) 250 style = wxPython.wx.wxDEFAULT_FRAME_STYLE \ 251 | wxPython.wx.wxNO_FULL_REPAINT_ON_RESIZE) 236 252 self.greenicon = wxPython.wx.wxIcon(os.path.join("..", "icons", "pykoticon-green.ico"), \ 237 253 wxPython.wx.wxBITMAP_TYPE_ICO) … … 275 291 if self.inTimer is False : # avoids re-entrance 276 292 self.inTimer = True 277 self.User = self.networkInterface.getUser (getCurrentUserName())293 self.User = self.networkInterface.getUserInfo(getCurrentUserName()) 278 294 if self.User.LimitBy == "balance" : 279 295 if self.User.Balance <= 0.0 : … … 283 299 else : 284 300 isRed = False 285 for q in self.User.Quotas : 286 if q.SoftLimit is not None : 287 if q.PageCounter >= q.SoftLimit : 301 for q in self.User.Quotas.keys() : 302 quota = self.User.Quotas[q] 303 if quota.SoftLimit is not None : 304 if quota.PageCounter >= quota.SoftLimit : 288 305 isRed = True 289 306 break 290 elif q .HardLimit is not None :291 if q .PageCounter >= q.HardLimit :307 elif quota.HardLimit is not None : 308 if quota.PageCounter >= quota.HardLimit : 292 309 isRed = True 293 310 break … … 300 317 self.quotasgrid.Destroy() 301 318 del self.quotasgrid 302 self.quotasgrid = PyKotIconGrid(self, self.User .Quotas)319 self.quotasgrid = PyKotIconGrid(self, self.User) 303 320 self.inTimer = False 304 321 # Now we want it every 3 minutes … … 320 337 self.chrono.Stop() 321 338 del self.chrono 339 if hasattr(self, "quotasgrid") : 340 self.quotasgrid.Close() 341 self.quotasgrid.Destroy() 342 del self.quotasgrid 322 343 if hasattr(self, "menu") : 323 344 self.menu.Destroy() … … 375 396 username = getCurrentUserName() 376 397 net = CGINetworkInterface(DUMPYKOTA_URL) 377 user = net.getUser (username)398 user = net.getUserInfo(username) 378 399 print "UserName : ", user.UserName 379 400 print "LimitBy : ", user.LimitBy 380 401 print "Balance : ", user.Balance 381 for q in user.Quotas : 382 print "\tPrinterName : ", q.PrinterName 383 print "\tPageCounter : ", q.PageCounter 384 print "\tSoftLimit : ", q.SoftLimit 385 print "\tHardLimit : ", q.HardLimit 386 print "\tDateLimit : ", q.DateLimit 402 for printername in user.Quotas.keys() : 403 quota = user.Quotas[printername] 404 print "\tPrinterName : ", printername 405 print "\tPageCounter : ", quota.PageCounter 406 print "\tSoftLimit : ", quota.SoftLimit 407 print "\tHardLimit : ", quota.HardLimit 408 print "\tDateLimit : ", quota.DateLimit 387 409 print 410 for printername in user.Printers.keys() : 411 printer = user.Printers[printername] 412 print "\tPrinterName : ", printername 413 print "\tPrice per Page : ", printer.PricePerPage 414 print "\tPrice per Job : ", printer.PricePerJob 415 print 416 417 388 418 389 419 if __name__ == '__main__':