-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
190 lines (158 loc) · 6.96 KB
/
main.py
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import os
import sys
# IMPORT / GUI AND MODULES AND WIDGETS
# ///////////////////////////////////////////////////////////////
from modules import *
from modules.HomePage import jsonEditor
from modules.YamlEditor import YamlMainWindow
from modules.cmdRunner import ScriptRunner
from modules.tools import EnvironmentChecker
os.environ["QT_FONT_DPI"] = "96" # FIX Problem for High DPI and Scale above 100%
widgets = None
class MainWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
# SET AS GLOBAL WIDGETS
# ///////////////////////////////////////////////////////////////
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
global widgets
widgets = self.ui
# USE CUSTOM TITLE BAR | USE AS "False" FOR MAC OR LINUX
# ///////////////////////////////////////////////////////////////
Settings.ENABLE_CUSTOM_TITLE_BAR = True
# APP NAME
# ///////////////////////////////////////////////////////////////
title = "启动器"
description = "Manyana"
# APPLY TEXTS
self.setWindowTitle(title)
widgets.titleRightInfo.setText(description)
# TOGGLE MENU
# ///////////////////////////////////////////////////////////////
widgets.toggleButton.clicked.connect(lambda: UIFunctions.toggleMenu(self, True))
# SET UI DEFINITIONS
# ///////////////////////////////////////////////////////////////
UIFunctions.uiDefinitions(self)
# QTableWidget PARAMETERS
# ///////////////////////////////////////////////////////////////
widgets.tableWidget.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
# BUTTONS CLICK
# ///////////////////////////////////////////////////////////////
# LEFT MENUS
widgets.btn_home.clicked.connect(self.buttonClick)
widgets.btn_widgets.clicked.connect(self.buttonClick)
widgets.btn_new.clicked.connect(self.buttonClick)
widgets.btn_save.clicked.connect(self.buttonClick)
widgets.btn_exit.clicked.connect(self.buttonClick)
try:
#yaml页面
self.yamlEditorPage1 = YamlMainWindow()
self.ui.stackedWidget.addWidget(self.yamlEditorPage1)
self.yamlEditorPage1.setStyleSheet(self.styleSheet())
except:
self.yamlEditorPage1=widgets.home
self.cmdRunner=ScriptRunner()
self.ui.stackedWidget.addWidget(self.cmdRunner)
#工具页面
self.setUpTools=EnvironmentChecker()
self.ui.stackedWidget.addWidget(self.setUpTools)
self.setUpTools.setStyleSheet("#EnvironmentChecker { background-image: url('images/chatbox.jpg'); }")
# 工具页面
try:
self.HomeP= jsonEditor()
self.ui.stackedWidget.addWidget(self.HomeP)
except:
CustomDialog.showMessage("未搭建Manyana,请在拉取源码并完成搭建后重启本启动器.")
self.HomeP=self.setUpTools
# EXTRA LEFT BOX
def openCloseLeftBox():
UIFunctions.toggleLeftBox(self, True)
widgets.toggleLeftBox.clicked.connect(openCloseLeftBox)
widgets.extraCloseColumnBtn.clicked.connect(openCloseLeftBox)
# EXTRA RIGHT BOX
def openCloseRightBox():
UIFunctions.toggleRightBox(self, True)
widgets.settingsTopBtn.clicked.connect(openCloseRightBox)
# SHOW APP
# ///////////////////////////////////////////////////////////////
self.show()
# SET HOME PAGE AND SELECT MENU
# ///////////////////////////////////////////////////////////////
widgets.stackedWidget.setCurrentWidget(self.HomeP)
widgets.btn_home.setStyleSheet(UIFunctions.selectMenu(widgets.btn_home.styleSheet()))
# BUTTONS CLICK
# Post here your functions for clicked buttons
# ///////////////////////////////////////////////////////////////
def buttonClick(self):
# GET BUTTON CLICKED
btn = self.sender()
btnName = btn.objectName()
# SHOW HOME PAGE
if btnName == "btn_home":
widgets.stackedWidget.setCurrentWidget(self.HomeP)
UIFunctions.resetStyle(self, btnName)
btn.setStyleSheet(UIFunctions.selectMenu(btn.styleSheet()))
# SHOW WIDGETS PAGE
if btnName == "btn_widgets":
index = self.ui.stackedWidget.indexOf(self.cmdRunner)
# Set the current widget of stackedWidget to YamlEditorPage
self.ui.stackedWidget.setCurrentIndex(index)
UIFunctions.resetStyle(self, btnName)
btn.setStyleSheet(UIFunctions.selectMenu(btn.styleSheet()))
# SHOW NEW PAGE
if btnName == "btn_new":
index = self.ui.stackedWidget.indexOf(self.yamlEditorPage1)
# Set the current widget of stackedWidget to YamlEditorPage
self.ui.stackedWidget.setCurrentIndex(index)
UIFunctions.resetStyle(self, btnName)
btn.setStyleSheet(UIFunctions.selectMenu(btn.styleSheet()))
if btnName == "btn_save":
index = self.ui.stackedWidget.indexOf(self.setUpTools)
# Set the current widget of stackedWidget to YamlEditorPage
self.ui.stackedWidget.setCurrentIndex(index)
UIFunctions.resetStyle(self, btnName)
btn.setStyleSheet(UIFunctions.selectMenu(btn.styleSheet()))
# PRINT BTN NAME
print(f'Button "{btnName}" pressed!')
# RESIZE EVENTS
# ///////////////////////////////////////////////////////////////
def resizeEvent(self, event):
# Update Size Grips
UIFunctions.resize_grips(self)
# MOUSE CLICK EVENTS
# ///////////////////////////////////////////////////////////////
def mousePressEvent(self, event):
# SET DRAG POS WINDOW
self.dragPos = event.globalPos()
# PRINT MOUSE EVENTS
if event.buttons() == Qt.LeftButton:
print('Mouse click: LEFT CLICK')
if event.buttons() == Qt.RightButton:
print('Mouse click: RIGHT CLICK')
def closeEvent(self, event: QEvent):
print("Main Window 关闭")
# 手动调用子页面的清理逻辑
self.cmdRunner.cleanup()
event.accept() # 接受关闭事件,正常关闭窗口
from PySide6.QtWidgets import QDialog, QVBoxLayout, QLabel, QPushButton
class CustomDialog(QDialog):
def __init__(self, message):
super().__init__()
self.setWindowTitle("Custom Dialog")
layout = QVBoxLayout()
label = QLabel(message)
layout.addWidget(label)
okButton = QPushButton("OK")
okButton.clicked.connect(self.accept) # Close the dialog when OK button is clicked
layout.addWidget(okButton)
self.setLayout(layout)
@staticmethod
def showMessage(message):
dialog = CustomDialog(message)
dialog.exec()
if __name__ == "__main__":
app = QApplication(sys.argv)
app.setWindowIcon(QIcon("icon.ico"))
window = MainWindow()
sys.exit(app.exec_())