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 | |
| 161 | class 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 | |
| 211 | class 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 | |
| 217 | def 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 | |
| 227 | def main(): |
| 228 | """Program's entry point.""" |
| 229 | app = PyKotIconApp() |
| 230 | app.MainLoop() |
| 231 | |
| 232 | def test() : |
| 233 | """Runs in test mode (console).""" |
| 234 | username = getWindowsUserName() |
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 | |
| 248 | if __name__ == '__main__': |
| 249 | if (len(sys.argv) == 2) and (sys.argv[1] == "--test") : |
| 250 | test() |
| 251 | else : |
| 252 | main() |
| 253 | |