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
|
config.ini
|
||||||
|
tasmotonov-gui-config.json
|
||||||
__pycache__/
|
__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 sys
|
||||||
import tasmotonov
|
import tasmotonov
|
||||||
import configparser
|
import json
|
||||||
from PySide6.QtUiTools import QUiLoader
|
from PySide6.QtUiTools import QUiLoader
|
||||||
from PySide6.QtWidgets import QApplication,QFileDialog
|
from PySide6.QtWidgets import QApplication,QFileDialog
|
||||||
from PySide6.QtCore import QFile, QUrl, QIODevice
|
from PySide6.QtCore import QFile, QUrl, QIODevice
|
||||||
@ -29,35 +29,36 @@ from PySide6.QtCore import QFile, QUrl, QIODevice
|
|||||||
filename = ""
|
filename = ""
|
||||||
action = "toggle"
|
action = "toggle"
|
||||||
|
|
||||||
def load_config(file="config.ini"): # load config from configparser.ConfigParser object
|
def load_config(file="tasmotonov-gui-config.json"): # load config from configparser.ConfigParser object
|
||||||
to_load = configparser.ConfigParser()
|
try:
|
||||||
to_load.read(file)
|
with open(file, "r") as f:
|
||||||
global filename, action
|
to_load = json.loads(f.read())
|
||||||
if "DEFAULT" in to_load:
|
global filename, action
|
||||||
if "file" in to_load['DEFAULT']:
|
if "file" in to_load:
|
||||||
filename = to_load['DEFAULT']['file']
|
filename = to_load['file']
|
||||||
if filename != "":
|
if filename != "":
|
||||||
try:
|
try:
|
||||||
tab1_load_file()
|
tab1_load_file()
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
tab1_clear()
|
tab1_clear()
|
||||||
if "inline" in to_load['DEFAULT']:
|
if "inline" in to_load:
|
||||||
window.tab2_plainTextEdit.setPlainText(to_load['DEFAULT']['inline'])
|
window.tab2_plainTextEdit.setPlainText(to_load['inline'])
|
||||||
if "action" in to_load['DEFAULT']:
|
if "action" in to_load:
|
||||||
a_new = to_load['DEFAULT']['action']
|
a_new = to_load['action']
|
||||||
if a_new != "":
|
if a_new != "":
|
||||||
action = a_new
|
action = a_new
|
||||||
# else: no config there yet
|
except FileNotFoundError:
|
||||||
def save_config(file="config.ini"):
|
pass # no config there yet
|
||||||
|
|
||||||
|
def save_config(file="tasmotonov-gui-config.json"):
|
||||||
window.tab3_textBrowser.append("Saving configuration!")
|
window.tab3_textBrowser.append("Saving configuration!")
|
||||||
global filename, action
|
global filename, action
|
||||||
to_save = configparser.ConfigParser()
|
to_save = {}
|
||||||
to_save['DEFAULT'] = {}
|
to_save['file'] = str(filename)
|
||||||
to_save['DEFAULT']['file'] = str(filename)
|
to_save['inline'] = str(window.tab2_plainTextEdit.toPlainText())
|
||||||
to_save['DEFAULT']['inline'] = str(window.tab2_plainTextEdit.toPlainText())
|
to_save['action'] = str(action)
|
||||||
to_save['DEFAULT']['action'] = str(action)
|
with open(file, 'w') as f:
|
||||||
with open(file, 'w') as configfile:
|
f.write(json.dumps(to_save))
|
||||||
to_save.write(configfile)
|
|
||||||
|
|
||||||
# tab1 slots
|
# tab1 slots
|
||||||
def tab1_load_file_pressed():
|
def tab1_load_file_pressed():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user