[aio.py]: 更改label/entry/optionmenu等控件的生成方式,使用循环实现,更加简洁和容易维护

This commit is contained in:
2024-06-09 13:54:39 +08:00
parent 35d7e41ffd
commit 8e64d18fb8
4 changed files with 146 additions and 255 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
./test.py
.idea/ .idea/
aio/.idea/ aio/.idea/
aio/__pycache__/ aio/__pycache__/

View File

@ -189,4 +189,5 @@ v0.1.5(2024/06/12)
4. [aio.py]: 重新调整界面配色 4. [aio.py]: 重新调整界面配色
5. [aio.py]: 修改了write2textbox函数定制化显示每一行的颜色针对每一行可自定义输出内容颜色 5. [aio.py]: 修改了write2textbox函数定制化显示每一行的颜色针对每一行可自定义输出内容颜色
6. [brake.py/iso.py/current.py]: 由于第 5 点的更改,同时修改了其他文件相关引用的部分 6. [brake.py/iso.py/current.py]: 由于第 5 点的更改,同时修改了其他文件相关引用的部分
7. [aio.py]: 更改label/entry/optionmenu等控件的生成方式使用循环实现更加简洁和容易维护 7. [aio.py]: 更改label/entry/optionmenu等控件的生成方式使用循环实现更加简洁和容易维护
8. [aio.py]: 新增tabview组件区分数据处理和自动化测试功能

View File

