developing settings system
This commit is contained in:
@@ -3,21 +3,31 @@ import json
|
|||||||
|
|
||||||
class Settings:
|
class Settings:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_settings():
|
def fix() -> None:
|
||||||
try:
|
|
||||||
with open("data/settings.json", "r") as file:
|
|
||||||
settings = json.load(file)
|
|
||||||
except FileNotFoundError:
|
|
||||||
settings = {
|
settings = {
|
||||||
"animation": "InOutQuart"
|
"animation": "InOutQuart",
|
||||||
|
"app_id": None,
|
||||||
|
"key": None,
|
||||||
|
"secret": None,
|
||||||
|
"cluster": None,
|
||||||
|
"client_id": None
|
||||||
}
|
}
|
||||||
with open("data/settings.json", "w") as file:
|
with open("data/settings.json", "w") as file:
|
||||||
json.dump(settings, file)
|
json.dump(settings, file)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_settings() -> dict:
|
||||||
|
try:
|
||||||
|
with open("data/settings.json", "r") as file:
|
||||||
|
settings = json.load(file)
|
||||||
|
except FileNotFoundError | json.decoder.JSONDecodeError | KeyError | ValueError | TypeError:
|
||||||
|
Settings.fix()
|
||||||
|
Settings.get_settings()
|
||||||
|
|
||||||
return settings
|
return settings
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def animation():
|
def animation() -> dict:
|
||||||
from PyQt5.QtCore import QEasingCurve
|
from PyQt5.QtCore import QEasingCurve
|
||||||
with open("data/settings.json", "r") as file:
|
with open("data/settings.json", "r") as file:
|
||||||
settings = json.load(file)
|
settings = json.load(file)
|
||||||
@@ -41,3 +51,15 @@ class Settings:
|
|||||||
"animation": animation,
|
"animation": animation,
|
||||||
"timing": timing
|
"timing": timing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def update(key: str, value: str) -> dict:
|
||||||
|
with open("data/settings.json", "r") as file:
|
||||||
|
settings = json.load(file)
|
||||||
|
|
||||||
|
settings[key] = value
|
||||||
|
|
||||||
|
with open("data/settings.json", "w") as file:
|
||||||
|
json.dump(settings, file)
|
||||||
|
|
||||||
|
return settings
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import sys
|
import sys
|
||||||
from PyQt5 import QtWidgets, QtCore, QtGui
|
from PyQt5 import QtWidgets, QtCore
|
||||||
from data.settings import Settings
|
from data.settings import Settings
|
||||||
sys.path.append('gui')
|
sys.path.append('gui')
|
||||||
|
|
||||||
@@ -15,12 +15,23 @@ MainWindow = QtWidgets.QMainWindow()
|
|||||||
ui = Ui_MainWindow()
|
ui = Ui_MainWindow()
|
||||||
ui.setupUi(MainWindow)
|
ui.setupUi(MainWindow)
|
||||||
|
|
||||||
|
|
||||||
|
def fill_settings() -> None:
|
||||||
ui.chooseAnimationBox.setCurrentText(settings["animation"])
|
ui.chooseAnimationBox.setCurrentText(settings["animation"])
|
||||||
|
ui.pusher_app_id_edit.setText(settings["app_id"])
|
||||||
|
ui.pusher_key_edit.setText(settings["key"])
|
||||||
|
ui.pusher_secret_edit.setText(settings["secret"])
|
||||||
|
ui.pusher_cluster_edit.setText(settings["cluster"])
|
||||||
|
ui.imgurClientId.setText(settings["client_id"])
|
||||||
|
try:
|
||||||
|
fill_settings()
|
||||||
|
except KeyError:
|
||||||
|
Settings.fix()
|
||||||
|
|
||||||
MainWindow.show()
|
MainWindow.show()
|
||||||
|
|
||||||
|
|
||||||
def openMenu():
|
def openMenu() -> None:
|
||||||
width = ui.leftMenu.geometry().width()
|
width = ui.leftMenu.geometry().width()
|
||||||
Ui_MainWindow.animation = QtCore.QPropertyAnimation(ui.leftMenu, b"minimumWidth")
|
Ui_MainWindow.animation = QtCore.QPropertyAnimation(ui.leftMenu, b"minimumWidth")
|
||||||
Ui_MainWindow.animation.setDuration(Settings.animation()["timing"])
|
Ui_MainWindow.animation.setDuration(Settings.animation()["timing"])
|
||||||
@@ -35,7 +46,7 @@ def openMenu():
|
|||||||
Ui_MainWindow.animation.start()
|
Ui_MainWindow.animation.start()
|
||||||
|
|
||||||
|
|
||||||
def handleMenuClick(text):
|
def handleMenuClick(text: str) -> None:
|
||||||
match text:
|
match text:
|
||||||
case "Menu":
|
case "Menu":
|
||||||
openMenu()
|
openMenu()
|
||||||
|
|||||||
Reference in New Issue
Block a user