diff options
author | Anthony Wang | 2024-01-02 20:06:09 -0600 |
---|---|---|
committer | Anthony Wang | 2024-01-02 20:06:09 -0600 |
commit | 33b76d4106a2024e8f095c7bbb232482b7883eee (patch) | |
tree | f79bba7bbde23cb04eaad90c388992480fe39003 /main.py | |
parent | fdd8f1fe2d5ad5b0e09b00c919499d9fe9008c1f (diff) |
Fix #1: PyQt6 and Tkinter GUIs
Diffstat (limited to 'main.py')
-rw-r--r-- | main.py | 50 |
1 files changed, 50 insertions, 0 deletions
@@ -0,0 +1,50 @@ +import subprocess +import sys +from PyQt6.QtWidgets import QApplication, QMainWindow, QLabel +from PyQt6.QtGui import QFont +from PyQt6.QtCore import Qt + + +class SDGUI(QMainWindow): + def __init__(self): + super().__init__() + + self.setGeometry(100, 100, 1280, 720) + self.setWindowTitle('SD GUI') + + # Start SD + self.proc = subprocess.Popen( + sys.argv[1:] + ['-n'], stdin=subprocess.PIPE, stdout=subprocess.PIPE + ) + + # Display key + key = self.proc.stdout.readline().decode('utf-8') + self.label = QLabel(key, self) + self.label.setFont(QFont('Arial', 48)) + self.label.setWordWrap(True) + self.label.setAlignment(Qt.AlignmentFlag.AlignCenter) + self.setCentralWidget(self.label) + + def keyPressEvent(self, event): + if self.label.text().count('\n') == 2 and event.text() not in 'yn': + # Manually quit here because stdout.readline blocks and doesn't error when SD exits + self.close() + + # Write to SD + self.proc.stdin.write((event.text() + '\n').encode('utf-8')) + self.proc.stdin.flush() + + # Get response + text = self.proc.stdout.readline().decode('utf-8') + if text.startswith('>'): + # Key + self.label.setText(text) + else: + # Value + self.label.setText(self.label.text() + text) + + +app = QApplication(sys.argv) +window = SDGUI() +window.show() +app.exec() |