Refactor config_launcher.py to improve code organization and UI readability

master
Yong-Jer Chuang 2024-04-26 14:31:59 +08:00
parent 6715769c9c
commit d35c3bea32
1 changed files with 21 additions and 38 deletions

View File

@ -297,50 +297,33 @@ def btn_items_run_event(event):
threading.Thread(target=util.launch_maxbot, args=(script_name,filename,)).start() threading.Thread(target=util.launch_maxbot, args=(script_name,filename,)).start()
def ConfigListTab(root, config_dict, language_code, UI_PADDING_X): def ConfigListTab(root, config_dict, language_code, UI_PADDING_X):
# output to GUI.
row_count = 0
frame_group_header = Frame(root) frame_group_header = Frame(root)
group_row_count = 0 widgets = {
'lbl_file_name': {},
'txt_file_name': {},
'txt_file_name_value': {},
'btn_browse': {},
'btn_run': {},
}
global lbl_file_name for i, filename in enumerate(config_dict["list"][:15]):
global txt_file_name widgets['lbl_file_name'][i] = Label(frame_group_header, text=str(i+1))
global txt_file_name_value widgets['lbl_file_name'][i].grid(column=0, row=i, sticky=E)
global btn_browse
global btn_run
lbl_file_name = {}
txt_file_name = {}
txt_file_name_value = {}
btn_browse = {}
btn_run = {}
print("config_dict[list]:",config_dict["list"]) widgets['txt_file_name_value'][i] = StringVar(frame_group_header, value=filename)
print("config_dict[list]:",len(config_dict["list"])) widgets['txt_file_name'][i] = Entry(frame_group_header, width=20, textvariable=widgets['txt_file_name_value'][i])
for i in range(15): widgets['txt_file_name'][i].grid(column=1, row=i, sticky=W)
filename = ""
if i <= len(config_dict["list"])-1:
filename = config_dict["list"][i]
lbl_file_name[i] = Label(frame_group_header, text=str(i+1))
lbl_file_name[i].grid(column=0, row=group_row_count, sticky = E)
txt_file_name_value[i] = StringVar(frame_group_header, value=filename) widgets['btn_browse'][i] = ttk.Button(frame_group_header, text=translate[language_code]['browse'] + " " + str(i+1))
txt_file_name[i] = Entry(frame_group_header, width=20, textvariable = txt_file_name_value[i]) widgets['btn_browse'][i].grid(column=2, row=i, sticky=W)
txt_file_name[i].grid(column=1, row=group_row_count, sticky = W) widgets['btn_browse'][i].bind('<Button-1>', btn_items_browse_event)
btn_browse[i] = ttk.Button(frame_group_header, text=translate[language_code]['browse'] + " " + str(i+1)) widgets['btn_run'][i] = ttk.Button(frame_group_header, text=translate[language_code]['run'] + " " + str(i+1))
btn_browse[i].grid(column=2, row=group_row_count, sticky = W) widgets['btn_run'][i].grid(column=3, row=i, sticky=W)
btn_browse[i].bind('<Button-1>', btn_items_browse_event) widgets['btn_run'][i].bind('<Button-1>', btn_items_run_event)
btn_run[i] = ttk.Button(frame_group_header, text=translate[language_code]['run'] + " " + str(i+1)) frame_group_header.grid(column=0, row=0, sticky=W, padx=UI_PADDING_X)
btn_run[i].grid(column=3, row=group_row_count, sticky = W) return widgets
btn_run[i].bind('<Button-1>', btn_items_run_event)
group_row_count+=1
# add first block to UI.
frame_group_header.grid(column=0, row=row_count, sticky = W, padx=UI_PADDING_X)
def AboutTab(root, language_code): def AboutTab(root, language_code):