Commit cc3d8977 authored by bliss administrator's avatar bliss administrator
Browse files

Created graphical interface table to see available samples + Corrected bugs

parent d29ec247
......@@ -7,16 +7,20 @@ from bliss.common.session import get_current_session
from bliss.config.settings import ParametersWardrobe
from bliss.common.standard import *
from bliss.common.axis import *
from bliss.shell.standard import *
from bliss.common.cleanup import *
from bliss.common.scans import *
from bliss.setup_globals import *
from bliss import setup_globals
from bliss.config.static import get_config
from bliss.shell.cli.user_dialog import *
from bliss.shell.cli.pt_widgets import BlissDialog,display
from PyTango import DeviceProxy
import tkinter as tk
from tkinter import ttk
class SampleChanger:
def __init__(self, name, config):
......@@ -30,18 +34,18 @@ class SampleChanger:
positions = config['positions'][0]
mr_positions = positions['Mr'][0]
calibration_positions = mr_positions['calibration'].to_dict()
robot_positions = mr_positions['robot'].to_dict()
experiment_positions = mr_positions['experiment'].to_dict()
axis = config['axis'][0]['Mr'].to_dict()
elif 'hrtomo' in get_current_session().object_names:
self.tomo = 'hrtomo'
positions = config['positions'][0]
hr_positions = positions['Hr']
calibration_positions = hr_positions['calibration'].to_dict()
robot_positions = hr_positions['robot'].to_dict()
experiment_positions = hr_positions['experiment'].to_dict()
axis = config['axis'][0]['Hr'].to_dict()
else:
print('No sample change positions defined for this setup')
......@@ -49,8 +53,7 @@ class SampleChanger:
self.robot_positions = robot_positions
self.experiment_positions = experiment_positions
self.calibration_positions = calibration_positions
self.axis = axis
self.sample_positions=list()
for col in ['A','B','C']:
......@@ -81,7 +84,7 @@ class SampleChanger:
while ret != False:
ret = BlissDialog( [[dlg_sample_size],[dlg_message],[dlg_sample_position],[dlg_sample_name],[dlg_next]], title='Add samples').show()
if ret != False:
sample = list()
sample.append(ret[dlg_sample_position])
......@@ -123,9 +126,7 @@ class SampleChanger:
dlg_sample_position = UserInput(label="Sample position", defval=self.sample_positions[self.sample_positions.index(ret[dlg_sample_position])+1])
dlg_sample_name = UserInput(label="Sample name", defval="Name")
print("\nAvailable samples:")
print(self.show_samples())
self.show_samples()
def add_default_samples(self,nb_samples,prefix,align_sz):
......@@ -517,7 +518,7 @@ class SampleChanger:
ret = BlissDialog([[dlg_message],[dlg_confirm]],title='Store sample alignment positions').show()
if ret != False:
align_pos = [sx.position,sy.position,sz.position]
align_pos = [self.axis.get('sx').position,self.axis.get('sy').position,self.axis.get('sz').position]
try:
self.samples_device.ActiveSampleAlignPos = align_pos
except Exception as exception:
......@@ -545,7 +546,28 @@ class SampleChanger:
return
sample = {}
print("Position\tName\tSizeX\tSizeY\tSizeZ\tAlignSX\tAlignSY\tAlignSZ\n")
window = tk.Tk()
window.title('Available samples')
table = ttk.Treeview(window)
table["columns"]=("name","sizex","sizey","sizez","alignsx","alignsy","alignsz")
table.column("#0", width=150, minwidth=150, stretch=tk.NO)
table.column("name", width=150, minwidth=150, stretch=tk.NO)
table.column("sizex", width=150, minwidth=150, stretch=tk.NO)
table.column("sizey", width=150, minwidth=150, stretch=tk.NO)
table.column("sizez", width=150, minwidth=150, stretch=tk.NO)
table.column("alignsx", width=150, minwidth=150, stretch=tk.NO)
table.column("alignsy", width=150, minwidth=150, stretch=tk.NO)
table.column("alignsz", width=150, minwidth=150, stretch=tk.NO)
table.heading("#0",text="Position",anchor=tk.W)
table.heading("name", text="Name",anchor=tk.W)
table.heading("sizex", text="Size X",anchor=tk.W)
table.heading("sizey", text="Size Y",anchor=tk.W)
table.heading("sizez", text="Size Z",anchor=tk.W)
table.heading("alignsx", text="Align SX",anchor=tk.W)
table.heading("alignsy", text="Align SY",anchor=tk.W)
table.heading("alignsz", text="Align SZ",anchor=tk.W)
for i in range(0,len(samples),2):
try:
self.samples_device.ActivateSample(samples[i])
......@@ -568,9 +590,11 @@ class SampleChanger:
except Exception as exception:
self._tango_error(exception)
return
print(f"{sample['position']}\t{sample['name']}\t{sample['size'][0]}\t \
{sample['size'][1]}\t{sample['size'][2]}\t{sample['alignpos'][0]}\t{sample['alignpos'][1]}\t{sample['alignpos'][2]}")
table.insert("", i+1, text=str(sample['position']), values=(str(sample['name']),str(sample['size'][0]),str(sample['size'][1]),str(sample['size'][2]),str(sample['alignpos'][0]),str(sample['alignpos'][1]),str(sample['alignpos'][2])))
table.pack(side=tk.TOP,fill=tk.X)
window.mainloop()
def reset_samples(self):
dlg_confirm = UserMsg(label=f"All defined samples are going to be deleted. Continue?")
......@@ -1038,21 +1062,21 @@ class SampleChanger:
def change_position(self):
# Move the detector away
det_pos = xc.position
det_pos = self.axis.get('xc').position
print(f"Current detector position: {det_pos}")
if self.robot_positions['xc'] > det_pos:
det_pos = self.robot_positions['xc']
print("\nMove the detector away")
print("Move detector to: {det_pos}")
umv(xc,det_pos)
umv(self.axis.get('xc'),det_pos)
pos1 = self.robot_positions['yrot']
umv(yrot,pos1)
umv(self.axis.get('yrot'),pos1)
if 'z0' in self.robot_positions:
if 'z0' in self.axis:
pos = self.robot_positions['z0']
print(f"\nMove z0 to: {pos}")
umv(z0,pos)
umv(self.axis.get('z0'),pos)
# move the dial positions
pos1 = self.robot_positions['srot']
......@@ -1060,7 +1084,7 @@ class SampleChanger:
pos3 = self.robot_positions['sy']
pos4 = self.robot_positions['sz']
print(f"\nMove sz to {pos4}")
umv(srot,pos1,sx,pos2,sy,pos3,sz,pos4)
umv(self.axis.get('srot'),pos1,self.axis.get('sx'),pos2,self.axis.get('sy'),pos3,self.axis.get('sz'),pos4)
# still some timeouts on the robot that are longer than 3 seconds!
try:
......@@ -1072,21 +1096,21 @@ class SampleChanger:
def experiment_position(self,sx_pos,sy_pos,sz_pos):
print(f"\nMove sz to: {sz_pos}")
umv(sx,sx_pos,sy,sy_pos,sz,sz_pos)
umv(self.axis.get('sx'),sx_pos,self.axis.get('sy'),sy_pos,self.axis.get('sz'),sz_pos)
if 'z0' in self.experiment_positions:
if 'z0' in self.axis:
pos = self.experiment_positions['z0']
print(f"\nMove z0 to: {pos}")
umv(z0,pos)
umv(self.axis.get('z0'),pos)
pos = self.experiment_positions['yrot']
print(f"\nMove yrot to: {pos}")
umv(yrot,pos)
umv(self.axis.get('yrot'),pos)
pos = self.experiment_positions['xc']
print("\nMove the detector closer")
print(f"Move detector to: {pos}")
umv(xc,pos)
umv(self.axis.get('xc'),pos)
def _tango_error(self,exception):
......@@ -1263,6 +1287,6 @@ def radio_all_samples(expo_time_tomo=0.5,expo_time_vis=0.5):
def robot_status():
sample_changer = SampleChanger()
sample_changer = get_config().get('samplechanger')
print(sample_changer.robot_device.Status())
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment