blob: 9d821d18bf2fe1d34080deea5ff47e11dd425933 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
#!/usr/bin/python
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.path[0] + '/sd', *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()
|