From fc2b21faefb74e6b044d39115804604e9e7075c9 Mon Sep 17 00:00:00 2001
From: "paolo.cinquegrana@elettra.eu" <paolo.cinquegrana@elettra.eu>
Date: Thu, 23 May 2024 11:26:05 +0200
Subject: [PATCH] rimossa sezione oscilloscopio da tab delay, aggiunti motori
 in tab pointing

---
 src/SluSourceMonitor.py | 526 +++++++++++++++++++++++++++++++---------
 1 file changed, 417 insertions(+), 109 deletions(-)

diff --git a/src/SluSourceMonitor.py b/src/SluSourceMonitor.py
index 3caa39b..7467149 100644
--- a/src/SluSourceMonitor.py
+++ b/src/SluSourceMonitor.py
@@ -6,7 +6,7 @@ import PyTango
 import os
 import csv
 import time
-from PyQt5.QtWidgets import QGroupBox, QApplication, QWidget, QHBoxLayout, QGridLayout, QPushButton, QLineEdit, QProgressBar, QLabel, QTabWidget, QFrame, QComboBox, QDialog, QCheckBox
+from PyQt5.QtWidgets import QGroupBox, QApplication, QWidget, QHBoxLayout, QGridLayout, QPushButton, QLineEdit, QVBoxLayout, QProgressBar, QLabel, QTabWidget, QFrame, QComboBox, QDialog, QCheckBox, QMessageBox
 from PyQt5.QtCore import QBasicTimer
 from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
 import matplotlib.pyplot as plt
@@ -40,6 +40,13 @@ try:
     sacco['ccd2'] = PyTango.DeviceProxy('srv-tango-srf-01:20000/slu/diagnostics/ccd_slu.04')
     sacco['ccd3'] = PyTango.DeviceProxy('srv-tango-srf-01:20000/slu/diagnostics/ccd_slu.08')
     sacco['ccd4'] = PyTango.DeviceProxy('srv-tango-srf-01:20000/slu/diagnostics/ccd_slu.08')
+    sacco['kom1'] = PyTango.DeviceProxy('srv-tango-srf-01:20000/slu/motor/kom_slu.05')
+    sacco['kom2'] = PyTango.DeviceProxy('srv-tango-srf-01:20000/slu/motor/kom_slu.06')
+    sacco['kom3'] = PyTango.DeviceProxy('srv-tango-srf-01:20000/slu/motor/kom_slu.01')
+    sacco['kom4'] = PyTango.DeviceProxy('srv-tango-srf-01:20000/slu/motor/kom_slu.02')
+    sacco['kom5'] = PyTango.DeviceProxy('srv-tango-srf-01:20000/slu/motor/kom_slu.04')
+    sacco['kom6'] = PyTango.DeviceProxy('srv-tango-srf-01:20000/slu/motor/kom_slu.03')
+    sacco['rots2'] = PyTango.DeviceProxy('srv-tango-srf-01:20000/slu/motor/rots_slu.02')
     sacco['vuoto1'] = PyTango.DeviceProxy('srv-tango-srf-01:20000/slu/vacuum/vgpi_slu_utdr.01')
     sacco['vuoto2'] = PyTango.DeviceProxy('srv-tango-srf-01:20000/slu/vacuum/vgpi_slu_uh.03')
     sacco['vuoto3'] = PyTango.DeviceProxy('srv-tango-srf-01:20000/slu/vacuum/vgpi_slu_ehf.01')
@@ -49,7 +56,6 @@ try:
     sacco['decima3'] = PyTango.DeviceProxy('srv-tango-srf-01:20000/f/timing/rttrigger_sl.03')
     sacco['decimacheck'] = PyTango.DeviceProxy('srv-tango-srf-01:20000/ec-sl-slpsr-01/rtevr/ff100000')
     sacco['frequenza'] = PyTango.DeviceProxy('srv-tango-srf-01:20000/f/timing/bunchnumber_f')
-    sacco['scope6'] = PyTango.DeviceProxy('srv-tango-srf-01:20000/sl/diagnostics/scope_sl.01')
     sacco['trls8_delay'] = PyTango.DeviceProxy('srv-tango-srf-01:20000/sl/motor/trls_sl.08')
     sacco['totem_delay'] = PyTango.DeviceProxy('srv-tango-srf-01:20000/slu/motor/trls_slu.05')
     sacco['triggerSL'] = PyTango.DeviceProxy('srv-tango-srf-01:20000/ec-sl-slpsr-01/evr/ff100000')
@@ -167,7 +173,7 @@ class MainWindow(QDialog):
         self.tab14 = QWidget()
         self.contienitab.addTab(self.tab1, "Monitor")
         self.contienitab.addTab(self.tab2, "Source")
-        self.contienitab.addTab(self.tab3, "Pointing FB")
+        self.contienitab.addTab(self.tab3, "Pointing and FB")
         self.contienitab.addTab(self.tab4, "Decimation")
         self.contienitab.addTab(self.tab6, "Vacuum")
         self.contienitab.addTab(self.tab7, "Temperature")
@@ -338,7 +344,28 @@ class MainWindow(QDialog):
         self.feedback3 = transport_fb_element("Totem up -> down", sacco['ccd3'].name(), sacco['piezo3'].name())
         self.feedback4 = transport_fb_element("Totem -> Beamline", 'boh', sacco['piezo4'].name())
         self.feedback4.tasto_ccd.clicked.connect(self.apriccd4)
