-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProcessNotifier.py
42 lines (33 loc) · 1.11 KB
/
ProcessNotifier.py
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
from Config import *
import psutil
import Logger
class ProcessNotifier(object):
screen = Wnck.Screen.get_default()
open_procs = {}
@staticmethod
def getProcNameByPID(pid):
return psutil.Process(pid).name()
@staticmethod
def isRunning(proc_name):
return (proc_name in ProcessNotifier.open_procs)
@staticmethod
def update():
ProcessNotifier.open_procs = ProcessNotifier.getOpenProcs()
@staticmethod
def getOpenProcsCached():
return ProcessNotifier.open_procs
@staticmethod
def getOpenProcs():
ProcessNotifier.screen.force_update()
wins = ProcessNotifier.screen.get_windows()
procs = {}
try:
for win in wins:
if win.get_pid() != os.getpid(): # if its not us
procs[ ProcessNotifier.getProcNameByPID(win.get_pid()) ] = win
except:
Logger.log("[ProcessNotifier] failed to update, removal in process?")
return procs
@staticmethod
def getActiveProc():
ProcessNotifier.getProcNameByPID(ProcessNotifier.screen.get_active_window.pid)