1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
import psutil
import wx
from ObjectListView import ObjectListView, ColumnDefn
import TrayIcon
import win32con
import ctypes
class Process(object):

    def __init__(self, name, pid, exe, user, cpu, mem, desc=None):
        
        self.name = name
        self.pid = pid
        self.exe = exe
        self.user = user
        self.cpu = cpu
        self.mem = mem
 
class MainPanel(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent=parent)
        self.procs = []
        self.procmonOlv = ObjectListView(self, style=wx.LC_REPORT|wx.SUNKEN_BORDER)
        self.setProcs()
        endProcBtn = wx.Button(self, label="End Process")
        endProcBtn.Bind(wx.EVT_BUTTON, self.onKillProc)
        mainSizer = wx.BoxSizer(wx.VERTICAL)
        mainSizer.Add(self.procmonOlv, 1, wx.EXPAND|wx.ALL, 5)
        mainSizer.Add(endProcBtn, 0, wx.ALIGN_RIGHT|wx.ALL, 5)
        self.SetSizer(mainSizer)
        self.updateDisplay()
        self.timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.update, self.timer)
        self.timer.Start(150000)
        self.Bind(wx.EVT_KEY_DOWN, self.onKey)
    def onKey(self, event):
        key_code = event.GetKeyCode()
        if key_code == wx.WXK_ESCAPE:
            self.GetParent().Close()
        else:
            event.Skip()
    def setProcs(self):
        """"""
        cols = [
            ColumnDefn("Name", "left", 150, "name"),
            ColumnDefn("EXE Location", "left", 100, "exe"),
            ColumnDefn("Username", "left", 75, "user"),
            #ColumnDefn("cpu", "left", 75, "cpu"),
            ColumnDefn("Mem", "left", 75, "mem")
            ]
        self.procmonOlv.SetColumns(cols)
        self.procmonOlv.SetObjects(self.procs)
 
    def update(self, event):
        
        self.updateDisplay()

    def updateDisplay(self):
        
        pids = psutil.get_pid_list()
        for pid in pids:
 
            try:
                p = psutil.Process(pid)
                new_proc = Process(p.name,
                                   str(p.pid),
                                   p.exe,
                                   p.username,
                                   str(p.get_cpu_percent()),
                                   str(p.get_memory_percent())
                                   )
                self.procs.append(new_proc)
            except:
                pass
 
        self.setProcs()
    def onKillProc(self, event):
       
        obj = self.procmonOlv.GetSelectedObject()
        print
        pid = int(obj.pid)
        try:
            p = psutil.Process(pid)
            p.terminate()
            self.update("")
        except Exception, e:
            pass
    def onSelect(self, event):
        
        item = event.GetItem()
        itemId = item.GetId()
        self.currentSelection = itemId
        print
class Panel2(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent=parent)
        self.procs = []
        self.procmonOlv = ObjectListView(self, style=wx.LC_REPORT|wx.SUNKEN_BORDER)
        self.setProcs()
        endProcBtn = wx.Button(self, label="End Process")
        endProcBtn.Bind(wx.EVT_BUTTON, self.onKillProc)
        mainSizer = wx.BoxSizer(wx.VERTICAL)
        mainSizer.Add(self.procmonOlv, 1, wx.EXPAND|wx.ALL, 5)
        mainSizer.Add(endProcBtn, 0, wx.ALIGN_RIGHT|wx.ALL, 5)
        self.SetSizer(mainSizer)
        self.updateDisplay()
        self.timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.update, self.timer)
        self.timer.Start(150000)
        self.Bind(wx.EVT_KEY_DOWN, self.onKey)
    def onKey(self, event):
        key_code = event.GetKeyCode()
        if key_code == wx.WXK_ESCAPE:
            self.GetParent().Close()
        else:
            event.Skip()
    def setProcs(self):
        """"""
        cols = [
            ColumnDefn("Name", "left", 150, "name"),
            ColumnDefn("username", "left", 75, "user")
            ]
        self.procmonOlv.SetColumns(cols)
        self.procmonOlv.SetObjects(self.procs)
 
    def update(self, event):
        
        self.updateDisplay()

    def updateDisplay(self):
        
        pids = psutil.get_pid_list()
        for pid in pids:
 
            try:
                p = psutil.Process(pid)
                new_proc = Process(p.name,
                                   str(p.pid),
                                   p.exe,
                                   p.username,
                                   str(p.get_cpu_percent()),
                                   str(p.get_memory_percent())
                                   )
                self.procs.append(new_proc)
            except:
                pass
 
        self.setProcs()
    def onKillProc(self, event):
       
        obj = self.procmonOlv.GetSelectedObject()
        print
        pid = int(obj.pid)
        try:
            p = psutil.Process(pid)
            p.terminate()
            self.update("")
        except Exception, e:
            pass
    def onSelect(self, event):
        
        item = event.GetItem()
        itemId = item.GetId()
        self.currentSelection = itemId
        print

    
class MainFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, title="PyTask", style = wx.DEFAULT_FRAME_STYLE)
        self.panelone = MainPanel(self)
        self.paneltwo = Panel2(self)
        self.panelone.Hide()
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.panelone, 1, wx.EXPAND)
        self.sizer.Add(self.paneltwo, 1, wx.EXPAND)
        self.SetSizer(self.sizer)
        self.menubar = wx.MenuBar()
        self.file = wx.Menu()
        self.SetMenuBar(self.menubar)
        self.menubar.Append(self.file,'&File')
        self.get = self.file.Append(wx.ID_ANY,'&Run\tCtrl+R')
        self.getlock = self.file.Append(wx.ID_ANY, '&Lock\tCtrl+L')
        self.getexit = self.file.Append(wx.ID_ANY, '&Exit and Minimize\tCtrl+Q')
        self.getexittotal = self.file.Append(wx.ID_ANY, '&Exit and Quit\tCtrl+Shift+Q')
        self.Bind(wx.EVT_MENU,self.GetApp,self.get)
        self.Bind(wx.EVT_MENU,self.lock,self.getlock)
        self.Bind(wx.EVT_MENU,self.exitm,self.getexit)
        self.Bind(wx.EVT_MENU,self.exitt,self.getexittotal)
        self.view = wx.Menu()
        self.menubar.Append(self.view,'&View')
        self.lesspanel = self.view.Append(wx.ID_ANY, '&Less Detail\tCtrl+N', 'Less Detail View', wx.ITEM_RADIO)
        self.switchpanel = self.view.Append(wx.ID_ANY, '&More Detail\tCtrl+M', 'Detailed View', wx.ITEM_RADIO)
        self.refresh = self.view.Append(wx.ID_ANY, '&Refresh\tCtrl+A')
        self.defaultview = self.view.Append(wx.ID_ANY, "&Normal Display\tCtrl+D", "Normal Display", wx.ITEM_RADIO)
        self.ontopview = self.view.Append(wx.ID_ANY, "&Always On Top\tCtrl+T", "On Top", wx.ITEM_RADIO)
        self.Bind(wx.EVT_MENU,self.lessview,self.lesspanel)
        self.Bind(wx.EVT_MENU,self.moreview,self.switchpanel)
        self.Bind(wx.EVT_MENU,self.ontop,self.ontopview)
        self.Bind(wx.EVT_MENU,self.normview,self.defaultview)
        self.Bind(wx.EVT_MENU,self.GetRefresh,self.refresh)
        self.updates = wx.Menu()
        self.Normal = self.updates.Append(wx.ID_ANY, "&Update Time - Normal\tCtrl+U", "Update every 2 minutes", wx.ITEM_RADIO) 
        self.fs = self.updates.Append(wx.ID_ANY, "&Update Time - 15 Seconds\tCtrl+1", "Update every 15 seconds", wx.ITEM_RADIO)
        self.ts = self.updates.Append(wx.ID_ANY, "&Update Time - 30 Seconds\tCtrl+2", "Update every 30 seconds", wx.ITEM_RADIO)
        self.ss = self.updates.Append(wx.ID_ANY,"&Update Time - 60 Seconds\tCtrl+3", "Update every 60 seconds", wx.ITEM_RADIO)
        self.ns = self.updates.Append(wx.ID_ANY, "&Update Time - 90 Seconds\tCtrl+4", "Update every 90 seconds", wx.ITEM_RADIO)
        self.Bind(wx.EVT_MENU,self.Default,self.Normal)
        self.Bind(wx.EVT_MENU,self.fsec,self.fs)
        self.Bind(wx.EVT_MENU,self.tsec,self.ts)
        self.Bind(wx.EVT_MENU,self.ssec,self.ss)
        self.Bind(wx.EVT_MENU,self.nsec,self.ns)
        self.menubar.Append(self.updates, '&Update Options')
        self.help = wx.Menu()
        self.helpd = self.help.Append(wx.ID_ANY, '&Help\tCtrl+H')
        self.about = self.help.Append(wx.ID_ANY, '&About\tCtrl+A')
        self.Bind(wx.EVT_MENU,self.onHelp,self.helpd)
        self.Bind(wx.EVT_MENU,self.onabt,self.about)
        self.menubar.Append(self.help, '&Help')
        self.tbIcon = TrayIcon.CustomTaskBarIcon(self)
        self.Bind(wx.EVT_ICONIZE, self.onMinimize)
        self.Size = (442, 573)
        iconFile = "pytask.ico"
        icon1 = wx.Icon(iconFile, wx.BITMAP_TYPE_ICO)
        self.SetIcon(icon1)
        self.regHotKey()
        self.Bind(wx.EVT_HOTKEY, self.handleHotKey, id=self.hotKeyId)
        self.Show()
    def lock(self, event):
        ctypes.windll.user32.LockWorkStation()
    def regHotKey(self):
        self.hotKeyId = 100
        self.RegisterHotKey(
            self.hotKeyId,
            win32con.MOD_CONTROL,
            win32con.VK_F6) 
    def handleHotKey(self, evt):
        if self.pannelone.IsShown():
            self.Hide()
        else:
            self.Show()
            self.Raise()
    def onClose(self, event):
        self.Hide()
    def onMinimize(self, event):
        self.Hide()
    def moreview(self, event):
        self.panelone.Show()
        self.paneltwo.Hide()
        self.Layout()
    def lessview(self, event):
        self.paneltwo.Show()
        self.panelone.Hide()
        self.Layout()
    def normview(self,event):
        style = wx.DEFAULT_FRAME_STYLE
        self.SetWindowStyle( style )
    def ontop(self,event):
        style = self.GetWindowStyle()
        self.SetWindowStyle( style | wx.STAY_ON_TOP )
    def Default(self,event):
        self.timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.update, self.timer)
        self.timer.Start(120000)
    def fsec(self,event):
        self.timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.update, self.timer)
        self.timer.Start(15000)
    def tsec(self,event):
        self.timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.update, self.timer)
        self.timer.Start(30000)
    def ssec(self,event):
        self.timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.update, self.timer)
        self.timer.Start(60000)
    def nsec(self,event):
        self.timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.update, self.timer)
        self.timer.Start(90000)
    def GetRefresh(self,event):
        self.updateDisplay()
    def GetApp(self, event):
        try:
            openFileDialog = wx.FileDialog(self, "Open EXE file", "", "",
                                       "EXE files (*.exe)|*.exe", wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)

            if openFileDialog.ShowModal() == wx.ID_CANCEL:
                return     
      
    

This paste never expires. View raw. Pasted through import.