-        self.feedback_motori_label = QLabel('some motors here')
+        self.feedback_motori_switch = rigabottoni()
+        self.feedback_motori_switch.selector_TMR.clicked.connect(lambda: self.switchtotemgo('TMR'))
+        self.feedback_motori_switch.selector_TMR.setToolTip('X: ' + str(sacco['costanti'].memo_totemswitch_tmrx) + ', Y: ' + str(sacco['costanti'].memo_totemswitch_tmry) + ', R: ' + str(sacco['costanti'].memo_totemswitch_tmrr))
+        self.feedback_motori_switch.new_TMR.clicked.connect(lambda: self.switchtotemsave('TMR'))
+        self.feedback_motori_switch.selector_TMX.clicked.connect(lambda: self.switchtotemgo('TMX'))
+        self.feedback_motori_switch.selector_TMX.setToolTip('X: ' + str(sacco['costanti'].memo_totemswitch_tmxx) + ', Y: ' + str(sacco['costanti'].memo_totemswitch_tmxy) + ', R: ' + str(sacco['costanti'].memo_totemswitch_tmxr))
+        self.feedback_motori_switch.new_TMX.clicked.connect(lambda: self.switchtotemsave('TMX'))
+        self.feedback_motori_switch.selector_DPI.clicked.connect(lambda: self.switchtotemgo('DPI'))
+        self.feedback_motori_switch.selector_DPI.setToolTip('X: ' + str(sacco['costanti'].memo_totemswitch_dpix) + ', Y: ' + str(sacco['costanti'].memo_totemswitch_dpiy) + ', R: ' + str(sacco['costanti'].memo_totemswitch_dpir))
+        self.feedback_motori_switch.new_DPI.clicked.connect(lambda: self.switchtotemsave('DPI'))
+        self.feedback_motori_switch.selector_LDM.clicked.connect(lambda: self.switchtotemgo('LDM'))
+        self.feedback_motori_switch.selector_LDM.setToolTip('X: ' + str(sacco['costanti'].memo_totemswitch_ldmx) + ', Y: ' + str(sacco['costanti'].memo_totemswitch_ldmy) + ', R: ' + str(sacco['costanti'].memo_totemswitch_ldmr))
+        self.feedback_motori_switch.new_LDM.clicked.connect(lambda: self.switchtotemsave('LDM'))
+        self.feedback_motori_switch.selector_MAG.clicked.connect(lambda: self.switchtotemgo('MAG'))
+        self.feedback_motori_switch.selector_MAG.setToolTip('X: ' + str(sacco['costanti'].memo_totemswitch_magx) + ', Y: ' + str(sacco['costanti'].memo_totemswitch_magy) + ', R: ' + str(sacco['costanti'].memo_totemswitch_magr))
+        self.feedback_motori_switch.new_MAG.clicked.connect(lambda: self.switchtotemsave('MAG'))
+        self.feedback_motori_1 = blocco_kom('SLR-T2 kom_slu.05', sacco['kom1'])
+        self.feedback_motori_2 = blocco_kom('SLR-T1 kom_slu.06', sacco['kom2'])
+        self.feedback_motori_3 = blocco_kom('UH-BB1 kom_slu.01', sacco['kom3'])
+        self.feedback_motori_4 = blocco_kom('UH-BB2 kom_slu.02', sacco['kom4'])
+        self.feedback_motori_5 = blocco_kom('TOTEM UP kom_slu.04', sacco['kom5'])
+        self.feedback_motori_6 = blocco_komrots('TOTEM Down kom_slu.03 rots_slu.02', sacco['kom6'], sacco['rots2'])
         riga = 0
         lot3.addWidget(self.feedbackstopothersauto, riga, 0, 1, 2)
         lot3.addWidget(self.feedbackstopothersccds, riga, 2, 1, 2)
@@ -347,7 +374,7 @@ class MainWindow(QDialog):
         lot3.addWidget(self.feedbackpannello, riga, 0)
         lot3.addWidget(self.feedbackstato, riga, 1)
         lot3.addWidget(self.feedbackon, riga, 2)
-        lot3.addWidget(self.feedbacksb, riga, 3)        
+        lot3.addWidget(self.feedbacksb, riga, 3)
         lot3.addWidget(self.feedbacksmarton, riga, 4)
         lot3.addWidget(self.feedbackconfig, riga, 5)
         riga += 1
@@ -366,11 +393,18 @@ class MainWindow(QDialog):
         riga += 1
         lot3.addWidget(QHLine(), riga, 0, 1, 6)
         riga += 1
-        lot3.addWidget(self.feedback_motori_label, riga, 0)
+        lot3.addWidget(self.feedback_motori_switch, riga, 0, 1, 6)
+        riga += 1
+        lot3.addWidget(self.feedback_motori_1, riga, 0)
+        lot3.addWidget(self.feedback_motori_2, riga, 1)
+        lot3.addWidget(self.feedback_motori_3, riga, 2)
+        lot3.addWidget(self.feedback_motori_4, riga, 3)
+        lot3.addWidget(self.feedback_motori_5, riga, 4)
+        lot3.addWidget(self.feedback_motori_6, riga, 5)
     #4 decimation
         self.decimators = QPushButton('Open decimation panel')
         self.decimators.clicked.connect(self.apridecimatori)
-        self.scope6 = QPushButton('Open scope-laser-06')
+        self.scope6 = QPushButton('Open scope with laser pulses')
         self.scope6.clicked.connect(self.apriscope6)
         self.deci1L = QLabel('Global SEED+SLU')
         self.deci1R = LineEditRO()
