コード例 #1
0
class BrokerDialog(QDialog):
    def __init__(self, *args, **kwargs):
        super(BrokerDialog, self).__init__(*args, **kwargs)

        self.setWindowTitle("MQTT Broker")

        self.settings = QSettings("{}/TDM/tdm.cfg".format(QDir.homePath()),
                                  QSettings.IniFormat)

        gbHost = QGroupBox("Hostname and port")
        hfl = QFormLayout()
        self.hostname = QLineEdit()
        self.hostname.setText(self.settings.value("hostname", "localhost"))
        self.port = SpinBox(maximum=65535)
        self.port.setValue(self.settings.value("port", 1883, int))
        hfl.addRow("Hostname", self.hostname)
        hfl.addRow("Port", self.port)
        gbHost.setLayout(hfl)

        gbLogin = QGroupBox("Credentials [optional]")
        lfl = QFormLayout()
        self.username = QLineEdit()
        self.username.setText(self.settings.value("username", ""))
        self.password = QLineEdit()
        self.password.setEchoMode(QLineEdit.PasswordEchoOnEdit)
        self.password.setText(self.settings.value("password", ""))
        lfl.addRow("Username", self.username)
        lfl.addRow("Password", self.password)
        gbLogin.setLayout(lfl)

        self.cbConnectStartup = QCheckBox("Connect on startup")
        self.cbConnectStartup.setChecked(
            self.settings.value("connect_on_startup", False, bool))

        hlBtn = HLayout()
        btnSave = QPushButton("Save")
        btnCancel = QPushButton("Cancel")
        hlBtn.addWidgets([btnSave, btnCancel])

        vl = VLayout()
        vl.addWidgets([gbHost, gbLogin, self.cbConnectStartup])
        vl.addLayout(hlBtn)

        self.setLayout(vl)

        btnSave.clicked.connect(self.accept)
        btnCancel.clicked.connect(self.reject)

    def accept(self):
        self.settings.setValue("hostname", self.hostname.text())
        self.settings.setValue("port", self.port.value())
        self.settings.setValue("username", self.username.text())
        self.settings.setValue("password", self.password.text())
        self.settings.setValue("connect_on_startup",
                               self.cbConnectStartup.isChecked())
        self.settings.sync()
        self.done(QDialog.Accepted)
コード例 #2
0
class PrefsDialog(QDialog):
    def __init__(self, *args, **kwargs):
        super(PrefsDialog, self).__init__(*args, **kwargs)
        self.setWindowTitle("Preferences")
        # self.setMinimumSize(QSize(300, 200))

        self.settings = QSettings("{}/TDM/tdm.cfg".format(QDir.homePath()),
                                  QSettings.IniFormat)

        self.devices_short_version = self.settings.value(
            "devices_short_version", True, bool)

        self.console_word_wrap = self.settings.value("console_word_wrap", True,
                                                     bool)
        self.console_font_size = self.settings.value("console_font_size", 9,
                                                     int)

        vl = VLayout()

        gbDevices = QGroupBox("Device list")
        fl_dev = QFormLayout()

        self.cbDevShortVersion = QCheckBox()
        self.cbDevShortVersion.setChecked(self.devices_short_version)

        fl_dev.addRow("Show short Tasmota version", self.cbDevShortVersion)

        fl_dev.setAlignment(self.cbDevShortVersion,
                            Qt.AlignTop | Qt.AlignRight)

        gbDevices.setLayout(fl_dev)

        gbConsole = QGroupBox("Console")
        fl_cons = QFormLayout()

        self.cbConsWW = QCheckBox()
        self.cbConsWW.setChecked(self.console_word_wrap)

        self.sbConsFontSize = SpinBox(minimum=9, maximum=100)
        self.sbConsFontSize.setValue(self.console_font_size)

        gbConsole.setLayout(fl_cons)

        fl_cons.addRow("Word wrap", self.cbConsWW)
        fl_cons.addRow("Font size", self.sbConsFontSize)

        fl_cons.setAlignment(self.cbConsWW, Qt.AlignTop | Qt.AlignRight)
        fl_cons.setAlignment(self.sbConsFontSize, Qt.AlignTop | Qt.AlignRight)

        btns = QDialogButtonBox(QDialogButtonBox.Save | QDialogButtonBox.Close)
        btns.accepted.connect(self.accept)
        btns.rejected.connect(self.reject)

        vl.addWidgets([gbDevices, gbConsole, btns])

        self.setLayout(vl)
