Skip to content

Commit

Permalink
系统语言编码提示
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroi-sora committed Sep 28, 2022
1 parent d65b1e9 commit 3708aa4
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,12 @@ class ClickTrayModeFlag(Enum):
'isTK': True,
},
# 计划任务设置
'isOpenExplorer': { # T时任务完成后打开资源管理器到输出目录。isOutputFile为T时才管用
'isOpenExplorer': { # T时任务完成后打开资源管理器到输出目录
'default': False,
'isSave': True,
'isTK': True,
},
'isOpenOutputFile': { # T时任务完成后打开输出文件。isOutputFile为T时才管用
'isOpenOutputFile': { # T时任务完成后打开输出文件
'default': False,
'isSave': True,
'isTK': True,
Expand Down Expand Up @@ -341,15 +341,15 @@ class ClickTrayModeFlag(Enum):
class ConfigModule:
# ↓ 在这些编码下能使用全部功能,其它编码不保证能使用如拖入含中文路径的图片等功能。
# ↓ 但识图功能是可以正常使用的。
__sysEncodingSalf = ['cp936', 'cp65001']
__sysEncodingSafe = ['cp936', 'cp65001']

__tkSaveTime = 200 # tk变量改变多长时间后写入本地。毫秒

# ==================== 初始化 ====================

def __init__(self):
self.main = None # win_main的self,可用来获取主it刷新界面或创建计时器
self.sysEncoding = 'cp936' # 系统编码。初始化时获取
self.sysEncoding = 'ascii' # 系统编码。初始化时获取
self.__saveTimer = None # 计时器,用来更新tk变量一段时间后写入本地
self.__optDict = {} # 配置项的数据
self.__tkDict = {} # tk绑定变量
Expand Down Expand Up @@ -400,6 +400,14 @@ def onTkVarChange(key): # 值改变的事件

def load(self):
'''从本地json文件读取配置。必须在initTK后执行'''

# 初始化编码,获取系统编码
# https://docs.python.org/zh-cn/3.8/library/locale.html#locale.getdefaultlocale
# https://docs.python.org/zh-cn/3.8/library/codecs.html#standard-encodings
syse = getdefaultlocale()[1]
if syse:
self.sysEncoding = syse

try:
with open(ConfigJsonFile, 'r', encoding='utf8')as fp:
jsonData = json.load(fp) # 读取json文件
Expand All @@ -415,20 +423,12 @@ def load(self):
exit(0)
except FileNotFoundError: # 无配置文件
# 当成是首次启动软件,提示
if self.sysEncoding not in self.__sysEncodingSalf: # 不安全的地区
if self.sysEncoding not in self.__sysEncodingSafe: # 不安全的地区
tk.messagebox.showwarning(
'警告',
f'您的系统地区编码为[{self.sysEncoding}],可能导致拖入图片的功能异常,建议使用浏览按钮导入图片。其它功能应该能正常使用。')
f'您的系统地区语言编码为[{self.sysEncoding}],可能导致拖入图片的功能异常,建议使用浏览按钮导入图片。其它功能不受影响。')
self.save()

def setSysEncoding(): # 获取系统编码
'''初始化编码'''
# https://docs.python.org/zh-cn/3.8/library/locale.html#locale.getdefaultlocale
# https://docs.python.org/zh-cn/3.8/library/codecs.html#standard-encodings
self.sysEncoding = getdefaultlocale()[1]
print(f'获取系统编码:{self.sysEncoding}')
setSysEncoding() # 初始化编码

def save(self):
'''保存配置到本地json文件'''
saveDict = {} # 提取需要保存的项
Expand Down

0 comments on commit 3708aa4

Please sign in to comment.