-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathappind.py
More file actions
executable file
·212 lines (185 loc) · 6.17 KB
/
appind.py
File metadata and controls
executable file
·212 lines (185 loc) · 6.17 KB
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
#!/usr/bin/env python
import os
import os.path
import pygtk
pygtk.require('2.0')
import gtk
import time
import subprocess
import threading
import atexit
import commands
import appindicator
from Xlib import display
MaxIdle = 10
lockFile = "/tmp/automouse.lck"
appFile = "/tmp/appfile.lck"
# Touch the signal file on script startup
open(appFile, 'a').close()
class AppIndicatorMouse:
def __init__(self):
self.ind = appindicator.Indicator ("AutoMouseMove-Indicator", "indicator-messages", appindicator.CATEGORY_APPLICATION_STATUS)
self.ind.set_status (appindicator.STATUS_ACTIVE)
self.ind.set_attention_icon ("indicator-messages-new")
self.ind.set_icon("distributor-logo")
self.start = True
self.timer = None
self.timer_text = ""
# create a menu
self.menu = gtk.Menu()
_radio = gtk.RadioMenuItem(None, "Demo")
_radio1 = gtk.RadioMenuItem(None, "Demo")
radio = gtk.RadioMenuItem(_radio, "Start")
radio.connect("activate", self.start_btn_pressed)
radio.show()
self.menu.append(radio)
radio1 = gtk.RadioMenuItem(_radio, "Stop")
radio1.connect("activate", self.stop_btn_pressed)
radio1.show()
self.menu.append(radio1)
self.dis_web = gtk.CheckMenuItem("kuku")
self.dis_web.connect("toggled", self.disable_webcam)
self.dis_web.show()
self.menu.append(self.dis_web)
button = gtk.MenuItem(label="Timer")
button.connect("activate", self.TimerpopUp)
button.show()
self.menu.append(button)
image = gtk.ImageMenuItem(gtk.STOCK_QUIT)
image.connect("activate", self.quit)
image.show()
self.menu.append(image)
self.menu.show()
self.ind.set_menu(self.menu)
self.thread = threading.Thread(target=self.StartbashScript)
self.thread.daemon = True
self.thread.start()
# self.thread.join()
def quit(self, widget, data=None):
# print self.thread
try:
self._bash.kill()
except:
pass
gtk.main_quit()
def start_btn_pressed(self, widget):
print "Start button clicked."
try:
os.remove(appFile)
except:
print "Unable to remove appFile"
def stop_btn_pressed(self, widget):
print "Stop clicked."
open(appFile, 'a').close()
# self.ind.set_label("Stopped")
def StartbashScript(self):
self._bash = None
self.thread1 = None
prev_pos = None
count = 0
# self.timer = 30
while True:
if self.timer is not None:
count = count + 1
if int(count) >= int(self.timer) and not os.path.isfile(lockFile):
try:
print "Timer reached"
count = 0
self.timer = None
open(appFile, 'a').close()
except:
print "Timer encountered an error!!"
pass
else:
count = 0
if os.path.isfile(appFile):
print "App is on stop mode!!"
time.sleep(1)
continue
else:
if not os.path.isfile(lockFile):
self._bash = None
prev_pos = None
idle = commands.getstatusoutput('expr $(xprintidle) / 1000')[1]
if (int(idle) > MaxIdle):
if self._bash is None:
print "system goes idle..!"
self.thread1 = threading.Thread(target=self.AutoMouseMove)
self.thread1.daemon = True
self.thread1.start()
self.thread1.join()
else:
print str(idle) + str(" : system active")
if self._bash is not None:
# print("The mouse position on the screen is {0}".format(self.mousepos()))
cur_pos = self.mousepos()
print "Current postion" + str(cur_pos)
if prev_pos is not None and cur_pos != prev_pos:
subprocess.Popen("exec " + "xte 'keyup Control_L' && xte 'keyup Alt_L'", shell=True, stdout=subprocess.PIPE)
print "System activated by user input"
self._bash.terminate()
self._bash = None
print "Lock file removed!"
os.remove(lockFile)
prev_pos = cur_pos
FirstRun = False
time.sleep(1)
def mousepos(self):
"""mousepos() --> (x, y) get the mouse coordinates on the screen (linux, Xlib)."""
data = display.Display().screen().root.query_pointer()._data
return data["root_x"]
def AutoMouseMove(self):
open(lockFile, 'a').close()
self._bash = subprocess.Popen("exec " + "./start-mouse.sh", shell=True, stdout=subprocess.PIPE)
print self._bash.pid
def TimerpopUp(self,btn):
#base this on a message dialog
dialog = gtk.MessageDialog(
None,
gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
gtk.MESSAGE_QUESTION,
gtk.BUTTONS_OK,
None)
dialog.set_markup('Please set the <b>timer</b>:')
#create the text input field
entry = gtk.Entry()
entry.set_text(self.timer_text)
#allow the user to press enter to do ok
entry.connect("activate", self.responseToDialog, dialog, gtk.RESPONSE_OK)
entry.connect('changed', self.on_changed)
#create a horizontal box to pack the entry and a label
hbox = gtk.HBox()
hbox.pack_start(gtk.Label("Timer (min):"), False, 5, 5)
hbox.pack_end(entry)
#some secondary text
# dialog.format_secondary_markup("This will be used for <i>identification</i> purposes")
#add it and show it
dialog.vbox.pack_end(hbox, True, True, 0)
dialog.show_all()
#go go go
dialog.run()
text = entry.get_text()
dialog.destroy()
if text == '':
self.timer_text = ""
self.timer = None
else:
self.timer_text = text
self.timer = int(text) * 60
print self.timer_text
print "Automation will be active for next " + str(self.timer_text) + str(" mins")
def on_changed(self, entry):
text = entry.get_text().strip()
entry.set_text(''.join([i for i in text if i in '123456789']))
def responseToDialog(entry, dialog, response):
dialog.response(response)
def disable_webcam(self, widget, data=None):
if widget.get_active():
os.system("echo 'passwd' | sudo -S modprobe -r uvcvideo")
else:
os.system("echo 'passwd' | sudo -S modprobe uvcvideo")
if __name__ == "__main__":
gtk.gdk.threads_init()
# test = Test1()
indicator = AppIndicatorMouse()
gtk.main()