add some new function
This commit is contained in:
parent
736a2a2506
commit
87bc21173f
169
src/main.py
169
src/main.py
|
@ -19,7 +19,7 @@ class App(ctk.CTk):
|
|||
gain_default = [1.30, 0.70, 1.10, 2.20, 0.50]
|
||||
gain_values = gain_default.copy()
|
||||
gain_values_store = gain_default.copy()
|
||||
gain_enable = [True for i in range(5)]
|
||||
gain_enable = [True for i in range(6)]
|
||||
system_platform = platform.system()
|
||||
|
||||
def __init__(self) -> None:
|
||||
|
@ -132,14 +132,87 @@ class App(ctk.CTk):
|
|||
slider.configure(state="normal")
|
||||
return None
|
||||
|
||||
def switchCorrection(i: int, slider: ctk.CTkSlider) -> None:
|
||||
def switchCorrection(
|
||||
i: int,
|
||||
slider: Optional[ctk.CTkSlider] = None,
|
||||
slider_1: Optional[ctk.CTkSlider] = None,
|
||||
slider_2: Optional[ctk.CTkSlider] = None,
|
||||
) -> None:
|
||||
def switchSign(i: int, is_open: bool) -> str:
|
||||
match i:
|
||||
case 0: # Color Correction 颜色矫正
|
||||
return "cmdbgo" if is_open else "cmdbcs"
|
||||
case 3: # Gamma
|
||||
return "cmdggo" if is_open else "cmdgcs"
|
||||
case 4: # Saturation 饱和度
|
||||
return "cmdsgo" if is_open else "cmdscs"
|
||||
case 5: # White Balance
|
||||
return "cmdwgo" if is_open else "cmdwcs"
|
||||
case _:
|
||||
return "error"
|
||||
|
||||
if i == 0:
|
||||
if self.gain_enable[i]:
|
||||
self.gain_enable[0] = False
|
||||
self.gain_enable[1] = False
|
||||
self.gain_enable[2] = False
|
||||
|
||||
if self.serial_status:
|
||||
self.serial.write((switchSign(i, False) + "ed").encode())
|
||||
else:
|
||||
messagebox.showError("Please Connect to Serial")
|
||||
|
||||
slider.configure(button_color="grey")
|
||||
slider.configure(state="disabled")
|
||||
slider_1.configure(button_color="grey")
|
||||
slider_1.configure(state="disabled")
|
||||
slider_2.configure(button_color="grey")
|
||||
slider_2.configure(state="disabled")
|
||||
else:
|
||||
self.gain_enable[0] = True
|
||||
self.gain_enable[1] = True
|
||||
self.gain_enable[2] = True
|
||||
|
||||
if self.serial_status:
|
||||
self.serial.write((switchSign(i, True) + "ed").encode())
|
||||
else:
|
||||
messagebox.showError("Please Connect to Serial")
|
||||
|
||||
slider.configure(button_color="#1f538d")
|
||||
slider.configure(state="normal")
|
||||
slider_1.configure(button_color="#1f538d")
|
||||
slider_1.configure(state="normal")
|
||||
slider_2.configure(button_color="#1f538d")
|
||||
slider_2.configure(state="normal")
|
||||
elif i == 5:
|
||||
if self.gain_enable[i]:
|
||||
self.gain_enable[i] = False
|
||||
if self.serial_status:
|
||||
self.serial.write((switchSign(i, False) + "ed").encode())
|
||||
else:
|
||||
messagebox.showError("Please Connect to Serial")
|
||||
else:
|
||||
self.gain_enable[i] = True
|
||||
if self.serial_status:
|
||||
self.serial.write((switchSign(i, True) + "ed").encode())
|
||||
else:
|
||||
messagebox.showError("Please Connect to Serial")
|
||||
else:
|
||||
if self.gain_enable[i]:
|
||||
self.gain_enable[i] = False
|
||||
if self.serial_status:
|
||||
self.serial.write((switchSign(i, False) + "ed").encode())
|
||||
else:
|
||||
messagebox.showError("Please Connect to Serial")
|
||||
|
||||
slider.configure(button_color="grey")
|
||||
slider.configure(state="disabled")
|
||||
else:
|
||||
self.gain_enable[i] = True
|
||||
if self.serial_status:
|
||||
self.serial.write((switchSign(i, True) + "ed").encode())
|
||||
else:
|
||||
messagebox.showError("Please Connect to Serial")
|
||||
|
||||
slider.configure(button_color="#1f538d")
|
||||
slider.configure(state="normal")
|
||||
|
@ -167,6 +240,9 @@ class App(ctk.CTk):
|
|||
data_frame.columnconfigure(0, weight=10)
|
||||
data_frame.columnconfigure(1, weight=3)
|
||||
|
||||
blender_frame = ctk.CTkFrame(data_frame, fg_color="#596062")
|
||||
blender_frame.grid(column=0, row=0, rowspan=3, sticky=ctk.NSEW, padx=20)
|
||||
|
||||
gain_frame = []
|
||||
gain_str = []
|
||||
gain_label = []
|
||||
|
@ -174,7 +250,34 @@ class App(ctk.CTk):
|
|||
gain_button = []
|
||||
gain_checkbox = []
|
||||
for i in range(5):
|
||||
if i == 0:
|
||||
label_frame = ctk.CTkFrame(blender_frame, fg_color="#596062")
|
||||
label_frame.pack(side='top', fill=ctk.BOTH)
|
||||
gain_checkbox.append(
|
||||
ctk.CTkCheckBox(
|
||||
label_frame,
|
||||
text="颜色矫正",
|
||||
font=self.font,
|
||||
)
|
||||
)
|
||||
gain_checkbox[i].select()
|
||||
gain_checkbox[i].pack(side="left", ipady=10, padx=70)
|
||||
gain_checkbox.append(
|
||||
ctk.CTkCheckBox(
|
||||
label_frame,
|
||||
text="自动白平衡",
|
||||
font=self.font,
|
||||
command=functools.partial(switchCorrection, 5)
|
||||
)
|
||||
)
|
||||
gain_checkbox[i + 1].select()
|
||||
gain_checkbox[i + 1].pack(side="right", ipady=10, padx=70)
|
||||
|
||||
# gain_frame
|
||||
if i < 3:
|
||||
gain_frame.append(ctk.CTkFrame(blender_frame, fg_color=fg_clolor[i]))
|
||||
gain_frame[i].pack(side="top", fill=ctk.X, pady=10, padx=20, ipady=10)
|
||||
else:
|
||||
gain_frame.append(ctk.CTkFrame(data_frame, fg_color=fg_clolor[i]))
|
||||
gain_frame[i].grid(column=0, sticky=ctk.EW, pady=10, padx=20, ipady=10)
|
||||
|
||||
|
@ -191,8 +294,8 @@ class App(ctk.CTk):
|
|||
font=self.font,
|
||||
)
|
||||
)
|
||||
gain_checkbox[i - 3].select()
|
||||
gain_checkbox[i - 3].pack(side="top", ipady=10)
|
||||
gain_checkbox[i - 1].select()
|
||||
gain_checkbox[i - 1].pack(side="top", ipady=10)
|
||||
|
||||
# slider
|
||||
gain_slider.append(
|
||||
|
@ -209,7 +312,10 @@ class App(ctk.CTk):
|
|||
command=functools.partial(setGain, i=i, stringVar=gain_str[i])
|
||||
)
|
||||
if i >= 3:
|
||||
gain_checkbox[i - 3].configure(
|
||||
gain_checkbox[0].configure(
|
||||
command=functools.partial(switchCorrection, 0, gain_slider[0], gain_slider[1], gain_slider[2])
|
||||
)
|
||||
gain_checkbox[i - 1].configure(
|
||||
command=functools.partial(switchCorrection, i, gain_slider[i])
|
||||
)
|
||||
|
||||
|
@ -248,6 +354,8 @@ class App(ctk.CTk):
|
|||
)
|
||||
button_frame.columnconfigure(0, weight=1)
|
||||
button_frame.columnconfigure(1, weight=1)
|
||||
button_frame.columnconfigure(2, weight=1)
|
||||
button_frame.columnconfigure(3, weight=1)
|
||||
switch_day = ctk.CTkButton(
|
||||
button_frame,
|
||||
text="切换为白天",
|
||||
|
@ -262,6 +370,25 @@ class App(ctk.CTk):
|
|||
command=functools.partial(self.setvideo, 1),
|
||||
)
|
||||
switch_night.grid(column=1, row=0, sticky=ctk.NSEW, padx=10, ipady=20)
|
||||
switch_start = ctk.CTkButton(
|
||||
button_frame,
|
||||
text="开始",
|
||||
font=self.font,
|
||||
command=functools.partial(self.setvideo, 2),
|
||||
)
|
||||
switch_start.grid(column=2, row=0, sticky=ctk.NSEW, padx=10, ipady=20)
|
||||
switch_pause = ctk.CTkButton(
|
||||
button_frame,
|
||||
text="停止",
|
||||
font=self.font,
|
||||
command=functools.partial(self.setvideo, 3),
|
||||
)
|
||||
switch_pause.grid(column=3, row=0, sticky=ctk.NSEW, padx=10, ipady=20)
|
||||
switch_terminal = ctk.CTkButton(
|
||||
button_frame,
|
||||
text="调试",
|
||||
font=self.font,
|
||||
)
|
||||
|
||||
return None
|
||||
|
||||
|
@ -351,27 +478,43 @@ class App(ctk.CTk):
|
|||
bytes = list(map(lambda x: ord(x), list(switchSign(i))))
|
||||
bytes.append(int(self.gain_values[i]))
|
||||
bytes.append(int(self.gain_values[i] % 1 * 256))
|
||||
bytes.append(ord('e'))
|
||||
bytes.append(ord('d'))
|
||||
print(f"Send:{bytes} \t Hex:0x" + f"{hex(int( self.gain_values[i] * 256 )).replace('0x', '')}".zfill(4))
|
||||
bytes.append(ord("e"))
|
||||
bytes.append(ord("d"))
|
||||
print(
|
||||
f"Send:{bytes} \t Hex:0x"
|
||||
+ f"{hex(int( self.gain_values[i] * 256 )).replace('0x', '')}".zfill(
|
||||
4
|
||||
)
|
||||
)
|
||||
self.serial.write(bytes)
|
||||
else:
|
||||
print("Please Connect to Serial")
|
||||
messagebox.showError("Please Connect Serial Port")
|
||||
|
||||
def setvideo(self, video: int) -> None:
|
||||
def switchSign (i:int) -> str:
|
||||
match i:
|
||||
case 0: # switch day
|
||||
return "cmdday"
|
||||
case 1: # night
|
||||
return "cmdnig"
|
||||
case 2: # start video
|
||||
return "cmdsta"
|
||||
case 3: # stop video
|
||||
return "cmdstp"
|
||||
case _:
|
||||
return "error"
|
||||
|
||||
try:
|
||||
is_open = self.serial.is_open
|
||||
except AttributeError:
|
||||
messagebox.showError("Please Connect to Serial")
|
||||
else:
|
||||
if is_open:
|
||||
if video == 0:
|
||||
self.serial.write("cmdd".encode())
|
||||
elif video == 1:
|
||||
self.serial.write("cmdn".encode())
|
||||
if video >= 0 and video < 4:
|
||||
self.serial.write(( switchSign(video) + 'ed' ).encode())
|
||||
else:
|
||||
messagebox.showError("Set Video Error!")
|
||||
messagebox.showError('Set Video Wrong')
|
||||
else:
|
||||
messagebox.showError("Please Open Serial")
|
||||
return None
|
||||
|
|
Loading…
Reference in New Issue