Skip to content
This repository was archived by the owner on Dec 29, 2024. It is now read-only.

Commit a043399

Browse files
committed
添加更新功能
1 parent 0064112 commit a043399

File tree

4 files changed

+132
-87
lines changed

4 files changed

+132
-87
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# costom
22
/MAA_bin
3-
3+
/json
44
# Byte-compiled / optimized / DLL files
55
__pycache__/
66
*.py[cod]
@@ -163,3 +163,5 @@ cython_debug/
163163
# and can be added to the global gitignore or merged into this file. For a more nuclear
164164
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
165165
#.idea/
166+
subprocess.py
167+
os.py

control.py

Lines changed: 33 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,41 @@
11
from ui import Win
22
import subprocess
33
import os
4-
import json
4+
from tool import *
55

6-
def Read_MAA_Config(path):
7-
if not os.path.exists(os.getcwd()+"\MAA_bin\config\maa_pi_config.json"):
8-
os.makedirs(os.getcwd()+"\MAA_bin\config\\")
9-
date = {"adb": {"adb_path":"请在此处填写ADB路径,回车确定","address":"请在此处填写ADB端口,回车确定","config": {}},"controller": {"name": "安卓端","type": "Adb"},"resource":"官服","task":[]}
10-
with open(os.getcwd()+"\MAA_bin\config\maa_pi_config.json","w",encoding='utf-8') as MAA_Config:
11-
json.dump(date,MAA_Config,indent=4,ensure_ascii=False)
12-
with open(path,"r",encoding='utf-8') as MAA_Config:
13-
# 打开json并传入MAA_data
14-
MAA_data = json.load(MAA_Config)
15-
return MAA_data
16-
17-
def Save_MAA_Config(path,date):
18-
# 打开json并写入data内数据
19-
with open(path,"w",encoding='utf-8') as MAA_Config:
20-
json.dump(date,MAA_Config,indent=4,ensure_ascii=False)
21-
22-
def Get_Values_list2(path,key1):
23-
List = []
24-
for i in Read_MAA_Config(path)[key1]:
25-
List.append(i)
26-
return List
27-
28-
def Get_Values_list_Option(path,key1):
29-
#获取组件的初始参数
30-
List = []
31-
for i in Read_MAA_Config(path)[key1]:
32-
33-
if i["option"]!=[]:
34-
Option_text = str(i["name"])+" "
35-
Option_Lens = len(i["option"])
36-
for t in range(0,Option_Lens,1):
37-
Option_text+=str(i["option"][t]["value"])+" "
38-
List.append(Option_text)
39-
else:
40-
List.append(i["name"])
41-
return List
42-
43-
def Get_Task_List(target):
44-
#输入option名称来输出一个包含所有该option中所有cases的name列表
45-
#具体逻辑为 interface.json文件/option键/选项名称/cases键/键为空,所以通过len计算长度来选择最后一个/name键
46-
lists = []
47-
Task_Config = Read_MAA_Config(os.getcwd()+"\MAA_bin\interface.json")["option"][target]["cases"]
48-
Lens = len(Task_Config)-1
49-
for i in range(Lens,-1,-1):
50-
lists.append(Task_Config[i]["name"])
51-
return lists
526

537
#获取初始resource序号
548
Add_Resource_Type_Select_Values = []
559
for i in Read_MAA_Config(os.getcwd()+"\MAA_bin\interface.json")["resource"]:
5610
Add_Resource_Type_Select_Values.append(i["name"])
5711
Resource_Type = Read_MAA_Config(os.getcwd()+"\MAA_bin\config\maa_pi_config.json")["resource"]
58-
count = 0
12+
13+
Resource_count = 0
5914
for i in Add_Resource_Type_Select_Values:
6015
if i == Resource_Type:
6116
break
6217
else:
63-
count+=1
18+
Resource_count+=1
19+
20+
#获取初始Controller序号
21+
Add_Controller_Type_Select_Values = []
22+
for i in Read_MAA_Config(os.getcwd()+"\MAA_bin\interface.json")["controller"]:
23+
Add_Controller_Type_Select_Values.append(i["name"])
24+
Controller_Type = Read_MAA_Config(os.getcwd()+"\MAA_bin\config\maa_pi_config.json")["controller"]["name"]
25+
26+
Controller_count = 0
27+
for i in Add_Controller_Type_Select_Values:
28+
if i == Controller_Type:
29+
break
30+
else:
31+
Controller_count+=1
32+
6433

