From 2f4c3103b8588f756e4b08cc837e0d645177ab3a Mon Sep 17 00:00:00 2001 From: BlueFox Date: Sat, 17 May 2025 14:49:04 +0200 Subject: [PATCH] Added options for single actions, saving config now, some backend improvements --- tasmotonov-gui.py | 118 ++++++++++++++++++++++++++++++++++------ tasmotonov.ui | 133 +++++++++++++++++++++++++++++++++++----------- 2 files changed, 206 insertions(+), 45 deletions(-) diff --git a/tasmotonov-gui.py b/tasmotonov-gui.py index 8d9320e..c4118f1 100755 --- a/tasmotonov-gui.py +++ b/tasmotonov-gui.py @@ -1,40 +1,113 @@ #!/usr/bin/python3 import sys -import subprocess +import tasmotonov +import configparser from PySide6.QtUiTools import QUiLoader from PySide6.QtWidgets import QApplication,QFileDialog from PySide6.QtCore import QFile, QUrl, QIODevice +# set some standard values filename = "" action = "toggle" -def tab1_load_file(): +def load_config(file="config.ini"): # load config from configparser.ConfigParser object + to_load = configparser.ConfigParser() + to_load.read(file) + global filename, action + if "DEFAULT" in to_load: + if "file" in to_load['DEFAULT']: + filename = to_load['DEFAULT']['file'] + if filename != "": + tab1_load_file() + if "inline" in to_load['DEFAULT']: + window.tab2_plainTextEdit.setPlainText(to_load['DEFAULT']['inline']) + if "action" in to_load['DEFAULT']: + a_new = to_load['DEFAULT']['action'] + if a_new != "": + action = a_new + # else: no config there yet +def save_config(file="config.ini"): + window.tab3_textBrowser.append("Saving configuration!") + global filename, action + to_save = configparser.ConfigParser() + to_save['DEFAULT'] = {} + to_save['DEFAULT']['file'] = str(filename) + to_save['DEFAULT']['inline'] = str(window.tab2_plainTextEdit.toPlainText()) + to_save['DEFAULT']['action'] = str(action) + with open(file, 'w') as configfile: + to_save.write(configfile) + +# tab1 slots +def tab1_load_file_pressed(): global filename dialog = QFileDialog() dialog.setFileMode(QFileDialog.AnyFile) - #fileNames = QStringList() if dialog.exec(): filename = dialog.selectedFiles()[0] - window.tab1_label.setText(f"File loaded: {filename}") - window.tab1_label.show() - window.tab1_filecontent_textBrowser.setSource(QUrl(filename)) + tab1_load_file() +def tab1_load_file(): + global filename + window.tab1_label.setText(f"File loaded: {filename}") + window.tab3_textBrowser.append(f"File loaded: {filename}") + window.tab1_label.show() + window.tab1_filecontent_textBrowser.setSource(QUrl(filename)) + window.tab1_label_help.show() + # clear listWidget and add the items + window.tab1_listWidget.clear() + window.tab1_listWidget.addItems(tasmotonov.TasmotonovRunner("file", filename, action, False, False).get_addresses()) +def tab1_clear(): + global filename + filename = "" + window.tab1_label.setText(f"File loaded: ") + window.tab3_textBrowser.append(f"File unloaded") + window.tab1_label.hide() + window.tab1_label_help.hide() + window.tab1_filecontent_textBrowser.clear() + window.tab1_listWidget.clear() def tab1_action(): if filename != "": - p = subprocess.Popen(["python3", "tasmotonov.py", "file", filename, action], stdout=subprocess.PIPE) - out, err = p.communicate() - window.tab3_textBrowser.append("==== RUNNING ====\n" + str(out) + "\n=================\n") + tasmotonov_runner = tasmotonov.TasmotonovRunner("file", filename, action, False, False) + tasmotonov_runner.run() + window.tab3_textBrowser.append("\n==== RUNNING ====\n\n" + str(tasmotonov_runner.logger.log_string) + "\n=================\n") + tasmotonov_runner.logger.log_string = "" else: window.tab3_textBrowser.append("Will not run, no file selected!") +def tab1_single_action(): + if filename != "": + tasmotonov_runner = tasmotonov.TasmotonovRunner("file", filename, action, False, False) + tasmotonov_runner.run_single(window.tab1_listWidget.currentRow()) + window.tab3_textBrowser.append(str(tasmotonov_runner.logger.log_string)) + +# tab2 slots +def tab2_plainTextEdit_change(): + # clear listWidget + window.tab2_listWidget.clear() + content = window.tab2_plainTextEdit.toPlainText() + if content != "": + tasmotonov_runner = tasmotonov.TasmotonovRunner("inline", content, action, False, False) + window.tab2_listWidget.addItems(tasmotonov_runner.get_addresses()) + window.tab3_textBrowser.append(str(tasmotonov_runner.logger.log_string)) def tab2_action(): content = window.tab2_plainTextEdit.toPlainText() if content != "": - p = subprocess.Popen(["python3", "tasmotonov.py", "inline", content, action], stdout=subprocess.PIPE) - out, err = p.communicate() - window.tab3_textBrowser.append("==== RUNNING ====\n" + str(out) + "\n=================\n") - print(out) + tasmotonov_runner = tasmotonov.TasmotonovRunner("inline", content, action, False, False) + tasmotonov_runner.run() + window.tab3_textBrowser.append("\n==== RUNNING ====\n\n" + str(tasmotonov_runner.logger.log_string) + "\n=================\n") else: window.tab3_textBrowser.append("Will not run, no input given!") +def tab2_single_action(): + content = window.tab2_plainTextEdit.toPlainText() + tasmotonov_runner = tasmotonov.TasmotonovRunner("inline", content, action, False, False) + if len(tasmotonov_runner.get_addresses()) != 0: + tasmotonov_runner.run_single(window.tab2_listWidget.currentRow()) + window.tab3_textBrowser.append(str(tasmotonov_runner.logger.log_string)) + +# tab3 slots +def tab3_clear(): + window.tab3_textBrowser.clear() + +# other slots def select_on(): global action action = "on" @@ -64,14 +137,29 @@ if __name__ == "__main__": sys.exit(-1) window.tab1_label.hide() - window.tab1_load_file_pushButton.clicked.connect(tab1_load_file) + window.tab1_label_help.hide() + + window.tab1_load_file_pushButton.clicked.connect(tab1_load_file_pressed) + window.tab1_clear_pushButton.clicked.connect(tab1_clear) window.tab1_action_pushButton.clicked.connect(tab1_action) + window.tab1_single_action_pushButton.clicked.connect(tab1_single_action) + + window.tab2_plainTextEdit.textChanged.connect(tab2_plainTextEdit_change) window.tab2_action_pushButton.clicked.connect(tab2_action) + window.tab2_single_action_pushButton.clicked.connect(tab2_single_action) + window.radioButton_on.clicked.connect(select_on) window.radioButton_off.clicked.connect(select_off) window.radioButton_toggle.clicked.connect(select_toggle) + + window.tab3_clear_button.clicked.connect(tab3_clear) + + load_config() window.show() - sys.exit(app.exec()) + # execute app loop and define exit strategy + code = app.exec() + save_config() + sys.exit(code) diff --git a/tasmotonov.ui b/tasmotonov.ui index 2de2aab..8637c0b 100644 --- a/tasmotonov.ui +++ b/tasmotonov.ui @@ -6,8 +6,8 @@ 0 0 - 630 - 404 + 1166 + 546 @@ -20,8 +20,8 @@ QTabWidget::TabShape::Rounded - - + + QTabWidget::TabPosition::East @@ -30,7 +30,7 @@ QTabWidget::TabShape::Rounded - 1 + 0 true @@ -40,20 +40,37 @@ - From File + Bulk From File - - - - QFrame::Shadow::Sunken + + + + + 414 + 0 + - - true + + Run bulk action (specified below) - + + + + Run single action (specified below) + + + + + + + Select an item and run an action: + + + + true @@ -69,28 +86,77 @@ - - - - Run! + + + + + 0 + 0 + + + + + 414 + 0 + + + + QFrame::Shadow::Sunken + + + true - + + + + Load file + + + + Clear + + + - From Inline + Bulk From Inline - - + + + + + + + + Run single action (specified below) + + + + + + + Run bulk action (specified below)! + + + + + + + Single actions: select the address and click the button below + + + + QPlainTextEdit::LineWrapMode::WidgetWidth @@ -106,13 +172,6 @@ - - - - Run! - - - @@ -128,13 +187,27 @@ - + + + false + + + true + + + + + + + Clear + + - +