@@ -568,27 +602,7 @@ class MainWindow(QDialog):
         self.delaycalcCALC.clicked.connect(self.calcoladelayslu)
         self.delaycalcAPPLYUNDO = QPushButton('...')
         self.delaycalcAPPLYUNDO.clicked.connect(self.muovidelayslu)
-        self.scope6M1L = QLabel('Seed-Pil')
-        self.scope6M1R1 = LineEditRO()
-        self.scope6M1R2 = LineEditRO()
-        self.scope6M2L = QLabel('SLU-Pil')
-        self.scope6M2R1 = LineEditRO()
-        self.scope6M2R2 = LineEditRO()
-        self.scope6M3L = QLabel('SLU-Seed')
-        self.scope6M3R1 = LineEditRO()
-        self.scope6M3R2 = LineEditRO()
-        self.scope6M4L = QLabel('Pil-Trg')
-        self.scope6M4R1 = LineEditRO()
-        self.scope6M4R2 = LineEditRO()
-        self.scope6M5L = QLabel('Seed-Trg')
-        self.scope6M5R1 = LineEditRO()
-        self.scope6M5R2 = LineEditRO()
-        self.scope6M6L = QLabel('SLU-trg')
-        self.scope6M6R1 = LineEditRO()
-        self.scope6M6R2 = LineEditRO()
-        self.scope6reset = QPushButton('Clear swap')
-        self.scope6reset.clicked.connect(self.scope6CW)
-        self.scope6apri = QPushButton('open scope6')
+        self.scope6apri = QPushButton('Open scope with laser pulses')
         self.scope6apri.clicked.connect(self.apriscope6)
         self.memo_tmr_R = QPushButton('Recall TMR memory')
         self.memo_tmr_R.clicked.connect(self.memoriaTMRr)
@@ -613,34 +627,8 @@ class MainWindow(QDialog):
         self.salvatrigger = QPushButton('Save trigger')
         self.salvatrigger.clicked.connect(self.funzionesalvatrigger)
         riga = 0
-        lot5.addWidget(QLabel('Measurament from scope-laser-06'), riga, 2, 1, 2)
-        riga += 1
-        lot5.addWidget(self.scope6M1L, riga, 0)
-        lot5.addWidget(self.scope6M2L, riga, 1)
-        lot5.addWidget(self.scope6M3L, riga, 2)
-        lot5.addWidget(self.scope6M4L, riga, 3)
-        lot5.addWidget(self.scope6M5L, riga, 4)
-        lot5.addWidget(self.scope6M6L, riga, 5)
-        riga += 1
-        lot5.addWidget(self.scope6M1R1, riga, 0)
-        lot5.addWidget(self.scope6M2R1, riga, 1)
-        lot5.addWidget(self.scope6M3R1, riga, 2)
-        lot5.addWidget(self.scope6M4R1, riga, 3)
-        lot5.addWidget(self.scope6M5R1, riga, 4)
-        lot5.addWidget(self.scope6M6R1, riga, 5)
-        lot5.addWidget(self.scope6apri, riga, 6)
-        lot5.addWidget(self.scope6reset, riga, 7)
-        riga += 1
-        lot5.addWidget(self.scope6M1R2, riga, 0)
-        lot5.addWidget(self.scope6M2R2, riga, 1)
-        lot5.addWidget(self.scope6M3R2, riga, 2)
-        lot5.addWidget(self.scope6M4R2, riga, 3)
-        lot5.addWidget(self.scope6M5R2, riga, 4)
-        lot5.addWidget(self.scope6M6R2, riga, 5)
-        riga += 1
-        lot5.addWidget(QHLine(), riga, 0, 1, 8)
-        riga += 1
         lot5.addWidget(QLabel('SLU delay calculator'), riga, 2, 1, 2)
+        lot5.addWidget(self.scope6apri, riga, 5, 1, 3)
         riga += 1
         lot5.addWidget(self.vergogna_canvas, riga, 0, 4, 3)
         lot5.addWidget(self.delaycalcL, riga, 3)
@@ -1171,7 +1159,7 @@ class MainWindow(QDialog):
         self.update()
 
     def update(self):
-        t0 = time.time()
+#        t0 = time.time()
         self.somethingred = 0
         #calendario
         if self.autodeterminazionedeipupoli == 0:
@@ -1650,13 +1638,13 @@ class MainWindow(QDialog):
         if READ_pesofeedback < 4:
             self.monitor_pointing.setStyleSheet("background-color: rgb(255, 0, 0)")
             self.somethingred += 1
-            self.contienitab.setTabText(2, "!! Pointing FB !!")
+            self.contienitab.setTabText(2, "!! Pointing and FB !!")
         elif READ_pesofeedback < 5:
             self.monitor_pointing.setStyleSheet("background-color: rgb(255, 255, 0)")
-            self.contienitab.setTabText(2, "Pointing FB")
+            self.contienitab.setTabText(2, "Pointing and FB")
         elif READ_pesofeedback == 5:
             self.monitor_pointing.setStyleSheet("background-color: rgb(0, 255, 0)")
-            self.contienitab.setTabText(2, "Pointing FB")
+            self.contienitab.setTabText(2, "Pointing and FB")
         if READ_statofeedback == 'ON':
             self.feedbackstato.setStyleSheet("background-color: rgb(0, 255, 0)")
         elif READ_statofeedback == 'STANDBY' or READ_statofeedback == 'WARNING':
@@ -1834,6 +1822,132 @@ class MainWindow(QDialog):
         else:
             self.feedbackstopothersauto.setDisabled(1)
             self.feedbackstopothersauto.setStyleSheet("background-color: lightgray")
