Fix the style to be more compliant with Python 2.7's general style for executables.

This also enables the user to import autorotate.py as a library, although why
anyone would want to do that is beyond me.
This commit is contained in:
Elf M. Sternberg 2017-11-16 13:38:01 -08:00
parent 8e8162a76b
commit ea81a9d141
1 changed files with 40 additions and 33 deletions

View File

@ -73,38 +73,45 @@ def is_in(pen):
return (res and res.group(1).lower() == 'in') return (res and res.group(1).lower() == 'in')
while True: def manage_orientation_and_palm_rejection(options):
int_displays = countdisplays() current_orientation = ''
time.sleep(1.0/freq) currently_proximate = False
if int_displays == 1:
# Check accelerometers while True:
# Do we need to check the touch_devices list every time? I int_displays = countdisplays()
# think we do; the list will change dynamically if we time.sleep(1.0/freq)
# dynamically load the stylus driver after the system has if int_displays == 1:
# booted.
touch_devices = filter(lambda n: DIGITIZER_RE.match(n),
subprocess.check_output(['xinput', '--list', '--name-only']).splitlines())
with open(x_accel_path, 'r') as fx:
with open(y_accel_path, 'r') as fy:
thex = float(fx.readline())
they = float(fy.readline())
for check in transforms:
if check.xrule(thex, they) and check.yrule(thex, they):
if current_orientation != check.name:
print "Switching to orientation %s" % check.name
os.system('xrandr -o %s' % check.name)
for device in touch_devices:
os.system("xinput set-prop '%s' 'Coordinate Transformation Matrix' %s" %
(device, check.matrix))
current_orientation = check.name
refreshtouch()
break
# Palm rejection (sort-of): # Check accelerometers
pen_devices = [p for p in touch_devices if PEN_RE.search(p)] # Do we need to check the touch_devices list every time? I
pen_status = bool([p for p in pen_devices if is_in(p)]) # think we do; the list will change dynamically if we
if pen_status != currently_proximate: # dynamically load the stylus driver after the system has
print "%s palm rejection" % ("Activating" if pen_status else "Deactivating") # booted.
currently_proximate = pen_status touch_devices = filter(lambda n: DIGITIZER_RE.match(n),
os.system("xinput %s '%s'" % (xinput_statemap[pen_status], devicename)) subprocess.check_output(['xinput', '--list', '--name-only']).splitlines())
with open(x_accel_path, 'r') as fx:
with open(y_accel_path, 'r') as fy:
thex = float(fx.readline())
they = float(fy.readline())
for check in transforms:
if check.xrule(thex, they) and check.yrule(thex, they):
if current_orientation != check.name:
print "Switching to orientation %s" % check.name
os.system('xrandr -o %s' % check.name)
for device in touch_devices:
os.system("xinput set-prop '%s' 'Coordinate Transformation Matrix' %s" %
(device, check.matrix))
current_orientation = check.name
refreshtouch()
break
# Palm rejection (sort-of):
pen_devices = [p for p in touch_devices if PEN_RE.search(p)]
pen_status = bool([p for p in pen_devices if is_in(p)])
if pen_status != currently_proximate:
print "%s palm rejection" % ("Activating" if pen_status else "Deactivating")
currently_proximate = pen_status
os.system("xinput %s '%s'" % (xinput_statemap[pen_status], devicename))
if __name__ == '__main__':
manage_orientation_and_palm_rejection(sys.argv[1:])