# -*- coding: utf-8 -*- """ Created on Thu Mar 11 15:39:17 2021 @author: alain """ import os import sys import yaml import tkinter as tk path = os.path.abspath("../../src") if path not in sys.path: sys.path.insert(0,path) import guitastro # ##################################################################### # ##################################################################### # ##################################################################### # Main # ##################################################################### # ##################################################################### # ##################################################################### if __name__ == "__main__": # --- Get path_images for examples ima = guitastro.Ima() path_products = ima.copy_data2products() fconfig = os.path.join(path_products,"visu_double.yml") if not os.path.exists(fconfig): config = {} conf = {} conf["fits_path"] = path_products config["visu1"] = conf conf = {} conf["fits_path"] = path_products config["visu2"] = conf else: with open(fconfig, 'r') as stream: try: config = yaml.safe_load(stream) except yaml.YAMLError as exc: print(exc) def save_config(): global fconfig with open(fconfig, 'w') as yaml_file: yaml.dump(config, yaml_file, default_flow_style=False) def ima1_load(): global widgets path_cur = config["visu1"]["fits_path"] ima1.path(path_cur) fullfile = ima1.load() if fullfile != "": path_new = os.path.dirname(fullfile) if path_cur != path_new and path_new != "": config["visu1"]["fits_path"] = path_new save_config() visu1.autocuts() visu1.disp() widgets["button_saveima_1"].configure(state= tk.NORMAL) def ima1_save(): ima1.save() def ima2_load(): global widgets path_cur = config["visu2"]["fits_path"] ima2.path(path_cur) fullfile = ima2.load() if fullfile != "": path_new = os.path.dirname(fullfile) if path_cur != path_new and path_new != "": config["visu2"]["fits_path"] = path_new save_config() visu2.autocuts() visu2.disp() widgets["button_saveima_2"].configure(state= tk.NORMAL) def ima2_save(): ima2.save() # --- load an image from a FITS file ima1 = guitastro.Ima() ima1.extension(".fit") ima2 = guitastro.Ima() ima2.extension(".fit") # --- Create a simple Tk interface tkroot = tk.Tk() tkroot.geometry("1000x500+120+80") tkroot.title("Guitastro double visu tool") # --- frame1 = tk.Frame(tkroot) frame1.pack(side = tk.LEFT, fill=tk.BOTH, expand=tk.YES) frame2 = tk.Frame(tkroot) frame2.pack(side = tk.LEFT, fill=tk.BOTH, expand=tk.YES) # --- widgets = {} # --- frame1m = tk.Frame(frame1) widgets["button_loadima_1"] = tk.Button(frame1m, text="Load FITS", command=ima1_load) widgets["button_loadima_1"].pack(side=tk.LEFT, padx = 2) widgets["button_saveima_1"] = tk.Button(frame1m, text="Save FITS", command=ima1_save, state= tk.DISABLED) widgets["button_saveima_1"].pack(side=tk.LEFT, padx = 2) frame1m.pack(fill=tk.BOTH, expand=tk.NO) # --- frame2m = tk.Frame(frame2) widgets["button_loadima_2"] = tk.Button(frame2m, text="Load FITS", command=ima2_load) widgets["button_loadima_2"].pack(side=tk.LEFT, padx = 2) widgets["button_saveima_2"] = tk.Button(frame2m, text="Save FITS", command=ima2_save, state= tk.DISABLED) widgets["button_saveima_2"].pack(side=tk.LEFT, padx = 2) frame2m.pack(fill=tk.BOTH, expand=tk.NO) # --- tkroot.pack_propagate(0) tkroot.update() # --- Create and use a visu try: frame1i = tk.Frame(frame1) frame1i.pack(side = tk.TOP, fill=tk.BOTH, expand=tk.YES) visu1 = guitastro.Visu(frame1i) visu1.ima(ima1) #visu1.autocuts() #visu1.disp() except: msg = "{}".format(sys.exc_info()) print(msg) # --- Create and use a visu try: frame2i = tk.Frame(frame2) frame2i.pack(side = tk.TOP, fill=tk.BOTH, expand=tk.YES) visu2 = guitastro.Visu(frame2i) visu2.ima(ima2) #visu2.autocuts() #visu2.disp() except: msg = "{}".format(sys.exc_info()) print(msg) # --- Launch the event loop of the user interface tkroot.update() tkroot.mainloop()