+        try:
+            tmp = sacco['kom1'].read_attributes(['Position_X', 'Position_Y', 'Status'])
+            tmpx = str(round(tmp[0].value, 4))
+            tmpy = str(round(tmp[1].value, 4))
+            tmps = str(tmp[2].value)
+        except:
+            tmpx = '#####'
+            tmpy = '#####'
+            tmps = '#####'
+        self.feedback_motori_1.lettura_x.setText(tmpx)
+        self.feedback_motori_1.lettura_y.setText(tmpy)
+        if 'X: MOVING' in tmps:
+            self.feedback_motori_1.lettura_x.setStyleSheet("background-color: rgb(150, 150, 255)")
+        else:
+            self.feedback_motori_1.lettura_x.setStyleSheet("background-color: rgb(200, 200, 200)")
+        if 'Y: MOVING' in tmps:
+            self.feedback_motori_1.lettura_y.setStyleSheet("background-color: rgb(150, 150, 255)")
+        else:
+            self.feedback_motori_1.lettura_y.setStyleSheet("background-color: rgb(200, 200, 200)")
+        try:
+            tmp = sacco['kom2'].read_attributes(['Position_X', 'Position_Y', 'Status'])
+            tmpx = str(round(tmp[0].value, 4))
+            tmpy = str(round(tmp[1].value, 4))
+            tmps = str(tmp[2].value)
+        except:
+            tmpx = '#####'
+            tmpy = '#####'
+            tmps = '#####'
+        self.feedback_motori_2.lettura_x.setText(tmpx)
+        self.feedback_motori_2.lettura_y.setText(tmpy)
+        if 'X: MOVING' in tmps:
+            self.feedback_motori_2.lettura_x.setStyleSheet("background-color: rgb(150, 150, 255)")
+        else:
+            self.feedback_motori_2.lettura_x.setStyleSheet("background-color: rgb(200, 200, 200)")
+        if 'Y: MOVING' in tmps:
+            self.feedback_motori_2.lettura_y.setStyleSheet("background-color: rgb(150, 150, 255)")
+        else:
+            self.feedback_motori_2.lettura_y.setStyleSheet("background-color: rgb(200, 200, 200)")
+        try:
+            tmp = sacco['kom3'].read_attributes(['Position_X', 'Position_Y', 'Status'])
+            tmpx = str(round(tmp[0].value, 4))
+            tmpy = str(round(tmp[1].value, 4))
+            tmps = str(tmp[2].value)
+        except:
+            tmpx = '#####'
+            tmpy = '#####'
+            tmps = '#####'
+        self.feedback_motori_3.lettura_x.setText(tmpx)
+        self.feedback_motori_3.lettura_y.setText(tmpy)
+        if 'X: MOVING' in tmps:
+            self.feedback_motori_3.lettura_x.setStyleSheet("background-color: rgb(150, 150, 255)")
+        else:
+            self.feedback_motori_3.lettura_x.setStyleSheet("background-color: rgb(200, 200, 200)")
+        if 'Y: MOVING' in tmps:
+            self.feedback_motori_3.lettura_y.setStyleSheet("background-color: rgb(150, 150, 255)")
+        else:
+            self.feedback_motori_3.lettura_y.setStyleSheet("background-color: rgb(200, 200, 200)")
+        try:
+            tmp = sacco['kom4'].read_attributes(['Position_X', 'Position_Y', 'Status'])
+            tmpx = str(round(tmp[0].value, 4))
+            tmpy = str(round(tmp[1].value, 4))
+            tmps = str(tmp[2].value)
+        except:
+            tmpx = '#####'
+            tmpy = '#####'
+            tmps = '#####'
+        self.feedback_motori_4.lettura_x.setText(tmpx)
+        self.feedback_motori_4.lettura_y.setText(tmpy)
+        if 'X: MOVING' in tmps:
+            self.feedback_motori_4.lettura_x.setStyleSheet("background-color: rgb(150, 150, 255)")
+        else:
+            self.feedback_motori_4.lettura_x.setStyleSheet("background-color: rgb(200, 200, 200)")
+        if 'Y: MOVING' in tmps:
+            self.feedback_motori_4.lettura_y.setStyleSheet("background-color: rgb(150, 150, 255)")
+        else:
+            self.feedback_motori_4.lettura_y.setStyleSheet("background-color: rgb(200, 200, 200)")
+        try:
+            tmp = sacco['kom5'].read_attributes(['Position_X', 'Position_Y', 'Status'])
+            tmpx = str(round(tmp[0].value, 4))
+            tmpy = str(round(tmp[1].value, 4))
+            tmps = str(tmp[2].value)
+        except:
+            tmpx = '#####'
+            tmpy = '#####'
+            tmps = '#####'
+        self.feedback_motori_5.lettura_x.setText(tmpx)
+        self.feedback_motori_5.lettura_y.setText(tmpy)
+        if 'X: MOVING' in tmps:
+            self.feedback_motori_5.lettura_x.setStyleSheet("background-color: rgb(150, 150, 255)")
+        else:
+            self.feedback_motori_5.lettura_x.setStyleSheet("background-color: rgb(200, 200, 200)")
+        if 'Y: MOVING' in tmps:
+            self.feedback_motori_5.lettura_y.setStyleSheet("background-color: rgb(150, 150, 255)")
+        else:
+            self.feedback_motori_5.lettura_y.setStyleSheet("background-color: rgb(200, 200, 200)")
+        try:
+            tmp = sacco['kom6'].read_attributes(['Position_X', 'Position_Y', 'Status'])
+            tmpx = str(round(tmp[0].value, 4))
+            tmpy = str(round(tmp[1].value, 4))
+            tmps = str(tmp[2].value)
+        except:
+            tmpx = '#####'
+            tmpy = '#####'
+            tmps = '#####'
+        self.feedback_motori_6.lettura_x.setText(tmpx)
+        self.feedback_motori_6.lettura_y.setText(tmpy)
+        if 'X: MOVING' in tmps:
+            self.feedback_motori_6.lettura_x.setStyleSheet("background-color: rgb(150, 150, 255)")
+        else:
+            self.feedback_motori_6.lettura_x.setStyleSheet("background-color: rgb(200, 200, 200)")
+        if 'Y: MOVING' in tmps:
+            self.feedback_motori_6.lettura_y.setStyleSheet("background-color: rgb(150, 150, 255)")
+        else:
+            self.feedback_motori_6.lettura_y.setStyleSheet("background-color: rgb(200, 200, 200)")
+        try:
+            tmp = sacco['rots2'].read_attributes(['UserPosition', 'Status'])
+            tmpr = str(round(tmp[0].value, 4))
+            tmps = str(tmp[1].value)
+        except:
+            tmpr = '#####'
+            tmps = '#####'
+        self.feedback_motori_6.lettura_r.setText(tmpr)
+        if 'MOVING' in tmps:
+            self.feedback_motori_6.lettura_r.setStyleSheet("background-color: rgb(150, 150, 255)")
+        else:
+            self.feedback_motori_6.lettura_r.setStyleSheet("background-color: rgb(200, 200, 200)")
 ####4 decimation
         try:
             tmp = sacco['decima1'].read_attributes(['DelayMode', 'StatusMode', 'Sequence', 'DelayOffset'])
