def __init__(self, parent): super().__init__() self.setWindowTitle("Flashing...") esptool.sw.read_start.connect(self.read_start) esptool.sw.read_progress.connect(self.read_progress) esptool.sw.read_finished.connect(self.read_finished) esptool.sw.erase_start.connect(self.erase_start) esptool.sw.erase_finished.connect(self.erase_finished) esptool.sw.write_start.connect(self.write_start) esptool.sw.write_progress.connect(self.write_progress) esptool.sw.write_finished.connect(self.write_finished) self.setFixedWidth(400) self.nrBinFile = QNetworkRequest() self.parent = parent vl = VLayout(10, 10) self.setLayout(vl) self.bin_data = b"" self.error_msg = None self.progress_task = QProgressBar() self.progress_task.setFixedHeight(45) self.task = QLabel() self.erase_timer = QTimer() self.erase_timer.setSingleShot(False) self.erase_timer.timeout.connect(self.erase_progress) self.btns = QDialogButtonBox(QDialogButtonBox.Abort) self.dlgText = QLabel( "Press the Boot button for a few seconds to start the flashing process" ) vl.addWidgets([self.dlgText, self.task, self.progress_task, self.btns]) self.btns.rejected.connect(self.abort) # process starts self.bin_file = parent.bin_file self.run_esptool()
def __init__(self, parent): super().__init__() self.setWindowTitle("Tasmotizing...") esptool.sw.read_start.connect(self.read_start) esptool.sw.read_progress.connect(self.read_progress) esptool.sw.read_finished.connect(self.read_finished) esptool.sw.erase_start.connect(self.erase_start) esptool.sw.erase_finished.connect(self.erase_finished) esptool.sw.write_start.connect(self.write_start) esptool.sw.write_progress.connect(self.write_progress) esptool.sw.write_finished.connect(self.write_finished) self.setFixedWidth(400) self.nrBinFile = QNetworkRequest() self.parent = parent vl = VLayout(10, 10) self.setLayout(vl) self.bin_data = b"" self.error_msg = None self.progress_task = QProgressBar() self.progress_task.setFixedHeight(45) self.task = QLabel() self.erase_timer = QTimer() self.erase_timer.setSingleShot(False) self.erase_timer.timeout.connect(self.erase_progress) self.btns = QDialogButtonBox(QDialogButtonBox.Abort) vl.addWidgets([ QLabel("Tasmotizing in progress..."), self.task, self.progress_task, self.btns ]) self.btns.rejected.connect(self.abort) # process starts if parent.mode in (1, 2): self.bin_file = parent.cbHackboxBin.currentData().split(";")[1] self.nrBinFile.setUrl( QUrl(parent.cbHackboxBin.currentData().split(";")[0])) self.bin_reply = parent.nam.get(self.nrBinFile) self.task.setText("Downloading binary from thehackbox.org...") self.bin_reply.readyRead.connect(self.appendBinFile) self.bin_reply.downloadProgress.connect(self.updateBinProgress) self.bin_reply.finished.connect(self.saveBinFile) else: self.bin_file = parent.bin_file self.run_esptool()
def create_ui(self): vl = VLayout(3) self.setLayout(vl) # Banner banner = QLabel() banner.setPixmap(QPixmap(':/banner.png')) vl.addWidget(banner) # Port groupbox gbPort = GroupBoxH('Selecionar porta', 3) self.cbxPort = QComboBox() pbRefreshPorts = QPushButton('Atualizar') gbPort.addWidget(self.cbxPort) gbPort.addWidget(pbRefreshPorts) gbPort.layout().setStretch(0, 4) gbPort.layout().setStretch(1, 1) # Buttons self.flash = QPushButton('Gravar firmware!') self.flash.setFixedHeight(60) self.flash.setStyleSheet('background-color: #0D2556;') hl_btns = HLayout([50, 3, 50, 3]) hl_btns.addWidgets([self.flash]) vl.addWidgets([gbPort]) vl.addLayout(hl_btns) pbRefreshPorts.clicked.connect(self.refreshPorts) self.flash.clicked.connect(self.start_process)
def __init__(self, port: QSerialPort): super(DeviceIP, self).__init__() self.setWindowTitle('Device IP address') self.setLayout(VLayout(10)) self.ip = QLineEdit() self.ip.setAlignment(Qt.AlignCenter) self.ip.setReadOnly(True) self.ip.setText('xx.xx.xx.xx') font = self.ip.font() font.setPointSize(24) self.ip.setFont(font) btn = QDialogButtonBox(QDialogButtonBox.Close) btn.rejected.connect(self.reject) self.layout().addWidgets([self.ip, btn]) self.data = b'' self.port = port self.re_ip = re.compile(r'(?:\()((?:[0-9]{1,3}\.){3}[0-9]{1,3})(?:\))') try: self.port.open(QIODevice.ReadWrite) self.port.readyRead.connect(self.read) self.port.write(bytes('IPAddress1\n', 'utf8')) except Exception as e: QMessageBox.critical(self, 'Error', f'Port access error:\n{e}')
def __init__(self, port, **kwargs): super().__init__() self.setWindowTitle('Preparando seu Satélite Educacional...') self.setFixedWidth(600) self.exception = None esptool.sw.progress.connect(self.update_progress) self.nam = QNetworkAccessManager() self.nrDownloads = 0 self.nrBinFile1 = QNetworkRequest() self.bin_data1 = b'' self.nrBinFile2 = QNetworkRequest() self.bin_data2 = b'' self.nrBinFile3 = QNetworkRequest() self.bin_data3 = b'' self.nrBinFile4 = QNetworkRequest() self.bin_data4 = b'' self.setLayout(VLayout(5, 5)) self.actions_layout = QFormLayout() self.actions_layout.setSpacing(5) self.layout().addLayout(self.actions_layout) self._actions = [] self._action_widgets = {} self.port = port self.file_path = kwargs.get('file_url') self.file_pathBoot = kwargs.get('file_urlBoot') self.file_pathBootloader = kwargs.get('file_urlBootloader') self.file_pathPart = kwargs.get('file_urlPart') self._actions.append('download') self.erase = kwargs.get('erase') if self.erase: self._actions.append('erase') if self.file_path: self._actions.append('write') self.create_ui() self.start_process()
def createUI(self): vl = VLayout() self.setLayout(vl) # Wifi groupbox self.gbWifi = QGroupBox("WiFi") self.gbWifi.setCheckable(False) flWifi = QFormLayout() self.leAP = QLineEdit() self.leAPPwd = QLineEdit() self.leAPPwd.setEchoMode(QLineEdit.Password) flWifi.addRow("SSID", self.leAP) flWifi.addRow("Password", self.leAPPwd) self.gbWifi.setLayout(flWifi) vl_wifis = VLayout(0) vl_wifis.addWidgets([self.gbWifi]) hl_wifis_mqtt = HLayout(0) hl_wifis_mqtt.addLayout(vl_wifis) vl.addLayout(hl_wifis_mqtt) btns = QDialogButtonBox(QDialogButtonBox.Save | QDialogButtonBox.Close) btns.accepted.connect(self.accept) btns.rejected.connect(self.reject) vl.addWidget(btns)
def __init__(self, port, **kwargs): super().__init__() self.setWindowTitle('Cooking your TinyGS station...') self.setFixedWidth(400) self.exception = None esptool.sw.progress.connect(self.update_progress) self.nam = QNetworkAccessManager() self.nrBinFile = QNetworkRequest() self.bin_data = b'' self.setLayout(VLayout(5, 5)) self.actions_layout = QFormLayout() self.actions_layout.setSpacing(5) self.layout().addLayout(self.actions_layout) self._actions = [] self._action_widgets = {} self.port = port self.auto_reset = kwargs.get('auto_reset', False) self.file_path = kwargs.get('file_path') if self.file_path and self.file_path.startswith('http'): self._actions.append('download') self.backup = kwargs.get('backup') if self.backup: self._actions.append('backup') self.backup_size = kwargs.get('backup_size') self.erase = kwargs.get('erase') if self.erase: self._actions.append('erase') if self.file_path: self._actions.append('write') self.create_ui() self.start_process()
def createUI(self): vl = VLayout() self.setLayout(vl) # Port groupbox gbPort = GroupBoxH("Select port", 3) self.cbxPort = QComboBox() pbRefreshPorts = QPushButton("Refresh") gbPort.addWidget(self.cbxPort) gbPort.addWidget(pbRefreshPorts) gbPort.layout().setStretch(0, 4) gbPort.layout().setStretch(1, 1) # Firmware groupbox gbFW = GroupBoxV("Select image", 3) self.wFile = QWidget() hl_file = HLayout(0) self.file = QLineEdit() self.file.setReadOnly(True) self.file.setText(self.bin_file) pbFile = QPushButton("Open") hl_file.addWidgets([self.file, pbFile]) self.wFile.setLayout(hl_file) gbFW.addWidgets([self.wFile]) # Buttons self.pbFlash = QPushButton("Flash!") self.pbFlash.setFixedHeight(50) self.pbFlash.setStyleSheet("background-color: #223579;") self.pbConfig = QPushButton("Setup WIFI") self.pbConfig.setStyleSheet("background-color: #571054;") self.pbConfig.setFixedHeight(50) self.pbQuit = QPushButton("Quit") self.pbQuit.setStyleSheet("background-color: #c91017;") self.pbQuit.setFixedSize(QSize(50, 50)) hl_btns = HLayout([50, 3, 50, 3]) hl_btns.addWidgets([self.pbFlash, self.pbConfig, self.pbQuit]) vl.addWidgets([gbPort, gbFW]) vl.addLayout(hl_btns) pbRefreshPorts.clicked.connect(self.refreshPorts) pbFile.clicked.connect(self.openBinFile) self.pbFlash.clicked.connect(self.start_process) self.pbConfig.clicked.connect(self.send_config) self.pbQuit.clicked.connect(self.reject)
def createUI(self): vl = VLayout() self.setLayout(vl) # Banner banner = QLabel() banner.setPixmap(QPixmap(":/banner.png")) vl.addWidget(banner) # Port groupbox gbPort = GroupBoxH("Select port", 3) self.cbxPort = QComboBox() pbRefreshPorts = QPushButton("Refresh") gbPort.addWidget(self.cbxPort) gbPort.addWidget(pbRefreshPorts) gbPort.layout().setStretch(0, 4) gbPort.layout().setStretch(1, 1) # Firmware groupbox gbFW = GroupBoxV("Select image", 3) hl_rb = HLayout(0) rbFile = QRadioButton("BIN file") self.rbRelease = QRadioButton("Release") self.rbRelease.setEnabled(False) self.rbDev = QRadioButton("Development") self.rbDev.setEnabled(False) rbgFW = QButtonGroup(gbFW) rbgFW.addButton(rbFile, 0) rbgFW.addButton(self.rbRelease, 1) rbgFW.addButton(self.rbDev, 2) hl_rb.addWidgets([rbFile, self.rbRelease, self.rbDev]) gbFW.addLayout(hl_rb) self.wFile = QWidget() hl_file = HLayout(0) self.file = QLineEdit() self.file.setReadOnly(True) self.file.setPlaceholderText("Click 'Open' to select the image") pbFile = QPushButton("Open") hl_file.addWidgets([self.file, pbFile]) self.wFile.setLayout(hl_file) self.cbHackboxBin = QComboBox() self.cbHackboxBin.setVisible(False) self.cbHackboxBin.setEnabled(False) self.cbBackup = QCheckBox("Backup original firmware") self.cbBackup.setToolTip( "Firmware backup is ESPECIALLY recommended when you flash a Sonoff, Tuya, Shelly etc. for the first time.\nWithout a backup you won't be able to restore the original functionality." ) self.cbErase = QCheckBox("Erase before flashing") self.cbErase.setToolTip( "Erasing previous firmware ensures all flash regions are clean for Tasmota, which prevents many unexpected issues.\nIf unsure, leave enabled." ) self.cbErase.setChecked(True) gbFW.addWidgets( [self.wFile, self.cbHackboxBin, self.cbBackup, self.cbErase]) # Buttons self.pbTasmotize = QPushButton("Tasmotize!") self.pbTasmotize.setFixedHeight(50) self.pbTasmotize.setStyleSheet("background-color: #223579;") self.pbConfig = QPushButton("Send config") self.pbConfig.setStyleSheet("background-color: #571054;") self.pbConfig.setFixedHeight(50) self.pbQuit = QPushButton("Quit") self.pbQuit.setStyleSheet("background-color: #c91017;") self.pbQuit.setFixedSize(QSize(50, 50)) hl_btns = HLayout([50, 3, 50, 3]) hl_btns.addWidgets([self.pbTasmotize, self.pbConfig, self.pbQuit]) vl.addWidgets([gbPort, gbFW]) vl.addLayout(hl_btns) pbRefreshPorts.clicked.connect(self.refreshPorts) rbgFW.buttonClicked[int].connect(self.setBinMode) rbFile.setChecked(True) pbFile.clicked.connect(self.openBinFile) self.pbTasmotize.clicked.connect(self.start_process) self.pbConfig.clicked.connect(self.send_config) self.pbQuit.clicked.connect(self.reject)
def createUI(self): vl = VLayout() self.setLayout(vl) # Wifi groupbox self.gbWifi = QGroupBox("WiFi") self.gbWifi.setCheckable(True) self.gbWifi.setChecked(False) flWifi = QFormLayout() self.leAP = QLineEdit() self.leAPPwd = QLineEdit() self.leAPPwd.setEchoMode(QLineEdit.Password) flWifi.addRow("SSID", self.leAP) flWifi.addRow("Password", self.leAPPwd) self.gbWifi.setLayout(flWifi) # Recovery Wifi groupbox self.gbRecWifi = QGroupBox("Recovery WiFi") self.gbRecWifi.setCheckable(True) self.gbRecWifi.setChecked(False) flRecWifi = QFormLayout() lbRecAP = QLabel("Recovery") lbRecAP.setAlignment(Qt.AlignVCenter | Qt.AlignRight) lbRecAPPwd = QLabel("a1b2c3d4") lbRecAPPwd.setAlignment(Qt.AlignVCenter | Qt.AlignRight) flRecWifi.addRow("SSID", lbRecAP) flRecWifi.addRow("Password", lbRecAPPwd) self.gbRecWifi.setLayout(flRecWifi) vl_wifis = VLayout(0) vl_wifis.addWidgets([self.gbWifi, self.gbRecWifi]) # MQTT groupbox self.gbMQTT = QGroupBox("MQTT") self.gbMQTT.setCheckable(True) self.gbMQTT.setChecked(False) flMQTT = QFormLayout() self.leBroker = QLineEdit() self.sbPort = SpinBox() self.sbPort.setValue(1883) self.leTopic = QLineEdit() self.leTopic.setText("tasmota") self.leFullTopic = QLineEdit() self.leFullTopic.setText("%prefix%/%topic%/") self.leFriendlyName = QLineEdit() self.leMQTTUser = QLineEdit() self.leMQTTPass = QLineEdit() self.leMQTTPass.setEchoMode(QLineEdit.Password) flMQTT.addRow("Host", self.leBroker) flMQTT.addRow("Port", self.sbPort) flMQTT.addRow("Topic", self.leTopic) flMQTT.addRow("FullTopic", self.leFullTopic) flMQTT.addRow("FriendlyName", self.leFriendlyName) flMQTT.addRow("User [optional]", self.leMQTTUser) flMQTT.addRow("Password [optional]", self.leMQTTPass) self.gbMQTT.setLayout(flMQTT) # Module/template groupbox self.gbModule = GroupBoxV("Module/template") self.gbModule.setCheckable(True) self.gbModule.setChecked(False) hl_m_rb = HLayout() self.rbModule = QRadioButton("Module") self.rbModule.setChecked(True) self.rbTemplate = QRadioButton("Template") hl_m_rb.addWidgets([self.rbModule, self.rbTemplate]) self.rbgModule = QButtonGroup(self.gbModule) self.rbgModule.addButton(self.rbModule, 0) self.rbgModule.addButton(self.rbTemplate, 1) self.cbModule = QComboBox() for mod_id, mod_name in modules.items(): self.cbModule.addItem(mod_name, mod_id) self.leTemplate = QLineEdit() self.leTemplate.setPlaceholderText("Paste template string here") self.leTemplate.setVisible(False) self.gbModule.addLayout(hl_m_rb) self.gbModule.addWidgets([self.cbModule, self.leTemplate]) self.rbgModule.buttonClicked[int].connect(self.setModuleMode) # layout all widgets hl_wifis_mqtt = HLayout(0) hl_wifis_mqtt.addLayout(vl_wifis) hl_wifis_mqtt.addWidget(self.gbMQTT) vl.addLayout(hl_wifis_mqtt) vl.addWidget(self.gbModule) btns = QDialogButtonBox(QDialogButtonBox.Save | QDialogButtonBox.Close) btns.accepted.connect(self.accept) btns.rejected.connect(self.reject) vl.addWidget(btns)
def create_ui(self): vl = VLayout(5) self.setLayout(vl) # Banner banner = QLabel() banner.setPixmap(QPixmap(':/banner.png')) vl.addWidget(banner) # Port groupbox gbPort = GroupBoxH('Select port', 3) self.cbxPort = QComboBox() pbRefreshPorts = QPushButton('Refresh') gbPort.addWidget(self.cbxPort) gbPort.addWidget(pbRefreshPorts) gbPort.layout().setStretch(0, 4) gbPort.layout().setStretch(1, 1) # Firmware groupbox gbFW = GroupBoxV('Select image', 3) hl_rb = HLayout(0) rbFile = QRadioButton('BIN file') self.rbRelease = QRadioButton('Release') self.rbRelease.setEnabled(False) self.rbDev = QRadioButton('Development') self.rbDev.setEnabled(False) self.rbgFW = QButtonGroup(gbFW) self.rbgFW.addButton(rbFile, 0) self.rbgFW.addButton(self.rbRelease, 1) self.rbgFW.addButton(self.rbDev, 2) hl_rb.addWidgets([rbFile, self.rbRelease, self.rbDev]) gbFW.addLayout(hl_rb) self.wFile = QWidget() hl_file = HLayout(0) self.file = QLineEdit() self.file.setReadOnly(True) self.file.setPlaceholderText('Click "Open" to select the image') pbFile = QPushButton('Open') hl_file.addWidgets([self.file, pbFile]) self.wFile.setLayout(hl_file) self.cbHackboxBin = QComboBox() self.cbHackboxBin.setVisible(False) self.cbHackboxBin.setEnabled(False) self.cbSelfReset = QCheckBox('Self-resetting device (NodeMCU, Wemos)') self.cbSelfReset.setToolTip( 'Check if your device has self-resetting capabilities supported by esptool' ) gbBackup = GroupBoxV('Backup') self.cbBackup = QCheckBox('Save original firmware') self.cbBackup.setToolTip( 'Firmware backup is ESPECIALLY recommended when you flash a Sonoff, Tuya, Shelly etc. for the first time.\nWithout a backup you will not be able to restore the original functionality.' ) self.cbxBackupSize = QComboBox() self.cbxBackupSize.addItems([f'{2 ** s}MB' for s in range(5)]) self.cbxBackupSize.setEnabled(False) hl_backup_size = HLayout(0) hl_backup_size.addWidgets([QLabel('Flash size:'), self.cbxBackupSize]) hl_backup_size.setStretch(0, 3) hl_backup_size.setStretch(1, 1) gbBackup.addWidget(self.cbBackup) gbBackup.addLayout(hl_backup_size) self.cbErase = QCheckBox('Erase before flashing') self.cbErase.setToolTip( 'Erasing previous firmware ensures all flash regions are clean for Tasmota, which prevents many unexpected issues.\nIf unsure, leave enabled.' ) self.cbErase.setChecked(True) gbFW.addWidgets( [self.wFile, self.cbHackboxBin, self.cbSelfReset, self.cbErase]) # Buttons self.pbTasmotize = QPushButton('Upload tinyGS firmware!') self.pbTasmotize.setFixedHeight(50) self.pbTasmotize.setStyleSheet('background-color: #223579;') self.pbConfig = QPushButton('Send config') self.pbConfig.setStyleSheet('background-color: #571054;') self.pbConfig.setFixedHeight(50) self.pbGetIP = QPushButton('Get IP') self.pbGetIP.setFixedSize(QSize(75, 50)) self.pbGetIP.setStyleSheet('background-color: #2a8a26;') self.pbQuit = QPushButton('Quit') self.pbQuit.setStyleSheet('background-color: #c91017;') self.pbQuit.setFixedSize(QSize(50, 50)) hl_btns = HLayout([50, 3, 50, 3]) hl_btns.addWidgets([self.pbTasmotize]) vl.addWidgets([gbPort]) vl.addLayout(hl_btns) pbRefreshPorts.clicked.connect(self.refreshPorts) self.rbgFW.buttonClicked[int].connect(self.setBinMode) rbFile.setChecked(True) pbFile.clicked.connect(self.openBinFile) self.cbBackup.toggled.connect(self.cbxBackupSize.setEnabled) self.pbTasmotize.clicked.connect(self.start_process) self.pbConfig.clicked.connect(self.send_config) self.pbGetIP.clicked.connect(self.get_ip) self.pbQuit.clicked.connect(self.reject)