コード例 #3
0
    def __init__(self, *args, **kwargs):
        super(BrokerDialog, self).__init__(*args, **kwargs)

        self.setWindowTitle("MQTT Broker")

        self.settings = QSettings()

        gbHost = QGroupBox("Hostname and port")
        hfl = QFormLayout()
        self.hostname = QLineEdit()
        self.hostname.setText(self.settings.value("hostname", "localhost"))
        self.port = SpinBox(maximum=65535)
        self.port.setValue(self.settings.value("port", 1883, int))
        hfl.addRow("Hostname", self.hostname)
        hfl.addRow("Port", self.port)
        gbHost.setLayout(hfl)

        gbLogin = QGroupBox("Credentials [optional]")
        lfl = QFormLayout()
        self.username = QLineEdit()
        self.username.setText(self.settings.value("username", ""))
        self.password = QLineEdit()
        self.password.setEchoMode(QLineEdit.PasswordEchoOnEdit)
        self.password.setText(self.settings.value("password", ""))
        lfl.addRow("Username", self.username)
        lfl.addRow("Password", self.password)
        gbLogin.setLayout(lfl)

        hlBtn = HLayout()
        btnSave = QPushButton("Save")
        btnCancel = QPushButton("Cancel")
        hlBtn.addWidgets([btnSave, btnCancel])

        vl = VLayout()
        vl.addWidgets([gbHost, gbLogin])
        vl.addLayout(hlBtn)

        self.setLayout(vl)

        btnSave.clicked.connect(self.accept)
        btnCancel.clicked.connect(self.reject)
