Skip to content
Snippets Groups Projects
Commit e03980f7 authored by Alexandros Asonitis's avatar Alexandros Asonitis
Browse files

removed filechooser(replaced with buttons and tkinter)

parent a80c3dd5
Branches
No related tags found
No related merge requests found
......@@ -11,10 +11,14 @@ enabing and disabling widgets for jupyter(lists)
"""
import sys
sys.path.append(r"C:\Users\user\labcode\hp4155")
sys.path.insert(0, '..') #append parent directory
import module
#import module
import matplotlib.pyplot as plt
import tkinter as tk
from tkinter import filedialog
import numpy as np
from IPython.display import display, clear_output
import pandas as pd
......@@ -194,3 +198,36 @@ def write_to_file(file,title,df):
f.write("\n")
f.write(df.to_string())
f.write("\n\n")
#### new functions ##############
def change_state(widgets_list):
for widget in widgets_list:
widget.disabled = not widget.disabled
#works
def initialize_tkinter(sample_series,field,DUT):
#open dialog and hide the main window
root = tk.Tk()
root.withdraw()
file_path = filedialog.asksaveasfilename(defaultextension=".txt", filetypes=[("Text files","*.txt")],title = "save results path",initialfile = f'{DUT.value}_Memristor.txt')
#check if the file path is correct(.txt)
while file_path.endswith(".txt") == False:
#open again filedialog with error message box
tk.messagebox.showerror(message='invalid filename!')
file_path = filedialog.asksaveasfilename(defaultextension=".txt", filetypes=[("Text files","*.txt")],title = "save results path",initialfile = f'{DUT.value}_Memristor.txt')
#the first time open the file in write mode!(replaces the old file)
#write sample series
with open(file_path,'w') as f:
title = f"Memristor Measurement"+"\n\n"+f"Sample series:{sample_series.value}" +"\n"+f"field:{field.value}"+"\n"+f"DUT:{DUT.value}"+"\n\n"
f.write(title)
root.destroy()
#return the file path
return file_path
\ No newline at end of file
......@@ -3,36 +3,10 @@ from help import *
import ipywidgets as widgets
from keyboard import add_hotkey,remove_hotkey
def memristor():
#parameters set by the user
Vset=1
CC_vset=10**(-3)
Vreset=-1
CC_vreset=10**(-3)
step = 0.02
integration_time='MED'
#additional variables
first = True #first measurement
file_path =os.getcwd()
file = None
#default ini file
ini_file_path=os.getcwd()
ini_file_name=r"default.ini"
ini_file=os.path.join(ini_file_path,ini_file_name)
#filechooser
fc = FileChooser(select_desc='load .ini')
fc.default_path = r"\\FILESERVER\public"
fc.filter_pattern = '*.ini'
display(fc)
#pathchooser
pc = FileChooser(select_desc="save path")
pc.default_path = r"\\FILESERVER\public"
pc.show_only_dirs = True
display(pc)
print()
file_path = None
# the three naming fields
......@@ -42,6 +16,7 @@ def memristor():
description = 'sample series:',
style = {'description_width': 'initial'}
)
field = widgets.Text(
value= '',
placeholder ='Enter text here:',
......@@ -60,41 +35,109 @@ def memristor():
display(all_text_boxes)
print()
#first series of parameters
step = widgets.BoundedFloatText(
value=0.01,
min=0,
max=200,
step=0.01,
description='Step(V):',
)
integration_time=widgets.Dropdown(
options=['SHORt', 'MEDium', 'LONG'],
value='MEDium',
description='Integration:',
#style = {'description_width': 'initial'},
)
sampling=widgets.Checkbox(description='sampling check')
#align the widgets horizontaly
line0=widgets.HBox([step,integration_time,sampling])
display(line0)
print()
# THE BUTTONS
#create buttons as it shown in the how_buttons_look
set=widgets.Button(description='SET')
reset=widgets.Button(description='RESET')
sampling=widgets.Checkbox(description='sampling check')
full=widgets.Button(description='full sweep')
number = widgets.BoundedIntText(value=1,min=1,max=sys.maxsize,step=1,description='full sweeps:',disabled=False) #number of measuremts for the full sweep
#parameter boxes
Vset=widgets.BoundedFloatText(
value=1,
min=0,
max=200,
step=0.1,
description='Voltage(V):',
)
#parameter buttons
CC_vset=widgets.BoundedFloatText(
value=1e-3,
min=-1,
max=1,
step=0.1,
description= 'Comp(A):',
)
#parameter buttons
Vreset=widgets.BoundedFloatText(
value=-1,
min=-200,
max=0,
step=0.1,
description='Voltage(V):',
)
#parameter buttons
CC_vreset=widgets.BoundedFloatText(
value=1e-3,
min=-1,
max=1,
step=0.1,
description='Comp(A):',
)
#align a button with a checkbox or integer bounded texts horizontaly
line1 = widgets.HBox([set,sampling])
line1 = widgets.HBox([set,Vset,CC_vset])
line2 = widgets.HBox([reset,Vreset,CC_vreset])
line3 = widgets.HBox([full,number])
#pack them into a single vertical box
all = widgets.VBox([line1,reset,line3])
all = widgets.VBox([line1,line2,line3])
output = widgets.Output()
#dispaly them all
print()
display(all,output)
#help lists for changing state of the buttons
information = [sample_series,field,DUT,sampling]
buttons = [set,reset,full]
parameters = [Vset,CC_vset,Vreset,CC_vreset,step,integration_time,number]
#connect to the device
device = module.HP4155a('GPIB0::17::INSTR')
device.reset()
#device = module.HP4155a('GPIB0::17::INSTR')
#device.reset()
#disable all irrelevant units for the measurement
#smu1 and smu3 are disabled
device.smu_disable_sweep(1)
device.smu_disable_sweep(3)
#device.smu_disable_sweep(1)
#device.smu_disable_sweep(3)
#disable vmus and vsus
device.disable_vsu(1)
device.disable_vsu(2)
device.disable_vmu(1)
device.disable_vmu(2)
#device.disable_vsu(1)
#device.disable_vsu(2)
#device.disable_vmu(1)
#device.disable_vmu(2)
""" the above is what happens when the programm starts all the rest have to be written into button trigger functions"""
""" the above is what happens when the programm starts all the rest have to be written into button trigger functions
def on_set_button_clicked(b):
nonlocal Vset,CC_vset,step,integration_time,device,first,DUT,sample_series,field,file_path,ini_file,file
......@@ -324,9 +367,7 @@ def memristor():
set.on_click(on_set_button_clicked)
reset.on_click(on_reset_button_clicked)
full.on_click(on_full_button_clicked)
"""
......
%% Cell type:code id:33f299ef-2302-4e0a-b45f-291460d944c6 tags:
``` python
from memristor import *
memristor()
%run memristor.py
```
%% Output
%% Cell type:code id:541c465a-2858-4998-8411-8c06ab4b466c tags:
%% Cell type:code id:2fc85780-0e32-4b77-9de5-684c87f55a6b tags:
``` python
```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment