class DevicesDialog(QDialog): def __init__(self, parent, measdef, client): self.measdef = measdef self.client = client QDialog.__init__(self, parent) loadUi(self, findResource('nicos_mlz/kws1/gui/devices.ui')) self.frame = QFrame(self) self.scrollArea.setWidget(self.frame) self.frame.setLayout(QVBoxLayout()) self.frame.layout().setContentsMargins(0, 0, 10, 0) self.frame.layout().addStretch() devlist = client.getDeviceList('nicos.core.device.Moveable') for dev in devlist: if dev not in DEV_BLACKLIST: QListWidgetItem(dev, self.devList) self._widgets = [] for group in measdef.devices: devs = group[0].keys() w = self._addWidget(devs) for entry in group: w.addRow([entry[x] for x in devs]) def toDefs(self): return [w.getDef() for w in self._widgets] def _addWidget(self, devs): w = DevicesWidget(self.frame, self.client, devs) self.frame.layout().insertWidget(self.frame.layout().count()-1, w) w.remove.connect(self.on_removeWidget) self._widgets.append(w) return w @pyqtSlot() def on_addBtn_clicked(self): devs = [] for item in self.devList.selectedItems(): devs.append(item.text()) if not devs: return self.devList.clearSelection() w = self._addWidget(devs) w.addRow() def on_removeWidget(self, widget): self.frame.layout().removeWidget(widget) self._widgets.remove(widget) widget.deleteLater()
class WatchdogDialog(QDialog): def __init__(self, main): QDialog.__init__(self, main) loadUi(self, 'dialogs/watchdog.ui') self.frame = QFrame(self) self.scrollArea.setWidget(self.frame) self.frame.setLayout(QVBoxLayout()) self.frame.layout().setContentsMargins(0, 0, 10, 0) self.frame.layout().addStretch() def btn(button): if self.buttonBox.buttonRole(button) == QDialogButtonBox.ResetRole: for w in self.frame.children(): if isinstance(w, QWidget): w.hide() else: self.close() self.buttonBox.clicked.connect(btn) def addEvent(self, data): # data: [event type, timestamp, message, watchdog entry id] layout = self.frame.layout() if data[0] == 'resolved': for i in range(layout.count()): widget = layout.itemAt(i).widget() if getattr(widget, 'entry_id', None) == data[3]: widget.datelabel.setText(widget.datelabel.text() + ' [RESOLVED]') return w = QWidget(self.frame) loadUi(w, 'dialogs/watchdog_item.ui') if len(data) > 3: # compatibility for older watchdogs w.entry_id = data[3] layout.insertWidget(self.frame.layout().count() - 1, w) timestamp = time.strftime('%Y-%m-%d %H:%M', time.localtime(data[1])) if data[0] == 'warning': w.datelabel.setText('Watchdog alert - ' + timestamp) w.messagelabel.setText(data[2]) elif data[0] == 'action': w.datelabel.setText('Watchdog action - ' + timestamp) w.messagelabel.setText('Executing action:\n' + data[2])