def __init__(self, device, *args, **kwargs): super(GPIODialog, self).__init__(*args, **kwargs) self.setWindowTitle("GPIO [{}]".format(device.p['FriendlyName1'])) self.setMinimumWidth(300) self.device = device self.gb = {} btns = QDialogButtonBox(QDialogButtonBox.Close) btns.rejected.connect(self.reject) gbxGPIO = QGroupBox("Select GPIO") fl = QFormLayout() if self.device.gpio: btns.addButton(QDialogButtonBox.Save) btns.accepted.connect(self.accept) for gp_name, gp_id in self.device.gpio.items(): gb = DictComboBox(self.device.gpios) gb.setCurrentText(self.device.gpios[gp_id]) self.gb[gp_name] = gb fl.addRow(gp_name, gb) else: fl.addWidget(QLabel("No configurable GPIOs")) gbxGPIO.setLayout(fl) vl = VLayout() vl.addWidgets([gbxGPIO, btns]) self.setLayout(vl)
class ModuleDialog(QDialog): sendCommand = pyqtSignal(str, str) def __init__(self, device, *args, **kwargs): super(ModuleDialog, self).__init__(*args, **kwargs) self.setWindowTitle("Module [{}]".format(device.name)) self.setMinimumWidth(300) self.device = device btns = QDialogButtonBox(QDialogButtonBox.Save | QDialogButtonBox.Close) btns.accepted.connect(self.accept) btns.rejected.connect(self.reject) gbxModules = GroupBoxV("Select Module") self.gb = DictComboBox(self.device.modules) self.gb.setCurrentText(self.device.modules[str(self.device.p['Module'])]) gbxModules.addWidget(self.gb) vl = VLayout() vl.addWidgets([gbxModules, btns]) self.setLayout(vl) def accept(self): self.sendCommand.emit(self.device.cmnd_topic("module"), self.gb.currentData()) QMessageBox.information(self, "Module saved", "Device will restart.") self.done(QDialog.Accepted)
def __init__(self, device, *args, **kwargs): super(TemplateDialog, self).__init__(*args, **kwargs) self.setWindowTitle("Template [{}]".format(device.p['FriendlyName1'])) self.setMinimumWidth(300) self.device = device self.gb = {} gpios = {"255": "User"} gpios.update(self.device.gpios) btns = QDialogButtonBox(QDialogButtonBox.Cancel) btns.rejected.connect(self.reject) gbxTmpl = QGroupBox("Configure template") fl = QFormLayout() if self.device.p['Template']: btns.addButton(QDialogButtonBox.Save) btns.accepted.connect(self.accept) tpl = self.device.p['Template'] print(tpl) self.leName = QLineEdit() self.leName.setMaxLength(14) self.leName.setText(tpl['NAME']) fl.addRow("Name", self.leName) self.gbxBase = DictComboBox(self.device.modules) self.gbxBase.setCurrentText(self.device.modules[str(tpl['BASE'])]) fl.addRow("Based on", self.gbxBase) for i, g in enumerate( [0, 1, 2, 3, 4, 5, 9, 10, 12, 13, 14, 15, 16]): gbx = DictComboBox(gpios) gbx.setCurrentText(gpios.get(str(tpl['GPIO'][i]))) fl.addRow( "<font color='{}'>GPIO{}</font>".format( 'red' if g in [9, 10] else 'black', g), gbx) self.gb[i] = gbx self.gbxADC = DictComboBox(template_adc) fl.addRow("ADC0", self.gbxADC) else: fl.addWidget( QLabel( "Templates not supported.\nUpgrade firmware to versions above 6.5" )) gbxTmpl.setLayout(fl) vl = VLayout() vl.addWidgets([gbxTmpl, btns]) self.setLayout(vl)
class TemplateDialog(QDialog): sendCommand = pyqtSignal(str, str) def __init__(self, device, *args, **kwargs): super(TemplateDialog, self).__init__(*args, **kwargs) self.setWindowTitle("Template [{}]".format(device.p['FriendlyName1'])) self.setMinimumWidth(300) self.device = device self.gb = {} gpios = {"255": "User"} gpios.update(self.device.gpios) btns = QDialogButtonBox(QDialogButtonBox.Cancel) btns.rejected.connect(self.reject) gbxTmpl = QGroupBox("Configure template") fl = QFormLayout() if self.device.p['Template']: btns.addButton(QDialogButtonBox.Save) btns.accepted.connect(self.accept) tpl = self.device.p['Template'] print(tpl) self.leName = QLineEdit() self.leName.setMaxLength(14) self.leName.setText(tpl['NAME']) fl.addRow("Name", self.leName) self.gbxBase = DictComboBox(self.device.modules) self.gbxBase.setCurrentText(self.device.modules[str(tpl['BASE'])]) fl.addRow("Based on", self.gbxBase) for i, g in enumerate( [0, 1, 2, 3, 4, 5, 9, 10, 12, 13, 14, 15, 16]): gbx = DictComboBox(gpios) gbx.setCurrentText(gpios.get(str(tpl['GPIO'][i]))) fl.addRow( "<font color='{}'>GPIO{}</font>".format( 'red' if g in [9, 10] else 'black', g), gbx) self.gb[i] = gbx self.gbxADC = DictComboBox(template_adc) fl.addRow("ADC0", self.gbxADC) else: fl.addWidget( QLabel( "Templates not supported.\nUpgrade firmware to versions above 6.5" )) gbxTmpl.setLayout(fl) vl = VLayout() vl.addWidgets([gbxTmpl, btns]) self.setLayout(vl) def accept(self): payload = { "NAME": self.leName.text(), "GPIO": [int(gpio.currentData()) for gpio in self.gb.values()], "FLAG": int(self.gbxADC.currentData()), "BASE": int(self.gbxBase.currentData()), } self.sendCommand.emit(self.device.cmnd_topic("template"), dumps(payload)) self.sendCommand.emit(self.device.cmnd_topic("modules"), "") QMessageBox.information(self, "Template saved", "Template configuration saved.") self.done(QDialog.Accepted)