visu_double.py
4.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# -*- 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()