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)
def __init__(self, controlPanel, buttonLabel, safetyCheck=False): GridLayout.__init__(self) self.controlPanel = controlPanel self.button = InnerButton(self, label=buttonLabel, safetyCheck=safetyCheck) self.addWidget(self.button, 0, 0)
def __init__(self, mwindow, title): QGroupBox.__init__(self) self.grid = GridLayout() self.setLayout(self.grid) self.setTitle(title) self.mwindow = mwindow self.setStyleSheet()
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 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)
def __init__(self, controlDialog): GridLayout.__init__(self) self.controlDialog = controlDialog self.button = SetButton(self) self.combo = ComboBox() self.combo.addItems(list(SetCryoMode.validModes)) self.addWidget(self.button, 0, 0) self.addWidget(self.combo, 0, 1)
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)
def __init__(self, controlPanel, fontSize=styles.smallFont): QGroupBox.__init__(self) self.controlPanel = controlPanel self.grid = GridLayout() self.grid.setContentsMargins(1, 7, 1, 1) self.setTitle('Commands') self.setLayout(self.grid) self.setStyleSheet( "QGroupBox {font-size: %ipt; border: 1px solid #d7d4d1;border-radius: 3px;margin-top: 1ex;} " % (fontSize) + "QGroupBox::title {subcontrol-origin: margin;subcontrol-position: top center; padding: 0 3px;}" )
def __init__(self, controlDialog, controllers): GridLayout.__init__(self) self.keyvar = controlDialog.moduleRow.keyVarDict['controllers'] self.keyvar.addCallback(self.setButtonLabel, callNow=False) self.controlDialog = controlDialog self.button = ConnectButton(self, label='CONNECT') self.combo = ComboBox() self.combo.addItems(controllers) self.combo.currentTextChanged.connect(self.setButtonLabel) self.addWidget(self.button, 0, 0) self.addWidget(self.combo, 0, 1)
def __init__(self): GridLayout.__init__(self) self.widgets = [ DoubleSpinBoxGB('X', -10, 10, 5), DoubleSpinBoxGB('Y', -10, 10, 5), DoubleSpinBoxGB('Z', -10, 10, 5), DoubleSpinBoxGB('U', -2, 2, 5), DoubleSpinBoxGB('V', -2, 2, 5), DoubleSpinBoxGB('W', -2, 2, 5) ] for i, spinbox in enumerate(self.widgets): self.addWidget(spinbox, i // 3, i % 3)
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 __init__(self, controlDialog, controllerName, title=None): title = controllerName.capitalize() if title is None else title self.controllerName = controllerName QGroupBox.__init__(self) self.controlDialog = controlDialog self.grid = GridLayout() self.grid.setSizeConstraint(QLayout.SetMinimumSize) self.grid.setContentsMargins(5, 5, 5, 5) self.setLayout(self.grid) self.createWidgets() self.setInLayout() self.setTitle(title) self.setCheckable(True) self.setEnabled(False)
class CamDevice(QGroupBox): def __init__(self, controlDialog, controllerName, title=None): title = controllerName.capitalize() if title is None else title self.controllerName = controllerName QGroupBox.__init__(self) self.controlDialog = controlDialog self.grid = GridLayout() self.grid.setSizeConstraint(QLayout.SetMinimumSize) self.grid.setContentsMargins(5, 5, 5, 5) self.setLayout(self.grid) self.createWidgets() self.setInLayout() self.setTitle(title) self.setCheckable(True) self.setEnabled(False) @property def moduleRow(self): return self.controlDialog.moduleRow @property def actorName(self): return self.controlDialog.moduleRow.actorName def addCommandSet(self, commands): ControlPanel.addCommandSet(self, commands) def updateIcon(self, a0): filename = 'green.png' if a0 else 'orange.png' self.setStyleSheet( "CamDevice {font-size: %dpt; font-weight:bold;border: 1px solid #000000;border-radius: 20;;margin-top: 10px;}" "CamDevice::title {subcontrol-origin: margin;subcontrol-position: top left; padding: 0 10px;}" "CamDevice::indicator { width:%ipx; height: %ipx;}" "CamDevice::indicator:checked {image: url(%s);} " % (styles.smallFont, styles.bigFont + 2, styles.bigFont + 2, os.path.join(imgPath, filename))) def setEnabled(self, a0): ControllerPanel.setEnabled(self, a0)
def __init__(self, controlDialog): GridLayout.__init__(self) self.controlDialog = controlDialog self.apply = PushButton('Apply') self.apply.clicked.connect(controlDialog.sendCommands) self.discard = PushButton('Discard') self.discard.clicked.connect(controlDialog.cancelCommands) self.showLogs = PushButton('Show Logs') self.hideLogs = PushButton('Hide Logs') self.showLogs.clicked.connect(partial(self.show, True)) self.hideLogs.clicked.connect(partial(self.show, False)) self.addWidget(self.showLogs, 0, 0) self.addWidget(self.hideLogs, 0, 0) self.addWidget(self.apply, 0, 9) self.addWidget(self.discard, 0, 10) self.show(False)
class CommandsGB(QGroupBox): def __init__(self, controlPanel, fontSize=styles.smallFont): QGroupBox.__init__(self) self.controlPanel = controlPanel self.grid = GridLayout() self.grid.setContentsMargins(1, 7, 1, 1) self.setTitle('Commands') self.setLayout(self.grid) self.setStyleSheet( "QGroupBox {font-size: %ipt; border: 1px solid #d7d4d1;border-radius: 3px;margin-top: 1ex;} " % (fontSize) + "QGroupBox::title {subcontrol-origin: margin;subcontrol-position: top center; padding: 0 3px;}" ) def setEnabled(self, a0: bool): 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)
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)
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))
def __init__(self, parent): QWidget.__init__(self) self.grid = GridLayout() self.grid.setContentsMargins(*(4 * (1, ))) self.setLayout(self.grid)
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 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'))
def setEnabled(self, a0: bool): GridLayout.setEnabled(self, a0) for button in [self.itemAt(i).widget() for i in range(self.count())]: button.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)