@ -13,6 +13,32 @@ customtkinter.set_default_color_theme("blue") # Themes: "blue" (standard), "gre
customtkinter.set_widget_scaling(1.1) # widget dimensions and text size customtkinter.set_widget_scaling(1.1) # widget dimensions and text size
customtkinter.set_window_scaling(1.1) # window geometry dimensions customtkinter.set_window_scaling(1.1) # window geometry dimensions
socket.setdefaulttimeout(1) socket.setdefaulttimeout(1)
# global vars
btns = {
'start': {'btn': '', 'row': 1, 'text': '开始运行'},
'check': {'btn': '', 'row': 2, 'text': '检查参数'},
'log': {'btn': '', 'row': 3, 'text': '保存日志'},
'end': {'btn': '', 'row': 4, 'text': '结束运行'},
}
widgits = {
'path': {'label': '', 'entry': '', 'row': 0, 'col': 2, 'text': '数据文件夹路径'},
'av': {'label': '', 'entry': '', 'row': 1, 'col': 2, 'text': '角速度'},
'rc': {'label': '', 'entry': '', 'row': 1, 'col': 4, 'text': 'optional'},
'rpm': {'label': '', 'entry': '', 'row': 1, 'col': 6, 'text': '额定转速'},
'rr': {'label': '', 'entry': '', 'row': 1, 'col': 8, 'text': '减速比'},
'dur': {'label': '', 'entry': '', 'row': 1, 'col': 10, 'text': '周期时间'},
'axis': {'label': '', 'optionmenu': '', 'row': 2, 'col': 2, 'text': ''},
'vel': {'label': '', 'optionmenu': '', 'row': 2, 'col': 4, 'text': ''},
'trq': {'label': '', 'optionmenu': '', 'row': 2, 'col': 6, 'text': ''},
'trqh': {'label': '', 'optionmenu': '', 'row': 2, 'col': 8, 'text': ''},
'sto': {'label': '', 'optionmenu': '', 'row': 2, 'col': 10, 'text': ''},
'rc1': {'label': '', 'entry': '', 'row': 3, 'col': 2, 'text': '额定电流'},
'rc2': {'label': '', 'entry': '', 'row': 3, 'col': 4, 'text': '额定电流'},
'rc3': {'label': '', 'entry': '', 'row': 3, 'col': 6, 'text': '额定电流'},
'rc4': {'label': '', 'entry': '', 'row': 3, 'col': 8, 'text': '额定电流'},
'rc5': {'label': '', 'entry': '', 'row': 3, 'col': 10, 'text': '额定电流'},
'rc6': {'label': '', 'entry': '', 'row': 3, 'col': 12, 'text': '额定电流'},
}
class App(customtkinter.CTk): class App(customtkinter.CTk):
@ -25,13 +51,11 @@ class App(customtkinter.CTk):
self.title("AIO - All in one automatic toolbox") self.title("AIO - All in one automatic toolbox")
# self.iconbitmap('./icon.ico') # self.iconbitmap('./icon.ico')
self.geometry("1180x550+30+30") self.geometry("1180x550+30+30")
self.protocol("WM_DELETE_WINDOW", self.func_end_call_back) self.protocol("WM_DELETE_WINDOW", self.func_end_callback)
self.config(bg='#E9E9E9') self.config(bg='#E9E9E9')
self.grid_rowconfigure(4, weight=1) self.grid_rowconfigure(4, weight=1)
self.grid_columnconfigure((1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13), weight=1) self.grid_columnconfigure((1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13), weight=1)
self.minsize(1180, 550) self.minsize(1180, 550)
# ===================================================================== # =====================================================================
# create frame sidebar(left) # create frame sidebar(left)
self.frame_func = customtkinter.CTkFrame(self, width=120, corner_radius=0, fg_color='#E9E9E9') self.frame_func = customtkinter.CTkFrame(self, width=120, corner_radius=0, fg_color='#E9E9E9')
@ -39,23 +63,18 @@ class App(customtkinter.CTk):
# create AIO logo # create AIO logo
self.label_logo = customtkinter.CTkLabel(self.frame_func, text="Rokae AIO", height=60, font=customtkinter.CTkFont(family="Segoe Script Bold", size=24, weight="bold"), text_color="#4F4F4F") self.label_logo = customtkinter.CTkLabel(self.frame_func, text="Rokae AIO", height=60, font=customtkinter.CTkFont(family="Segoe Script Bold", size=24, weight="bold"), text_color="#4F4F4F")
self.label_logo.grid(row=0, column=0, padx=15, pady=15) self.label_logo.grid(row=0, column=0, padx=15, pady=15)
# create start button # create buttons
self.btn_start = customtkinter.CTkButton(self.frame_func, corner_radius=10, text='开始运行', fg_color='#4F4F4F', font=self.my_font, command=lambda: self.thread_it(self.func_start_callback)) for func in btns:
self.btn_start.grid(row=1, column=0, sticky='new', padx=10, pady=10, ipadx=5, ipady=5) btns[func]['btn'] = customtkinter.CTkButton(self.frame_func, corner_radius=10, text=btns[func]['text'], fg_color='#4F4F4F', font=self.my_font)
# create param check button btns[func]['btn'].grid(row=btns[func]['row'], column=0, sticky='new', padx=10, pady=10, ipadx=5, ipady=5)
self.btn_check = customtkinter.CTkButton(self.frame_func, corner_radius=10, text='检查参数', fg_color='#4F4F4F', font=self.my_font, command=lambda: self.thread_it(self.func_check_callback)) btns['start']['btn'].configure(command=lambda: self.thread_it(self.func_start_callback))
self.btn_check.grid(row=2, column=0, sticky='new', padx=10, pady=10, ipadx=5, ipady=5) btns['check']['btn'].configure(command=lambda: self.thread_it(self.func_check_callback))
# create start button btns['log']['btn'].configure(command=lambda: self.thread_it(self.func_log_callback))
self.btn_log = customtkinter.CTkButton(self.frame_func, corner_radius=10, text='保存日志', fg_color='#4F4F4F', font=self.my_font, command=lambda: self.thread_it(self.func_log_callback)) btns['end']['btn'].configure(command=lambda: self.thread_it(self.func_end_callback))
self.btn_log.grid(row=3, column=0, sticky='new', padx=10, pady=10, ipadx=5, ipady=5)
# create start button
self.btn_end = customtkinter.CTkButton(self.frame_func, corner_radius=10, text='结束运行', fg_color='#4F4F4F', font=self.my_font, command=self.func_end_call_back)
self.btn_end.grid(row=4, column=0, sticky='new', padx=10, pady=10, ipadx=5, ipady=5)
# create version info # create version info
self.label_version = customtkinter.CTkLabel(self.frame_func, justify='left', text="Vers: 0.1.4\nDate: 06/06/2024", font=self.my_font, text_color="#4F4F4F") self.label_version = customtkinter.CTkLabel(self.frame_func, justify='left', text="Vers: 0.1.4\nDate: 06/06/2024", font=self.my_font, text_color="#4F4F4F")
self.frame_func.rowconfigure(6, weight=1) self.frame_func.rowconfigure(6, weight=1)
self.label_version.grid(row=6, column=0, padx=20, pady=20, sticky='s') self.label_version.grid(row=6, column=0, padx=20, pady=20, sticky='s')
# ===================================================================== # =====================================================================
# create frame # create frame
self.frame_param = customtkinter.CTkFrame(self, corner_radius=5, fg_color='#E9E9E9', border_width=2, border_color='#CDCDCD') self.frame_param = customtkinter.CTkFrame(self, corner_radius=5, fg_color='#E9E9E9', border_width=2, border_color='#CDCDCD')
@ -66,108 +85,34 @@ class App(customtkinter.CTk):
self.menu_main.set("Start Here!") self.menu_main.set("Start Here!")
# create sub menu # create sub menu
self.menu_sub = customtkinter.CTkOptionMenu(self.frame_param) self.menu_sub = customtkinter.CTkOptionMenu(self.frame_param)
# =====================================================================
# create path related # create path related
self.label_path = customtkinter.CTkLabel(self.frame_param, text="Path", font=self.my_font) self.label_path = customtkinter.CTkLabel(self.frame_param, text="PATH", font=self.my_font)
self.label_path.grid(row=0, column=2, sticky='e', pady=(10, 5)) self.label_path.grid(row=0, column=2, sticky='e', pady=(10, 5))
self.entry_path = customtkinter.CTkEntry(self.frame_param, width=670, placeholder_text="数据文件夹路径", font=self.my_font) self.entry_path = customtkinter.CTkEntry(self.frame_param, width=670, placeholder_text="数据文件夹路径", font=self.my_font)
self.entry_path.grid(row=0, column=3, columnspan=11, padx=(5, 10), pady=(10, 5), sticky='we') self.entry_path.grid(row=0, column=3, columnspan=11, padx=(5, 10), pady=(10, 5), sticky='we')
self.entry_path.configure(state='disabled') self.entry_path.configure(state='disabled')
# create av related # =====================================================================
self.label_av = customtkinter.CTkLabel(self.frame_param, text="AV", font=self.my_font) # create widgits
self.label_av.grid(row=1, column=2, sticky='e', pady=(5, 5)) for widgit in widgits:
self.entry_av = customtkinter.CTkEntry(self.frame_param, width=self.w_param, placeholder_text=f"角速度", font=self.my_font) if widgit == 'path':
self.entry_av.grid(row=1, column=3, padx=(5, 10), pady=(5, 5), sticky='w') widgits[widgit]['label'] = customtkinter.CTkLabel(self.frame_param, text=f'{widgit.upper()}', font=self.my_font)
self.entry_av.configure(state='disabled') widgits[widgit]['label'].grid(row=widgits[widgit]['row'], column=widgits[widgit]['col'], sticky='e', pady=(10, 5))
# create rc related widgits[widgit]['entry'] = customtkinter.CTkEntry(self.frame_param, width=670, placeholder_text=widgits[widgit]['text'], font=self.my_font)
self.label_rc = customtkinter.CTkLabel(self.frame_param, text="RC", font=self.my_font) widgits[widgit]['entry'].grid(row=widgits[widgit]['row'], column=widgits[widgit]['col']+1, columnspan=11, padx=(5, 10), pady=(10, 5), sticky='we')
self.label_rc.grid(row=1, column=4, sticky='e', pady=(5, 5)) widgits[widgit]['entry'].configure(state='disabled')
self.entry_rc = customtkinter.CTkEntry(self.frame_param, width=self.w_param, placeholder_text=f"额定电流", font=self.my_font) elif widgit in ['av', 'rc', 'rpm', 'rr', 'dur', 'rc1', 'rc2', 'rc3', 'rc4', 'rc5', 'rc6']:
self.entry_rc.grid(row=1, column=5, padx=(5, 10), pady=(5, 5), sticky='w') widgits[widgit]['label'] = customtkinter.CTkLabel(self.frame_param, text=f"{widgit.upper()}", font=self.my_font)
self.entry_rc.configure(state='disabled') widgits[widgit]['label'].grid(row=widgits[widgit]['row'], column=widgits[widgit]['col'], sticky='e', pady=(5, 5))
# create rpm related widgits[widgit]['entry'] = customtkinter.CTkEntry(self.frame_param, width=self.w_param, placeholder_text=f"{widgits[widgit]['text']}", font=self.my_font)
self.label_rpm = customtkinter.CTkLabel(self.frame_param, text="RPM", font=self.my_font) widgits[widgit]['entry'].grid(row=widgits[widgit]['row'], column=widgits[widgit]['col']+1, padx=(5, 10), pady=(5, 5), sticky='w')
self.label_rpm.grid(row=1, column=6, sticky='e', pady=(5, 5)) widgits[widgit]['entry'].configure(state='disabled')
self.entry_rpm = customtkinter.CTkEntry(self.frame_param, width=self.w_param, placeholder_text=f"额定转速", font=self.my_font) elif widgit in ['axis', 'vel', 'trq', 'trqh', 'sto']:
self.entry_rpm.grid(row=1, column=7, padx=(5, 10), pady=(5, 5), sticky='w') widgits[widgit]['label'] = customtkinter.CTkLabel(self.frame_param, text=f"{widgit.upper()}", font=self.my_font)
self.entry_rpm.configure(state='disabled') widgits[widgit]['label'].grid(row=widgits[widgit]['row'], column=widgits[widgit]['col'], sticky='e', pady=(5, 5))
# create rr related widgits[widgit]['optionmenu'] = customtkinter.CTkOptionMenu(self.frame_param, button_color='#708090', fg_color='#778899', values=["1", "2", "3", "4", "5", "6", "7"], width=self.w_param, font=self.my_font)
self.label_rr = customtkinter.CTkLabel(self.frame_param, text="RR", font=self.my_font) widgits[widgit]['optionmenu'].grid(row=widgits[widgit]['row'], column=widgits[widgit]['col']+1, padx=(5, 10), pady=(5, 5), sticky='w')
self.label_rr.grid(row=1, column=8, sticky='e', pady=(5, 5)) widgits[widgit]['optionmenu'].configure(state='disabled')
self.entry_rr = customtkinter.CTkEntry(self.frame_param, width=self.w_param, placeholder_text=f"减速比", font=self.my_font)
self.entry_rr.grid(row=1, column=9, padx=(5, 10), pady=(5, 5), sticky='w')
self.entry_rr.configure(state='disabled')
# create duration related
self.label_dur = customtkinter.CTkLabel(self.frame_param, text="Dur", font=self.my_font)
self.label_dur.grid(row=1, column=10, sticky='e', pady=(5, 5))
self.entry_dur = customtkinter.CTkEntry(self.frame_param, width=self.w_param, placeholder_text=f"周期", font=self.my_font)
self.entry_dur.grid(row=1, column=11, padx=(5, 10), pady=(5, 5), sticky='w')
self.entry_dur.configure(state='disabled')
# create axis related
self.label_axis = customtkinter.CTkLabel(self.frame_param, text="AXIS", font=self.my_font)
self.label_axis.grid(row=2, column=2, sticky='e', pady=(5, 5))
self.option_axis = customtkinter.CTkOptionMenu(self.frame_param, button_color='#708090', fg_color='#778899', values=["1", "2", "3", "4", "5", "6", "7"], width=self.w_param, font=self.my_font)
self.option_axis.grid(row=2, column=3, padx=(5, 10), pady=(5, 5), sticky='w')
self.option_axis.configure(state='disabled')
# create vel related
self.label_vel = customtkinter.CTkLabel(self.frame_param, text="Vel", font=self.my_font)
self.label_vel.grid(row=2, column=4, sticky='e', pady=(5, 5))
self.option_vel = customtkinter.CTkOptionMenu(self.frame_param, button_color='#708090', fg_color='#778899', values=["1", "2", "3", "4", "5", "6", "7"], width=self.w_param, font=self.my_font)
self.option_vel.grid(row=2, column=5, padx=(5, 10), pady=(5, 5), sticky='w')
self.option_vel.configure(state='disabled')
# create trq related
self.label_trq = customtkinter.CTkLabel(self.frame_param, text="Trq", font=self.my_font)
self.label_trq.grid(row=2, column=6, sticky='e', pady=(5, 5))
self.option_trq = customtkinter.CTkOptionMenu(self.frame_param, button_color='#708090', fg_color='#778899', values=["1", "2", "3", "4", "5", "6", "7"], width=self.w_param, font=self.my_font)
self.option_trq.grid(row=2, column=7, padx=(5, 10), pady=(5, 5), sticky='w')
self.option_trq.configure(state='disabled')
# create trqH related
self.label_trqh = customtkinter.CTkLabel(self.frame_param, text="TrqH", font=self.my_font)
self.label_trqh.grid(row=2, column=8, sticky='e', pady=(5, 5))
self.option_trqh = customtkinter.CTkOptionMenu(self.frame_param, button_color='#708090', fg_color='#778899', values=["1", "2", "3", "4", "5", "6", "7"], width=self.w_param, font=self.my_font)
self.option_trqh.grid(row=2, column=9, padx=(5, 10), pady=(5, 5), sticky='w')
self.option_trqh.configure(state='disabled')
# create STO related
self.label_sto = customtkinter.CTkLabel(self.frame_param, text="STO", font=self.my_font)
self.label_sto.grid(row=2, column=10, sticky='e', pady=(5, 5))
self.option_sto = customtkinter.CTkOptionMenu(self.frame_param, button_color='#708090', fg_color='#778899', values=["1", "2", "3", "4", "5", "6", "7"], width=self.w_param, font=self.my_font)
self.option_sto.grid(row=2, column=11, padx=(5, 10), pady=(5, 5), sticky='w')
self.option_sto.configure(state='disabled')
# create rc1
self.label_rc_1 = customtkinter.CTkLabel(self.frame_param, text="RC1", font=self.my_font)
self.label_rc_1.grid(row=3, column=2, sticky='e', pady=(5, 5))
self.entry_rc_1 = customtkinter.CTkEntry(self.frame_param, width=self.w_param, placeholder_text=f"optional", font=self.my_font)
self.entry_rc_1.grid(row=3, column=3, padx=(5, 10), pady=(5, 5), sticky='w')
self.entry_rc_1.configure(state='disabled')
self.label_rc_2 = customtkinter.CTkLabel(self.frame_param, text="RC2", font=self.my_font)
self.label_rc_2.grid(row=3, column=4, sticky='e', pady=(5, 5))
self.entry_rc_2 = customtkinter.CTkEntry(self.frame_param, width=self.w_param, placeholder_text=f"optional", font=self.my_font)
self.entry_rc_2.grid(row=3, column=5, padx=(5, 10), pady=(5, 5), sticky='w')
self.entry_rc_2.configure(state='disabled')
self.label_rc_3 = customtkinter.CTkLabel(self.frame_param, text="RC3", font=self.my_font)
self.label_rc_3.grid(row=3, column=6, sticky='e', pady=(5, 5))
self.entry_rc_3 = customtkinter.CTkEntry(self.frame_param, width=self.w_param, placeholder_text=f"optional", font=self.my_font)
self.entry_rc_3.grid(row=3, column=7, padx=(5, 10), pady=(5, 5), sticky='w')
self.entry_rc_3.configure(state='disabled')
self.label_rc_4 = customtkinter.CTkLabel(self.frame_param, text="RC4", font=self.my_font)
self.label_rc_4.grid(row=3, column=8, sticky='e', pady=(5, 5))
self.entry_rc_4 = customtkinter.CTkEntry(self.frame_param, width=self.w_param, placeholder_text=f"optional", font=self.my_font)
self.entry_rc_4.grid(row=3, column=9, padx=(5, 10), pady=(5, 5), sticky='w')
self.entry_rc_4.configure(state='disabled')
self.label_rc_5 = customtkinter.CTkLabel(self.frame_param, text="RC5", font=self.my_font)
self.label_rc_5.grid(row=3, column=10, sticky='e', pady=(5, 5))
self.entry_rc_5 = customtkinter.CTkEntry(self.frame_param, width=self.w_param, placeholder_text=f"optional", font=self.my_font)
self.entry_rc_5.grid(row=3, column=11, padx=(5, 10), pady=(5, 5), sticky='w')
self.entry_rc_5.configure(state='disabled')
self.label_rc_6 = customtkinter.CTkLabel(self.frame_param, text="RC6", font=self.my_font)
self.label_rc_6.grid(row=3, column=12, sticky='e', pady=(5, 5))
self.entry_rc_6 = customtkinter.CTkEntry(self.frame_param, width=self.w_param, placeholder_text=f"optional", font=self.my_font)
self.entry_rc_6.grid(row=3, column=13, padx=(5, 10), pady=(5, 5), sticky='w')
self.entry_rc_6.configure(state='disabled')
# ===================================================================== # =====================================================================
# create textbox # create textbox
self.textbox = customtkinter.CTkTextbox(self, wrap='none', font=customtkinter.CTkFont(family="consolas", size=14), text_color="blue", fg_color='#E9E9E9', border_width=2, border_color='#CDCDCD', border_spacing=5) self.textbox = customtkinter.CTkTextbox(self, wrap='none', font=customtkinter.CTkFont(family="consolas", size=14), text_color="blue", fg_color='#E9E9E9', border_width=2, border_color='#CDCDCD', border_spacing=5)
@ -192,41 +137,13 @@ class App(customtkinter.CTk):
self.myThread.start() self.myThread.start()
def initialization(self): def initialization(self):
self.label_path.configure(text="Path", text_color="black") for widgit in widgits:
self.label_av.configure(text="AV", text_color="black") if widgit in ['path', 'av', 'rc', 'rpm', 'rr', 'dur', 'rc1', 'rc2', 'rc3', 'rc4', 'rc5', 'rc6']:
self.label_rc.configure(text="RC", text_color="black") widgits[widgit]['label'].configure(text=f'{widgit.upper()}', text_color='black')
self.label_rpm.configure(text="RPM", text_color="black") widgits[widgit]['entry'].configure(placeholder_text=widgits[widgit]['text'], state='disabled')
self.label_rr.configure(text="RR", text_color="black") elif widgit in ['axis', 'vel', 'trq', 'trqh', 'sto']:
self.label_dur.configure(text="Dur", text_color="black") widgits[widgit]['label'].configure(text=f'{widgit.upper()}', text_color="black")
self.label_axis.configure(text="AXIS", text_color="black") widgits[widgit]['optionmenu'].configure(state='disabled')
self.label_vel.configure(text="Vel", text_color="black")
self.label_trq.configure(text="Trq", text_color="black")
self.label_trqh.configure(text="TrqH", text_color="black")
self.label_sto.configure(text="STO", text_color="black")
self.label_rc_1.configure(text="RC1", text_color="black")
self.label_rc_2.configure(text="RC2", text_color="black")
self.label_rc_3.configure(text="RC3", text_color="black")
self.label_rc_4.configure(text="RC4", text_color="black")
self.label_rc_5.configure(text="RC5", text_color="black")
self.label_rc_6.configure(text="RC6", text_color="black")
self.entry_path.configure(placeholder_text="数据文件夹路径", state="disabled")
self.entry_av.configure(placeholder_text="角速度", state="disabled")
self.entry_rc.configure(placeholder_text="额定电流", state="disabled")
self.entry_rpm.configure(placeholder_text="额定转速", state="disabled")
self.entry_rr.configure(placeholder_text="减速比", state="disabled")
self.entry_dur.configure(placeholder_text="周期", state="disabled")
self.option_axis.configure(state="disabled")
self.option_vel.configure(state="disabled")
self.option_trq.configure(state="disabled")
self.option_trqh.configure(state="disabled")
self.option_sto.configure(state="disabled")
self.entry_rc_1.configure(placeholder_text="optional", state="disabled")
self.entry_rc_2.configure(placeholder_text="optional", state="disabled")
self.entry_rc_3.configure(placeholder_text="optional", state="disabled")
self.entry_rc_4.configure(placeholder_text="optional", state="disabled")
self.entry_rc_5.configure(placeholder_text="optional", state="disabled")
self.entry_rc_6.configure(placeholder_text="optional", state="disabled")
self.menu_sub.grid_forget() self.menu_sub.grid_forget()
self.textbox.delete(index1='1.0', index2='end') self.textbox.delete(index1='1.0', index2='end')
@ -236,83 +153,61 @@ class App(customtkinter.CTk):
self.initialization() self.initialization()
if func_name == 'brake': if func_name == 'brake':
self.label_path.configure(text="Path", text_color='red') for widgit in widgits:
self.label_av.configure(text="AV", text_color='red') if widgit in ['path', 'av', 'rr']:
self.label_rr.configure(text="RR", text_color='red') widgits[widgit]['label'].configure(text_color='red')
self.label_axis.configure(text="AXIS", text_color='red') widgits[widgit]['entry'].configure(state='normal')
self.label_vel.configure(text="Vel", text_color='red') elif widgit in ['axis', 'vel', 'trq', 'sto']:
self.label_trq.configure(text="Trq", text_color='red') widgits[widgit]['label'].configure(text_color="red")
self.label_sto.configure(text="STO", text_color='red') widgits[widgit]['optionmenu'].configure(state='normal')
self.entry_path.configure(state="normal")
self.entry_av.configure(state="normal")
self.entry_rr.configure(state="normal")
self.option_axis.configure(state="normal")
self.option_vel.configure(state="normal")
self.option_trq.configure(state="normal")
self.option_sto.configure(state="normal")
elif func_name == 'current': elif func_name == 'current':
self.menu_sub = customtkinter.CTkOptionMenu(self.frame_param, values=["max", "avg", "cycle"], font=self.my_font, command=self.func_sub_callback) self.menu_sub = customtkinter.CTkOptionMenu(self.frame_param, values=["max", "avg", "cycle"], font=self.my_font, button_color='red', fg_color='green', command=self.func_sub_callback)
self.menu_sub.grid(row=1, column=1, sticky='we', padx=(20, 10), pady=(5, 5)) self.menu_sub.grid(row=1, column=1, sticky='we', padx=(20, 10), pady=(5, 5))
self.menu_sub.set("--select--") self.menu_sub.set("--select--")
self.menu_sub.configure(text_color='yellow')
self.label_path.configure(text="Path", text_color='red') for widgit in widgits:
self.label_rc.configure(text="RC", text_color='blue') if widgit in ['path', 'rc', 'rc1', 'rc2', 'rc3', 'rc4', 'rc5', 'rc6']:
self.label_trqh.configure(text="TrqH", text_color='red') color = 'blue' if widgit == 'rc' else 'red'
self.label_rc_1.configure(text="RC1", text_color='red') widgits[widgit]['label'].configure(text_color=color)
self.label_rc_2.configure(text="RC2", text_color='red') widgits[widgit]['entry'].configure(state='normal')
self.label_rc_3.configure(text="RC3", text_color='red') elif widgit in ['trqh',]:
self.label_rc_4.configure(text="RC4", text_color='red') widgits[widgit]['label'].configure(text_color="red")
self.label_rc_5.configure(text="RC5", text_color='red') widgits[widgit]['optionmenu'].configure(state='normal')
self.label_rc_6.configure(text="RC6", text_color='red')
self.entry_path.configure(state="normal")
self.entry_rc.configure(state="normal", placeholder_text="optional")
self.option_trqh.configure(state="normal")
self.entry_rc_1.configure(state="normal", placeholder_text="额定电流")
self.entry_rc_2.configure(state="normal", placeholder_text="额定电流")
self.entry_rc_3.configure(state="normal", placeholder_text="额定电流")
self.entry_rc_4.configure(state="normal", placeholder_text="额定电流")
self.entry_rc_5.configure(state="normal", placeholder_text="额定电流")
self.entry_rc_6.configure(state="normal", placeholder_text="额定电流")
elif func_name == 'iso': elif func_name == 'iso':
self.label_path.configure(text="Path", text_color='red') for widgit in widgits:
self.entry_path.configure(state="normal") if widgit in ['path',]:
widgits[widgit]['label'].configure(text_color='red')
widgits[widgit]['entry'].configure(state='normal')
else: else:
self.initialization() self.initialization()
self.menu_main.set("Start Here!") self.menu_main.set("Start Here!")
self.menu_main.configure(text_color='yellow')
def func_sub_callback(self, func_name): def func_sub_callback(self, func_name):
if func_name == "max": if func_name == "max":
self.label_rpm.configure(text="RPM", text_color='black') for widgit in widgits:
self.entry_rpm.configure(placeholder_text='额定转速', state="disabled") if widgit in ['rpm', 'dur']:
self.label_dur.configure(text="Dur", text_color='black') widgits[widgit]['label'].configure(text_color='black')
self.entry_dur.configure(state="disabled") widgits[widgit]['entry'].configure(state='disabled')
self.label_vel.configure(text="Vel", text_color='black') elif widgit in ['vel', 'trq']:
self.option_vel.configure(state="disabled") widgits[widgit]['label'].configure(text_color='black')
self.label_trq.configure(text="Trq", text_color='black') widgits[widgit]['optionmenu'].configure(state='disabled')
self.option_trq.configure(state="disabled")
elif func_name == 'avg': elif func_name == 'avg':
self.label_rpm.configure(text="RPM", text_color='black') for widgit in widgits:
self.entry_rpm.configure(placeholder_text='额定转速', state="disabled") if widgit in ['rpm', 'dur']:
self.label_dur.configure(text="Dur", text_color='black') widgits[widgit]['label'].configure(text_color='black')
self.entry_dur.configure(state="disabled") widgits[widgit]['entry'].configure(state='disabled')
self.label_vel.configure(text="Vel", text_color='black') elif widgit in ['vel', 'trq']:
self.option_vel.configure(state="disabled") widgits[widgit]['label'].configure(text_color='black')
self.label_trq.configure(text="Trq", text_color='black') widgits[widgit]['optionmenu'].configure(state='disabled')
self.option_trq.configure(state="disabled")
elif func_name == 'cycle': elif func_name == 'cycle':
self.label_rpm.configure(text="RPM", text_color='blue') for widgit in widgits:
self.entry_rpm.configure(state="normal", placeholder_text='额定转速') if widgit in ['rpm', 'dur']:
self.label_dur.configure(text="Dur", text_color='blue') widgits[widgit]['label'].configure(text_color='blue')
self.entry_dur.configure(state="normal", placeholder_text='周期') widgits[widgit]['entry'].configure(state='normal')
self.label_vel.configure(text="Vel", text_color='red') elif widgit in ['vel', 'trq']:
self.option_vel.configure(state="normal") widgits[widgit]['label'].configure(text_color="red")
self.label_trq.configure(text="Trq", text_color='red') widgits[widgit]['optionmenu'].configure(state='normal')
self.option_trq.configure(state="normal")
def write2textbox(self, text, wait=0, exitcode=0, color='blue'): def write2textbox(self, text, wait=0, exitcode=0, color='blue'):
self.textbox.tag_add(color, 'insert', 'end') self.textbox.tag_add(color, 'insert', 'end')
@ -349,58 +244,52 @@ class App(customtkinter.CTk):
def check_param(self): def check_param(self):
func_name = self.menu_main.get() func_name = self.menu_main.get()
if func_name == 'brake': if func_name == 'brake':
path = self.entry_path.get().strip(' ') path = widgits['path']['entry'].get().strip()
av = self.entry_av.get().strip('- ') av = widgits['av']['entry'].get().strip('- ')
rr = self.entry_rr.get().strip('- ') rr = widgits['rr']['entry'].get().strip('- ')
axis = self.option_axis.get() axis = widgits['axis']['optionmenu'].get()
vel = self.option_vel.get() vel = widgits['vel']['optionmenu'].get()
trq = self.option_trq.get() trq = widgits['trq']['optionmenu'].get()
sto = self.option_sto.get() sto = widgits['sto']['optionmenu'].get()
sub_func = self.menu_sub.get()
c1 = exists(path) c1 = exists(path)
c2 = self.is_float('required', av, rr) c2 = self.is_float('required', av, rr)
# c3 = rpm = 1
c3 = True if len({vel, trq, sto}) == 3 else False c3 = True if len({vel, trq, sto}) == 3 else False
c4 = sub_func in ['industrial', 'cobot']
c5 = True if vel != trq else False
if c1 and c2 and c3 and c4 and c5: if c1 and c2 and c3:
return 1, path, float(av), float(rr), int(sto), int(axis), int(vel), int(trq) return 1, path, float(av), float(rr), int(axis), int(vel), int(trq), int(sto)
else: else:
return 0, 0 return 0, 0
# ======================================================= # =======================================================
elif func_name == 'current': elif func_name == 'current':
path = self.entry_path.get() path = widgits['path']['entry'].get().strip()
rc = self.entry_rc.get() rc = widgits['rc']['entry'].get().strip('- ')
rpm = self.entry_rpm.get() rpm = widgits['rpm']['entry'].get().strip()
dur = self.entry_dur.get() dur = widgits['dur']['entry'].get().strip()
vel = self.option_vel.get() rc1 = widgits['rc1']['entry'].get().strip()
trq = self.option_trq.get() rc2 = widgits['rc2']['entry'].get().strip()
trqh = self.option_trqh.get() rc3 = widgits['rc3']['entry'].get().strip()
rc4 = widgits['rc4']['entry'].get().strip()
rc5 = widgits['rc5']['entry'].get().strip()
rc6 = widgits['rc6']['entry'].get().strip()
vel = widgits['vel']['optionmenu'].get()
trq = widgits['trq']['optionmenu'].get()
trqh = widgits['trqh']['optionmenu'].get()
sub = self.menu_sub.get() sub = self.menu_sub.get()
rc1 = self.entry_rc_1.get()
rc2 = self.entry_rc_2.get()
rc3 = self.entry_rc_3.get()
rc4 = self.entry_rc_4.get()
rc5 = self.entry_rc_5.get()
rc6 = self.entry_rc_6.get()
c0 = exists(path) c1 = exists(path)
c1 = sub in ['max', 'avg', 'cycle'] c2 = sub in ['max', 'avg', 'cycle']
c2 = self.is_float('optional', rc) c3 = self.is_float('optional', rc, rpm)
c3 = self.is_float('optional', rpm) c4 = self.is_float('required', rc1, rc2, rc3, rc4, rc5, rc6)
_ = [rc1, rc2, rc3, rc4, rc5, rc6]
c4 = self.is_float('required', *_)
c5 = c6 = True c5 = c6 = True
if sub == 'cycle': if sub == 'cycle':
c5 = True if vel != trq else False c5 = True if len({vel, trq}) == 2 else False
c6 = self.is_float('optional', dur) c6 = self.is_float('optional', dur)
if c0 and c1 and c2 and c3 and c4 and c5 and c6: if c1 and c2 and c3 and c4 and c5 and c6:
rcs = [] rcs = []
for x in _: for x in [rc1, rc2, rc3, rc4, rc5, rc6]:
rcs.append(float(x)) rcs.append(float(x))
rc = 0 if rc == '' else rc rc = 0 if rc == '' else rc
dur = 0 if sub != 'cycle' or dur == '' else dur dur = 0 if sub != 'cycle' or dur == '' else dur
@ -411,7 +300,7 @@ class App(customtkinter.CTk):
return 0, 0 return 0, 0
# ======================================================= # =======================================================
elif func_name == 'iso': elif func_name == 'iso':
path = self.entry_path.get() path = widgits['path']['entry'].get().strip()
c1 = exists(path) c1 = exists(path)
if c1: if c1:
return 3, path return 3, path
@ -426,11 +315,9 @@ class App(customtkinter.CTk):
flag, *args = self.check_param() flag, *args = self.check_param()
func_dict = {1: brake.main, 2: current.main, 3: iso.main} func_dict = {1: brake.main, 2: current.main, 3: iso.main}
if flag == 1: if flag == 1:
func_dict[flag](path=args[0], av=args[1], rr=args[2], sto=args[3], axis=args[4], vel=args[5], trq=args[6], w2t=self.write2textbox) func_dict[flag](path=args[0], av=args[1], rr=args[2], axis=args[3], vel=args[4], trq=args[5], sto=args[6], w2t=self.write2textbox)
elif flag == 2: elif flag == 2:
# tkinter.messagebox.showinfo(title="TBD", message="功能待实现......")
func_dict[flag](path=args[0], sub=args[1], rcs=args[2], vel=args[3], trq=args[4], trqh=args[5], dur=args[6], rpm=args[7], w2t=self.write2textbox) func_dict[flag](path=args[0], sub=args[1], rcs=args[2], vel=args[3], trq=args[4], trqh=args[5], dur=args[6], rpm=args[7], w2t=self.write2textbox)
elif flag == 3: elif flag == 3:
func_dict[flag](path=args[0], w2t=self.write2textbox) func_dict[flag](path=args[0], w2t=self.write2textbox)
@ -442,11 +329,13 @@ class App(customtkinter.CTk):
def func_check_callback(self): def func_check_callback(self):
self.textbox.configure(state='normal') self.textbox.configure(state='normal')
self.textbox.delete(index1='1.0', index2='end') self.textbox.delete(index1='1.0', index2='end')
flag, *args = self.check_param() flag, *args = self.check_param()
if flag: if flag:
tkinter.messagebox.showinfo(title="参数正确", message="所有参数形式上填写无误,可以开始运行!") tkinter.messagebox.showinfo(title="参数正确", message="所有参数形式上填写无误,可以开始运行!")
else: else:
tkinter.messagebox.showerror(title="参数错误", message="需要检查对应参数是否填写正确!", ) tkinter.messagebox.showerror(title="参数错误", message="需要检查对应参数是否填写正确!", )
self.textbox.configure(state='disabled') self.textbox.configure(state='disabled')
def func_log_callback(self): def func_log_callback(self):
@ -465,7 +354,7 @@ class App(customtkinter.CTk):
else: else:
tkinter.messagebox.showwarning(title="未能保存", message="日志数据为空,不可保存!") tkinter.messagebox.showwarning(title="未能保存", message="日志数据为空,不可保存!")
def func_end_call_back(self): def func_end_callback(self):
if tkinter.messagebox.askyesno(title="关闭程序", message="相关数据可能未保存,正在运行程序时有概率会损坏数据文件,确定要终止程序运行吗?"): if tkinter.messagebox.askyesno(title="关闭程序", message="相关数据可能未保存,正在运行程序时有概率会损坏数据文件,确定要终止程序运行吗?"):
self.destroy() self.destroy()

View File

@ -253,7 +253,7 @@ def traversal_files(path, w2t):
return dirs, files return dirs, files
def main(path, av, rr, sto, axis, vel, trq, w2t): def main(path, av, rr, axis, vel, trq, sto, w2t):
# 功能:执行处理所有数据文件 # 功能:执行处理所有数据文件
# 参数initialization函数的返回值 # 参数initialization函数的返回值
# 返回值:- # 返回值:-
@ -291,4 +291,4 @@ def main(path, av, rr, sto, axis, vel, trq, w2t):
if __name__ == "__main__": if __name__ == "__main__":
stop = 0 stop = 0
main(path=argv[1], av=argv[2], rr=argv[3], sto=argv[4], axis=argv[5], vel=argv[6], trq=argv[7], w2t=argv[8]) main(path=argv[1], av=argv[2], rr=argv[3], axis=argv[4], vel=argv[5], trq=argv[6], sto=argv[7], w2t=argv[8])