| 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 | |
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"), \ |
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 |