代码拉取完成,页面将自动刷新
# -*- coding: utf-8 -*-
import enum
import json
import os
from language import Language, Locale
from theme import Theme
from utils import FileUtils, LanguageUtils, ThemeUtils
# settings(settings.json)
class Setting:
def __init__(self):
self.language = Language.Chinese.value
self.theme = Theme.COMMON_DEFAULT
def get_locale(self):
if self.language == Language.English.value:
return Locale.English
else:
return Locale.Chinese
def get_language(self):
return self.language
def get_theme(self):
return FileUtils.get_fullname(self.theme)
def load(self):
path = os.path.join(os.getcwd(), "setting.json")
if not os.path.exists(path):
print("Setting: file does not exist(%s)" % path)
return
with open(path, "r", encoding="utf-8") as f:
content = f.read()
if len(content) == 0:
return
# noinspection PyBroadException
try:
setting = json.loads(content)
except:
setting = None
if not setting:
return
if isinstance(setting, dict):
language = setting.get("language")
if LanguageUtils.validate(language):
self.language = language
theme = setting.get("theme")
if ThemeUtils.validate(theme):
self.theme = theme
@staticmethod
def save(language, theme):
if not language or not theme:
return
path = os.path.join(os.getcwd(), "setting.json")
with open(path, "w", encoding="utf-8") as f:
setting = {"language": language, "theme": theme}
f.write(json.dumps(setting))
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。