-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathui.py
115 lines (92 loc) · 3.92 KB
/
ui.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
"""
该模块提供一个PyQt5应用,该应用可以在选项卡界面中管理多个"ClickerPage"实例。
"""
import subprocess
import os
from PyQt5.QtWidgets import (QApplication, QMainWindow, QPushButton, QVBoxLayout,
QTabWidget, QWidget, QGroupBox, QHBoxLayout, )
from PyQt5.QtCore import Qt, QSettings
from PyQt5.QtGui import QIcon
from childpage import ClickerPage
class ClickerApp(QMainWindow):
"""
ClickerApp的主应用类。
"""
def __init__(self):
super().__init__()
self.setWindowTitle('Alphay')
self.setGeometry(100, 100, 480, 320)
self.setFixedSize(480, 469)
self.setWindowIcon(QIcon('AY.ico'))
self.add_page_button = QPushButton("+")
self.add_page_button.clicked.connect(self.add_page)
self.remove_page_button = QPushButton("-")
self.remove_page_button.clicked.connect(self.remove_page)
self.buttons_widget = QWidget()
self.buttons_layout = QHBoxLayout(self.buttons_widget)
self.buttons_layout.setContentsMargins(0, 0, 0, 0)
self.buttons_layout.addWidget(self.add_page_button)
self.buttons_layout.addWidget(self.remove_page_button)
self.tab_widget = QTabWidget()
self.tab_widget.setCornerWidget(self.buttons_widget, Qt.TopRightCorner)
self.layout = QVBoxLayout()
self.layout.addWidget(self.tab_widget)
self.group_box = QGroupBox("账号")
self.group_box.setLayout(self.layout)
self.setCentralWidget(self.group_box)
# 在初始化和读取设置的时候,将读取到的端口信息处理成字符串
self.settings = QSettings("YourOrganization", "YourApplication")
ports = self.settings.value("ports", [], type=str)
if ports:
for port in ports:
self.add_page(port)
else:
self.add_page("")
self.show()
self.apply_qss()
def apply_qss(self):
"""
从外部.qss文件应用QSS样式到应用程序。
"""
with open('style.qss', 'r', encoding='utf-8') as style_file: # specify the encoding
self.setStyleSheet(style_file.read())
def add_page(self, port=None): # 默认值设置为None,而不是""
if port is None or port is False: # 如果没有给出port,或者port为False,则将其设置为空字符串
port = ""
page = ClickerPage(port, self.tab_widget.count())
self.tab_widget.addTab(page, f"账号 {self.tab_widget.count() + 1}")
def remove_page(self):
"""
如果有多个页面,则从QTabWidget中移除当前的"ClickerPage"。
"""
if self.tab_widget.currentIndex() != 0 and self.tab_widget.count() > 1:
self.tab_widget.removeTab(self.tab_widget.currentIndex())
def save_ports(self):
ports = [self.tab_widget.widget(i).port for i in range(self.tab_widget.count())]
self.settings.setValue("ports", ports)
# 当需要保存设置时(比如在窗口关闭事件中),调用 save_settings 函数。
def closeEvent(self, event):
self.save_ports()
event.accept()
def kill_adb_server():
# 获取当前脚本的目录
current_dir = os.path.dirname(os.path.abspath(__file__))
# 构建ADB可执行文件的路径
adb_path = os.path.join(current_dir, 'adb.exe')
# 检查ADB文件是否存在
if os.path.exists(adb_path):
# 杀死ADB服务端
try:
subprocess.run([adb_path, 'kill-server'])
print('ADB服务端已停止。')
except Exception as e:
print(f'停止ADB服务端时出错:{e}')
else:
print(f'路径不正确,未找到ADB文件:{adb_path}')
if __name__ == '__main__':
app = QApplication([])
# 连接 aboutToQuit 信号
#app.aboutToQuit.connect(kill_adb_server)
# 假设 ClickerApp 是您定义的类
ex = ClickerApp()
app.exec_()