Changeset 58

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

Preliminary windows taskbar functionnality working

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykoticon/trunk/bin/pykoticon

    r57 r58  
    3434except ImportError :     
    3535    hasWindowsExtensions = 0 
    36      
    37  
     36    raise ImportError, "Mark Hammond's Win32 Extensions are missing. Please install them." 
     37     
     38try :     
     39    import wxPython.wx 
     40    import wx 
     41    hasWxPython = 1 
     42except ImportError :     
     43    hasWxPython = 0 
     44    raise ImportError, "wxPython for Windows is missing. Please install it." 
     45     
    3846DUMPYKOTA_URL = "http://cgi.librelogiciel.com/cgi-bin/dumpykota.cgi" 
    3947 
     
    129137                      "filter" : "username=%s" % username, 
    130138                    }   
    131         return self.retrieveDatas(arguments, ("limitby", "balance", "lifetimepaid")) 
     139        return self.retrieveDatas(arguments, ("limitby", "balance", \ 
     140                                                         "lifetimepaid")) 
    132141         
    133142    def getUserPQuotas(self, username) : 
     
    137146                    }   
    138147        return self.retrieveDatas(arguments, ("printername", "pagecounter", \ 
    139                                               "softlimit", "hardlimit", "datelimit")) 
     148                                              "softlimit", "hardlimit", \ 
     149                                              "datelimit")) 
    140150                                               
    141151    def getUser(self, username) : 
     
    147157def getWindowsUserName() :     
    148158    """Retrieves the current user's name under MS Windows.""" 
    149     dc = win32net.NetServerEnum(None, 100, win32netcon.SV_TYPE_DOMAIN_CTRL) 
    150     user = win32api.GetUserName() 
    151     if dc[0] : 
    152         dcname = dc[0][0]['name'] 
    153         return win32net.NetUserGetInfo("\\\\" + dcname, user, 1) 
    154     else: 
    155         return win32net.NetUserGetInfo(None, user, 1) 
    156      
    157 if __name__ == "__main__" : 
     159    return win32api.GetUserName() 
     160     
     161class PyKotIcon(wxPython.wx.wxFrame): 
     162    def __init__(self, parent, id, title): 
     163        wxPython.wx.wxFrame.__init__(self, parent, -1, title, size=(800, 600), \ 
     164                   style = wxPython.wx.wxDEFAULT_FRAME_STYLE | wxPython.wx.wxNO_FULL_REPAINT_ON_RESIZE) 
     165        icon = wxPython.wx.wxIcon('pykoticon.ico', \ 
     166                                  wxPython.wx.wxBITMAP_TYPE_ICO) 
     167        self.SetIcon(icon) 
     168         
     169        self.tbicon = wxPython.wx.wxTaskBarIcon() 
     170        self.tbicon.SetIcon(icon, "PyKotIcon") 
     171        wxPython.wx.EVT_TASKBAR_LEFT_DCLICK(self.tbicon, self.OnTaskBarActivate) 
     172        wxPython.wx.EVT_TASKBAR_RIGHT_UP(self.tbicon, self.OnTaskBarMenu) 
     173        wxPython.wx.EVT_ICONIZE(self, self.OnIconify) 
     174         
     175        self.TBMENU_RESTORE = wx.NewId() 
     176        self.TBMENU_CLOSE = wx.NewId() 
     177        wxPython.wx.EVT_MENU(self.tbicon, self.TBMENU_RESTORE, \ 
     178                                          self.OnTaskBarActivate) 
     179        wxPython.wx.EVT_MENU(self.tbicon, self.TBMENU_CLOSE, \ 
     180                                          self.OnTaskBarClose) 
     181        self.menu = wxPython.wx.wxMenu() 
     182        self.menu.Append(self.TBMENU_RESTORE, "Show Print Quota") 
     183        self.menu.Append(self.TBMENU_CLOSE, "Quit") 
     184 
     185    def OnIconify(self, evt): 
     186        self.Hide() 
     187 
     188    def OnTaskBarActivate(self, event): 
     189        if self.IsIconized(): 
     190            self.Iconize(False) 
     191        if not self.IsShown(): 
     192            self.Show(True) 
     193        self.Raise() 
     194 
     195    def OnCloseWindow(self, event): 
     196        if hasattr(self, "menu") : 
     197            menu.Destroy() 
     198            del self.menu 
     199        if hasattr(self, "tbicon"): 
     200            self.tbicon.Destroy() 
     201            del self.tbicon 
     202        self.Destroy() 
     203 
     204    def OnTaskBarMenu(self, evt): 
     205        self.tbicon.PopupMenu(self.menu) 
     206 
     207    def OnTaskBarClose(self, evt): 
     208        self.Close() 
     209        wxPython.wx.wxGetApp().ProcessIdle() 
     210 
     211class PyKotIconApp(wxPython.wx.wxApp): 
     212    def OnInit(self) : 
     213        frame = PyKotIcon(None, -1, "PyKota Print Quota Manager") 
     214        frame.Show(True) 
     215        return True 
     216         
     217def crashed() :     
     218    """Minimal crash method.""" 
     219    import traceback 
     220    lines = [] 
     221    for line in traceback.format_exception(*sys.exc_info()) : 
     222        lines.extend([l for l in line.split("\n") if l]) 
     223    msg = "ERROR: ".join(["%s\n" % l for l in (["ERROR: PyKotIcon"] + lines)]) 
     224    sys.stderr.write(msg) 
     225    sys.stderr.flush() 
     226     
     227def main(): 
     228    """Program's entry point.""" 
     229    app = PyKotIconApp() 
     230    app.MainLoop() 
     231     
     232def test() : 
     233    """Runs in test mode (console).""" 
     234    username = getWindowsUserName() 
    158235    net = CGINetworkInterface(DUMPYKOTA_URL) 
    159     #print "List of printers : ", net.getPrinterNames() 
    160      
    161     #print "User : ", net.getUserInfo("jerome") 
    162      
    163     #print "User print quotas : ", net.getUserPQuotas("jerome") 
    164     #jerome = net.getUser("jerome") 
    165     print getWindowsUserName() 
    166  
     236    user = net.getUser(username) 
     237    print "UserName : ", user.Name 
     238    print "LimitBy : ", user.LimitBy 
     239    print "Balance : ", user.Balance 
     240    for q in user.Quotas : 
     241        print "\tPrinterName : ", q.PrinterName 
     242        print "\tPageCounter : ", q.PageCounter 
     243        print "\tSoftLimit : ", q.SoftLimit 
     244        print "\tHardLimit : ", q.HardLimit 
     245        print "\tDateLimit : ", q.DateLimit 
     246        print 
     247 
     248if __name__ == '__main__': 
     249    if (len(sys.argv) == 2) and (sys.argv[1] == "--test") : 
     250        test() 
     251    else :     
     252        main() 
     253