This repository was archived by the owner on Mar 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwindow_main.py
More file actions
152 lines (120 loc) · 4.9 KB
/
Copy pathwindow_main.py
File metadata and controls
152 lines (120 loc) · 4.9 KB
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
from PySide2 import QtCore, QtGui, QtWidgets
from PySide2.QtCore import Signal
import os,json,subprocess
from UI.MainWindow import Ui_MainWindow as Main_window
from Environment import path, dir_mix,next_,Show_bin
def message_info(type, title, msgs):
msg = {
'type': type,
'title': title,
'msg': msgs
}
return json.dumps(msg)
# 包装message数据
class ReadConfig(QtCore.QThread):
message = Signal(str)
model_add = Signal(int, int, int)
# 传参(传出):x,y,ID
def __init__(self):
super().__init__()
self.configs = []
self.pkg_root = []
def run(self) -> None:
Path = None # 图包父目录
Child_path = None # 图包文件夹目录名[list]
# 遍历图包目录
for paths, child_path, j in os.walk(path + next_+'Data'):
Path = paths
Child_path = child_path
break
now_Process = None
try:
for pkg_name in Child_path:
now_Process = pkg_name
config_file = dir_mix(
Path,
pkg_name,
'config.json'
)
# 合并多段数据 组成config文件的目录数据
with open(config_file, 'r', encoding='utf-8') as f:
self.configs.append(json.loads(f.read()))
self.pkg_root.append(dir_mix(
Path,
pkg_name,
))
except:
self.message.emit(message_info(type='wrong', title='error', msgs='包:[' + now_Process + ']异常'))
# 回调,发送出错的包的名称
All_model_count = len(self.configs)
count = 0
# print(int(All_model_count / 5))
for y in range(1, 6):
for x in range(1, 6):
if count == All_model_count:
break
# print(x,y,configs[count]["Name"],configs[count]["Description"])
self.model_add.emit(x, y, count)
count += 1
class window_main(QtWidgets.QMainWindow, Main_window):
def __init__(self):
super().__init__()
self.checkBox = []
self.label = []
self.pixmap = []
self.setupUi(self)
self.scrollArea.setFrameShape(QtWidgets.QFrame.NoFrame)
# 设置滚动区域无边框
def show(self) -> None:
super().show()
self.Add = ReadConfig()
self.Add.message.connect(self.message) # 绑定事件: message事件
self.Add.model_add.connect(self.Create_model)
self.Add.start() # 启动图包加载线程
# #人物计数器归零
# for y in range(1,30):
# for x in range(1,6):
# self.Create_model(x,y)
def message(self, msg):
data = json.loads(msg)
if data["type"] == "wrong":
QtWidgets.QMessageBox.warning(self, data["title"], data["msg"], QtWidgets.QMessageBox.Yes)
def Create_model(self, x, y, ID):
name = self.configs[ID]["Name"]
Description = self.configs[ID]["Description"]
cover = dir_mix(self.pkg_root[ID], self.configs[ID]["cover"])
list_length = 10 + 176 * y
self.scrollAreaWidgetContents.setMinimumSize(QtCore.QSize(760, list_length))
x_label = 10 + 150 * (x - 1)
y_label = 10 + 176 * (y - 1)
self.label.append(QtWidgets.QLabel(self.scrollAreaWidgetContents))
self.label[ID].setGeometry(QtCore.QRect(x_label, y_label, 140, 140))
self.label[ID].setStyleSheet("background-color: rgb(255, 255, 255);")
self.label[ID].setToolTip(Description)
pix = QtGui.QPixmap(cover)
hight = pix.height()*140/pix.width()
pix = pix.scaled(140, int(hight)) # 展示图片自适应
self.pixmap.append(pix)
self.label[ID].setPixmap(self.pixmap[ID])
x_checkBox = 10 + 150 * (x - 1)
y_checkBox = 10 + 150 * y + 26 * (y - 1)
self.checkBox.append(QtWidgets.QCheckBox(self.scrollAreaWidgetContents))
self.checkBox[ID].setGeometry(QtCore.QRect(x_checkBox, y_checkBox, 140, 16))
self.checkBox[ID].setText(name)
self.checkBox[ID].setToolTip(Description)
self.label[ID].show()
self.checkBox[ID].show()
def About_Window(self):
print('https://github.com/Cardinal-Designer')
def MakePath(Show, Pkg_path):
return Show + ' "' + Pkg_path + '"'
# 避免出现因为路径中有空格导致的无法执行
def Play_selected(self):
self.selected = [] # 记录被选择的ID
for i in range(0, len(self.configs)):
if self.checkBox[i].isChecked():
self.checkBox[i].setChecked(False)
os.popen(self.MakePath(Show_bin,self.pkg_root[i]))
def Play_all(self):
for i in range(0, len(self.configs)):
os.popen(self.MakePath(Show_bin, self.pkg_root[i]))