diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d3d7e83 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.*~ +*.*-* +*.*+* +__pycache__ diff --git a/__pycache__/guiheader.cpython-37.pyc b/__pycache__/guiheader.cpython-37.pyc index 9c00d2a..340d23b 100644 Binary files a/__pycache__/guiheader.cpython-37.pyc and b/__pycache__/guiheader.cpython-37.pyc differ diff --git a/guiheader.py b/guiheader.py index c40a5f9..8965069 100644 --- a/guiheader.py +++ b/guiheader.py @@ -2,23 +2,14 @@ """ from datetime import datetime import random -import time from qtpy.QtCore import Qt, QTimer -from qtpy.QtGui import QFont, QIntValidator -from qtpy.QtWidgets import (QApplication, QFrame, QGridLayout, QGroupBox, - QHBoxLayout, QLabel, QLineEdit, QMessageBox, - QPushButton, QRadioButton, QSizePolicy, QSpacerItem, - QSpinBox, QTabWidget, QToolButton, QVBoxLayout, - QWidget) -from caqtwidgets.pvwidgets import (CAQDoubleSpinBox, CAQLabel, CAQLineEdit, - CAQMenu, CAQMessageButton, CAQSpinBox, - CAQTableWidget, CAQTextEntry, QHLine, QVLine, - QResultsWidget) - -from pyqtacc.bdbase.enumkind import MsgSeverity, UserMode - +from qtpy.QtGui import QFont +from qtpy.QtWidgets import (QApplication, QGridLayout, QGroupBox, QHBoxLayout, + QLabel, QRadioButton, QWidget) +from caqtwidgets.pvwidgets import CAQLabel, QHLine, QVLine +from pyqtacc.bdbase.enumkind import UserMode class GUIHeader(QWidget): """ GUI Header Class @@ -34,10 +25,10 @@ class GUIHeader(QWidget): self.extended = extended self.cafe = parent.cafe self.cyca = parent.cyca - - self.input_parameters = parent.input_parameters + + self.input_parameters = parent.input_parameters self.input_labels = parent.input_labels - self.expert_parameters = parent.expert_parameters + self.expert_parameters = parent.expert_parameters self.expert_labels = parent.expert_labels self.aramis_status = None @@ -50,13 +41,13 @@ class GUIHeader(QWidget): self.font_pts10.setPointSize(10) self.widget_height = self.settings.data["StyleGuide"]["widgetHeight"] self.extra_height = self.settings.data["StyleGuide"]["extraGroupHeight"] - self.aramis_color = self.settings.data["Aramis"]["color"] - self.athos_color = self.settings.data["Athos"]["color"] - self.porthos_color = self.settings.data["Porthos"]["color"] + self.aramis_color = self.settings.data["Aramis"]["color"] + self.athos_color = self.settings.data["Athos"]["color"] + self.porthos_color = self.settings.data["Porthos"]["color"] beamline = ["Aramis", "Athos", "Porthos"] pvlist = [] - for item in beamline: + for item in beamline: if item not in self.settings.data: continue try: @@ -65,13 +56,13 @@ class GUIHeader(QWidget): pvlist.append(self.settings.data[item]["beamStatus"]) pvlist.append(self.settings.data[item]["energy"]) pvlist.append(self.settings.data[item]["charge"]) - pvlist.append(self.settings.data[item]["photonEnergy"]) + pvlist.append(self.settings.data[item]["photonEnergy"]) except KeyError as error: - print("KeyError in guiheader.py __init__", error) - - for key, pv in self.settings.data["OpMsg"].items(): + print("KeyError in guiheader.py __init__", str(error)) + + for pv in self.settings.data["OpMsg"].values(): pvlist.append(pv) - + print(datetime.now()) self.cafe.openPrepare() self.cafe.open(pvlist) @@ -79,36 +70,29 @@ class GUIHeader(QWidget): print(datetime.now()) self.cafe.printDisconnected() - self.station_width = 200 #default self.station_height = 100 self.hor_layout = QHBoxLayout() self.hor_layout.addWidget(self.status_widget()) self.hor_layout.addWidget(self.aramis_widget()) self.hor_layout.addWidget(self.athos_widget()) - yr_diff = abs(2030 - datetime.now().year) + yr_diff = abs(2032 - datetime.now().year) show_porthos = False try: if self.settings.data["showPorthos"]: show_porthos = True else: - if random.randint(1, 10) > yr_diff: - show_porthos = True + if random.randint(2, 12) > yr_diff: + show_porthos = True except KeyError as error: - print("KeyError in guiheader.py initialization:", error) - if random.randint(1, 10) > yr_diff: - show_porthos = True + print("KeyError in guiheader.py initialization:", str(error)) + if random.randint(2, 12) > yr_diff: + show_porthos = True if show_porthos: self.hor_layout.addWidget(self.porthos_widget()) self.hor_layout.setSpacing(10) - #self.header_layout.addItem(QSpacerItem(0, 20)) self.hor_layout.setAlignment(Qt.AlignLeft) - self.hor_layout.setContentsMargins(5, 0, 5, 0) #default 11 pixels - #self.top_widget = QLabel("SwissFEL") - - #self.top_layout = QVBoxLayout() - #self.top_layout.addWidget(self.top_widget) - #self.top_layout.addLayout(self.hor_layout) + self.hor_layout.setContentsMargins(5, 0, 5, 0) self.header_wgt = QGroupBox() self.header_wgt.setObjectName(self.user_mode.name) @@ -116,14 +100,11 @@ class GUIHeader(QWidget): self.header_wgt.setFixedHeight(110) title = "SwissFEL {0}".format(self.user_mode.name) if self.title: - title += ": {0}".format(self.title) + title += ": {0}".format(self.title) self.header_wgt.setTitle(title) self.target_beamline = None - - #self.set_target_beamline("Athos", reset=False) - #QApplication.processEvents() - + self.timer = QTimer() self.timer.timeout.connect(self.blink_target_beamline) self.timer.start(500) @@ -140,8 +121,8 @@ class GUIHeader(QWidget): if self.timer_count > 4: self.timer.stop() QApplication.processEvents() - - def set_target_beamline(self, target, reset = True): + + def set_target_beamline(self, target, reset=True): """ Select beamline target and modify color scheme accordinly """ if not target: @@ -149,7 +130,7 @@ class GUIHeader(QWidget): if target == "Aramis": self.aramis_status.setObjectName("TARGET") self.aramis_status.setTitle("Target: Aramis") - self.aramis_status.style().polish(self.aramis_status) + self.aramis_status.style().polish(self.aramis_status) elif target == "Athos": self.athos_status.setObjectName("TARGET") self.athos_status.setTitle("Target: Athos") @@ -159,13 +140,13 @@ class GUIHeader(QWidget): self.porthos_status.setObjectName("TARGET") self.porthos_status.setTitle("Target: Porthos") self.porthos_status.style().polish(self.porthos_status) - - if reset: - self.reset_beamline() + + if reset: + self.reset_beamline() self.target_beamline = target - + def reset_beamline(self): - """ Reset QGroupBox for previous target to original colors + """ Reset QGroupBox for previous target to original colors """ if self.target_beamline == "Aramis": self.reset_aramis() @@ -175,21 +156,21 @@ class GUIHeader(QWidget): self.reset_porthos() def reset_aramis(self): - """ Reset Aramis QGroupBox color + """ Reset Aramis QGroupBox color """ self.aramis_status.setObjectName("ARAMIS") self.aramis_status.setTitle("Aramis") self.aramis_status.style().polish(self.aramis_status) def reset_athos(self): - """ Reset Athos QGroupBox color + """ Reset Athos QGroupBox color """ self.athos_status.setObjectName("ATHOS") self.athos_status.setTitle("Athos") self.athos_status.style().polish(self.athos_status) def reset_porthos(self): - """ Reset Porthos QGroupBox color + """ Reset Porthos QGroupBox color """ if self.porthos_status: self.porthos_status.setObjectName("PORTHOS") @@ -197,43 +178,40 @@ class GUIHeader(QWidget): self.porthos_status.style().polish(self.porthos_status) def reset_operation_mode(self): - """ Reset header colors to application operation mode + """ Reset header colors to application operation mode """ self.change_operation_mode(user_mode=self.user_mode) - + def change_operation_mode(self, user_mode=UserMode.OPERATION): - """ Different operation modes have different color schemes + """ Different operation modes have different color schemes """ self.header_wgt.setObjectName(user_mode.name) self.header_wgt.setTitle(self.header_wgt.title().replace( self.current_user_mode.name, user_mode.name)) self.header_wgt.style().polish(self.header_wgt) self.current_user_mode = user_mode - - #self.header_wgt.setStyleSheet("QGroupBox#OPERATION{background-color:#8b1a96; color:white;}" "QGroupBox::title#OPERATION{background-color:#8b1a96;} ") - def beamline_widget(self, beamline="Aramis"): - """ QGroupBox template for beamlines + """ QGroupBox template for beamlines """ station = QGroupBox() station.setObjectName(beamline.upper()) - station.setAlignment(Qt.AlignHCenter | Qt.AlignTop) - station.setFlat(False) - station.setTitle(beamline) + station.setAlignment(Qt.AlignHCenter | Qt.AlignTop) + station.setFlat(False) + station.setTitle(beamline) laser = CAQLabel(self, pv_name=self.settings.data[beamline]["laser"]) laser.setFixedHeight(self.widget_height) - freq = CAQLabel(self, pv_name=self.settings.data[beamline]["freq"], + freq = CAQLabel(self, pv_name=self.settings.data[beamline]["freq"], show_units=True) freq.setAlignment(Qt.AlignRight) freq.setFixedHeight(self.widget_height) freq.setFixedWidth(84) beamstatus = CAQLabel( - self, pv_name=self.settings.data[beamline]["beamStatus"], + self, pv_name=self.settings.data[beamline]["beamStatus"], color_mode="alarm") beamstatus.setFixedHeight(self.widget_height) - grid_layout = QGridLayout() + grid_layout = QGridLayout() grid_layout.addWidget(laser, 0, 0, 1, 1, Qt.AlignCenter) grid_layout.addWidget(freq, 0, 1, 1, 1, Qt.AlignCenter) grid_layout.addWidget(beamstatus, 1, 0, 1, 2, Qt.AlignCenter) @@ -244,17 +222,17 @@ class GUIHeader(QWidget): self, pv_name=self.settings.data[beamline]["energy"], show_units=True) filtered_energy.setFixedHeight(self.widget_height) - charge = CAQLabel( + charge = CAQLabel( self, pv_name=self.settings.data[beamline]["charge"], show_units=True, notify_freq_hz=2) charge.setFixedHeight(self.widget_height) charge.setFixedWidth(78) - photon_energy = CAQLabel( + photon_energy = CAQLabel( self, pv_name=self.settings.data[beamline]["photonEnergy"], show_units=False, suffix='\u00B5J') photon_energy.setFixedHeight(self.widget_height) photon_energy.setFixedWidth(66) #So aramis/Athos are the same - + grid_layout.addWidget(filtered_energy, 0, 3, 1, 2, Qt.AlignCenter) grid_layout.addWidget(charge, 1, 3, 1, 1, Qt.AlignCenter) grid_layout.addWidget(photon_energy, 1, 4, 1, 1, Qt.AlignCenter) @@ -265,7 +243,7 @@ class GUIHeader(QWidget): #print(grid_layout.getContentsMargins()) station.setLayout(grid_layout) - self.station_height = laser.height() + freq.height() + self.extra_height + self.station_height = laser.height() + freq.height() + self.extra_height station.setFixedHeight(self.station_height) self.station_width = laser.width() + freq.width() + 10 if self.extended: @@ -275,29 +253,29 @@ class GUIHeader(QWidget): return station def aramis_widget(self): - """ QGroupBox encompassing main Aramis parameters + """ QGroupBox encompassing main Aramis parameters """ self.aramis_status = self.beamline_widget(beamline="Aramis") return self.aramis_status def athos_widget(self): - """ QGroupBox encompassing main Athos parameters + """ QGroupBox encompassing main Athos parameters """ self.athos_status = self.beamline_widget(beamline="Athos") return self.athos_status def porthos_widget(self): - """ QGroupBox encompassing main Porthos parameters + """ QGroupBox encompassing main Porthos parameters """ #porthos = self.beamline_widget(beamline="Porthos") station = QGroupBox() station.setObjectName("Porthos".upper()) - station.setAlignment(Qt.AlignHCenter | Qt.AlignTop) - station.setFlat(False) - station.setTitle("Porthos") - grid_layout = QGridLayout() + station.setAlignment(Qt.AlignHCenter | Qt.AlignTop) + station.setFlat(False) + station.setTitle("Porthos") + grid_layout = QGridLayout() text = "Honest and extrovert!" \ - if random.randint(1,10) > 9 else "Arriving 2029" + if random.randint(1, 10) > 9 else "Arriving 2032" qlabel = QLabel(text) qlabel.setFont(self.font_pts10) qlabel.setAlignment(Qt.AlignCenter) @@ -306,7 +284,7 @@ class GUIHeader(QWidget): station.setFixedWidth(self.station_width) station.setFixedHeight(self.station_height) self.porthos_status = station - return self.porthos_status + return self.porthos_status def status_widget(self): """ QGroupBox encompassing machine status info @@ -318,8 +296,9 @@ class GUIHeader(QWidget): station.setTitle("Status") date = CAQLabel(self, pv_name=self.settings.data["OpMsg"]["pvDate1"]) date.setFixedHeight(self.widget_height) - eventno = CAQLabel(self, pv_name=self.settings.data["OpMsg"]["pvEventNo"], - notify_freq_hz=10) + eventno = CAQLabel( + self, pv_name=self.settings.data["OpMsg"]["pvEventNo"], + notify_freq_hz=10) eventno.setFixedHeight(self.widget_height) eventno.setAlignment(Qt.AlignCenter) message = CAQLabel( @@ -327,41 +306,41 @@ class GUIHeader(QWidget): message.setFixedHeight(self.widget_height) message.setFixedWidth(eventno.width() + date.width() + 2) - grid_layout = QGridLayout() + grid_layout = QGridLayout() grid_layout.addWidget(date, 0, 0, 1, 1, Qt.AlignCenter) grid_layout.addWidget(eventno, 0, 1, 1, 1, Qt.AlignCenter) grid_layout.addWidget(message, 1, 0, 1, 2, Qt.AlignCenter) grid_layout.setVerticalSpacing(0) grid_layout.setHorizontalSpacing(0) grid_layout.setContentsMargins(0, 10, 0, 0) - + station.setLayout(grid_layout) station.setFixedHeight(eventno.height() + date.height() + self.extra_height) station.setFixedWidth(eventno.width() + date.width() + 10) self.machine_status = station return self.machine_status - + def operator_group_header(self): return self.radio_target_beamline() - + def radio_target_beamline(self): widget = QWidget() layout = QGridLayout() layout.setContentsMargins(0, 0, 0, 0) self.setLayout(layout) target_list = ["Aramis", "Athos"] + self.radiobutton = [QRadioButton("Aramis"), QRadioButton("Athos")] try: if self.settings.data["showPorthos"]: - target_list.append("Porthos") + target_list.append("Porthos") + self.radiobutton.append(QRadioButton("Porthos")) except KeyError as error: - print("KeyError in guiheader.py, def radio_target_beamline:", error) - + print("KeyError in guiheader.py, def radio_target_beamline:", + str(error)) color_list = [self.aramis_color, self.athos_color, self.porthos_color] - self.radiobutton = [QRadioButton("Aramis"), QRadioButton("Athos"), - QRadioButton("Porthos")] width_list = [70, 64, 84] #width_list = [80, 74, 92] #pts 11 layout.addWidget(QHLine(), 0, 0, 1, 3) @@ -375,44 +354,23 @@ class GUIHeader(QWidget): radio.toggled.connect(self.on_target_clicked) layout.addWidget(radio, 1, i) radio.setFixedWidth(width) - - try: - target = self.settings.data["Parameters"]["undulator"]["data"]["value"] + + try: + target = self.settings.data["Parameters"]["undulator"]["data"][ + "value"] except KeyError as error: - print("KeyError in guiheader.py, def radio_target_beamline:", error) + print("KeyError in guiheader.py, def radio_target_beamline:", + str(error)) target = target_list[0] try: idx = target_list.index(target) except ValueError as error: - print("ValueError in guiheader.py, def radio_target_beamline:", error) + print("ValueError in guiheader.py, def radio_target_beamline:", + str(error)) idx = 0 self.radiobutton[idx].setChecked(True) - self.radiobutton[idx].toggled.emit(True) - - ''' - radiobutton = QRadioButton("Aramis") - radiobutton.setFont(self.font_gui) - radiobutton.setStyleSheet("color : {0};".format(self.aramis_color)) - radiobutton.setChecked(True) - radiobutton.target = "Aramis" - radiobutton.toggled.connect(self.on_target_clicked) - layout.addWidget(radiobutton, 0, 0) - - radiobutton = QRadioButton("Athos") - radiobutton.setFont(self.font_gui) - radiobutton.setStyleSheet("color : {0};".format(self.athos_color)) - radiobutton.target = "Athos" - radiobutton.toggled.connect(self.on_target_clicked) - layout.addWidget(radiobutton, 0, 1) - - radiobutton = QRadioButton("Porthos") - radiobutton.setFont(self.font_gui) - radiobutton.setStyleSheet("color : {0};".format(self.porthos_color)) - radiobutton.target = "Porthos" - radiobutton.toggled.connect(self.on_target_clicked) - layout.addWidget(radiobutton, 0, 2) - ''' + self.radiobutton[idx].toggled.emit(True) layout.addWidget(QHLine(), 2, 0, 1, 3) @@ -428,11 +386,8 @@ class GUIHeader(QWidget): radio_button.setText(radio_button.target.upper()) self.timer.start(500) self.timer_count = 0 - #print (self.parent.input_parameters['undulator']) self.parent.input_parameters['undulator'] = radio_button.target - print (self.parent.input_parameters['undulator']) for radio in self.radiobutton: if not radio.isChecked(): radio.setText(radio.target) -