6534
#初始显示
6635
init_ADB_Path = Read_MAA_Config(os.getcwd()+"\MAA_bin\config\maa_pi_config.json")["adb"]["adb_path"]
6736
init_ADB_Address = Read_MAA_Config(os.getcwd()+"\MAA_bin\config\maa_pi_config.json")["adb"]["address"]
68-
init_Resource_Type = count
37+
init_Resource_Type = Resource_count
38+
init_Controller_Type = Controller_count
6939

7040
class Controller:
7141
# 导入UI类后,替换以下的 object 类型,将获得 IDE 属性提示功能
@@ -83,7 +53,8 @@ def init(self,ui):
8353
#ADB地址和端口输入框
8454
self.ui.tk_input_ADB_Address_Input.insert(0,init_ADB_Address)
8555
self.ui.tk_input_ADB_Path_Input.insert(0,init_ADB_Path)
86-
#服务器和任务下拉框
56+
#服务器和任务下拉框和控制端下拉框
57+
self.ui.tk_select_box_Controller_Type_Select.current(init_Controller_Type)
8758
self.ui.tk_select_box_Resource_Type_Select.current(init_Resource_Type)
8859
self.ui.tk_select_box_Add_Task_Select.current(0)
8960

@@ -122,6 +93,13 @@ def Save_Resource_Type_Select(self,evt):
12293
MAA_Pi_Config["resource"] = Resource_Type_Select
12394
Save_MAA_Config(os.getcwd()+"\MAA_bin\config\maa_pi_config.json",MAA_Pi_Config)
12495

96+
def Save_Controller_Type_Select(self,evt):
97+
#打开maa_pi_config.json并写入新的资源
98+
Resource_Type_Select = self.ui.tk_select_box_Resource_Type_Select.get()
99+
MAA_Pi_Config = Read_MAA_Config(os.getcwd()+"\MAA_bin\config\maa_pi_config.json")
100+
MAA_Pi_Config["controller"] = Resource_Type_Select
101+
Save_MAA_Config(os.getcwd()+"\MAA_bin\config\maa_pi_config.json",MAA_Pi_Config)
102+
125103
def Add_Task(self,evt):
126104
#添加任务至GUI列表并保存配置文件
127105
task = self.ui.tk_select_box_Add_Task_Select.get()
@@ -174,6 +152,7 @@ def Click_Move_Up_Button(self,evt):
174152
self.ui.tk_list_box_Task_List.delete(0,100)
175153
for item in Get_Values_list_Option(os.getcwd()+"\MAA_bin\config\maa_pi_config.json","task"):
176154
self.ui.tk_list_box_Task_List.insert(100, item)
155+
self.ui.tk_list_box_Task_List.selection_set(Select_Target-1)
177156
self.ui.tk_list_box_Task_List.update()
178157

179158
def Click_Move_Down_Button(self,evt):
@@ -187,6 +166,7 @@ def Click_Move_Down_Button(self,evt):
187166
self.ui.tk_list_box_Task_List.delete(0,100)
188167
for item in Get_Values_list_Option(os.getcwd()+"\MAA_bin\config\maa_pi_config.json","task"):
189168
self.ui.tk_list_box_Task_List.insert(100, item)
169+
self.ui.tk_list_box_Task_List.selection_set(Select_Target+1)
190170
self.ui.tk_list_box_Task_List.update()
191171

192172
def Click_Delete_Button(self,evt):
@@ -199,7 +179,9 @@ def Click_Delete_Button(self,evt):
199179
del MAA_Pi_Config["task"]
200180
MAA_Pi_Config.update({"task":Task_List})
201181
Save_MAA_Config(os.getcwd()+"/\MAA_bin\config\maa_pi_config.json",MAA_Pi_Config)
182+
self.ui.tk_list_box_Task_List.selection_set(Select_Target-1)
202183
self.ui.tk_list_box_Task_List.update()
184+
203185

204186
def Add_Task_Select_More_Select(self,evt):
205187
#不用了之后隐藏控件