@@ -1916,52 +2030,6 @@ class MainWindow(QDialog):
             self.monitor_decimation.setText('unknown')
             self.monitor_decimation.setStyleSheet("background-color: #ff0000")
 ####5 delay
-        if self.contienitab.currentIndex() == 7:
-            try:
-                tmp = sacco['scope6'].read_attributes(['P1AVG', 'P1Sigma', 'P2AVG', 'P2Sigma', 'P3AVG', 'P3Sigma', 'P4AVG', 'P4Sigma', 'P5AVG', 'P5Sigma', 'P6AVG', 'P6Sigma'])
-                self.scope6M1R1.setText('avg ' + str(round(tmp[0].value * 10**9, 3)) + ' ns')
-                self.scope6M2R1.setText('avg ' + str(round(tmp[2].value * 10**9, 3)) + ' ns')
-                self.scope6M3R1.setText('avg ' + str(round(tmp[4].value * 10**9, 3)) + ' ns')
-                self.scope6M4R1.setText('avg ' + str(round(tmp[6].value * 10**9, 3)) + ' ns')
-                self.scope6M5R1.setText('avg ' + str(round(tmp[8].value * 10**9, 3)) + ' ns')
-                self.scope6M6R1.setText('avg ' + str(round(tmp[10].value * 10**9, 3)) + ' ns')
-                self.scope6M1R2.setText('std ' + str(round(tmp[1].value * 10**9, 1)) + ' ns')
-                self.scope6M2R2.setText('std ' + str(round(tmp[3].value * 10**9, 1)) + ' ns')
-                self.scope6M3R2.setText('std ' + str(round(tmp[5].value * 10**9, 1)) + ' ns')
-                self.scope6M4R2.setText('std ' + str(round(tmp[7].value * 10**9, 1)) + ' ns')
-                self.scope6M5R2.setText('std ' + str(round(tmp[9].value * 10**9, 1)) + ' ns')
-                self.scope6M6R2.setText('std ' + str(round(tmp[11].value * 10**9, 1)) + ' ns')
-                if tmp[11].value * 10**9 > 1.5:
-                    self.scope6M6R2.setStyleSheet("background-color: #ff0000")
-                    self.somethingred += 1
-                else:
-                    self.scope6M6R2.setStyleSheet("background-color: rgb(200, 200, 200)")
-            except:
-                self.scope6M1R1.setText('avg ... ns')
-                self.scope6M2R1.setText('avg ... ns')
-                self.scope6M3R1.setText('avg ... ns')
-                self.scope6M4R1.setText('avg ... ns')
-                self.scope6M5R1.setText('avg ... ns')
-                self.scope6M6R1.setText('avg ... ns')
-                self.scope6M1R2.setText('std ... ns')
-                self.scope6M2R2.setText('std ... ns')
-                self.scope6M3R2.setText('std ... ns')
-                self.scope6M4R2.setText('std ... ns')
-                self.scope6M5R2.setText('std ... ns')
-                self.scope6M6R2.setText('std ... ns')
-        else:
-            self.scope6M1R1.setText('avg ' + str(round(-1, 3)))
-            self.scope6M2R1.setText('avg ' + str(round(-1, 3)))
-            self.scope6M3R1.setText('avg ' + str(round(-1, 3)))
-            self.scope6M4R1.setText('avg ' + str(round(-1, 3)))
-            self.scope6M5R1.setText('avg ' + str(round(-1, 3)))
-            self.scope6M6R1.setText('avg ' + str(round(-1, 3)))
-            self.scope6M1R2.setText('std ' + str(round(-1, 1)))
-            self.scope6M2R2.setText('std ' + str(round(-1, 1)))
-            self.scope6M3R2.setText('std ' + str(round(-1, 1)))
-            self.scope6M4R2.setText('std ' + str(round(-1, 1)))
-            self.scope6M5R2.setText('std ' + str(round(-1, 1)))
-            self.scope6M6R2.setText('std ' + str(round(-1, 1)))
         if self.linea == 'TIMER':
             self.memo_tmr_W.setEnabled(1)
             self.memo_tmx_W.setDisabled(1)