コード例 #4
0
ファイル: DeviceConfig.py プロジェクト: rodcnx/tdm
    def tabRules(self):
        rules = QWidget()
        rules.setLayout(VLayout())
        hl = HLayout(0)
        vl_l = VLayout(0)
        self.rg = RuleGroupBox(rules, "Rule editor")
        self.rg.setFlat(True)
        self.rg.cbRule.currentIndexChanged.connect(self.loadRule)
        vl_l.addWidget(self.rg)

        gRT = GroupBoxH("Rule timers")
        vl_RT_func = VLayout(margin=[0, 0, 3, 0])
        self.pbRTPoll = QPushButton("Poll")
        self.pbRTPoll.setCheckable(True)
        self.pbRTSet = QPushButton("Set")

        vl_RT_func.addWidgets([self.pbRTPoll, self.pbRTSet])
        vl_RT_func.addStretch(1)
        gRT.layout().addLayout(vl_RT_func)

        self.twRT = QTableWidget(1, 8)
        self.twRT.setHorizontalHeaderLabels(
            ["T{}".format(i) for i in range(1, 9)])
        for c in range(8):
            self.twRT.horizontalHeader().setSectionResizeMode(
                c, QHeaderView.Stretch)
            self.twRT.setCellWidget(0, c, SpinBox(minimum=0, maximum=32766))
        self.twRT.verticalHeader().hide()

        self.twRT.verticalHeader().setDefaultSectionSize(
            self.twRT.horizontalHeader().height() * 2 + 1)
        self.twRT.setMaximumHeight(self.twRT.horizontalHeader().height() +
                                   self.twRT.rowHeight(0))
        gRT.layout().addWidget(self.twRT)

        gVM = GroupBoxH("VAR/MEM")
        vl_VM_func = VLayout(margin=[3, 0, 0, 0])
        self.pbVMPoll = QPushButton("Poll")
        self.pbVMPoll.setCheckable(True)
        self.pbVMSet = QPushButton("Set")

        vl_VM_func.addWidgets([self.pbVMPoll, self.pbVMSet])
        vl_VM_func.addStretch(1)
        gVM.layout().addLayout(vl_VM_func)

        self.twVM = QTableWidget(2, 5)
        self.twVM.setHorizontalHeaderLabels(
            ["{}".format(i) for i in range(1, 9)])
        self.twVM.setVerticalHeaderLabels(["VAR", "MEM"])
        self.twVM.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        for c in range(5):
            self.twVM.horizontalHeader().setSectionResizeMode(
                c, QHeaderView.Stretch)

        for r in range(2):
            for c in range(5):
                self.twVM.setCellWidget(r, c, QLineEdit())

        self.twVM.verticalHeader().setDefaultSectionSize(
            self.twVM.horizontalHeader().height())
        self.twVM.setMaximumHeight(self.twVM.horizontalHeader().height() +
                                   self.twVM.rowHeight(0) * 2)
        gVM.layout().addWidget(self.twVM)

        hl_rt_vm = HLayout(0)
        hl_rt_vm.addWidgets([gRT, gVM])

        hl.addLayout(vl_l)

        vl_r = VLayout(0)
        self.gbTimers = GroupBoxV("Timers", spacing=5)
        self.gbTimers.setCheckable(True)
        self.gbTimers.setChecked(False)
        self.gbTimers.toggled.connect(self.toggleTimers)

        self.cbTimer = QComboBox()
        self.cbTimer.addItems(["Timer{}".format(nr + 1) for nr in range(16)])
        self.cbTimer.currentIndexChanged.connect(self.loadTimer)

        hl_tmr_arm_rpt = HLayout(0)
        self.cbTimerArm = QCheckBox("Arm")
        self.cbTimerArm.clicked.connect(lambda x: self.describeTimer())
        self.cbTimerRpt = QCheckBox("Repeat")
        self.cbTimerRpt.clicked.connect(lambda x: self.describeTimer())
        hl_tmr_arm_rpt.addWidgets([self.cbTimerArm, self.cbTimerRpt])

        hl_tmr_out_act = HLayout(0)
        self.cbxTimerOut = QComboBox()
        self.cbxTimerOut.currentIndexChanged.connect(
            lambda x: self.describeTimer())
        self.cbxTimerAction = QComboBox()
        self.cbxTimerAction.addItems(["Off", "On", "Toggle", "Rule"])
        self.cbxTimerAction.currentIndexChanged.connect(
            lambda x: self.describeTimer())
        hl_tmr_out_act.addWidgets([self.cbxTimerOut, self.cbxTimerAction])

        self.TimerMode = QButtonGroup()
        rbTime = QRadioButton("Time")
        rbSunrise = QRadioButton("Sunrise ({})")
        rbSunset = QRadioButton("Sunset ({})")
        self.TimerMode.addButton(rbTime, 0)
        self.TimerMode.addButton(rbSunrise, 1)
        self.TimerMode.addButton(rbSunset, 2)
        self.TimerMode.buttonClicked.connect(lambda x: self.describeTimer())
        gbTimerMode = GroupBoxH("Mode")
        gbTimerMode.addWidgets(self.TimerMode.buttons())

        hl_tmr_time = HLayout(0)
        self.cbxTimerPM = QComboBox()
        self.cbxTimerPM.addItems(["+", "-"])
        self.cbxTimerPM.currentIndexChanged.connect(
            lambda x: self.describeTimer())

        self.TimerMode.buttonClicked[int].connect(
            lambda x: self.cbxTimerPM.setEnabled(x != 0))
        self.teTimerTime = QTimeEdit()
        self.teTimerTime.setButtonSymbols(QTimeEdit.NoButtons)
        self.teTimerTime.setAlignment(Qt.AlignCenter)
        self.teTimerTime.timeChanged.connect(lambda x: self.describeTimer())

        lbWnd = QLabel("Window:")
        lbWnd.setAlignment(Qt.AlignVCenter | Qt.AlignRight)
        self.cbxTimerWnd = QComboBox()
        self.cbxTimerWnd.addItems([str(x).zfill(2) for x in range(0, 16)])
        self.cbxTimerWnd.currentIndexChanged.connect(
            lambda x: self.describeTimer())

        hl_tmr_days = HLayout(0)
        self.TimerWeekday = QButtonGroup()
        self.TimerWeekday.setExclusive(False)
        for i, wd in enumerate(
            ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]):
            cb = QCheckBox(wd)
            cb.clicked.connect(lambda x: self.describeTimer())
            hl_tmr_days.addWidget(cb)
            self.TimerWeekday.addButton(cb, i)

        gbTimerDesc = GroupBoxV("Timer description", 5)
        gbTimerDesc.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Expanding)
        self.lbTimerDesc = QLabel()
        self.lbTimerDesc.setAlignment(Qt.AlignCenter)
        self.lbTimerDesc.setWordWrap(True)
        gbTimerDesc.layout().addWidget(self.lbTimerDesc)
        hl_tmr_btns = HLayout(0)
        btnCopyTrigger = QPushButton("Copy trigger")
        btnTimerSave = QPushButton("Save")
        hl_tmr_btns.addWidgets([btnCopyTrigger, btnTimerSave])
        hl_tmr_btns.insertStretch(1)

        btnTimerSave.clicked.connect(self.saveTimer)
        btnCopyTrigger.clicked.connect(self.copyTrigger)

        hl_tmr_time.addWidgets(
            [self.cbxTimerPM, self.teTimerTime, lbWnd, self.cbxTimerWnd])

        self.gbTimers.layout().addWidget(self.cbTimer)
        self.gbTimers.layout().addLayout(hl_tmr_arm_rpt)
        self.gbTimers.layout().addLayout(hl_tmr_out_act)
        self.gbTimers.layout().addWidget(gbTimerMode)
        self.gbTimers.layout().addLayout(hl_tmr_time)
        self.gbTimers.layout().addLayout(hl_tmr_days)
        self.gbTimers.layout().addWidget(gbTimerDesc)
        self.gbTimers.layout().addLayout(hl_tmr_btns)

        vl_r.addWidget(self.gbTimers)

        hl.addLayout(vl_r)
        hl.setStretch(0, 2)
        hl.setStretch(1, 1)

        rules.layout().addLayout(hl)
        rules.layout().addLayout(hl_rt_vm)
        rules.layout().setStretch(0, 3)
        rules.layout().setStretch(1, 0)

        return rules
