diff --git a/.gitignore b/.gitignore index fd1ac68..23f74cf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ config.ini +tasmotonov-gui-config.json __pycache__/ diff --git a/tasmotonov-gui-config.json b/tasmotonov-gui-config.json new file mode 100644 index 0000000..ff4f70f --- /dev/null +++ b/tasmotonov-gui-config.json @@ -0,0 +1 @@ +{"file": "", "inline": "# Dies ist ein Test\n\n# 192.168.30.10\n# \u2191 so ein Kommentar wird auch gespeichert!\n\n192.168.30.68\n192.168.30.69\n192.168.30.70\n192.168.30.71 # Leselampe Benni\n192.168.30.72\n", "action": "toggle"} \ No newline at end of file diff --git a/tasmotonov-gui.py b/tasmotonov-gui.py index b8118bf..2cd0b49 100755 --- a/tasmotonov-gui.py +++ b/tasmotonov-gui.py @@ -20,7 +20,7 @@ along with this program. If not, see . import sys import tasmotonov -import configparser +import json from PySide6.QtUiTools import QUiLoader from PySide6.QtWidgets import QApplication,QFileDialog from PySide6.QtCore import QFile, QUrl, QIODevice @@ -29,35 +29,36 @@ from PySide6.QtCore import QFile, QUrl, QIODevice filename = "" action = "toggle" -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'] +def load_config(file="tasmotonov-gui-config.json"): # load config from configparser.ConfigParser object + try: + with open(file, "r") as f: + to_load = json.loads(f.read()) + global filename, action + if "file" in to_load: + filename = to_load['file'] if filename != "": try: tab1_load_file() except FileNotFoundError: tab1_clear() - 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 "inline" in to_load: + window.tab2_plainTextEdit.setPlainText(to_load['inline']) + if "action" in to_load: + a_new = to_load['action'] if a_new != "": action = a_new - # else: no config there yet -def save_config(file="config.ini"): + except FileNotFoundError: + pass # no config there yet + +def save_config(file="tasmotonov-gui-config.json"): 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) + to_save = {} + to_save['file'] = str(filename) + to_save['inline'] = str(window.tab2_plainTextEdit.toPlainText()) + to_save['action'] = str(action) + with open(file, 'w') as f: + f.write(json.dumps(to_save)) # tab1 slots def tab1_load_file_pressed():