Commit 94c41643a028a2e17283cf18c9d41b273807c281
1 parent
811f0a5f
Exists in
master
Add schemes to TP CCD
Showing
5 changed files
with
180 additions
and
36 deletions
Show diff stats
18 KB
11 KB
69.5 KB
52 KB
gui/tp_audine_elec/tp_audine_elec.py
... | ... | @@ -13,9 +13,12 @@ import sys |
13 | 13 | import yaml |
14 | 14 | import subprocess |
15 | 15 | import time |
16 | -from PIL import ImageTk | |
16 | +from PIL import ImageTk, Image | |
17 | 17 | import tkinter as tk |
18 | 18 | from tkinter import ttk |
19 | +import tkinter.font as tkFont | |
20 | +import tkinter.scrolledtext as tkscrolled | |
21 | + | |
19 | 22 | import platform |
20 | 23 | |
21 | 24 | path = os.path.abspath("../../src") |
... | ... | @@ -34,8 +37,10 @@ import guitastro |
34 | 37 | if __name__ == "__main__": |
35 | 38 | |
36 | 39 | # --- Get path_images for examples |
37 | - ima = guitastro.Ima() | |
38 | - path_products = ima.copy_data2products() | |
40 | + ima1 = guitastro.Ima() | |
41 | + path_products = ima1.copy_data2products() | |
42 | + | |
43 | + # --- Global variable config for the YML file | |
39 | 44 | fconfig = os.path.join(path_products,"tp_audine_elec.yml") |
40 | 45 | if not os.path.exists(fconfig): |
41 | 46 | config = {} |
... | ... | @@ -49,14 +54,29 @@ if __name__ == "__main__": |
49 | 54 | except yaml.YAMLError as exc: |
50 | 55 | print(exc) |
51 | 56 | |
57 | + # --- Global variable to select the method | |
52 | 58 | methods = ["full_frame", "zi_zh", "fast_line", "read_pel_fast", "read_pel_fast2", "fast_vidage", "square_signal"] |
53 | 59 | |
60 | + # --- Global variable to define info messages | |
54 | 61 | infos = {} |
55 | 62 | infos['demarrer_acq'] = "Appuyez sur le bouton Acquisition pour envoyer des signaux ร la camรฉra" |
56 | 63 | infos['acq_en_cours'] = "Acquisition en cours. Attendre quelques secondes... Prendre des mesures ร l'oscilloscope" |
57 | 64 | infos['acq_impossible'] = "Acquisition impossible sur cet OS. Utiliser un Raspberry PI" |
58 | 65 | infos['bad_method'] = f"Method not found amonsgt {methods}" |
66 | + | |
67 | + # --- Global variable for Tk variables | |
59 | 68 | var = {} |
69 | + var['executable'] = "/home/user/iut/tp_ccd/bin/Debug/tp_ccd" | |
70 | + var['c_code_filename'] = os.path.join(os.getcwd(), "main.cpp") | |
71 | + var['image_path'] = "/home/user/Documents" | |
72 | + var['image_filename'] = "image.fit" | |
73 | + | |
74 | + | |
75 | + # =================================================== | |
76 | + # =================================================== | |
77 | + # Function definitions | |
78 | + # =================================================== | |
79 | + # =================================================== | |
60 | 80 | |
61 | 81 | def save_config(): |
62 | 82 | global fconfig |
... | ... | @@ -80,7 +100,6 @@ if __name__ == "__main__": |
80 | 100 | def ima1_save(): |
81 | 101 | ima1.save() |
82 | 102 | |
83 | - # Fonction appelรฉe par l'appui du bouton | |
84 | 103 | def acquisition(): |
85 | 104 | global widgets |
86 | 105 | global infos |
... | ... | @@ -119,7 +138,7 @@ if __name__ == "__main__": |
119 | 138 | tkroot.update() |
120 | 139 | # --- |
121 | 140 | argus = [] |
122 | - argus.append("/home/user/iut/tp_ccd/bin/Debug/tp_ccd") | |
141 | + argus.append(var['executable']) | |
123 | 142 | argus.append(f"{meth}") |
124 | 143 | argus.append(f"{expo}") |
125 | 144 | argus.append(f"{binn}") |
... | ... | @@ -148,7 +167,8 @@ if __name__ == "__main__": |
148 | 167 | print(message) # --- |
149 | 168 | if meth=="full_frame" and image==True: |
150 | 169 | time.sleep(0.5) |
151 | - fullfile = ima1.load("/home/user/Documents/image.fit") | |
170 | + fname = os.path.join(var['image_path'],var['image_filename']) | |
171 | + fullfile = ima1.load(fname) | |
152 | 172 | path_new = os.path.dirname(fullfile) |
153 | 173 | config["visu1"]["fits_path"] = path_new |
154 | 174 | ima1.rootdir = path_new |
... | ... | @@ -161,42 +181,55 @@ if __name__ == "__main__": |
161 | 181 | widgets["button_saveima_1"].configure(state= tk.NORMAL) |
162 | 182 | widgets["button_acq"].configure(state= tk.NORMAL) |
163 | 183 | var['info'].set(infos['demarrer_acq']) |
164 | - | |
165 | - # update the plot | |
184 | + # --- update the plot | |
166 | 185 | tkroot.update() |
167 | 186 | |
168 | - # --- load an image from a FITS file | |
169 | - ima1 = guitastro.Ima() | |
170 | - ima1.extension = ".fit" | |
187 | + # =================================================== | |
188 | + # =================================================== | |
189 | + # Start main code | |
190 | + # =================================================== | |
191 | + # =================================================== | |
171 | 192 | |
172 | - # --- Create a simple Tk interface | |
193 | + # --- Create a Tk interface | |
173 | 194 | tkroot = tk.Tk() |
174 | - dimx = 930 | |
195 | + dimx = 1300 #840 | |
175 | 196 | dimy = 880 |
176 | - geom = f"{dimx}x{dimy}+120+80" | |
197 | + geom = f"{dimx}x{dimy}+80+0" | |
177 | 198 | tkroot.geometry(geom) |
178 | 199 | tkroot.title("TP CCD Electronique - BUT S5") |
179 | 200 | tkroot.minsize(height=dimy, width=dimx) |
180 | 201 | tkroot.maxsize(height=dimy+50, width=dimx+50) |
181 | 202 | |
182 | - # --- | |
203 | + fontStyle_1 = tkFont.Font(family="Arial", size=14, weight="bold") | |
204 | + fontStyle_2 = tkFont.Font(family="Arial", size=12, weight="bold") | |
205 | + fontStyle_3 = tkFont.Font(family="Arial", size=10, weight="bold") | |
206 | + fontStyle_c3 = tkFont.Font(family="courier", size=10, weight="bold") | |
207 | + | |
208 | + # =================================================== | |
209 | + # =================================================== | |
210 | + # Frame1. Acquisition button and image visu | |
211 | + # =================================================== | |
212 | + # =================================================== | |
183 | 213 | frame1 = tk.Frame(tkroot) |
184 | - frame1.pack(side = tk.TOP, fill=tk.X, expand=tk.NO) | |
214 | + | |
215 | + # --- | |
216 | + frame101 = tk.Frame(frame1) | |
217 | + frame101.pack(side = tk.TOP, fill=tk.X, expand=tk.NO) | |
185 | 218 | # --- |
186 | 219 | widgets = {} |
187 | 220 | # --- |
188 | - frame1m = tk.Frame(frame1) | |
221 | + frame101m = tk.Frame(frame101) | |
189 | 222 | # --- |
190 | - test = ImageTk.PhotoImage(file='logo_iut_mp.png') | |
191 | - label1 = tk.Label(frame1m, image=test) | |
192 | - label1.image = test | |
223 | + photo_logo = ImageTk.PhotoImage(file='logo_iut_mp.png') | |
224 | + label1 = tk.Label(frame101m, image=photo_logo) | |
225 | + label1.image = photo_logo | |
193 | 226 | label1.pack(side = tk.LEFT, padx=2) |
194 | 227 | # --- |
195 | 228 | var_method = tk.StringVar() |
196 | 229 | var_method.set(methods[0]) |
197 | - label_method = tk.Label(frame1m, text="Method") | |
230 | + label_method = tk.Label(frame101m, text="Method") | |
198 | 231 | label_method.pack(side = tk.LEFT) |
199 | - entry_method = ttk.Combobox(frame1m, textvariable=var_method, width=12) | |
232 | + entry_method = ttk.Combobox(frame101m, textvariable=var_method, width=12) | |
200 | 233 | entry_method['values'] = methods |
201 | 234 | entry_method['state'] = 'readonly' |
202 | 235 | entry_method.pack(side = tk.LEFT) |
... | ... | @@ -204,47 +237,158 @@ if __name__ == "__main__": |
204 | 237 | # --- |
205 | 238 | var_exp = tk.DoubleVar() |
206 | 239 | var_exp.set(2.0) |
207 | - label_exp = tk.Label(frame1m, text="Temps de pose (s)") | |
240 | + label_exp = tk.Label(frame101m, text="Temps de pose (s)") | |
208 | 241 | label_exp.pack(side = tk.LEFT) |
209 | - entry_exp = tk.Entry(frame1m, width=4, textvariable=var_exp) | |
242 | + entry_exp = tk.Entry(frame101m, width=4, textvariable=var_exp) | |
210 | 243 | entry_exp.pack(side = tk.LEFT) |
211 | 244 | # --- |
212 | 245 | var_bin = tk.IntVar() |
213 | 246 | var_bin.set(1) |
214 | - label_bin = tk.Label(frame1m, text="Binning") | |
247 | + label_bin = tk.Label(frame101m, text="Binning") | |
215 | 248 | label_bin.pack(side = tk.LEFT) |
216 | - entry_bin = tk.Entry(frame1m, width=4, textvariable=var_bin) | |
249 | + entry_bin = tk.Entry(frame101m, width=4, textvariable=var_bin) | |
217 | 250 | entry_bin.pack(side = tk.LEFT) |
218 | 251 | # --- |
219 | - widgets["button_acq"] = tk.Button(frame1m, text="Acquisition", command=acquisition, padx=20, pady=20, font='sans 16 bold') | |
252 | + widgets["button_acq"] = tk.Button(frame101m, text="Acquisition", command=acquisition, padx=20, pady=20, font='sans 16 bold') | |
220 | 253 | widgets["button_acq"].pack(side = tk.LEFT, pady=5, padx=5) |
221 | 254 | # --- |
222 | - widgets["button_loadima_1"] = tk.Button(frame1m, text="Load FITS", command=ima1_load) | |
255 | + widgets["button_loadima_1"] = tk.Button(frame101m, text="Load FITS", command=ima1_load) | |
223 | 256 | widgets["button_loadima_1"].pack(side=tk.LEFT, padx = 2) |
224 | - widgets["button_saveima_1"] = tk.Button(frame1m, text="Save FITS", command=ima1_save, state= tk.DISABLED) | |
257 | + widgets["button_saveima_1"] = tk.Button(frame101m, text="Save FITS", command=ima1_save, state= tk.DISABLED) | |
225 | 258 | widgets["button_saveima_1"].pack(side=tk.LEFT, padx = 2) |
226 | - frame1m.pack(side = tk.TOP, fill=tk.X, expand=tk.NO) | |
259 | + frame101m.pack(side = tk.TOP, fill=tk.X, expand=tk.NO) | |
227 | 260 | |
228 | 261 | # --- |
229 | - frame2 = tk.Frame(tkroot) | |
262 | + frame102 = tk.Frame(frame1) | |
230 | 263 | # --- |
231 | 264 | var['info'] = tk.StringVar() |
232 | 265 | var['info'].set(infos['demarrer_acq']) |
233 | - widgets["label_info"] = tk.Label(frame2, textvariable=var['info'], padx = 10) | |
266 | + widgets["label_info"] = tk.Label(frame102, textvariable=var['info'], padx = 10) | |
234 | 267 | widgets["label_info"].pack(side = tk.LEFT) |
235 | - frame2.pack(side = tk.TOP, fill=tk.X, expand=tk.NO) | |
268 | + frame102.pack(side = tk.TOP, fill=tk.X, expand=tk.NO) | |
236 | 269 | |
237 | 270 | # --- Create and use a visu |
238 | 271 | try: |
239 | - frame1i = tk.Frame(tkroot) | |
240 | - visu1 = guitastro.Visu(frame1i) | |
272 | + frame101i = tk.Frame(frame1) | |
273 | + visu1 = guitastro.Visu(frame101i) | |
241 | 274 | visu1.ima(ima1) |
242 | - frame1i.pack(side = tk.TOP, fill=tk.BOTH, expand=tk.YES) | |
275 | + frame101i.pack(side = tk.TOP, fill=tk.BOTH, expand=tk.YES) | |
243 | 276 | except: |
244 | 277 | msg = "{}".format(sys.exc_info()) |
245 | 278 | print(msg) |
246 | 279 | |
280 | + frame1.pack(fill=tk.Y, side = tk.LEFT, anchor=tk.NW) | |
281 | + | |
282 | + # =================================================== | |
283 | + # =================================================== | |
284 | + # Frame2. Display C code | |
285 | + # =================================================== | |
286 | + # =================================================== | |
287 | + frame2 = tk.Frame(tkroot) | |
288 | + | |
289 | + frame_display_code = tk.Frame(frame2) | |
290 | + | |
291 | + scrollbar = tk.Scrollbar(frame_display_code) | |
292 | + text_code_txt = tk.Text(frame_display_code, height=15, wrap="word", yscrollcommand=scrollbar.set, font=fontStyle_3) | |
293 | + | |
294 | + scrollbar.config(command=text_code_txt.yview) | |
295 | + scrollbar.pack(side=tk.RIGHT, fill=tk.Y) | |
296 | + | |
297 | + text_code_txt.tag_config('red', foreground="red") | |
298 | + text_code_txt.tag_config('blue', foreground="blue") | |
299 | + text_code_txt.tag_config('black', foreground="black") | |
300 | + text_code_txt.tag_config('green', foreground="green") | |
301 | + lignes = "" | |
302 | + with open(var['c_code_filename'], "rt") as fid: | |
303 | + lignes = fid.readlines() | |
304 | + for ligne in lignes: | |
305 | + text_code_txt.insert(tk.END, ligne, "blue") | |
306 | + text_code_txt.yview_moveto(1.0) | |
307 | + text_code_txt.pack(side = tk.TOP, padx=5, pady=1) | |
308 | + frame_display_code.pack(side = tk.TOP, pady=5) | |
309 | + | |
310 | + | |
311 | + | |
312 | + notebook = ttk.Notebook(frame2) | |
313 | + tab201 = ttk.Frame(notebook) | |
314 | + tab202 = ttk.Frame(notebook) | |
315 | + tab203 = ttk.Frame(notebook) | |
316 | + tab204 = ttk.Frame(notebook) | |
317 | + | |
318 | + # ===================================================== | |
319 | + # Tab 201 == | |
320 | + # ===================================================== | |
321 | + | |
322 | + frame_display_timing = tk.Frame(tab201) | |
323 | + image = Image.open('timing_diagram1.png') | |
324 | + zoom = 0.7 | |
325 | + image_size = tuple([int(zoom * x) for x in image.size]) | |
326 | + # canvas for image | |
327 | + canvas = tk.Canvas(frame_display_timing, width=image_size[0], height=image_size[1], relief=tk.RAISED, cursor="crosshair") | |
328 | + timing_image = ImageTk.PhotoImage(image.resize(image_size)) | |
329 | + canvas.create_image(0, 0, anchor = tk.NW, image = timing_image) | |
330 | + canvas.pack() | |
331 | + frame_display_timing.pack() | |
332 | + | |
333 | + tab201.pack() | |
334 | + | |
335 | + # ===================================================== | |
336 | + # Tab 202 == | |
337 | + # ===================================================== | |
338 | + frame_display_code = tk.Frame(tab202) | |
339 | + | |
340 | + frame_display_ccd = tk.Frame(tab202) | |
341 | + image = Image.open('ccd.png') | |
342 | + zoom = 0.6 | |
343 | + image_size = tuple([int(zoom * x) for x in image.size]) | |
344 | + ccd_canvas = tk.Canvas(frame_display_ccd, width=image_size[0], height=image_size[1], relief=tk.RAISED, cursor="crosshair") | |
345 | + ccd_image = ImageTk.PhotoImage(image.resize(image_size), Image.ANTIALIAS) | |
346 | + ccd_canvas.create_image(0, 0, anchor = tk.NW, image = ccd_image) | |
347 | + ccd_canvas.pack() | |
348 | + frame_display_ccd.pack() | |
349 | + | |
350 | + # ===================================================== | |
351 | + # Tab 203 == | |
352 | + # ===================================================== | |
353 | + frame_display_ampli = tk.Frame(tab203) | |
354 | + image = Image.open('ampli.png') | |
355 | + zoom = 0.5 | |
356 | + image_size = tuple([int(zoom * x) for x in image.size]) | |
357 | + ampli_canvas = tk.Canvas(frame_display_ampli, width=image_size[0], height=image_size[1], relief=tk.RAISED, cursor="crosshair") | |
358 | + ampli_image = ImageTk.PhotoImage(image.resize(image_size), Image.ANTIALIAS) | |
359 | + ampli_canvas.create_image(0, 0, anchor = tk.NW, image = ampli_image) | |
360 | + ampli_canvas.pack() | |
361 | + frame_display_ampli.pack() | |
362 | + | |
363 | + # ===================================================== | |
364 | + # Tab 204 == | |
365 | + # ===================================================== | |
366 | + frame_display_can = tk.Frame(tab204) | |
367 | + image = Image.open('can.png') | |
368 | + zoom = 0.6 | |
369 | + image_size = tuple([int(zoom * x) for x in image.size]) | |
370 | + can_canvas = tk.Canvas(frame_display_can, width=image_size[0], height=image_size[1], relief=tk.RAISED, cursor="crosshair") | |
371 | + can_image = ImageTk.PhotoImage(image.resize(image_size), Image.ANTIALIAS) | |
372 | + can_canvas.create_image(0, 0, anchor = tk.NW, image = can_image) | |
373 | + can_canvas.pack() | |
374 | + frame_display_can.pack() | |
375 | + tab202.pack() | |
376 | + | |
377 | + # ===================================================== | |
378 | + # Pack frame of tabs | |
379 | + # ===================================================== | |
380 | + | |
381 | + notebook.add(tab201, text="Timings") | |
382 | + notebook.add(tab202, text="CCD") | |
383 | + notebook.add(tab203, text="Analogic output") | |
384 | + notebook.add(tab204, text="CAN and multiplexer") | |
385 | + notebook.pack(fill = tk.Y) | |
386 | + | |
387 | + frame2.pack(fill = tk.Y, side=tk.LEFT, anchor="nw") | |
388 | + | |
389 | + # =================================================== | |
247 | 390 | # --- Launch the event loop of the user interface |
391 | + # =================================================== | |
248 | 392 | tkroot.pack_propagate(0) |
249 | 393 | tkroot.update() |
250 | 394 | tkroot.mainloop() | ... | ... |