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')
while True:
int_displays = countdisplays()
time.sleep(1.0/freq)
if int_displays == 1:
def manage_orientation_and_palm_rejection(options):
current_orientation = ''
currently_proximate = False
# Check accelerometers
# Do we need to check the touch_devices list every time? I
# think we do; the list will change dynamically if we
# dynamically load the stylus driver after the system has
# 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
while True:
int_displays = countdisplays()
time.sleep(1.0/freq)
if int_displays == 1:
# Check accelerometers
# Do we need to check the touch_devices list every time? I
# think we do; the list will change dynamically if we
# dynamically load the stylus driver after the system has
# 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):
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))
# 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:])