tp_audine_elec.py
3.2 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
# -*- 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,"tp_audine_elec.yml")
if not os.path.exists(fconfig):
config = {}
conf = {}
conf["fits_path"] = path_products
config["visu1"] = 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.rootdir = 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()
# --- load an image from a FITS file
ima1 = guitastro.Ima()
ima1.extension = ".fit"
# --- Create a simple Tk interface
tkroot = tk.Tk()
tkroot.geometry("800x600+120+80")
tkroot.title("TP Audine Electronique")
# ---
frame1 = tk.Frame(tkroot)
frame1.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)
# ---
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)
# --- Launch the event loop of the user interface
tkroot.update()
tkroot.mainloop()