Changeset 63 for pykoticon/trunk/bin
- Timestamp:
- 01/15/05 19:56:57 (19 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykoticon/trunk/bin/pykoticon
r60 r63 24 24 25 25 import sys 26 import os 26 27 import urllib 27 28 import urllib2 … … 39 40 import wxPython.wx 40 41 import wx 42 import wx.grid as gridlib 41 43 hasWxPython = 1 42 44 except ImportError : … … 156 158 return User(username, info, quotas) 157 159 160 class PyKotIconGrid(gridlib.Grid) : 161 """A class for user print quota entries.""" 162 def __init__(self, parent, quotas) : 163 gridlib.Grid.__init__(self, parent, -1) 164 self.CreateGrid(len(quotas), 4) 165 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") 170 attr = gridlib.GridCellAttr() 171 attr.SetAlignment(wx.ALIGN_RIGHT, wx.ALIGN_RIGHT) 172 attr.SetReadOnly(True) 173 self.SetColAttr(0, attr) 174 self.SetColAttr(1, attr) 175 self.SetColAttr(2, attr) 176 attr = gridlib.GridCellAttr() 177 attr.SetAlignment(wx.ALIGN_CENTRE, wx.ALIGN_CENTRE) 178 attr.SetReadOnly(True) 179 self.SetColAttr(3, attr) 180 for i in range(len(quotas)) : 181 q = quotas[i] 182 self.SetRowLabelValue(i, quotas[i].PrinterName) 183 self.SetCellValue(i, 0, str(q.PageCounter)) 184 self.SetCellValue(i, 1, str(q.SoftLimit)) 185 self.SetCellValue(i, 2, str(q.HardLimit)) 186 self.SetCellValue(i, 3, str(q.DateLimit)) 187 attr = gridlib.GridCellAttr() 188 colour = wx.GREEN 189 if q.SoftLimit is not None : 190 if q.PageCounter >= q.SoftLimit : 191 colour = wx.RED 192 elif q.HardLimit is not None : 193 if q.PageCounter >= q.HardLimit : 194 colour = wx.RED 195 attr.SetBackgroundColour(colour) 196 self.SetRowAttr(i, attr) 197 158 198 class PyKotIcon(wxPython.wx.wxFrame): 159 def __init__(self, parent, id, title): 160 wxPython.wx.wxFrame.__init__(self, parent, -1, title, size=(800, 600), \ 161 style = wxPython.wx.wxDEFAULT_FRAME_STYLE | wxPython.wx.wxNO_FULL_REPAINT_ON_RESIZE) 162 icon = wxPython.wx.wxIcon('pykoticon.ico', \ 199 """Main class.""" 200 def __init__(self, parent, id): 201 wxPython.wx.wxFrame.__init__(self, parent, -1, \ 202 "PyKota Print Quota for user %s" % self.getCurrentUserName(), \ 203 # size=(640, 480), \ 204 style = wxPython.wx.wxDEFAULT_FRAME_STYLE | wxPython.wx.wxNO_FULL_REPAINT_ON_RESIZE) 205 self.greenicon = wxPython.wx.wxIcon(os.path.join("..", "icons", "pykoticon-green.ico"), \ 163 206 wxPython.wx.wxBITMAP_TYPE_ICO) 164 self.SetIcon(icon) 207 self.redicon = wxPython.wx.wxIcon(os.path.join("..", "icons", "pykoticon-red.ico"), \ 208 wxPython.wx.wxBITMAP_TYPE_ICO) 209 self.SetIcon(self.greenicon) 165 210 166 211 self.tbicon = wxPython.wx.wxTaskBarIcon() 167 self.tbicon.SetIcon(icon, "PyKotIcon") 212 self.tbicon.SetIcon(self.greenicon, "PyKotIcon") 213 168 214 wxPython.wx.EVT_TASKBAR_LEFT_DCLICK(self.tbicon, self.OnTaskBarActivate) 169 215 wxPython.wx.EVT_TASKBAR_RIGHT_UP(self.tbicon, self.OnTaskBarMenu) … … 181 227 182 228 self.TBTIMER = wx.NewId() 183 self.chrono = wx .wxTimer(self, self.TBTIMER)184 EVT_TIMER(self, self.TBTIMER, self.OnChronoTimer)229 self.chrono = wxPython.wx.wxTimer(self, self.TBTIMER) 230 wxPython.wx.EVT_TIMER(self, self.TBTIMER, self.OnChronoTimer) 185 231 186 232 self.User = None 187 233 self.networkInterface = CGINetworkInterface(DUMPYKOTA_URL) 188 self.inTimer = 0189 self.chrono.Start( 1000 * 60 * 3) # every 3 minutes234 self.inTimer = False 235 self.chrono.Start(200) # first time in 0.25 second 190 236 191 237 def getCurrentUserName(self) : … … 195 241 def OnChronoTimer(self, event) : 196 242 """Retrieves user's data quota information.""" 197 if not self.inTimer : # avoids re-entrance 198 self.inTimer = 1 243 # we stop it there, needed because we want to 244 # change the delay the first time. 245 self.chrono.Stop() 246 if self.inTimer is False : # avoids re-entrance 247 self.inTimer = True 199 248 self.User = self.networkInterface.getUser(self.getCurrentUserName()) 200 self.inTimer = 0 249 if self.User.LimitBy == "balance" : 250 if self.User.Balance <= 0.0 : 251 self.tbicon.SetIcon(self.redicon, "PyKotIcon") 252 else : 253 self.tbicon.SetIcon(self.greenicon, "PyKotIcon") 254 else : 255 isRed = False 256 for q in self.User.Quotas : 257 if q.SoftLimit is not None : 258 if q.PageCounter >= q.SoftLimit : 259 isRed = True 260 break 261 elif q.HardLimit is not None : 262 if q.PageCounter >= q.HardLimit : 263 isRed = True 264 break 265 if isRed is True : 266 self.tbicon.SetIcon(self.redicon, "PyKotIcon") 267 else : 268 self.tbicon.SetIcon(self.greenicon, "PyKotIcon") 269 if hasattr(self, "quotasgrid") : 270 self.quotasgrid.Destroy() 271 del self.quotasgrid 272 self.quotasgrid = PyKotIconGrid(self, self.User.Quotas) 273 self.inTimer = False 274 # Now we want it every 3 minutes 275 self.chrono.Start(1000 * 60 * 3) # every 3 minutes 201 276 202 277 def OnIconify(self, event) : … … 231 306 class PyKotIconApp(wxPython.wx.wxApp): 232 307 def OnInit(self) : 233 frame = PyKotIcon(None, -1, "PyKota Print Quota Manager") 234 frame.Show(True) 308 try : 309 frame = PyKotIcon(None, -1) 310 except : 311 crashed() 312 else : 313 frame.Show(True) 235 314 return True 236 315 316 def main(): 317 """Program's entry point.""" 318 app = PyKotIconApp() 319 app.MainLoop() 320 237 321 def crashed() : 238 322 """Minimal crash method.""" … … 244 328 sys.stderr.write(msg) 245 329 sys.stderr.flush() 246 247 def main():248 """Program's entry point."""249 app = PyKotIconApp()250 app.MainLoop()251 330 252 331 def test() :