From b04b366bce84201567f0a4e41b834d5f90eeccb4 Mon Sep 17 00:00:00 2001 From: "paolo.cinquegrana@elettra.eu" <paolo.cinquegrana@elettra.eu> Date: Mon, 21 Feb 2022 18:24:59 +0100 Subject: [PATCH] aggiunta verifica stado device all'avvio del pannello. --- src/{pil-trigger.py => PilTrigger.py} | 221 ++++++++------------------ 1 file changed, 68 insertions(+), 153 deletions(-) rename src/{pil-trigger.py => PilTrigger.py} (77%) diff --git a/src/pil-trigger.py b/src/PilTrigger.py similarity index 77% rename from src/pil-trigger.py rename to src/PilTrigger.py index 39c4140..d380345 100644 --- a/src/pil-trigger.py +++ b/src/PilTrigger.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 # restore PIL trigger values and reset Legend BWD interlock import PyTango @@ -9,10 +9,6 @@ from PyQt4.QtCore import * from PyQt4.QtGui import * import sys -devicetrgEVR = PyTango.DeviceProxy('srv-tango-srf-01:20000/ec-pil-plpsr-01/evr/ff100000') -devicetrgDGQ = PyTango.DeviceProxy('srv-tango-srf-01:20000/pil/delay/dgq_pil.01') -devicetrgSDG = PyTango.DeviceProxy('srv-tango-srf-01:20000/pil/delay/sdg_pil.01') - nomecartella = '/home/lfo/data/salvatutto/PIL_trigger/' os.chdir(nomecartella) defaultreffile = 'auto' @@ -21,6 +17,31 @@ defaultreffile = 'auto' class MainWindow(QDialog): def __init__(self, parent = None): super(MainWindow, self).__init__(parent) + # creo device proxy + try: + global devicetrgEVR + devicetrgEVR = PyTango.DeviceProxy('srv-tango-srf-01:20000/ec-pil-plpsr-01/evr/ff100000') + except: + msgBox = QMessageBox() + msgBox.setIcon(QMessageBox.Critical) + msgBox.setText("ec-pil-plpsr-01/evr/ff100000 is not working, fix the problem and restat the panel") + msgBox.exec_() + try: + global devicetrgDGQ + devicetrgDGQ = PyTango.DeviceProxy('srv-tango-srf-01:20000/pil/delay/dgq_pil.01') + except: + msgBox = QMessageBox() + msgBox.setIcon(QMessageBox.Critical) + msgBox.setText("pil/delay/dgq_pil.01 is not working, fix the problem and restat the panel") + msgBox.exec_() + try: + global devicetrgSDG + devicetrgSDG = PyTango.DeviceProxy('srv-tango-srf-01:20000/pil/delay/sdg_pil.01') + except: + msgBox = QMessageBox() + msgBox.setIcon(QMessageBox.Critical) + msgBox.setText("pil/delay/sdg_pil.01 is not working, fix the problem and restat the panel") + msgBox.exec_() #canali self.scialuppa = [] self.riga0 = canaleEVR('PIL MASTER', devicetrgEVR, 0, 'Shift all the signals') @@ -83,7 +104,7 @@ class MainWindow(QDialog): self.riga19 = canaleSDG('PC2', devicetrgSDG, 2, 'PC2') self.riga19.sorgente = 'SDG 2' self.scialuppa.append(self.riga19) - self.titoli = titolicanali(self.riga0.name.geometry(), self.riga0.devicelist.geometry(), self.riga0.delay_read.geometry(), self.riga0.delay_reference.geometry(), self.riga0.delay_write.geometry(), self.riga0.delay_alarm_low.geometry(), self.riga0.delay_alarm_hi.geometry(), self.riga0.width_read.geometry(), self.riga0.width_write.geometry(), self.riga0.enable_read.geometry(), self.riga0.enable_write.geometry(), self.riga0.applica.geometry()) + self.titoli = titolicanali() self.titoli.sorgente = 'titoli 0' self.scialuppa.append(self.titoli) self.scrollArea = QScrollArea(self) @@ -114,12 +135,6 @@ class MainWindow(QDialog): lo_canali.addWidget(self.riga18) lo_canali.addWidget(self.riga19) lo_canali.setSpacing(0) - for i in range(len(self.scialuppa)): - self.scialuppa[i].delay_alarm_low.hide() - self.scialuppa[i].delay_alarm_hi.hide() - self.scialuppa[i].width_read.hide() - self.scialuppa[i].width_write.hide() - self.scialuppa[i].enable_write.hide() #altro self.tempodiriferimento = 0 self.ladatadelfile = QLineEdit('') @@ -150,8 +165,6 @@ class MainWindow(QDialog): self.applicatutti.clicked.connect(self.funzioneapplicatutti) self.fixalarmthreshold = QPushButton('fix alarms thresholds') self.fixalarmthreshold.clicked.connect(self.manosanta) - self.showmore = QCheckBox('show more') - self.showmore.clicked.connect(self.funzioneshowmore) lo = QGridLayout() lo.addWidget(self.EVR_State, 1, 0, 1, 1) lo.addWidget(self.DGQ_State, 1, 1, 1, 1) @@ -167,10 +180,8 @@ class MainWindow(QDialog): lo.addWidget(self.copyreferencetowrite, 20, 4, 1, 2) lo.addWidget(self.applicatutti, 20, 6, 1, 2) lo.addWidget(self.fixalarmthreshold, 20, 8, 1, 2) -# lo.addWidget(self.showmore, 21, 4, 1, 2) self.setLayout(lo) self.setWindowTitle("PIL trigger") - self.show() self.setStyleSheet("QDialog {background-color: rgb(255, 255, 200)}") #creo il timer self.timer = QBasicTimer() @@ -209,7 +220,7 @@ class MainWindow(QDialog): self.scialuppa[i].delay_reference.setText(str(dizionarioriferimenti[self.scialuppa[i].sorgente])) else: self.scialuppa[i].delay_reference.setText(dizionarioriferimenti[self.scialuppa[i].sorgente]) - print('Ref.file letto ' + str(time.time()-tempista1)) +# print('Ref.file letto ' + str(time.time()-tempista1)) else: ultimo = defaultreffile self.tempodiriferimento = time.localtime(int(os.path.getmtime(ultimo))) @@ -230,7 +241,7 @@ class MainWindow(QDialog): self.scialuppa[i].delay_reference.setText(str(dizionarioriferimenti[self.scialuppa[i].sorgente])) else: self.scialuppa[i].delay_reference.setText(dizionarioriferimenti[self.scialuppa[i].sorgente]) - print('Ref.file letto ' + str(time.time()-tempista1)) +# print('Ref.file letto ' + str(time.time()-tempista1)) #lettura stati device tempista2 = time.time() lettura_stato_evr = str(devicetrgEVR.State()) @@ -254,51 +265,46 @@ class MainWindow(QDialog): else: self.SDG_State.setText('SDG ' + str(lettura_stato_sdg)) self.SDG_State.setStyleSheet("background-color: rgb(255, 0, 0)") - print('stati letti ' + str(time.time()-tempista2)) +# print('stati letti ' + str(time.time()-tempista2)) #leggo tutto EVR tempista3 = time.time() EVR_ritardi = devicetrgEVR.ChanDelay time.sleep(0.05) - #EVR_durate = devicetrgEVR.ChanWidth - #time.sleep(0.05) EVR_abilitazioni = devicetrgEVR.ChanEnable for i in range(len(self.scialuppa)): [strumento, canale] = self.scialuppa[i].sorgente.split(' ') if strumento == 'EVR': self.scialuppa[i].delay_read.setText(str(EVR_ritardi[int(canale)])) - #self.scialuppa[i].width_read.setText(str(EVR_durate[int(canale)])) - self.scialuppa[i].enable_write.setChecked(EVR_abilitazioni[int(canale)]) if EVR_abilitazioni[int(canale)]: self.scialuppa[i].enable_read.setStyleSheet("background-color: rgb(0, 255, 0)") else: self.scialuppa[i].enable_read.setStyleSheet("background-color: rgb(255, 0, 0)") - print('EVR letto ' + str(time.time()-tempista3)) +# print('EVR letto ' + str(time.time()-tempista3)) #leggo canali DGQ tempista4 = time.time() - leggipropriotutto = self.showmore.isChecked() - self.riga10.funzioneaggiornavalori(leggipropriotutto) + self.riga10.funzioneaggiornavalori() time.sleep(0.05) - self.riga11.funzioneaggiornavalori(leggipropriotutto) + self.riga11.funzioneaggiornavalori() time.sleep(0.05) - self.riga12.funzioneaggiornavalori(leggipropriotutto) + self.riga12.funzioneaggiornavalori() time.sleep(0.05) - self.riga13.funzioneaggiornavalori(leggipropriotutto) + self.riga13.funzioneaggiornavalori() time.sleep(0.05) - self.riga14.funzioneaggiornavalori(leggipropriotutto) + self.riga14.funzioneaggiornavalori() time.sleep(0.05) - self.riga15.funzioneaggiornavalori(leggipropriotutto) + self.riga15.funzioneaggiornavalori() time.sleep(0.05) - self.riga16.funzioneaggiornavalori(leggipropriotutto) + self.riga16.funzioneaggiornavalori() time.sleep(0.05) - self.riga17.funzioneaggiornavalori(leggipropriotutto) + self.riga17.funzioneaggiornavalori() time.sleep(0.05) - print('DGQ letto ' + str(time.time()-tempista4)) +# print('DGQ letto ' + str(time.time()-tempista4)) #leggo canali SDG tempista5 = time.time() self.riga18.funzioneaggiornavalori() time.sleep(0.05) self.riga19.funzioneaggiornavalori() - print('SDG letto ' + str(time.time()-tempista5)) +# print('SDG letto ' + str(time.time()-tempista5)) # comparazione read-reference tempista6 = time.time() for i in range(len(self.scialuppa)): @@ -307,9 +313,9 @@ class MainWindow(QDialog): self.scialuppa[i].delay_read.setStyleSheet("background-color: rgb(255, 150, 150)") else: self.scialuppa[i].delay_read.setStyleSheet("background-color: rgb(220, 220, 220)") - print('confronto fatto ' + str(time.time()-tempista6)) +# print('confronto fatto ' + str(time.time()-tempista6)) tempista7 = time.time() - print('Done ' + str(tempista7-tempista1)) +# print('Done ' + str(tempista7-tempista1)) def funzionecopyreadtowrite(self): for i in range(len(self.scialuppa)): @@ -453,17 +459,8 @@ class canaleEVR(QWidget): self.delay_write.setDecimals(3) self.delay_write.setMaximum(10000000.000) self.delay_write.setSingleStep(12.675) - self.delay_alarm_low = QLineEdit('') - self.delay_alarm_low.setStyleSheet("background-color: rgb(220, 220, 220)") - self.delay_alarm_hi = QLineEdit('') - self.delay_alarm_hi.setStyleSheet("background-color: rgb(220, 220, 220)") - self.width_read = QLineEdit('') - self.width_read.setReadOnly(1) - self.width_read.setStyleSheet("background-color: rgb(220, 220, 220)") - self.width_write = QLineEdit('') self.enable_read = QLineEdit('') self.enable_read.setMaximumWidth(20) - self.enable_write = QCheckBox() self.applica = QPushButton('Apply') self.applica.clicked.connect(lambda: self.funzioneapplica()) self.dev = dev @@ -474,14 +471,10 @@ class canaleEVR(QWidget): layoutriga.addWidget(self.delay_reference) layoutriga.addWidget(self.delay_read) layoutriga.addWidget(self.delay_write) - layoutriga.addWidget(self.delay_alarm_low) - layoutriga.addWidget(self.delay_alarm_hi) - layoutriga.addWidget(self.width_read) - layoutriga.addWidget(self.width_write) layoutriga.addWidget(self.enable_read) - layoutriga.addWidget(self.enable_write) layoutriga.addWidget(self.applica) self.setLayout(layoutriga) + def funzionemostradevice(self, info): msg = QMessageBox() msg.setIcon(QMessageBox.Information) @@ -490,6 +483,7 @@ class canaleEVR(QWidget): msg.setText('Event receiver channel ' + str(titolone[1])) msg.setWindowTitle('Info') msg.exec_() + def funzioneapplica(self): print(self.delay_write.value()) eval('self.dev.write_attribute("Chan' + str(self.ch) + 'Delay", float(self.delay_write.value()))') @@ -513,17 +507,8 @@ class canaleDGQ(QWidget): self.delay_write.setDecimals(3) self.delay_write.setMaximum(20000000.000) self.delay_write.setSingleStep(0.25) - self.delay_alarm_low = QLineEdit('') - self.delay_alarm_low.setStyleSheet("background-color: rgb(220, 220, 220)") - self.delay_alarm_hi = QLineEdit('') - self.delay_alarm_hi.setStyleSheet("background-color: rgb(220, 220, 220)") - self.width_read = QLineEdit('') - self.width_read.setReadOnly(1) - self.width_read.setStyleSheet("background-color: rgb(220, 220, 220)") - self.width_write = QLineEdit('') self.enable_read = QLineEdit('') self.enable_read.setMaximumWidth(20) - self.enable_write = QCheckBox() self.applica = QPushButton('Apply') self.applica.clicked.connect(lambda: self.funzioneapplica()) self.dev = dev @@ -534,14 +519,10 @@ class canaleDGQ(QWidget): layoutriga.addWidget(self.delay_reference) layoutriga.addWidget(self.delay_read) layoutriga.addWidget(self.delay_write) - layoutriga.addWidget(self.delay_alarm_low) - layoutriga.addWidget(self.delay_alarm_hi) - layoutriga.addWidget(self.width_read) - layoutriga.addWidget(self.width_write) layoutriga.addWidget(self.enable_read) - layoutriga.addWidget(self.enable_write) layoutriga.addWidget(self.applica) self.setLayout(layoutriga) + def funzionemostradevice(self, info): msg = QMessageBox() msg.setIcon(QMessageBox.Information) @@ -550,30 +531,25 @@ class canaleDGQ(QWidget): msg.setText('Quantum channel ' + str(titolone[1])) msg.setWindowTitle('Info') msg.exec_() + def funzioneapplica(self): valore = self.delay_write.value() print(valore) eval('self.dev.write_attribute("chan' + str(self.ch) + 'delay", ' + str(valore) + ')') - def funzioneaggiornavalori(self, tutto): + + def funzioneaggiornavalori(self): try: ritardo = eval('self.dev.chan' + str(self.ch) + 'delay') abilitazione = eval('self.dev.chan' + str(self.ch) + 'enable') - if tutto: - durata = eval('self.dev.chan' + str(self.ch) + 'width') except: ritardo = -99999 abilitazione = False - if tutto: - durata = -99999 if abilitazione: self.enable_read.setStyleSheet("background-color: rgb(0, 255, 0)") - self.enable_write.setChecked(abilitazione) else: self.enable_read.setStyleSheet("background-color: rgb(255, 0, 0)") - self.enable_write.setChecked(abilitazione) self.delay_read.setText(str(ritardo)) - if tutto: - self.width_read.setText(str(durata)) + class canaleSDG(QWidget): def __init__(self, nome, dev, ch, info, parent = None): @@ -594,15 +570,8 @@ class canaleSDG(QWidget): self.delay_write.setDecimals(3) self.delay_write.setMaximum(20000000.000) self.delay_write.setSingleStep(0.25) - self.delay_alarm_low = QLineEdit('') - self.delay_alarm_low.setStyleSheet("background-color: rgb(220, 220, 220)") - self.delay_alarm_hi = QLineEdit('') - self.delay_alarm_hi.setStyleSheet("background-color: rgb(220, 220, 220)") - self.width_read = QLineEdit('') - self.width_write = QLineEdit('') self.enable_read = QLineEdit('') self.enable_read.setMaximumWidth(20) - self.enable_write = QCheckBox() self.applica = QPushButton('Apply') self.applica.clicked.connect(lambda: self.funzioneapplica()) self.dev = dev @@ -613,14 +582,10 @@ class canaleSDG(QWidget): layoutriga.addWidget(self.delay_reference) layoutriga.addWidget(self.delay_read) layoutriga.addWidget(self.delay_write) - layoutriga.addWidget(self.delay_alarm_low) - layoutriga.addWidget(self.delay_alarm_hi) - layoutriga.addWidget(self.width_read) - layoutriga.addWidget(self.width_write) layoutriga.addWidget(self.enable_read) - layoutriga.addWidget(self.enable_write) layoutriga.addWidget(self.applica) self.setLayout(layoutriga) + def funzionemostradevice(self, info): msg = QMessageBox() msg.setIcon(QMessageBox.Information) @@ -629,9 +594,11 @@ class canaleSDG(QWidget): msg.setText('SDG channel ' + str(titolone[1])) msg.setWindowTitle('Info') msg.exec_() + def funzioneapplica(self): valore = self.delay_write.value() eval('self.dev.command_inout("SetDelay", [' + str(self.ch) + ', valore])') + def funzioneaggiornavalori(self): try: ritardo = eval('self.dev.Channel' + str(self.ch) + 'Delay') @@ -642,88 +609,36 @@ class canaleSDG(QWidget): abilitazione = False if abilitazione: self.enable_read.setStyleSheet("background-color: rgb(0, 255, 0)") - self.enable_write.setChecked(abilitazione) else: self.enable_read.setStyleSheet("background-color: rgb(255, 0, 0)") - self.enable_write.setChecked(abilitazione) class titolicanali(QWidget): - def __init__(self, in1, in2, in3, in4, in5, in6, in7, in8, in9, in10, in11, in12, parent = None): + def __init__(self, parent = None): super(titolicanali, self).__init__(parent) self.name = QLabel('NAME') - self.name.setGeometry(in1) - self.name.setAlignment(Qt.AlignRight) - self.devicelist = QLabel(' ') - self.devicelist.setGeometry(in2) self.delay_read = QLabel('READ') self.delay_read.setFont(font_importante) - self.delay_read.setAlignment(Qt.AlignRight) - self.delay_read.setGeometry(in3) self.delay_reference = QLabel('Ref. value') - self.delay_reference.setAlignment(Qt.AlignRight) - self.delay_reference.setGeometry(in4) - self.delay_write = QLabel('') - self.delay_write.setAlignment(Qt.AlignRight) - self.delay_write.setGeometry(in5) - self.delay_alarm_low = QLabel('Alarm lo') - self.delay_alarm_low.setAlignment(Qt.AlignRight) - self.delay_alarm_low.setGeometry(in6) - self.delay_alarm_hi = QLabel('Alarm hi') - self.delay_alarm_hi.setAlignment(Qt.AlignRight) - self.delay_alarm_hi.setGeometry(in7) - self.width_read = QLabel('Width R') - self.width_read.setAlignment(Qt.AlignRight) - self.width_read.setGeometry(in8) - self.width_write = QLabel('Width W') - self.width_write.setAlignment(Qt.AlignRight) - self.width_write.setGeometry(in9) - self.enable_read = QLabel(' ') - self.enable_read.setGeometry(in10) - self.enable_write = QLabel('ACTIVE') - self.enable_write.setAlignment(Qt.AlignRight) - self.enable_write.setGeometry(in11) - self.applica = QLabel(' ') - self.applica.setGeometry(in12) + self.delay_write = QLabel('WRITE') + self.spazio1 = QLabel(' ') + self.spazio2 = QLabel(' ') + self.spazio3 = QLabel(' ') layoutriga = QHBoxLayout() layoutriga.addWidget(self.name) - layoutriga.addWidget(self.devicelist) + layoutriga.addWidget(self.spazio1) layoutriga.addWidget(self.delay_reference) + layoutriga.addWidget(self.spazio2) layoutriga.addWidget(self.delay_read) + layoutriga.addWidget(self.spazio3) layoutriga.addWidget(self.delay_write) - layoutriga.addWidget(self.delay_alarm_low) - layoutriga.addWidget(self.delay_alarm_hi) - layoutriga.addWidget(self.width_read) - layoutriga.addWidget(self.width_write) - layoutriga.addWidget(self.enable_read) - layoutriga.addWidget(self.enable_write) - layoutriga.addWidget(self.applica) self.setLayout(layoutriga) -if __name__ == '__main__': - app = QApplication([]) - try: - tmpdim = sys.argv[1] - tmpdim = tmpdim.split('x') - dimensione = [float(tmpdim[0]), float(tmpdim[1])] - except: - screen = QDesktopWidget().screenGeometry() - larghezzaaltezza = [screen.width(), screen.height()] - print(larghezzaaltezza) - if max(larghezzaaltezza) > 3000: - dimensione = max(larghezzaaltezza)*0.38 - elif max(larghezzaaltezza) > 2000: - dimensione = max(larghezzaaltezza)*0.6 - elif max(larghezzaaltezza) > 1000: - dimensione = max(larghezzaaltezza)*0.7 - else: - dimensione = max(larghezzaaltezza)*2 - font_grande = QFont("Arial", round(dimensione/100.0), -1, False) - font_importante = QFont("Arial", round(dimensione/130.0), 1, True) - font_pannello = QFont("Arial", round(dimensione/140.0), -1, False) - app.setFont(font_pannello) - window = MainWindow() - window.resize(larghezzaaltezza[0]/4, larghezzaaltezza[1]/2) - window.show() - app.exec_() +app = QApplication([]) +font_importante = QFont("Arial", 14, 1, True) +font_pannello = QFont("Arial", 12, -1, False) +app.setFont(font_pannello) +main = MainWindow() +main.show() +app.exec_() -- GitLab