Changeset 63 for pykoticon

Show
Ignore:
Timestamp:
01/15/05 19:56:57 (19 years ago)
Author:
jerome
Message:

Added the grid

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykoticon/trunk/bin/pykoticon

    r60 r63  
    2424 
    2525import sys 
     26import os 
    2627import urllib 
    2728import urllib2 
     
    3940    import wxPython.wx 
    4041    import wx 
     42    import wx.grid as gridlib 
    4143    hasWxPython = 1 
    4244except ImportError :     
     
    156158            return User(username, info, quotas) 
    157159     
     160class 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             
    158198class 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"), \ 
    163206                                  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) 
    165210         
    166211        self.tbicon = wxPython.wx.wxTaskBarIcon() 
    167         self.tbicon.SetIcon(icon, "PyKotIcon") 
     212        self.tbicon.SetIcon(self.greenicon, "PyKotIcon") 
     213         
    168214        wxPython.wx.EVT_TASKBAR_LEFT_DCLICK(self.tbicon, self.OnTaskBarActivate) 
    169215        wxPython.wx.EVT_TASKBAR_RIGHT_UP(self.tbicon, self.OnTaskBarMenu) 
     
    181227         
    182228        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) 
    185231         
    186232        self.User = None 
    187233        self.networkInterface = CGINetworkInterface(DUMPYKOTA_URL) 
    188         self.inTimer = 0 
    189         self.chrono.Start(1000 * 60 * 3) # every 3 minutes 
     234        self.inTimer = False 
     235        self.chrono.Start(200) # first time in 0.25 second 
    190236 
    191237    def getCurrentUserName(self) : 
     
    195241    def OnChronoTimer(self, event) : 
    196242        """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 
    199248            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 
    201276     
    202277    def OnIconify(self, event) : 
     
    231306class PyKotIconApp(wxPython.wx.wxApp): 
    232307    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) 
    235314        return True 
    236315         
     316def main(): 
     317    """Program's entry point.""" 
     318    app = PyKotIconApp() 
     319    app.MainLoop() 
     320     
    237321def crashed() :     
    238322    """Minimal crash method.""" 
     
    244328    sys.stderr.write(msg) 
    245329    sys.stderr.flush() 
    246      
    247 def main(): 
    248     """Program's entry point.""" 
    249     app = PyKotIconApp() 
    250     app.MainLoop() 
    251330     
    252331def test() :