class Module(QGroupBox): def __init__(self, mwindow, title): QGroupBox.__init__(self) self.grid = GridLayout() self.setLayout(self.grid) self.setTitle(title) self.mwindow = mwindow self.setStyleSheet() @property def rows(self): return [] def populateLayout(self): for i, row in enumerate(self.rows): for j, widget in enumerate(row.displayed): if widget is None: continue self.grid.addWidget(widget, i, j) def setEnabled(self, a0: bool) -> None: for row in self.rows: row.setOnline(a0) QGroupBox.setEnabled(self, a0) def setStyleSheet(self, styleSheet=None): styleSheet = "QGroupBox {font-size: %ipt;border: 1px solid lightgray;border-radius: 3px;margin-top: 6px;} " % round( 0.9 * styles.bigFont) \ + "QGroupBox::title {subcontrol-origin: margin;subcontrol-position: top left; padding: 0 0px;}" QGroupBox.setStyleSheet(self, styleSheet)
class SpsWidget(QWidget): def __init__(self, spsGUI): QWidget.__init__(self) self.spsGUI = spsGUI self.tronLayout = TronLayout() self.mainLayout = GridLayout() self.mainLayout.setSpacing(1) self.mainLayout.setContentsMargins(0, 0, 0, 0) self.mainLayout.addLayout(self.tronLayout, 0, 0) self.mainLayout.addWidget(Aitmodule(self), 1, 0) for smId in range(1, 12): if 'sm%d' % smId not in self.actor.config.sections(): continue arms = [ arm.strip() for arm in self.actor.config.get('sm%d' % smId, 'arms').split(',') if arm ] enu = self.actor.config.getboolean('sm%d' % smId, 'enu') self.mainLayout.addWidget( Specmodule(self, smId=smId, enu=enu, arms=arms), smId + 1, 0) self.setLayout(self.mainLayout) @property def actor(self): return self.spsGUI.actor @property def isConnected(self): return self.spsGUI.isConnected def sendCommand(self, actor, cmdStr, callFunc): import opscore.actor.keyvar as keyvar self.actor.cmdr.bgCall(**dict(actor=actor, cmdStr=cmdStr, timeLim=1600, callFunc=callFunc, callCodes=keyvar.AllCodes)) def heartBeat(self): self.tronLayout.tronStatus.dial.heartBeat() def showError(self, title, error): reply = QMessageBox.critical(self, title, error, QMessageBox.Ok) def setEnabled(self, a0: bool) -> None: widgets = [ self.mainLayout.itemAt(i).widget() for i in range(self.mainLayout.count()) ] for widget in widgets: widget.setEnabled(a0)
class ControlPanel(QWidget): def __init__(self, controlDialog): QWidget.__init__(self) self.controlDialog = controlDialog self.grid = GridLayout() self.grid.setContentsMargins(*(4 * (1, ))) self.grid.setSizeConstraint(QLayout.SetMinimumSize) self.setLayout(self.grid) self.createWidgets() self.setInLayout() self.setEnabled(False) @property def moduleRow(self): return self.controlDialog.moduleRow @property def actorName(self): return self.controlDialog.moduleRow.actorName def createWidgets(self): pass def setInLayout(self): pass def addCommandSet(self, commands): self.commands = commands self.grid.addWidget(self.commands, 0, self.grid.columnCount(), self.grid.rowCount(), self.grid.columnCount()) self.spacer = QSpacerItem(0, 0, QSizePolicy.Minimum, QSizePolicy.MinimumExpanding) self.grid.addItem(self.spacer, self.grid.rowCount(), 0) def updateIcon(self, a0): icon = Icon('green.png') if a0 else Icon('orange.png') self.controlDialog.tabWidget.setTabIcon( self.controlDialog.tabWidget.indexOf(self), icon) self.controlDialog.tabWidget.setIconSize( QSize(styles.bigFont + 2, styles.bigFont + 2)) def setEnabled(self, a0: bool): self.updateIcon(a0) for item in [self.grid.itemAt(i) for i in range(self.grid.count())]: if issubclass(type(item), QSpacerItem): continue elif issubclass(type(item), QLayout): item.setEnabled(a0) else: item.widget().setEnabled(a0)
class MultiplePanel(QWidget): def __init__(self, parent): QWidget.__init__(self) self.grid = GridLayout() self.grid.setContentsMargins(*(4 * (1, ))) self.setLayout(self.grid) def addWidget(self, *args, **kwargs): return self.grid.addWidget(*args, **kwargs)
class TronStatus(ValueGB): def __init__(self, fontSize=styles.smallFont): self.fontSize = fontSize QGroupBox.__init__(self) self.setTitle('TRON') self.grid = GridLayout() self.grid.setContentsMargins(5, 0, 0, 0) self.value = QLabel() self.dial = TronDial() self.grid.addWidget(self.value, 0, 0) self.grid.addWidget(self.dial, 0, 1) self.setLayout(self.grid) def setEnabled(self, isOnline): text = 'ONLINE' if isOnline else 'OFFLINE' key = text if isOnline else 'failed' self.value.setText(text) self.setColor(*styles.colorWidget(key))
class ValueGB(QGroupBox): def __init__(self, moduleRow, key, title, ind, fmt, fontSize=styles.smallFont, callNow=False): self.moduleRow = moduleRow self.keyvar = moduleRow.keyVarDict[key] self.title = title self.fontSize = fontSize QGroupBox.__init__(self) self.setTitle('%s' % self.title) self.grid = GridLayout() self.grid.setContentsMargins(*[2, 4, 2, 4]) self.value = QLabel() self.grid.addWidget(self.value, 0, 0) self.setLayout(self.grid) self.cb = partial(self.updateVals, ind, fmt) self.keyvar.addCallback(self.cb, callNow=callNow) def __del__(self): self.keyvar.removeCallback(self.cb) def updateVals(self, ind, fmt, keyvar): values = keyvar.getValue(doRaise=False) values = (values, ) if not isinstance(values, tuple) else values value = values[ind] try: strValue = fmt.format(value) except TypeError: strValue = 'nan' self.setText(strValue) self.moduleRow.mwindow.heartBeat() def setBackground(self, background): col1, col2 = styles.colormap(background) bckColor = 'qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 %s, stop: 1 %s)' % ( col1, col2) fontSize = max(8, round(0.85 * self.fontSize)) self.setStyleSheet( "QGroupBox {font-size: %ipt; background-color: %s ;border: 1px solid gray;border-radius: 3px;margin-top: 1ex;} " % (fontSize, bckColor) + "QGroupBox::title {subcontrol-origin: margin;subcontrol-position: top center; padding: 0 0px;}" ) return bckColor def setColor(self, background, police='white'): self.setBackground(background=background) self.value.setStyleSheet( "QLabel{font-size: %ipt; qproperty-alignment: AlignCenter; color:%s;}" % (self.fontSize, police)) def setText(self, txt): self.value.setText(txt) self.customize() def customize(self): background, police = self.getStyles(self.value.text()) self.setColor(background=background, police=police) self.setEnabled(self.moduleRow.isOnline) def getStyles(self, text): try: background, police = styles.colorWidget(text) except KeyError: background, police = styles.colorWidget('default') return background, police def setEnabled(self, isOnline): if not isOnline: self.setColor(*styles.colorWidget('offline'))