""" Gui header for HIPA """ from qtpy.QtCore import Qt from qtpy.QtGui import QFont from qtpy.QtWidgets import ( QGridLayout, QGroupBox, QHBoxLayout, QLabel, QProxyStyle, QVBoxLayout, QWidget) from caqtwidgets.pvwidgets import CAQLabel from pyqtacc.bdbase.enumkind import UserMode class GUIHeader(QWidget): """ GUI Header Class """ def __init__(self, parent, user_mode=UserMode.OPERATION, extended=True): super(GUIHeader, self).__init__() self.parent = parent self.appname = parent.appname self.title = parent.title self.settings = parent.settings self.user_mode = user_mode self.current_user_mode_name = user_mode.name self.extended = extended self.cafe = parent.cafe self.cyca = parent.cyca self.input_parameters = parent.input_parameters self.input_labels = parent.input_labels self.expert_parameters = parent.expert_parameters self.expert_labels = parent.expert_labels self.header_groups = self.settings.data['header'] #self.header_colors = ['Machine', 'Machine', 'Athos', 'Athos', 'Aramis', # 'Aramis', 'Porthos'] self.header_status = [None] * len(self.header_groups) self.font_gui = QFont("sans serif") self.font_gui.setPointSize(11) self.font_pts10 = QFont("sans serif") self.font_pts10.setPointSize(10) self.widget_height = self.settings.data["StyleGuide"]["widgetHeight"] self.extra_height = self.settings.data["StyleGuide"]["extraGroupHeight"] pvlist = [] header_colors = [] for sector in self.header_groups: pvlist.append(self.settings.data[sector]["current"]) header_colors.append(self.settings.data[sector]["colorObj"]) self.cafe.openPrepare() self.cafe.open(pvlist) self.cafe.openNowAndWait(0.4) self.cafe.printDisconnected() self.station_width = 200 #default self.station_height = 100 self.hor_layout = QHBoxLayout() self.beam_current_wgt_dict = {} for sector, pv, color in zip(self.header_groups, pvlist, header_colors): self.hor_layout.addWidget(self.beam_current_widget( header=sector, pv= pv, color_obj=color)) self.hor_layout.setSpacing(6) self.hor_layout.setAlignment(Qt.AlignLeft) self.hor_layout.setContentsMargins(5, 0, 5, 0) self.header_wgt = QGroupBox() self.header_wgt.setObjectName(self.user_mode.name) self.header_wgt.setLayout(self.hor_layout) self.header_wgt.setFixedHeight(110) #self.header_wgt.setStyle(QProxyStyle()) title = "HIPA {0}".format(self.user_mode.name) if self.title: title += ": {0}".format(self.title) self.header_wgt.setTitle(title) def reset_operation_mode(self): """ 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 """ title_name = user_mode.name dry_run_tags = ['HUSH', 'Dry'] #print('title', self.header_wgt.title(), flush=True) if any([x in self.header_wgt.title() for x in dry_run_tags]): title_name = 'DRY RUN' if user_mode.name == 'SIMULATION' \ else user_mode.name self.header_wgt.setObjectName(user_mode.name) self.header_wgt.setTitle(self.header_wgt.title().replace( self.current_user_mode_name, title_name)) self.header_wgt.style().polish(self.header_wgt) self.current_user_mode_name = title_name def beam_current_widget(self, header: str="", pv: str ="", color_obj: str="MACHINE"): """ QGroupBox encompassing beam current info """ station = QGroupBox() station.setObjectName(color_obj.upper()) station.setAlignment(Qt.AlignmentFlag(Qt.AlignHCenter|Qt.AlignTop)) station.setFlat(False) station.setTitle(header) beam_current = CAQLabel(self, pv_name=pv, show_units=True) beam_current.setFixedHeight(self.widget_height) beam_current.setFixedWidth(140) grid_layout = QGridLayout() grid_layout.addWidget(beam_current, 0, 0, 1, 1, Qt.AlignCenter) grid_layout.setVerticalSpacing(0) grid_layout.setHorizontalSpacing(0) grid_layout.setContentsMargins(2, 9, 2, 0) if header == "UCN": beam_req_status = CAQLabel( self, pv_name="UCNQ:BEAMREQ:STATUS", prefix="BEAMREQ: ") beam_req_status.setFixedHeight(self.widget_height) beam_req_status.setFixedWidth(146) grid_layout.addWidget(beam_req_status, 1, 0, 1, 1, Qt.AlignCenter) self.extra_height += 25 self.beam_current_wgt_dict["UCNQ"] = beam_req_status station.setLayout(grid_layout) station.setFixedHeight(beam_current.height() + self.extra_height) station.setFixedWidth(beam_current.width() + 15) self.beam_current_wgt_dict[header] = beam_current return station