From c6881cf7bd17486761193917881ecf22a941e671 Mon Sep 17 00:00:00 2001 From: Alain Klotz Date: Sun, 29 Oct 2023 00:25:00 +0200 Subject: [PATCH] Pad device GUI. --- gui/pad_device/pad_device.py | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------- src/guitastro/component_detector_focuser.py | 6 +++++- src/guitastro/component_mount_pointing.py | 12 ++++++++++-- 3 files changed, 113 insertions(+), 13 deletions(-) diff --git a/gui/pad_device/pad_device.py b/gui/pad_device/pad_device.py index c05817f..e0585c0 100644 --- a/gui/pad_device/pad_device.py +++ b/gui/pad_device/pad_device.py @@ -398,12 +398,39 @@ class Devicepad(): else: self._main.camera_acq_modpoi(exp, binning, side, fitsdark, self._visu1) - def pad_cbk_button_pushed(self, key): - print(f"Select command {key=}") + def pad_cbk_button_pushed(self, cmd): + #print(f"Select command {cmd=}") device = self._device - res = device.commandstring(key) + component_name = cmd.split()[0] + #component = device.component(component_name) + res = device.commandstring(cmd) + #print(f"device.commandstring {res=}") self.pad_var_component[component_name].set(res) + def pad_cbk_button_param_pushed(self, cmd, widget, special_case): + #print(f"Select command {cmd=}") + device = self._device + component_name = cmd.split()[0] + component = device.component(component_name) + res = device.commandstring(cmd) + #print(f"device.commandstring {res=}") + if special_case == 1: + # - motion + msg = component.motion2string(res) + res = f"{msg} ({res})" + if special_case == 2: + # - status + msg = component.status2string(res) + res = f"{msg} ({res})" + widget.configure(text = res) + self.tkroot.update() + + def pad_cbk_devstatus(self): + if self._device.real: + msg = "Status mode real" + else: + msg = "Status mode simulation" + return msg # ========================================== # ========================================== @@ -433,7 +460,7 @@ class Devicepad(): max_height = 700 if screen_height>max_height: screen_height = max_height - self.tkroot.geometry(str(screen_width)+"x"+str(screen_height)+"+0+0") + self.tkroot.geometry(str(int(0.8*screen_width))+"x"+str(int(0.8*screen_height))+"+0+0") self.tkroot.title("Device pad for "+ device.param['NAME']) self.tkroot.protocol('WM_DELETE_WINDOW', self.pad_cbk_quit) @@ -462,6 +489,10 @@ class Devicepad(): fontStyle_3 = tkFont.Font(family="Arial", size=10, weight="bold") fontStyle_c3 = tkFont.Font(family="courier", size=10, weight="bold") + #s = ttk.Style() + #s.configure('TFrame', background='red') + #s.configure('Frame1.TFrame', background='blue') + # ===================================================== # === All the tabs are in a X scrollable frame # ===================================================== @@ -475,6 +506,21 @@ class Devicepad(): # ===================================================== # ===================================================== + # Frame of Status + # ===================================================== + # ===================================================== + label = {} + + frame_status = tk.Frame(self.tkroot) + msg = self.pad_cbk_devstatus() + self.pad_var_status = tk.StringVar() + label['dev_status'] = tk.Label(frame_status, textvariable = self.pad_var_status, font=fontStyle_3) + label['dev_status'].pack(side = tk.LEFT) + self.pad_var_status.set(msg) + frame_status.pack(side = tk.TOP, anchor = tk.W) + + # ===================================================== + # ===================================================== # (100) Frame Pilot # ===================================================== # ===================================================== @@ -492,11 +538,12 @@ class Devicepad(): # ===================================================== frame = {} button = {} - label = {} entry = {} self.pad_var_component = {} + kcol = 0 for kcomp, component_name in zip(kcomps, device.component_names): - tabs[kcomp] = ttk.Frame(notebook) + kcol += 1 + tabs[kcomp] = ttk.Frame(notebook) # , style='Frame1.TFrame' component = device.component(component_name) # --- frame[kcomp] = tk.Frame(tabs[kcomp]) @@ -538,7 +585,7 @@ class Devicepad(): frame_tmp = tk.Frame(frame[kcomp]) label[lab_comp_key] = tk.Label(frame_tmp, text = "Result", font=fontStyle_3) label[lab_comp_key].pack(side = tk.LEFT) - entry[lab_comp_key] = tk.Entry(frame_tmp, textvariable = self.pad_var_component[component_name], font=fontStyle_3) + entry[lab_comp_key] = tk.Entry(frame_tmp, textvariable = self.pad_var_component[component_name], font=fontStyle_3, width = 40) entry[lab_comp_key].pack(side = tk.LEFT) frame_tmp.pack(side = tk.TOP, anchor = tk.W) @@ -565,32 +612,73 @@ class Devicepad(): entry[lab_comp_key] = tk.Entry(frame_tmp, textvariable = self.pad_var_binning, font=fontStyle_3) entry[lab_comp_key].pack(side = tk.LEFT) frame_tmp.pack(side = tk.TOP, anchor = tk.W) + # --- + lab_comp_key = str(kcomp) + "_status" + frame_tmp = tk.Frame(frame[kcomp]) + cmd = cmd = f"{component_name} GET status" + button[lab_comp_key] = tk.Button(frame_tmp, text = "status", font=fontStyle_3) + button[lab_comp_key].pack(side = tk.LEFT) + entry[lab_comp_key] = tk.Label(frame_tmp, text = "Unknown", font=fontStyle_3) + entry[lab_comp_key].pack(side = tk.LEFT) + special_case = 2 + button[lab_comp_key].configure(command=functools.partial(self.pad_cbk_button_param_pushed, cmd, entry[lab_comp_key], special_case)) + frame_tmp.pack(side = tk.TOP, anchor = tk.W) + self.pad_cbk_button_param_pushed(cmd, entry[lab_comp_key], special_case) + if component.category == 'MountPointing': # --- val = component.command("GET", "target") lab_comp_key = str(kcomp) + "_target" self.pad_var_target = tk.StringVar() - self.pad_var_target.set("RADEC 6h 30d") + target = "RADEC 6h 30d" + component.command("SET", "target", target) + self.pad_var_target.set(target) frame_tmp = tk.Frame(frame[kcomp]) label[lab_comp_key] = tk.Label(frame_tmp, text = "Target", font=fontStyle_3) label[lab_comp_key].pack(side = tk.LEFT) entry[lab_comp_key] = tk.Entry(frame_tmp, textvariable = self.pad_var_target, font=fontStyle_3) entry[lab_comp_key].pack(side = tk.LEFT) frame_tmp.pack(side = tk.TOP, anchor = tk.W) + # --- + lab_comp_key = str(kcomp) + "_motion" + frame_tmp = tk.Frame(frame[kcomp]) + cmd = cmd = f"{component_name} GET motion" + button[lab_comp_key] = tk.Button(frame_tmp, text = "motion", font=fontStyle_3) + button[lab_comp_key].pack(side = tk.LEFT) + entry[lab_comp_key] = tk.Label(frame_tmp, text = "Unknown", font=fontStyle_3) + entry[lab_comp_key].pack(side = tk.LEFT) + special_case = 1 + button[lab_comp_key].configure(command=functools.partial(self.pad_cbk_button_param_pushed, cmd, entry[lab_comp_key], special_case)) + frame_tmp.pack(side = tk.TOP, anchor = tk.W) + self.pad_cbk_button_param_pushed(cmd, entry[lab_comp_key], special_case) + if component.category == 'DetectorFocuser': # --- val = component.command("GET", "target") lab_comp_key = str(kcomp) + "_target" self.pad_var_detectorfocuser_target = tk.DoubleVar() - self.pad_var_detectorfocuser_target.set("1000") + target = float(val) + self.pad_var_detectorfocuser_target.set(target) frame_tmp = tk.Frame(frame[kcomp]) label[lab_comp_key] = tk.Label(frame_tmp, text = "Target", font=fontStyle_3) label[lab_comp_key].pack(side = tk.LEFT) entry[lab_comp_key] = tk.Entry(frame_tmp, textvariable = self.pad_var_detectorfocuser_target, font=fontStyle_3) entry[lab_comp_key].pack(side = tk.LEFT) frame_tmp.pack(side = tk.TOP, anchor = tk.W) + # --- + lab_comp_key = str(kcomp) + "_motion" + frame_tmp = tk.Frame(frame[kcomp]) + cmd = cmd = f"{component_name} GET motion" + button[lab_comp_key] = tk.Button(frame_tmp, text = "motion", font=fontStyle_3) + button[lab_comp_key].pack(side = tk.LEFT) + entry[lab_comp_key] = tk.Label(frame_tmp, text = "Unknown", font=fontStyle_3) + entry[lab_comp_key].pack(side = tk.LEFT) + special_case = 1 + button[lab_comp_key].configure(command=functools.partial(self.pad_cbk_button_param_pushed, cmd, entry[lab_comp_key], special_case)) + frame_tmp.pack(side = tk.TOP, anchor = tk.W) + self.pad_cbk_button_param_pushed(cmd, entry[lab_comp_key], special_case) - frame[kcomp].pack(side = tk.TOP, pady=5) + frame[kcomp].pack(side = tk.TOP, pady=5, anchor = tk.W) # ===================================================== # Pack frame pilot diff --git a/src/guitastro/component_detector_focuser.py b/src/guitastro/component_detector_focuser.py index b0c8d69..e90d493 100644 --- a/src/guitastro/component_detector_focuser.py +++ b/src/guitastro/component_detector_focuser.py @@ -109,7 +109,7 @@ class ComponentDetectorFocuser(ComponentDetectorFocuserException, Component, Gui param["motion_simu"] = self.MOTION_STATE_UNKNOWN param["motion_real"] = self.MOTION_STATE_UNKNOWN param["unit"] = "inc" # inc, rot, lin, phy - param["target"] = 0 # unit + param["target"] = (self._focuser_params["LIM_INF"]+self._focuser_params["LIM_SUP"])/2.0 # unit param["speed_slew"] = 100 # unit/s self._queue.put(param) time.sleep(0.02) # wait to be sure the thread has record the new value @@ -245,6 +245,10 @@ class ComponentDetectorFocuser(ComponentDetectorFocuserException, Component, Gui raise ComponentException(ComponentException.ERR_OPERATION_NOT_FOUND, msg) # --- if operation == "GOTO": + # For real and simu + target = self.database.query('target') + if target == None: + raise ComponentException(ComponentException.ERR_TARGET_NOT_FOUND) result = self._do_goto(*args, **kwargs) elif operation == "STOP": result = self._do_stop(*args, **kwargs) diff --git a/src/guitastro/component_mount_pointing.py b/src/guitastro/component_mount_pointing.py index 71cb780..9c23e4c 100644 --- a/src/guitastro/component_mount_pointing.py +++ b/src/guitastro/component_mount_pointing.py @@ -70,8 +70,9 @@ class ComponentMountPointingException(GuitastroException): ERR_AXIS_SYMBOL_NOT_FOUND = 5 ERR_SIMU_KEY_NOT_FOUND = 6 ERR_REAL_READING_COORDINATES = 7 + ERR_TARGET_NOT_FOUND = 8 - errors = [""]*8 + errors = [""]*9 errors[ERR_POINTING_MUST_BE_STOPED] = "The pointing must be stoped before asking a motion" errors[ERR_TARGET_OUTSIDE_LIMITS] = "The asked target is outside the limits" errors[ERR_MOUNT_TYPE_NOT_SUPPORTED] = "The asked mount type is not supported" @@ -80,6 +81,7 @@ class ComponentMountPointingException(GuitastroException): errors[ERR_AXIS_SYMBOL_NOT_FOUND] = "Axis symbol not found" errors[ERR_SIMU_KEY_NOT_FOUND] = "Key 'simu' not found" errors[ERR_REAL_READING_COORDINATES] = "Problem during reading real coordinates (inc)" + errors[ERR_TARGET_NOT_FOUND] = "Target key is not found in parameters" class ComponentMountPointing(ComponentMountPointingException, Component, GuitastroTools): @@ -343,7 +345,10 @@ class ComponentMountPointing(ComponentMountPointingException, Component, Guitast """ operation = args[0].upper() param = self.database.query() - target = param['target'] + target = param.get('target') + if target == "": + print("*** STEP CMP 2050 ***") + # --- Read the start position inc_start = self.read_inc() #print(f"inc_start = {inc_start['simu']}") @@ -534,6 +539,9 @@ class ComponentMountPointing(ComponentMountPointingException, Component, Guitast kwargs['operation'] = operation if operation == "GOTO": # For real and simu + target = self.database.query('target') + if target == None: + raise ComponentException(ComponentException.ERR_TARGET_NOT_FOUND) result = self._do_goto(*args, **kwargs) elif operation == "TRAJECTORY": # For simu only. Real is processed in _my_do -- libgit2 0.21.2