forked from YunMengs/Firefly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
179 lines (157 loc) · 5.66 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
import ctypes
import json
import subprocess
import threading
import time
from PySide2 import QtWidgets
from PySide2.QtGui import QIcon
from PySide2.QtWidgets import QApplication, QMessageBox, QTableWidgetItem, QAbstractItemView, QHeaderView
from PySide2.QtUiTools import QUiLoader
from Dnconsole import Dnconsole
from model.func import stop_thread
from task.FriendTask import FriendTask
from task.TestTask import TestTask
class MainModel:
# 当前控制的vm index
index = None
# 当前控制的vm index
setupUI = None
# 当前控制的VM
vm = None
# 启动的列表
startList = {}
# 启动的线程列表
threadingtList = {}
def screenshotButtonHandle(self):
"""
截图
:return:
"""
self.getVM()
# ' + str(int(time.time())) + '
Dnconsole.dnld(self.index, 'screencap -p /mnt/shared/Pictures/' + str(self.index) + 'screencap.png')
def setupButtonHandle(self):
"""
打开设置
:return:
"""
self.setupUI = QUiLoader().load('setup.ui')
self.setupUI.show()
def pauseButtonHandle(self):
"""
暂停 继续 处理
:return:
"""
dn = Dnconsole
self.getVM()
self.startList[self.index].pause()
arr = ["未开始", "暂停", "继续"]
self.ui.pauseButton.setText(arr[self.startList[self.index].status])
def stopButtonHandle(self):
"""
游戏结束
:return:
"""
self.getVM()
# 停止所有子线程
self.startList[self.index].game_over()
# 停止主线程
stop_thread(self.threadingtList[self.index])
print("停止游戏")
def StartUpSimulatorButtonHandle(self):
dn = Dnconsole
"""
启动模拟器处理事件
:return: None
"""
item = self.ui.tableWidget.selectedItems()
index = int(item[0].text())
dn.set_screen_size(index)
dn.launch(index)
self.vm = dn.get_one_list(index)
def StartUpScriptButtonHandle(self):
"""
启动脚本处理事件
:return: None
"""
dn = Dnconsole
self.getVM()
index = self.ui.comboBoxTask.currentIndex()
print("index:" + str(index))
if index == 1:
start = FriendTask(self.vm, self.index)
else:
start = TestTask(self.vm, self.index)
self.startList[self.index] = start
# 创建线程
self.threadingtList[self.index] = threading.Thread(target=start.start_game(), args=())
# 启动线程
self.threadingtList[self.index].start()
def getVM(self):
"""
获取VM模拟器
:return:
"""
dn = Dnconsole
item = self.ui.tableWidget.selectedItems()
if len(item) <= 0:
self.index = 0
else:
self.index = int(item[0].text())
self.vm = dn.get_one_list(self.index)
def __init__(self):
# 读取配置
dn = Dnconsole
with open('data.json') as f:
jdata = json.load(f)
print(jdata)
dn.console = jdata['console']
dn.ld = jdata['ld']
# 从文件中加载UI定义
# 从 UI 定义中动态 创建一个相应的窗口对象
# 注意:里面的控件对象也成为窗口对象的属性了
# 比如 self.ui.button , self.ui.textEdit
self.ui = QUiLoader().load('main.ui')
self.ui.tableWidget.setStyleSheet(
'''QWidget{min-height: 20px; font-size:10pt;border-radius:3px;background-color:rgb(240,248,255);color:
rgb(0,0,0)}''')
# self.ui.pushButton_3.clicked.connect(lambda: self.add_timer(self.ui.pushButton_3))
vmlist = dn.get_list()
# 遍历模拟器
for index in range(len(vmlist)):
item = vmlist[index]
print(index)
col_1 = QtWidgets.QTableWidgetItem(str(item.index))
col_2 = QtWidgets.QTableWidgetItem(item.name)
if item.is_in_android:
openStatus = "打开"
else:
openStatus = "关闭"
col_3 = QtWidgets.QTableWidgetItem(openStatus)
self.ui.tableWidget.insertRow(int(self.ui.tableWidget.rowCount()))
self.ui.tableWidget.setItem(index, 0, col_1)
self.ui.tableWidget.setItem(index, 1, col_2)
self.ui.tableWidget.setItem(index, 2, col_3)
self.ui.tableWidget.update()
# 自动拉升最后一列
# self.ui.tableWidget.horizontalHeader().setStretchLastSection(True)
# 每一列都拉伸, 使用QHeaderView的setSectionResizeMode函数,将resizemode设置为QHeaderView::Stretch。
self.ui.tableWidget.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
# 禁止编辑
self.ui.tableWidget.setEditTriggers(QAbstractItemView.NoEditTriggers)
# 只允许单行选中
self.ui.tableWidget.setSelectionMode(QAbstractItemView.SingleSelection)
self.ui.tableWidget.setSelectionBehavior(QAbstractItemView.SelectRows)
# 为按钮绑定事件
self.ui.StartUpSimulatorButton.clicked.connect(self.StartUpSimulatorButtonHandle)
self.ui.StartUpScriptButton.clicked.connect(self.StartUpScriptButtonHandle)
self.ui.pauseButton.clicked.connect(self.pauseButtonHandle)
self.ui.stopButton.clicked.connect(self.stopButtonHandle)
self.ui.setupButton.clicked.connect(self.setupButtonHandle)
self.ui.screenshotButton.clicked.connect(self.screenshotButtonHandle)
app = QApplication([])
# 加载 icon
app.setWindowIcon(QIcon('./img/logo.ico'))
stats = MainModel()
stats.ui.show()
app.exec_()