aboutsummaryrefslogtreecommitdiff
path: root/main.py
diff options
context:
space:
mode:
Diffstat (limited to 'main.py')
-rw-r--r--main.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/main.py b/main.py
new file mode 100644
index 0000000..8bba5b5
--- /dev/null
+++ b/main.py
@@ -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()