-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfrontend.pyw
105 lines (79 loc) · 2.99 KB
/
frontend.pyw
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
# from PyQt5.QtCore import *
import yuki
import threading
import logging
import asyncio
from functools import partial
class QTextEditLogger(logging.Handler):
def __init__(self, parent):
super().__init__()
self.widget = QTextEdit(parent)
self.widget.setReadOnly(True)
def emit(self, record):
colorDict = {
"INFO": "<font color=blue>",
"ERROR": "<font color=red>",
"WARNING": "<font color=darkorange>"
}
self.widget.append(
colorDict.get(record.levelname, "<font color=black>") +
self.format(record) +
"</font>"
)
# self.widget.append("</span>")
app.processEvents()
class AppForm(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.resize(640, 480)
self.setWindowTitle("Yukiko")
self.setWindowIcon(QIcon("assets/yukikoIcon.png"))
self.channelTextBox = QLineEdit(self)
self.channelTextBox.setPlaceholderText("Channel ID")
# self.channelTextBox.textChanged.connect(partial(await yuki.start_typing, self.channelTextBox.text()))
self.msgTextBox = QLineEdit(self)
self.msgTextBox.setPlaceholderText("Message Content")
# self.applyPlayingBtn.clicked.connect(self.applyPlayingStatus)
self.sendMSGButton = QPushButton("Send Message", self)
self.logTextBox = QTextEditLogger(self)
self.logTextBox.setFormatter(logging.Formatter("%(asctime)s - %(levelname)s - %(message)s"))
logging.getLogger().addHandler(self.logTextBox)
logging.getLogger().setLevel(logging.INFO)
self.layout = QVBoxLayout()
self.layout.addWidget(self.logTextBox.widget)
self.layout.addWidget(self.channelTextBox)
self.layout.addWidget(self.msgTextBox)
self.layout.addWidget(self.sendMSGButton)
self.setLayout(self.layout)
def applyPlayingStatus(self):
yuki.changePlayingStatus(self.playingTextbox.text())
class RedirToLogger(object):
# https://www.electricmonk.nl/log/2011/08/14/redirect-stdout-and-stderr-to-a-logger-in-python/
def __init__(self, logger, log_level = logging.INFO):
self.logger = logger
self.log_level = log_level
self.linebuf = ""
def write(self, buf):
for line in buf.rstrip().splitlines():
self.logger.log(self.log_level, line.rstrip())
if __name__ == "__main__":
"""stdout_logger = logging.getLogger("STDOUT")
sl = RedirToLogger(stdout_logger, logging.INFO)
sys.stdout = sl
"""
stderr_logger = logging.getLogger("STDERR")
sl = RedirToLogger(stderr_logger, logging.ERROR)
sys.stderr = sl
app = QApplication(sys.argv)
# app.setStyle("Fusion")
window = AppForm()
t = threading.Thread(target = yuki.run_bot, name = "Runs the bot")
t.daemon = True
t.start()
window.show()
sys.exit(app.exec_())