-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalyzer.py
92 lines (82 loc) · 2.79 KB
/
analyzer.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
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
#!/usr/bin/env python
import pwd
import os
import sqlite3 as lite
import subprocess
import time
#variables
program="plasmashell"
previousProgram="none"
programList=[]
setMouse=""
mouseDefault="F3"
currentMode="F3"
newMode=[]
newColor=[]
newBut1=[]
newBut2=[]
newG4=[]
newG5=[]
newG6=[]
newG7=[]
newG8=[]
newG9=[]
specialCharacters=["—","-"]
trunc="none"
def getUsername():
return pwd.getpwuid( os.getuid() )[ 0 ]
#Get the data from database
getList = lite.connect('/home/%s/.config/ratslap/ratslap_config.db'%(getUsername()))
with getList:
getList.row_factory = lite.Row
listCursor = getList.cursor()
listCursor.execute("select * from config")
appList = listCursor.fetchall()
for app in appList:
programList.append(app['Application'])
newMode.append(app['Mode'])
newColor.append(app['Color'])
newG4.append(app['G4'])
newG5.append(app['G5'])
newG6.append(app['G6'])
newG7.append(app['G7'])
newG8.append(app['G8'])
newG9.append(app['G9'])
for i in range(len(programList)):
print ("%s: %s; %s"%(programList[i], newMode[i], newColor[i]))
#Returns the active window name
def activeWindow(process):
window = subprocess.Popen(['xdotool', 'getactiveWindow', 'getwindowname'],stdout=subprocess.PIPE,universal_newlines=True)
(windowName, err) = window.communicate()
return windowName
#formats the active window name for comparison
def formatName(appName):
for i in range(len(specialCharacters)):
reverse=activeWindow(program)[::-1]
trunc=(reverse.split(specialCharacters[i])[0]).strip()[::-1]
return(trunc)
#Checks for changes to the active window
while True:
time.sleep(.5)
for i in range(len(programList)):
if (formatName(program)==previousProgram):
continue
elif (formatName(program) in programList):
pos=programList.index(formatName(program))
print("Setting mouse to %s."%(newMode[pos]))
print(formatName(program))
subprocess.Popen(['ratslap', '--modify', newMode[pos], '-c', newColor[pos], '-4', newG4[pos], '-5', newG5[pos], '-6', newG6[pos], '-7', newG7[pos], '-8', newG8[pos], '-9', newG9[pos],'--select', newMode[pos]])
previousProgram=formatName(program)
currentMode=newMode[pos]
print(currentMode)
else:
if (currentMode == mouseDefault):
previousProgram=formatName(program)
continue
else:
print("Mouse currently set to: %s."%(currentMode))
print("Setting mouse to %s."%(mouseDefault))
print(formatName(program))
subprocess.Popen(['ratslap', '--select', newMode[0]])
previousProgram=formatName(program)
currentMode=mouseDefault