Tasmotonov/tasmotonov-gui.py

78 lines
2.6 KiB
Python
Executable File

#!/usr/bin/python3
import sys
import subprocess
from PySide6.QtUiTools import QUiLoader
from PySide6.QtWidgets import QApplication,QFileDialog
from PySide6.QtCore import QFile, QUrl, QIODevice
filename = ""
action = "toggle"
def tab1_load_file():
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))
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")
else:
window.tab3_textBrowser.append("Will not run, no file selected!")
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)
else:
window.tab3_textBrowser.append("Will not run, no input given!")
def select_on():
global action
action = "on"
window.tab3_textBrowser.append("Now turning everything on when running.")
def select_off():
global action
action = "off"
window.tab3_textBrowser.append("Now turning everything off when running.")
def select_toggle():
global action
action = "toggle"
window.tab3_textBrowser.append("Now toggling when running.")
if __name__ == "__main__":
app = QApplication(sys.argv)
ui_file_name = "tasmotonov.ui"
ui_file = QFile(ui_file_name)
if not ui_file.open(QIODevice.ReadOnly):
print(f"Cannot open {ui_file_name}: {ui_file.errorString()}")
sys.exit(-1)
loader = QUiLoader()
window = loader.load(ui_file)
ui_file.close()
if not window:
print(loader.errorString())
sys.exit(-1)
window.tab1_label.hide()
window.tab1_load_file_pushButton.clicked.connect(tab1_load_file)
window.tab1_action_pushButton.clicked.connect(tab1_action)
window.tab2_action_pushButton.clicked.connect(tab2_action)
window.radioButton_on.clicked.connect(select_on)
window.radioButton_off.clicked.connect(select_off)
window.radioButton_toggle.clicked.connect(select_toggle)
window.show()
sys.exit(app.exec())