Changed config save mechanism
This commit is contained in:
parent
023b29fcae
commit
3999de77d7
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
config.ini
|
||||
tasmotonov-gui-config.json
|
||||
__pycache__/
|
||||
|
1
tasmotonov-gui-config.json
Normal file
1
tasmotonov-gui-config.json
Normal file
@ -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"}
|
@ -20,7 +20,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
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)
|
||||
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 "DEFAULT" in to_load:
|
||||
if "file" in to_load['DEFAULT']:
|
||||
filename = to_load['DEFAULT']['file']
|
||||
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():
|
||||
|
Loading…
x
Reference in New Issue
Block a user