@@ -3020,12 +3088,60 @@ class MainWindow(QDialog):
             print('sequencer on')
         print('fine')
 
+    def switchtotemgo(self, linea):
+        if linea == 'TMR':
+            sacco['kom6'].write_attribute('Position_X', sacco['costanti'].memo_totemswitch_tmrx)
+            sacco['kom6'].write_attribute('Position_Y', sacco['costanti'].memo_totemswitch_tmry)
+            sacco['rots2'].write_attribute('UserPosition', sacco['costanti'].memo_totemswitch_tmrr)
+        elif linea == 'TMX':
+            sacco['kom6'].write_attribute('Position_X', sacco['costanti'].memo_totemswitch_tmxx)
+            sacco['kom6'].write_attribute('Position_Y', sacco['costanti'].memo_totemswitch_tmxy)
+            sacco['rots2'].write_attribute('UserPosition', sacco['costanti'].memo_totemswitch_tmxr)
+        elif linea == 'DPI':
+            sacco['kom6'].write_attribute('Position_X', sacco['costanti'].memo_totemswitch_dpix)
+            sacco['kom6'].write_attribute('Position_Y', sacco['costanti'].memo_totemswitch_dpiy)
+            sacco['rots2'].write_attribute('UserPosition', sacco['costanti'].memo_totemswitch_dpir)
+        elif linea == 'LDM':
+            sacco['kom6'].write_attribute('Position_X', sacco['costanti'].memo_totemswitch_ldmx)
+            sacco['kom6'].write_attribute('Position_Y', sacco['costanti'].memo_totemswitch_ldmy)
+            sacco['rots2'].write_attribute('UserPosition', sacco['costanti'].memo_totemswitch_ldmr)
+        elif linea == 'MAG':
+            sacco['kom6'].write_attribute('Position_X', sacco['costanti'].memo_totemswitch_magx)
+            sacco['kom6'].write_attribute('Position_Y', sacco['costanti'].memo_totemswitch_magy)
+            sacco['rots2'].write_attribute('UserPosition', sacco['costanti'].memo_totemswitch_magr)
+
+    def switchtotemsave(self, linea):
+        if linea == 'TMR':
+            sacco['costanti'].write_attribute('memo_totemswitch_tmrx', sacco['kom6'].Position_X)
+            sacco['costanti'].write_attribute('memo_totemswitch_tmry', sacco['kom6'].Position_Y)
+            sacco['costanti'].write_attribute('memo_totemswitch_tmrr', sacco['rots2'].UserPosition)
+            self.feedback_motori_switch.selector_TMR.setToolTip('X: ' + str(sacco['costanti'].memo_totemswitch_tmrx) + ', Y: ' + str(sacco['costanti'].memo_totemswitch_tmry) + ', R: ' + str(sacco['costanti'].memo_totemswitch_tmrr))
+        elif linea == 'TMX':
+            sacco['costanti'].write_attribute('memo_totemswitch_tmxx', sacco['kom6'].Position_X)
+            sacco['costanti'].write_attribute('memo_totemswitch_tmxy', sacco['kom6'].Position_Y)
+            sacco['costanti'].write_attribute('memo_totemswitch_tmxr', sacco['rots2'].UserPosition)
+            self.feedback_motori_switch.selector_TMX.setToolTip('X: ' + str(sacco['costanti'].memo_totemswitch_tmxx) + ', Y: ' + str(sacco['costanti'].memo_totemswitch_tmxy) + ', R: ' + str(sacco['costanti'].memo_totemswitch_tmxr))
+        elif linea == 'DPI':
+            sacco['costanti'].write_attribute('memo_totemswitch_dpix', sacco['kom6'].Position_X)
+            sacco['costanti'].write_attribute('memo_totemswitch_dpiy', sacco['kom6'].Position_Y)
+            sacco['costanti'].write_attribute('memo_totemswitch_dpir', sacco['rots2'].UserPosition)
+            self.feedback_motori_switch.selector_DPI.setToolTip('X: ' + str(sacco['costanti'].memo_totemswitch_dpix) + ', Y: ' + str(sacco['costanti'].memo_totemswitch_dpiy) + ', R: ' + str(sacco['costanti'].memo_totemswitch_dpir))
+        elif linea == 'LDM':
+            sacco['costanti'].write_attribute('memo_totemswitch_ldmx', sacco['kom6'].Position_X)
+            sacco['costanti'].write_attribute('memo_totemswitch_ldmy', sacco['kom6'].Position_Y)
+            sacco['costanti'].write_attribute('memo_totemswitch_ldmr', sacco['rots2'].UserPosition)
+            self.feedback_motori_switch.selector_LDM.setToolTip('X: ' + str(sacco['costanti'].memo_totemswitch_ldmx) + ', Y: ' + str(sacco['costanti'].memo_totemswitch_ldmy) + ', R: ' + str(sacco['costanti'].memo_totemswitch_ldmr))
+        elif linea == 'MAG':
+            sacco['costanti'].write_attribute('memo_totemswitch_magx', sacco['kom6'].Position_X)
+            sacco['costanti'].write_attribute('memo_totemswitch_magy', sacco['kom6'].Position_Y)
+            sacco['costanti'].write_attribute('memo_totemswitch_magr', sacco['rots2'].UserPosition)
+            self.feedback_motori_switch.selector_MAG.setToolTip('X: ' + str(sacco['costanti'].memo_totemswitch_magx) + ', Y: ' + str(sacco['costanti'].memo_totemswitch_magy) + ', R: ' + str(sacco['costanti'].memo_totemswitch_magr))
 
     def apridecimatori(self):
         os.system("/runtime/bin/sl-decimators-gui &")
 
     def apriscope6(self):
