Skip to content

Instantly share code, notes, and snippets.

@lemon32767
Last active July 31, 2021 09:31
Show Gist options
  • Save lemon32767/2aef4338d8ddbc97a4fcca4f9065ff3a to your computer and use it in GitHub Desktop.
Save lemon32767/2aef4338d8ddbc97a4fcca4f9065ff3a to your computer and use it in GitHub Desktop.
gui program to rotate touchscreen for lenovo ideapad flex 5 14ARE05
#!/bin/python
import tkinter as tk
import subprocess as sp
import os
rot = ["normal", "left", "inverted", "right"]
trans = ["1 0 0 0 1 0 0 0 1", "0 -1 1 1 0 0 0 0 1", "-1 0 1 0 -1 1 0 0 1", "0 1 0 -1 0 1 0 0 1"]
devs = ["Wacom HID 5215 Finger touch", "Wacom HID 5215 Pen stylus", "Wacom HID 5215 Pen eraser"]
def rotate(r):
nxt = rot.index(r)
print(rot[nxt])
sp.run(["xrandr", "-o", rot[nxt]])
sp.run(["sleep", "1.5"])
for dev in devs:
sp.run(["xinput", "set-prop", dev, 'Coordinate Transformation Matrix'] + trans[nxt].split())
class Application(tk.Frame):
def __init__(self, master=None):
super().__init__(master)
self.master = master
self.pack()
self.buttons = []
for r in rot:
but = tk.Button(self)
but["text"] = r
but["command"] = (lambda r: lambda: rotate(r))(r)
but["font"] = "{courier 14 bold}"
but.pack(side="left")
self.buttons.append(but)
root = tk.Tk()
app = Application(master=root)
app.master.title("rotater")
app.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment