Skip to content

Commit 0f81935

Browse files
- [tool] Update Codes.
Signed-off-by: ColdWindScholar <[email protected]>
1 parent 0e02177 commit 0f81935

File tree

4 files changed

+125
-4
lines changed

4 files changed

+125
-4
lines changed

bin/setting.ini

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
[setting]
22
theme = dark
3-
path =
3+
path =
44
ai_engine = 0
55
version = 4.1.0
66
barlevel = 0.89
7-
oobe = 0
8-
language = English
7+
oobe = 5
8+
language = Chinese-Simplified
99
contextpatch = 0
1010
project_struct = single
1111
plugin_repo = https://raw.githubusercontent.com/ColdWindScholar/MPK_Plugins/main/

requirements.txt

+2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ pycryptodome>=3.19.1
33
Requests>2.31.0
44
protobuf>5
55
sv_ttk
6+
pyqt6
67
pyinstaller
78
chlorophyll
89
future
910
pip
11+
darkdetect
1012
Pygments
1113
zstandard
1214
asn1crypto

src/qtui/tool.py

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
import sys
2+
import time
3+
4+
from PyQt6.QtCore import Qt, QTimer, QMimeData
5+
from PyQt6.QtGui import QTextCursor, QFont, QDropEvent
6+
from PyQt6.QtWidgets import QApplication, QMainWindow, QHBoxLayout, QVBoxLayout, QTabWidget, QLabel, QWidget, \
7+
QPlainTextEdit
8+
9+
10+
11+
# Custom Controls
12+
class DropLabel(QLabel):
13+
def __init__(self, *args, **kwargs):
14+
super().__init__(*args, **kwargs)
15+
self.setStyleSheet("border: 2px dashed grey;")
16+
self.on_drop = lambda text:print(text)
17+
18+
def set_drop_func(self, func:callable):
19+
if func.__code__.co_argcount != 1:
20+
print(f"Set drop func fail!\nThe arg_count of {func.__name__} must be 1, but its {func.__code__.co_argcount}")
21+
self.on_drop = func
22+
23+
def dragEnterEvent(self, event):
24+
event.accept()
25+
26+
def dropEvent(self, event:QDropEvent):
27+
self.on_drop(event.mimeData())
28+
event.accept()
29+
30+
def mousePressEvent(self, event):
31+
if event.button() == Qt.MouseButton.LeftButton:
32+
print("Left button pressed")
33+
elif event.button() == Qt.MouseButton.RightButton:
34+
print("Right button pressed")
35+
36+
# Main Class
37+
class Tool(QMainWindow):
38+
def __init__(self):
39+
super(Tool, self).__init__()
40+
self.log_output = None
41+
self.timers = set()
42+
self.setWindowTitle('MIO-KITCHEN')
43+
self.main_layout = QHBoxLayout()
44+
self.log_area = QVBoxLayout()
45+
self.func_area = QVBoxLayout()
46+
self.main_layout.addLayout(self.log_area)
47+
self.main_layout.addLayout(self.func_area)
48+
self.log_area_content()
49+
self.func_area_content()
50+
self.start_timers()
51+
widget = QWidget()
52+
widget.setLayout(self.main_layout)
53+
self.setCentralWidget(widget)
54+
55+
def log_area_content(self):
56+
time_show = QLabel('MIO-KITCHEN')
57+
ft = QFont()
58+
ft.setPointSize(18)
59+
ft.setBold(True)
60+
time_show.setFont(ft)
61+
if not self.log_output:
62+
self.log_output = QPlainTextEdit()
63+
drag_and_drop = DropLabel("Drop URL / Path / FileName Here.")
64+
drag_and_drop.setMinimumHeight(80)
65+
drag_and_drop.setMinimumWidth(240)
66+
drag_and_drop.set_drop_func(lambda :...)
67+
self.log_area.addWidget(time_show)
68+
self.log_area.addWidget(drag_and_drop)
69+
drag_and_drop.setAlignment(Qt.AlignmentFlag.AlignCenter)
70+
time_show.setAlignment(Qt.AlignmentFlag.AlignCenter)
71+
drag_and_drop.setAcceptDrops(True)
72+
self.log_area.addWidget(self.log_output)
73+
show_timer = QTimer(self)
74+
show_timer.timeout.connect(lambda: time_show.setText(time.strftime("%H:%M:%S")))
75+
self.timers.add(show_timer)
76+
77+
def func_area_content(self):
78+
tabs = QTabWidget()
79+
self.func_area.addWidget(
80+
tabs
81+
)
82+
tabs.setMovable(True)
83+
84+
for n, color in enumerate(["red", "green", "blue", "yellow"]):
85+
tabs.addTab(QLabel(color), str(n))
86+
87+
def start_timers(self):
88+
for i in self.timers:
89+
i.start(1000)
90+
91+
92+
class StdoutRedirector:
93+
def __init__(self, text_widget: QPlainTextEdit, is_error=False):
94+
self.text_space = text_widget
95+
self.flush = ...
96+
self.error = ''
97+
self.is_error = is_error
98+
99+
def write(self, string):
100+
if self.is_error:
101+
self.error += string
102+
print(string)
103+
self.text_space.insertPlainText(string)
104+
self.text_space.moveCursor(QTextCursor.MoveOperation.End)
105+
106+
107+
def init(args: list):
108+
if args:
109+
print(args)
110+
app = QApplication(sys.argv)
111+
window = Tool()
112+
sys.stdout = StdoutRedirector(window.log_output)
113+
sys.stderr = StdoutRedirector(window.log_output, is_error=True)
114+
window.show()
115+
app.exec()
116+
117+
118+
if __name__ == '__main__':
119+
init([])

tool.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
f"Not supported: [{sys.version}] yet\nEnter to quit\nSorry for any inconvenience caused")
1919
sys.exit(1)
2020
try:
21-
from src.tkui.tool import *
21+
from src.qtui.tool import *
2222
except Exception as e:
2323
input(f"Sorry! We cannot init the tool.\nPlease clone source again!\n{e}")
2424
sys.exit(1)

0 commit comments

Comments
 (0)