-        os.system('/usr/bin/vncviewer scope-laser-06 &')
+        os.system('/usr/bin/vncviewer scope-laser-03 &')
 
     def accendidecimatore(self, chi, metodo):
         if metodo == 'random':
@@ -3268,9 +3384,6 @@ class MainWindow(QDialog):
         else:
             print('no')
         
-    def scope6CW(self):
-        sacco['scope6'].command_inout('ClearSweeps')
-        
     def memoriaTMRr(self):
         sacco['trls8_delay'].write_attribute('Position', sacco['costanti'].memo_delay_tmr1)
         sacco['triggerSL'].write_attribute('Chan2Delay', sacco['costanti'].memo_delay_tmr2)
@@ -3844,6 +3957,201 @@ class transport_fb_element(QFrame):
     def apripannellotiptilt(self, ttnome):
         eval("os.system('/runtime/bin/slutiptilt " + ttnome + " &')")
 
+class blocco_kom(QFrame):
+    def __init__(self, stringa, devpoxy):
+        super(blocco_kom, self).__init__()
+        self.device = devpoxy
+        self.nomekom = QLabel(stringa)
+        self.etichetta_x = QLabel('X')
+        self.etichetta_x.setMaximumWidth(15)
+        self.lettura_x = LineEditRO()
+        self.lettura_x.setMaximumWidth(80)
+        self.muovim_x = QPushButton('<')
+        self.muovim_x.setMaximumWidth(30)
+        self.muovim_x.clicked.connect(self.spostaXm)
+        self.step_x = QLineEdit('0.01')
+        self.step_x.setMaximumWidth(50)
+        self.muovip_x = QPushButton('>')
+        self.muovip_x.setMaximumWidth(30)
+        self.muovip_x.clicked.connect(self.spostaXp)
+        self.etichetta_y = QLabel('Y')
+        self.etichetta_y.setMaximumWidth(15)
+        self.lettura_y = LineEditRO()
+        self.lettura_y.setMaximumWidth(80)
+        self.muovim_y = QPushButton('<')
+        self.muovim_y.setMaximumWidth(30)
+        self.muovim_y.clicked.connect(self.spostaYm)
+        self.step_y = QLineEdit('0.01')
+        self.step_y.setMaximumWidth(50)
+        self.muovip_y = QPushButton('>')
+        self.muovip_y.setMaximumWidth(30)
+        self.muovip_y.clicked.connect(self.spostaYp)
+        lo_rigax = QHBoxLayout()
+        lo_rigax.addWidget(self.etichetta_x)
+        lo_rigax.addWidget(self.lettura_x)
+        lo_rigax.addWidget(self.muovim_x)
+        lo_rigax.addWidget(self.step_x)
+        lo_rigax.addWidget(self.muovip_x)
+        lo_rigay = QHBoxLayout()
+        lo_rigay.addWidget(self.etichetta_y)
+        lo_rigay.addWidget(self.lettura_y)
+        lo_rigay.addWidget(self.muovim_y)
+        lo_rigay.addWidget(self.step_y)
+        lo_rigay.addWidget(self.muovip_y)
+        ilsuolayout = QVBoxLayout()
+        ilsuolayout.addWidget(self.nomekom)
+        ilsuolayout.addLayout(lo_rigax)
+        ilsuolayout.addLayout(lo_rigay)
+        self.setLayout(ilsuolayout)
+
+    def spostaXp(self):
+        goal = float(self.step_x.text())
+        self.device.command_inout('Forward_X', goal)
+
+    def spostaYp(self):
+        goal = float(self.step_y.text())
+        self.device.command_inout('Forward_Y', goal)
+
+    def spostaXm(self):
+        goal = float(self.step_x.text())
+        self.device.command_inout('Backward_X', goal)
+
+    def spostaYm(self):
+        goal = float(self.step_y.text())
+        self.device.command_inout('Backward_Y', goal)
+
+
+class blocco_komrots(QFrame):
+    def __init__(self, stringa, devproxykom, devpoxyrots):
+        super(blocco_komrots, self).__init__()
+        self.devicerots = devpoxyrots
+        self.devicekom = devproxykom
+        self.nome = QLabel(stringa)
+        self.etichetta_x = QLabel('X')
+        self.etichetta_x.setMaximumWidth(15)
+        self.lettura_x = LineEditRO()
+        self.lettura_x.setMaximumWidth(80)
+        self.muovim_x = QPushButton('<')
+        self.muovim_x.setMaximumWidth(30)
+        self.muovim_x.clicked.connect(self.spostaXm)
+        self.step_x = QLineEdit('0.01')
+        self.step_x.setMaximumWidth(50)
+        self.muovip_x = QPushButton('>')
+        self.muovip_x.setMaximumWidth(30)
+        self.muovip_x.clicked.connect(self.spostaXp)
+        self.etichetta_y = QLabel('Y')
+        self.etichetta_y.setMaximumWidth(15)
+        self.lettura_y = LineEditRO()
+        self.lettura_y.setMaximumWidth(80)
+        self.muovim_y = QPushButton('<')
+        self.muovim_y.setMaximumWidth(30)
+        self.muovim_y.clicked.connect(self.spostaYm)
+        self.step_y = QLineEdit('0.01')
+        self.step_y.setMaximumWidth(50)
+        self.muovip_y = QPushButton('>')
+        self.muovip_y.setMaximumWidth(30)
+        self.muovip_y.clicked.connect(self.spostaYp)
+        self.etichetta_r = QLabel('R')
+        self.etichetta_r.setMaximumWidth(15)
+        self.lettura_r = LineEditRO()
+        self.lettura_r.setMaximumWidth(80)
+        self.muovim_r = QPushButton('<')
+        self.muovim_r.setMaximumWidth(30)
+        self.muovim_r.clicked.connect(self.spostaRm)
+        self.step_r = QLineEdit('0.01')
+        self.step_r.setMaximumWidth(50)
+        self.muovip_r = QPushButton('>')
+        self.muovip_r.setMaximumWidth(30)
+        self.muovip_r.clicked.connect(self.spostaRp)
+        lo_rigax = QHBoxLayout()
+        lo_rigax.addWidget(self.etichetta_x)
+        lo_rigax.addWidget(self.lettura_x)
+        lo_rigax.addWidget(self.muovim_x)
+        lo_rigax.addWidget(self.step_x)
+        lo_rigax.addWidget(self.muovip_x)
+        lo_rigay = QHBoxLayout()
+        lo_rigay.addWidget(self.etichetta_y)
+        lo_rigay.addWidget(self.lettura_y)
+        lo_rigay.addWidget(self.muovim_y)
+        lo_rigay.addWidget(self.step_y)
+        lo_rigay.addWidget(self.muovip_y)
+        lo_rigar = QHBoxLayout()
+        lo_rigar.addWidget(self.etichetta_r)
+        lo_rigar.addWidget(self.lettura_r)
+        lo_rigar.addWidget(self.muovim_r)
+        lo_rigar.addWidget(self.step_r)
+        lo_rigar.addWidget(self.muovip_r)
+        ilsuolayout = QVBoxLayout()
+        ilsuolayout.addWidget(self.nome)
+        ilsuolayout.addLayout(lo_rigax)
+        ilsuolayout.addLayout(lo_rigay)
+        ilsuolayout.addLayout(lo_rigar)
+        self.setLayout(ilsuolayout)
+
+    def spostaXp(self):
+        goal = float(self.step_x.text())
+        self.devicekom.command_inout('Forward_X', goal)
+
+    def spostaYp(self):
+        goal = float(self.step_y.text())
+        self.devicekom.command_inout('Forward_Y', goal)
+
+    def spostaXm(self):
+        goal = float(self.step_x.text())
+        self.devicekom.command_inout('Backward_X', goal)
+
+    def spostaYm(self):
+        goal = float(self.step_y.text())
+        self.devicekom.command_inout('Backward_Y', goal)
+
+    def spostaRp(self):
+        goal = float(self.step_r.text())
+        self.devicerots.command_inout('Forward', goal)
+
+    def spostaRm(self):
+        goal = float(self.step_r.text())
+        self.devicerots.command_inout('Backward', goal)
+
+
+class rigabottoni(QFrame):
+    def __init__(self):
+        super(rigabottoni, self).__init__()
+        self.testo = QLabel('TOTEM down BL switch:')
+        self.testo.setMaximumWidth(160)
+        self.selector_TMR = QPushButton('Set TMR')
+        self.selector_TMR.setMaximumWidth(80)
+        self.new_TMR = QPushButton('Save TMR')
+        self.new_TMR.setMaximumWidth(80)
+        self.selector_TMX = QPushButton('Set TMX')
+        self.selector_TMX.setMaximumWidth(80)
+        self.new_TMX = QPushButton('Save TMX')
+        self.new_TMX.setMaximumWidth(80)
+        self.selector_DPI = QPushButton('Set DPI')
+        self.selector_DPI.setMaximumWidth(80)
+        self.new_DPI = QPushButton('Save DPI')
+        self.new_DPI.setMaximumWidth(80)
+        self.selector_LDM = QPushButton('Set LDM')
+        self.selector_LDM.setMaximumWidth(80)
+        self.new_LDM = QPushButton('Save LDM')
+        self.new_LDM.setMaximumWidth(80)
+        self.selector_MAG = QPushButton('Set MAG')
+        self.selector_MAG.setMaximumWidth(80)
+        self.new_MAG = QPushButton('Save MAG')
+        self.new_MAG.setMaximumWidth(80)
+        ilsuolayout = QHBoxLayout()
+        ilsuolayout.addWidget(self.testo)
+        ilsuolayout.addWidget(self.selector_TMR)
+        ilsuolayout.addWidget(self.new_TMR)
+        ilsuolayout.addWidget(self.selector_TMX)
+        ilsuolayout.addWidget(self.new_TMX)
+        ilsuolayout.addWidget(self.selector_DPI)
+        ilsuolayout.addWidget(self.new_DPI)
+        ilsuolayout.addWidget(self.selector_LDM)
+        ilsuolayout.addWidget(self.new_LDM)
+        ilsuolayout.addWidget(self.selector_MAG)
+        ilsuolayout.addWidget(self.new_MAG)
+        self.setLayout(ilsuolayout)
+
 
 class QHLine(QFrame):
     def __init__(self):
-- 
GitLab