|
| 1 | +import sys |
| 2 | +from ast import literal_eval |
| 3 | +from threading import Thread |
| 4 | +from PyQt5.QtGui import QWindow |
| 5 | +from PyQt5.QtCore import Qt, QTimer |
| 6 | +from PyQt5.QtWidgets import QWidget, QApplication, QHBoxLayout |
| 7 | +from types import SimpleNamespace as _G |
| 8 | + |
| 9 | +G = _G() |
| 10 | + |
| 11 | +G.running = False |
| 12 | +G.done = False |
| 13 | +__version__ = "0.1.0" |
| 14 | + |
| 15 | + |
| 16 | +def event_loop(): |
| 17 | + print("commands: start - starts click through, exit - gracefully stop") |
| 18 | + try: |
| 19 | + while True: |
| 20 | + data = input(">").lower() |
| 21 | + if data == "start": |
| 22 | + print("start") |
| 23 | + G.running = True |
| 24 | + |
| 25 | + if data == "exit": |
| 26 | + sys.exit(0) |
| 27 | + print("exit") |
| 28 | + if "opacity" in data: |
| 29 | + print("to be implemented") |
| 30 | + |
| 31 | + except (KeyboardInterrupt, EOFError): |
| 32 | + sys.exit(0) |
| 33 | + |
| 34 | + |
| 35 | +class Main(QWidget): |
| 36 | + def __init__(self, hwnd, parent=None): |
| 37 | + QWidget.__init__(self, parent) |
| 38 | + window = QWindow.fromWinId(hwnd) |
| 39 | + self.container = self.createWindowContainer(window) |
| 40 | + self.setGeometry(100, 100, 1024, 768) |
| 41 | + # layout = QVBoxLayout(self) |
| 42 | + layout = QHBoxLayout(self) |
| 43 | + layout.addWidget(self.container) |
| 44 | + self.setLayout(layout) |
| 45 | + self.show() |
| 46 | + self.launch_timer() |
| 47 | + |
| 48 | + def launch_timer(self): |
| 49 | + self.timer = QTimer() |
| 50 | + self.timer.setInterval(15) |
| 51 | + self.timer.timeout.connect(self.interal_event_loop) |
| 52 | + self.timer.start() |
| 53 | + |
| 54 | + def interal_event_loop(self): |
| 55 | + if G.running and not G.done: |
| 56 | + self.make_overlay() |
| 57 | + G.done = True |
| 58 | + |
| 59 | + def make_overlay(self): |
| 60 | + print("overlay created") |
| 61 | + self.setWindowFlags( |
| 62 | + Qt.Window |
| 63 | + | Qt.CustomizeWindowHint |
| 64 | + | Qt.WindowStaysOnTopHint |
| 65 | + | Qt.FramelessWindowHint |
| 66 | + | Qt.X11BypassWindowManagerHint |
| 67 | + | Qt.WindowTransparentForInput |
| 68 | + ) |
| 69 | + self.show() |
| 70 | + |
| 71 | + |
| 72 | +if __name__ == "__main__": |
| 73 | + print("You should provide window id, get it using xwininfo") |
| 74 | + |
| 75 | + Thread(target=event_loop).start() |
| 76 | + app = QApplication(sys.argv) |
| 77 | + win = Main(int(literal_eval(sys.argv[1]))) |
| 78 | + win.setWindowTitle("Window container") |
| 79 | + sys.exit(app.exec_()) |
0 commit comments