From b8dced60d7144d3b8c551ed1d70db846358dec19 Mon Sep 17 00:00:00 2001 From: jens Date: Mon, 23 Nov 2020 19:58:56 +0100 Subject: [PATCH] =?UTF-8?q?Alles=20Vorbereitrungen=20f=C3=BCr=20die=20Kali?= =?UTF-8?q?brierung=20ok?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- JFSphoto.py | 77 +++++++++++++++++++++++++++++++++++++++++++++++++---- config.ini | 5 ++++ pyCCDGUI.py | 1 + 3 files changed, 78 insertions(+), 5 deletions(-) create mode 100644 config.ini diff --git a/JFSphoto.py b/JFSphoto.py index f89e06a..bd259d2 100644 --- a/JFSphoto.py +++ b/JFSphoto.py @@ -5,6 +5,7 @@ from tkinter import messagebox import tkinter as tk import csv import numpy as np +from configparser import ConfigParser ####################################### object class Jfsphoto (object): @@ -14,10 +15,17 @@ class Jfsphoto (object): self.nmi = 0 self.nm2 = 0 self.nm2i = 0 - + self.nm_left = 0 + self.nm_right = 0 + self.nm_step = 0 + self.tnm_left = tk.StringVar() + self.tnm_right = tk.StringVar() + self.tnm_step = tk.StringVar() + self.nmData16 = np.zeros(3694, np.uint16) + def test1(self): win = tk.Toplevel() - win.geometry("400x200+30+30") + win.geometry("450x200+100+100") self.lab1 = tk.Label(win, text='please enter filenames and nm of the peaks').grid(row=0,column=0,columnspan=6) ########## first peak self.tnm = tk.StringVar() @@ -41,6 +49,20 @@ class Jfsphoto (object): self.lnm2 = tk.Label(win,textvariable =self.tnm2).grid(row=2,column=3) self.lnm2 = tk.Label(win,text =" nm by index ").grid(row=2,column=4) self.lm2i = tk.Label(win,textvariable=self.tnm2i).grid(row=2,column=5) + ########### calibration + self.tnm_left.set(str(self.nm_left)) + self.tnm_right.set(str(self.nm_right)) + self.tnm_step.set(str(self.nm_step)) + self.lab4 = tk.Label(win,text="left border [nm]").grid(row=3,column=0) + self.lab5 = tk.Label(win,textvariable=self.tnm_left).grid(row=3,column=1) + self.lab6 = tk.Label(win,text="right border [nm]").grid(row=3,column=2) + self.lab7 = tk.Label(win,textvariable=self.tnm_right).grid(row=3,column=3) + self.lab8 = tk.Label(win,text="[nm]/point").grid(row=3,column=4) + self.lab9 = tk.Label(win,textvariable=self.tnm_step).grid(row=3,column=5) + self.bt3 = tk.Button(win,text="Calibrieren",command=self.calibrate,state=tk.DISABLED) + self.bt3.grid(row=4,column=0) + self.bt4 = tk.Button(win,text="Load Config",command=self.conf_read).grid(row=4,column=1) + self.bt5 = tk.Button(win,text="Save Config",command=self.conf_write).grid(row=4,column=2) #a=tk.Label(win,text='Hi there') #a.place(x=10,y=10,width=40,height=25) #b=tk.Button(win,text='Ok then',command=win.destroy) @@ -51,12 +73,28 @@ class Jfsphoto (object): win.wait_window() def checkit(self): - print(self.tnm.get()) + self.nm = int(self.tnm.get()) + self.nmi = int(self.tnmi.get()) + self.nm2 = int(self.tnm2.get()) + self.nm2i = int(self.tnm2i.get()) + if ((self.nm > 0) & (self.nmi > 0) & (self.nm2 > 0) & (self.nm2i > 0)): + self.bt3.config(state = tk.NORMAL) + + def calibrate(self): + self.nm_step = round((self.nm2 - self.nm)/(self.nm2i-self.nmi),5) + self.nm_left = round(self.nm-(self.nm_step*self.nmi),0) + self.nm_right = round(self.nm2 + self.nm_step*(3694-self.nm2i),0) + self.tnm_left.set(str(self.nm_left)) + self.tnm_right.set(str(self.nm_right)) + self.tnm_step.set(str(self.nm_step)) + + def set_nm_scale(self): + if ((self.nm_step > 0) & (self.nm_left > 0)): + for i in range(0,3694): + self.nmData16[i] = self.nm_left + self.nm_step*i - def info(self): - print(f'nm {self.nm} nmi {self.nmi}') def openfile(self,xx): rxData16 = np.zeros(3694, np.uint16) @@ -84,3 +122,32 @@ class Jfsphoto (object): except IOError: messagebox.showerror("By the great otter!","There's a problem opening the file.") + def conf_write(self): + config = ConfigParser() + config.read('config.ini') + lis = config.sections() + if ('main' not in lis): + config.add_section('main') + config.set('main','nm_left',str(self.nm_left)) + config.set('main','nm_right',str(self.nm_right)) + config.set('main','nm_step',str(self.nm_step)) + + with open('config.ini','w') as f: + config.write(f) + + def conf_read(self): + config = ConfigParser() + try: + config.read('config.ini') + self.nm_left = float(config.get('main','nm_left',fallback='0')) + self.tnm_left.set(config.get('main','nm_left',fallback='0')) + self.nm_right = float(config.get('main','nm_right',fallback='0')) + self.tnm_right.set(config.get('main','nm_right',fallback='0')) + self.nm_step = float(config.get('main','nm_step',fallback='0')) + self.tnm_step.set(config.get('main','nm_step',fallback='0')) + self.set_nm_scale() + except IOError: + print("By the great otter!","No config.ini file") + + + diff --git a/config.ini b/config.ini new file mode 100644 index 0000000..6be8816 --- /dev/null +++ b/config.ini @@ -0,0 +1,5 @@ +[main] +nm_left = 320.0 +nm_right = 811.0 +nm_step = 0.13279 + diff --git a/pyCCDGUI.py b/pyCCDGUI.py index 8d51035..eaf7e46 100644 --- a/pyCCDGUI.py +++ b/pyCCDGUI.py @@ -47,6 +47,7 @@ if __name__ == '__main__': menu = CCDmenusetup.buildmenu(root) CCDplot = CCDplots.buildplot(root) jfs =Jfsphoto() + jfs.conf_read() panel = CCDpanelsetup.buildpanel(root, CCDplot, SerQueue,jfs) panel.grid(row=0, column=2)