tool.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import os
2+
import json
3+
4+
def Read_MAA_Config(path):
5+
if not os.path.exists(os.getcwd()+"\MAA_bin\config\maa_pi_config.json"):
6+
os.makedirs(os.getcwd()+"\MAA_bin\config\\")
7+
date = {"adb": {"adb_path":"请在此处填写ADB路径,回车确定","address":"请在此处填写ADB端口,回车确定","config": {}},"controller": {"name": "安卓端","type": "Adb"},"resource":"官服","task":[]}
8+
with open(os.getcwd()+"\MAA_bin\config\maa_pi_config.json","w",encoding='utf-8') as MAA_Config:
9+
json.dump(date,MAA_Config,indent=4,ensure_ascii=False)
10+
with open(path,"r",encoding='utf-8') as MAA_Config:
11+
# 打开json并传入MAA_data
12+
MAA_data = json.load(MAA_Config)
13+
return MAA_data
14+
15+
def Save_MAA_Config(path,date):
16+
# 打开json并写入data内数据
17+
with open(path,"w",encoding='utf-8') as MAA_Config:
18+
json.dump(date,MAA_Config,indent=4,ensure_ascii=False)
19+
20+
def Get_Values_list2(path,key1):
21+
List = []
22+
for i in Read_MAA_Config(path)[key1]:
23+
List.append(i)
24+
return List
25+
26+
def Get_Values_list(path,key1):
27+
#获取组件的初始参数
28+
List = []
29+
for i in Read_MAA_Config(path)[key1]:
30+
List.append(i["name"])
31+
return List
32+
33+
def Get_Values_list_Option(path,key1):
34+
#获取组件的初始参数
35+
List = []
36+
for i in Read_MAA_Config(path)[key1]:
37+
if i["option"]!=[]:
38+
Option_text = str(i["name"])+" "
39+
Option_Lens = len(i["option"])
40+
for t in range(0,Option_Lens,1):
41+
Option_text+=str(i["option"][t]["value"])+" "
42+
List.append(Option_text)
43+
else:
44+
List.append(i["name"])
45+
return List
46+
47+
def Get_Task_List(target):
48+
#输入option名称来输出一个包含所有该option中所有cases的name列表
49+
#具体逻辑为 interface.json文件/option键/选项名称/cases键/键为空,所以通过len计算长度来选择最后一个/name键
50+
lists = []
51+
Task_Config = Read_MAA_Config(os.getcwd()+"\MAA_bin\interface.json")["option"][target]["cases"]
52+
Lens = len(Task_Config)-1
53+
for i in range(Lens,-1,-1):
54+
lists.append(Task_Config[i]["name"])
55+
return lists

ui.py

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,8 @@
1+
from tool import *
12
from tkinter import *
23
from tkinter.ttk import *
3-
import os
4-
import json
54

65

7-
def Read_MAA_Config(path):
8-
9-
with open(path,"r",encoding='utf-8') as MAA_Config:
10-
#打开json并传入MAA_data
11-
MAA_data = json.load(MAA_Config)
12-
return MAA_data
13-
14-
def Save_MAA_Config(path,date):
15-
#打开json并写入data内数据
16-
with open(path,"w",encoding='utf-8') as MAA_Config:
17-
json.dump(date,MAA_Config,indent=4,ensure_ascii=False)
18-
19-
def Get_Values_list(path,key1):
20-
#获取组件的初始参数
21-
List = []
22-
for i in Read_MAA_Config(path)[key1]:
23-
List.append(i["name"])
24-
return List
25-
26-
def Get_Values_list_Option(path,key1):
27-
#获取组件的初始参数
28-
List = []
29-
for i in Read_MAA_Config(path)[key1]:
30-
if i["option"]!=[]:
31-
Option_text = str(i["name"])+" "
32-
Option_Lens = len(i["option"])
33-
for t in range(0,Option_Lens,1):
34-
Option_text+=str(i["option"][t]["value"])+" "
35-
List.append(Option_text)
36-
else:
37-
List.append(i["name"])
38-
return List
39-
406
class WinGUI(Tk):
417
def __init__(self):
428
super().__init__()
@@ -65,6 +31,13 @@ def __init__(self):
6531
self.tk_label_Add_Task_Label_4 = self.__tk_label_Add_Task_Label_4(self)
6632
self.tk_label_Add_Task_Label_5 = self.__tk_label_Add_Task_Label_5(self)
6733
self.tk_label_Add_Task_Label_6 = self.__tk_label_Add_Task_Label_6(self)
34+
self.tk_label_Controller_Type_Label = self.__tk_label_Controller_Type_Label(self)
35+
self.tk_select_box_Controller_Type_Select = self.__tk_select_box_Controller_Type_Select(self)
36+
self.tk_input_Input_Author_Name = self.__tk_input_Input_Author_Name(self)
37+
self.tk_button_Update_button = self.__tk_button_Update_button(self)
38+
self.tk_label_Author_Name_Label = self.__tk_label_Author_Name_Label(self)
39+
self.tk_label_Project_Name_Label = self.__tk_label_Project_Name_Label(self)
40+
self.tk_input_Project_Name = self.__tk_input_Project_Name(self)
6841
def __win(self):
6942
self.title("MAA-GUI")
7043
# 设置窗口大小、居中
@@ -166,6 +139,11 @@ def __tk_list_box_Task_List(self,parent):
166139
lb.insert(END, item)
167140
lb.place(x=360, y=40, width=220, height=400)
168141
return lb
142+
def __tk_select_box_Controller_Type_Select(self,parent):
143+
cb = Combobox(parent, state="readonly", )
144+
cb['values'] = (Get_Values_list(os.getcwd()+"\MAA_bin\interface.json","controller"))
145+
cb.place(x=260, y=80, width=80, height=30)
146+
return cb
169147
def __tk_button_Move_Up_Button(self,parent):
170148
btn = Button(parent, text="上移", takefocus=False,)
171149
btn.place(x=360, y=460, width=50, height=30)
@@ -214,6 +192,30 @@ def __tk_label_Add_Task_Label_6(self,parent):
214192
label = Label(parent,text="4号标签",anchor="center", )
215193
label.place(x=0, y=320, width=70, height=30)
216194
return label
195+
def __tk_label_Controller_Type_Label(self,parent):
196+
label = Label(parent,text="控制端",anchor="center", )
197+
label.place(x=180, y=80, width=70, height=30)
198+
return label
199+
def __tk_input_Input_Author_Name(self,parent):
200+
ipt = Entry(parent, )
201+
ipt.place(x=80, y=360, width=80, height=30)
202+
return ipt
203+
def __tk_button_Update_button(self,parent):
204+
btn = Button(parent, text="更新", takefocus=False,)
205+
btn.place(x=290, y=400, width=50, height=30)
206+
return btn
207+
def __tk_label_Author_Name_Label(self,parent):
208+
label = Label(parent,text="作者名",anchor="center", )
209+
label.place(x=0, y=360, width=70, height=30)
210+
return label
211+
def __tk_label_Project_Name_Label(self,parent):
212+
label = Label(parent,text="项目名",anchor="center", )
213+
label.place(x=180, y=360, width=70, height=30)
214+
return label
215+
def __tk_input_Project_Name(self,parent):
216+
ipt = Entry(parent, )
217+
ipt.place(x=260, y=360, width=80, height=30)
218+
return ipt
217219
class Win(WinGUI):
218220
def __init__(self, controller):
219221
self.ctl = controller
@@ -227,11 +229,15 @@ def __event_bind(self):
227229
self.tk_input_ADB_Path_Input.bind('<Return>',self.ctl.Save_ADB_Path)
228230
self.tk_input_ADB_Address_Input.bind('<Return>',self.ctl.Save_ADB_Address)
229231
self.tk_select_box_Resource_Type_Select.bind('<<ComboboxSelected>>',self.ctl.Save_Resource_Type_Select)
232+
self.tk_select_box_Resource_Type_Select.bind('<Button-1>',self.ctl.Save_ADB_Path)
230233
self.tk_select_box_Add_Task_Select.bind('<<ComboboxSelected>>',self.ctl.Add_Task_Select_More_Select)
234+
self.tk_select_box_Add_Task_Select.bind('<Enter>',self.ctl.Save_ADB_Address)
231235
self.tk_button_Add_Task_Button.bind('<Button-1>',self.ctl.Add_Task)
232236
self.tk_button_Move_Up_Button.bind('<Button-1>',self.ctl.Click_Move_Up_Button)
233237
self.tk_button_Move_Down_Button.bind('<Button-1>',self.ctl.Click_Move_Down_Button)
234238
self.tk_button_Delete_Button.bind('<Button-1>',self.ctl.Click_Delete_Button)
239+
self.tk_select_box_Controller_Type_Select.bind('<<ComboboxSelected>>',self.ctl.Save_Controller_Type_Select)
240+
self.tk_list_box_Task_List.bind('<Delete>',self.ctl.Click_Delete_Button)
235241
pass
236242
def __style_config(self):
237243
pass

0 commit comments

Comments
 (0)