コード例 #5
0
    def tabRules(self):
        rules = QWidget()
        rules.setLayout(VLayout())

        for r in range(3):
            rg = RuleGroupBox(rules, "Rule buffer {}".format(r + 1))
            rg.pbLoad.clicked.connect(lambda x, r=r + 1: self.loadRule(r))
            self.rule_grps.append(rg)
            rules.layout().addWidget(rg)
            rules.layout().setStretch(r, 1)

        gRT = GroupBoxH("Rule timers")
        vl_RT_func = VLayout(margin=[0, 0, 3, 0])
        self.pbRTPoll = QPushButton("Poll")
        self.pbRTPoll.setCheckable(True)
        self.pbRTSet = QPushButton("Set")

        vl_RT_func.addWidgets([self.pbRTPoll, self.pbRTSet])
        vl_RT_func.addStretch(1)
        gRT.layout().addLayout(vl_RT_func)

        self.twRT = QTableWidget(1, 8)
        self.twRT.setHorizontalHeaderLabels(
            ["T{}".format(i) for i in range(1, 9)])
        for c in range(8):
            self.twRT.horizontalHeader().setSectionResizeMode(
                c, QHeaderView.Stretch)
            self.twRT.setCellWidget(0, c, SpinBox(minimum=0, maximum=32766))
        self.twRT.verticalHeader().hide()

        self.twRT.verticalHeader().setDefaultSectionSize(
            self.twRT.horizontalHeader().height() * 2 + 1)
        self.twRT.setMaximumHeight(self.twRT.horizontalHeader().height() +
                                   self.twRT.rowHeight(0))
        gRT.layout().addWidget(self.twRT)

        gVM = GroupBoxH("VAR/MEM")
        vl_VM_func = VLayout(margin=[3, 0, 0, 0])
        self.pbVMPoll = QPushButton("Poll")
        self.pbVMPoll.setCheckable(True)
        self.pbVMSet = QPushButton("Set")

        vl_VM_func.addWidgets([self.pbVMPoll, self.pbVMSet])
        vl_VM_func.addStretch(1)
        gVM.layout().addLayout(vl_VM_func)

        self.twVM = QTableWidget(2, 5)
        self.twVM.setHorizontalHeaderLabels(
            ["{}".format(i) for i in range(1, 9)])
        self.twVM.setVerticalHeaderLabels(["VAR", "MEM"])
        self.twVM.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        for c in range(5):
            self.twVM.horizontalHeader().setSectionResizeMode(
                c, QHeaderView.Stretch)

        for r in range(2):
            for c in range(5):
                self.twVM.setCellWidget(r, c, QLineEdit())

        self.twVM.verticalHeader().setDefaultSectionSize(
            self.twVM.horizontalHeader().height())
        self.twVM.setMaximumHeight(self.twVM.horizontalHeader().height() +
                                   self.twVM.rowHeight(0) * 2)
        gVM.layout().addWidget(self.twVM)

        hl_rt_vm = HLayout()
        hl_rt_vm.addWidgets([gRT, gVM])
        rules.layout().addLayout(hl_rt_vm)
        rules.layout().setStretch(3, 0)

        return rules