1
0
Эх сурвалжийг харах

feat: 添加窗口缩放设置

SongZihuan 3 жил өмнө
parent
commit
1a77c3a0f0

+ 4 - 1
.gitignore

@@ -137,4 +137,7 @@ dmypy.json
 .pytype/
 
 # Cython debug symbols
-cython_debug/
+cython_debug/
+
+# HGSSystem
+HGSSystem.conf.py

+ 1 - 0
conf/__init__.py

@@ -3,6 +3,7 @@
 配置文件
 """
 
+from .conf import conf_args
 from .font.noto import noto_font, noto_bold_font, noto_medium_font, noto_thin_font, noto_black_font, noto_regular_font
 from .picture import head_pic, rank_bg_pic, logo_pic, logo_ico
 from .args import p_args

+ 12 - 0
conf/conf.py

@@ -0,0 +1,12 @@
+import os
+import sys
+
+conf_path = os.path.dirname(os.path.abspath(sys.argv[0]))
+
+try:
+    with open(os.path.join(conf_path, "HGSSystem.conf.py"), "r", encoding='utf-8') as f:
+        code = f.read()
+        conf_args = {}
+        exec(code, conf_args)
+except Exception:
+    conf_args = {}

+ 12 - 10
conf/sys_default.py

@@ -1,4 +1,5 @@
 from .args import p_args
+from .conf import conf_args
 
 
 class ConfigSecretRelease:
@@ -9,23 +10,23 @@ class ConfigSecretRelease:
 
 class ConfUserRelease:
     """ 用户信息相关配置 """
-    default_score = 10
-    default_reputation = 300
+    default_score = int(conf_args.get("default_score", 10))
+    default_reputation = int(conf_args.get("default_reputation", 300))
 
-    max_rubbish_week = 34
-    limit_rubbish_week = 50
+    max_rubbish_week = int(conf_args.get("max_rubbish_week", 34))
+    limit_rubbish_week = int(conf_args.get("limit_rubbish_week", 50))
 
-    max_score = 500  # 积分上限为500分
+    max_score = int(conf_args.get("max_score", 500))
 
 
 class ConfigSystemRelease:
     """ 系统信息相关配置 """
 
-    base_location = "KZ"
-    search_reset_time = 10  # 搜索间隔的时间
+    base_location = conf_args.get("base_location", "KZ")
+    search_reset_time = int(conf_args.get("search_reset_time", 10))  # 搜索间隔的时间
 
-    show_uid_len = 12  # 展示uid的长度
-    show_gid_len = 12  # 展示uid的长度
+    show_uid_len = int(conf_args.get("show_uid_len", 12))  # 展示uid的长度
+    show_gid_len = int(conf_args.get("show_gid_len", 12))  # 展示gid的长度
 
     about_info = f'''
 HGSSystem is Garbage Sorting System
@@ -54,8 +55,9 @@ HGSSystem 版权归属 SuperHuan
 
 class ConfigTkinterRelease:
     """ tkinter 相关配置 """
-    tk_refresh_delay = 50  # 延时任务的时间
+    tk_refresh_delay = int(conf_args.get("tk_refresh_delay", 50))  # 延时任务的时间
 
+    tk_zoom = int(conf_args.get("tk_zoom", 1))  # 文字缩放
     tk_second_win_bg = "#fffffb"  # tkinter 第二窗口 标准颜色
     tk_win_bg = "#F0FFF0"  # tkinter 一般窗口 标准颜色 蜜瓜绿
     tk_btn_bg = "#dcdcdc"  # tkinter 按钮 标准颜色

+ 1 - 1
tk_ui/admin.py

@@ -299,7 +299,7 @@ class AdminStation(AdminStationBase):
 
         self._loading_pro = ttk.Progressbar(self._window)
 
-    def __conf_font_size(self, n: int = 1):
+    def __conf_font_size(self, n: int = Config.tk_zoom):
         self._login_title_font_size = int(12 * n)
         self._login_btn_font_size = int(12 * n)
         self._win_ctrl_font_size = int(15 * n)

+ 3 - 2
tk_ui/admin_menu.py

@@ -1,6 +1,7 @@
 import abc
 import tkinter as tk
 
+from conf import Config
 from tool.typing import *
 from tool.tk import make_font, set_tk_disable_from_list
 
@@ -20,7 +21,7 @@ class AdminMenu(metaclass=abc.ABCMeta):
         self.btn_name: List[str] = []
         self.__conf_font()
 
-    def __conf_font(self, n: int = 1):
+    def __conf_font(self, n: int = Config.tk_zoom):
         self.btn_font_size = int(16 * n)
 
     def set_disable(self):
@@ -30,7 +31,7 @@ class AdminMenu(metaclass=abc.ABCMeta):
         set_tk_disable_from_list(self.btn, flat='normal')
 
     def conf_gui(self, color: str, n: int = 1):
-        self.__conf_font(n)
+        self.__conf_font(n * Config.tk_zoom)
 
         btn_font = make_font(size=self.btn_font_size, weight="bold")
         height = 0.02

+ 38 - 38
tk_ui/admin_program.py

@@ -67,12 +67,12 @@ class WelcomeProgram(AdminProgram):
         self.info = tk.Label(self.frame)
         self.__conf_font()
 
-    def __conf_font(self, n: int = 1):
+    def __conf_font(self, n: int = Config.tk_zoom):
         self.title_font_size = int(25 * n)
         self.info_font_size = int(14 * n)
 
     def conf_gui(self, n: int = 1):
-        self.__conf_font(n)
+        self.__conf_font(n * Config.tk_zoom)
 
         title_font = make_font(size=self.title_font_size, weight="bold")
         info_font = make_font(size=self.info_font_size)
@@ -123,12 +123,12 @@ class AboutProgram(AdminProgram):
         self.info = tk.Label(self.frame)
         self.__conf_font()
 
-    def __conf_font(self, n: int = 1):
+    def __conf_font(self, n: int = Config.tk_zoom):
         self.title_font_size = int(25 * n)
         self.info_font_size = int(14 * n)
 
     def conf_gui(self, n: int = 1):
-        self.__conf_font(n)
+        self.__conf_font(n * Config.tk_zoom)
 
         title_font = make_font(size=self.title_font_size, weight="bold")
         info_font = make_font(size=self.info_font_size)
@@ -171,12 +171,12 @@ class CreateUserProgramBase(AdminProgram):
         self.is_manager = is_manager
         return self
 
-    def __conf_font(self, n: int = 1):
+    def __conf_font(self, n: int = Config.tk_zoom):
         self.title_font_size = int(16 * n)
         self.btn_font_size = int(14 * n)
 
     def conf_gui(self, n: int = 1):
-        self.__conf_font(n)
+        self.__conf_font(n * Config.tk_zoom)
 
         title_font = make_font(size=self.title_font_size)
         btn_font = make_font(size=self.btn_font_size)
@@ -269,12 +269,12 @@ class CreateAutoNormalUserProgram(AdminProgram):
 
         self.__conf_font()
 
-    def __conf_font(self, n: int = 1):
+    def __conf_font(self, n: int = Config.tk_zoom):
         self.title_font_size = int(16 * n)
         self.btn_font_size = int(14 * n)
 
     def conf_gui(self, n: int = 1):
-        self.__conf_font(n)
+        self.__conf_font(n * Config.tk_zoom)
 
         title_font = make_font(size=self.title_font_size)
         btn_font = make_font(size=self.btn_font_size)
@@ -330,12 +330,12 @@ class CreateGarbageProgram(AdminProgram):
 
         self.__conf_font()
 
-    def __conf_font(self, n: int = 1):
+    def __conf_font(self, n: int = Config.tk_zoom):
         self.title_font_size = int(16 * n)
         self.btn_font_size = int(14 * n)
 
     def conf_gui(self, n: int = 1):
-        self.__conf_font(n)
+        self.__conf_font(n * Config.tk_zoom)
 
         title_font = make_font(size=self.title_font_size)
         btn_font = make_font(size=self.btn_font_size)
@@ -424,12 +424,12 @@ class ExportProgramBase(AdminProgram):
         self.title_where = title_where
         self.title_command = title_command
 
-    def __conf_font(self, n: int = 1):
+    def __conf_font(self, n: int = Config.tk_zoom):
         self.title_font_size = int(16 * n)
         self.btn_font_size = int(14 * n)
 
     def conf_gui(self, n: int = 1):
-        self.__conf_font(n)
+        self.__conf_font(n * Config.tk_zoom)
 
         title_font = make_font(size=self.title_font_size)
         btn_font = make_font(size=self.btn_font_size)
@@ -585,12 +585,12 @@ class CreateUserFromCSVProgram(AdminProgram):
 
         self.__conf_font()
 
-    def __conf_font(self, n: int = 1):
+    def __conf_font(self, n: int = Config.tk_zoom):
         self.title_font_size = int(16 * n)
         self.btn_font_size = int(14 * n)
 
     def conf_gui(self, n: int = 1):
-        self.__conf_font(n)
+        self.__conf_font(n * Config.tk_zoom)
 
         title_font = make_font(size=self.title_font_size)
         btn_font = make_font(size=self.btn_font_size)
@@ -692,12 +692,12 @@ class DeleteUserProgram(AdminProgram):
 
         self.__conf_font()
 
-    def __conf_font(self, n: int = 1):
+    def __conf_font(self, n: int = Config.tk_zoom):
         self.title_font_size = int(16 * n)
         self.btn_font_size = int(14 * n)
 
     def conf_gui(self, n: int = 1):
-        self.__conf_font(n)
+        self.__conf_font(n * Config.tk_zoom)
 
         title_font = make_font(size=self.title_font_size)
         btn_font = make_font(size=self.btn_font_size)
@@ -790,12 +790,12 @@ class DeleteUsersProgram(AdminProgram):
 
         self.__conf_font()
 
-    def __conf_font(self, n: int = 1):
+    def __conf_font(self, n: int = Config.tk_zoom):
         self.title_font_size = int(16 * n)
         self.btn_font_size = int(14 * n)
 
     def conf_gui(self, n: int = 1):
-        self.__conf_font(n)
+        self.__conf_font(n * Config.tk_zoom)
 
         title_font = make_font(size=self.title_font_size)
         btn_font = make_font(size=self.btn_font_size)
@@ -873,12 +873,12 @@ class DeleteGarbageProgramBase(AdminProgram):
         self.frame_color = color
         self.support_del_all = support_del_all
 
-    def __conf_font(self, n: int = 1):
+    def __conf_font(self, n: int = Config.tk_zoom):
         self.title_font_size = int(16 * n)
         self.btn_font_size = int(14 * n)
 
     def conf_gui(self, n: int = 1):
-        self.__conf_font(n)
+        self.__conf_font(n * Config.tk_zoom)
 
         title_font = make_font(size=self.title_font_size)
         btn_font = make_font(size=self.btn_font_size)
@@ -1017,13 +1017,13 @@ class DeleteAllGarbageProgram(AdminProgram):
 
         self.__conf_font()
 
-    def __conf_font(self, n: int = 1):
+    def __conf_font(self, n: int = Config.tk_zoom):
         self.danger_font_size = int(20 * n)
         self.title_font_size = int(16 * n)
         self.btn_font_size = int(14 * n)
 
     def conf_gui(self, n: int = 1):
-        self.__conf_font(n)
+        self.__conf_font(n * Config.tk_zoom)
 
         danger_font = make_font(size=self.danger_font_size, weight="bold", underline=1)
         title_font = make_font(size=self.title_font_size)
@@ -1150,12 +1150,12 @@ class SearchUserProgram(SearchProgramBase):
                             "积分[Score]", "垃圾分类信用[Reputation]", "是否管理员[IsManager]"]
         self.__conf_font()
 
-    def __conf_font(self, n: int = 1):
+    def __conf_font(self, n: int = Config.tk_zoom):
         self.title_font_size = int(16 * n)
         self.btn_font_size = int(14 * n)
 
     def conf_gui(self, n: int = 1):
-        self.__conf_font(n)
+        self.__conf_font(n * Config.tk_zoom)
 
         title_font = make_font(size=self.title_font_size)
         btn_font = make_font(size=self.btn_font_size)
@@ -1249,12 +1249,12 @@ class SearchAdvancedProgramBase(SearchProgramBase, metaclass=abc.ABCMeta):
         self._columns_ch = columns_ch
         return self
 
-    def __conf_font(self, n: int = 1):
+    def __conf_font(self, n: int = Config.tk_zoom):
         self.title_font_size = int(16 * n)
         self.btn_font_size = int(14 * n)
 
     def conf_gui(self, n: int = 1):
-        self.__conf_font(n)
+        self.__conf_font(n * Config.tk_zoom)
 
         title_font = make_font(size=self.title_font_size)
         btn_font = make_font(size=self.btn_font_size)
@@ -1326,12 +1326,12 @@ class SearchGarbageProgram(SearchProgramBase):
         self.btn: tk.Button = tk.Button(self.frame)
         self.__conf_font()
 
-    def __conf_font(self, n: int = 1):
+    def __conf_font(self, n: int = Config.tk_zoom):
         self.title_font_size = int(16 * n)
         self.btn_font_size = int(14 * n)
 
     def conf_gui(self, n: int = 1):
-        self.__conf_font(n)
+        self.__conf_font(n * Config.tk_zoom)
 
         title_font = make_font(size=self.title_font_size)
         btn_font = make_font(size=self.btn_font_size)
@@ -1453,12 +1453,12 @@ class UpdateUserProgramBase(AdminProgram):
         self.bg_color_where = bg_color
         self.enter_title = title
 
-    def __conf_font(self, n: int = 1):
+    def __conf_font(self, n: int = Config.tk_zoom):
         self.title_font_size = int(16 * n)
         self.btn_font_size = int(14 * n)
 
     def conf_gui(self, n: int = 1):
-        self.__conf_font(n)
+        self.__conf_font(n * Config.tk_zoom)
 
         title_font = make_font(size=self.title_font_size)
         btn_font = make_font(size=self.btn_font_size)
@@ -1581,12 +1581,12 @@ class UpdateGarbageTypeProgram(AdminProgram):
         self.btn: List[tk.Button] = [tk.Button(self.frame), tk.Button(self.frame)]
         self.__conf_font()
 
-    def __conf_font(self, n: int = 1):
+    def __conf_font(self, n: int = Config.tk_zoom):
         self.title_font_size = int(16 * n)
         self.btn_font_size = int(14 * n)
 
     def conf_gui(self, n: int = 1):
-        self.__conf_font(n)
+        self.__conf_font(n * Config.tk_zoom)
 
         title_font = make_font(size=self.title_font_size)
         btn_font = make_font(size=self.btn_font_size)
@@ -1685,12 +1685,12 @@ class UpdateGarbageCheckResultProgram(AdminProgram):
         self.btn: List[tk.Button] = [tk.Button(self.frame), tk.Button(self.frame)]
         self.__conf_font()
 
-    def __conf_font(self, n: int = 1):
+    def __conf_font(self, n: int = Config.tk_zoom):
         self.title_font_size = int(16 * n)
         self.btn_font_size = int(14 * n)
 
     def conf_gui(self, n: int = 1):
-        self.__conf_font(n)
+        self.__conf_font(n * Config.tk_zoom)
 
         title_font = make_font(size=self.title_font_size)
         btn_font = make_font(size=self.btn_font_size)
@@ -1807,7 +1807,7 @@ class StatisticsTimeProgramBase(AdminProgram):
     def _conf(self, bg_color):
         self.bg_color = bg_color
 
-    def __conf_font(self, n: int = 1):
+    def __conf_font(self, n: int = Config.tk_zoom):
         self.btn_font_size = int(14 * n)
         self.little_btn_font_size = int(12 * n)
 
@@ -1873,7 +1873,7 @@ class StatisticsTimeProgramBase(AdminProgram):
             self.color_show_dict[res] = color
 
     def conf_gui(self, n: int = 1):
-        self.__conf_font(n)
+        self.__conf_font(n * Config.tk_zoom)
         btn_font = make_font(size=self.btn_font_size)
         little_btn_font = make_font(size=self.little_btn_font_size)
 
@@ -2238,11 +2238,11 @@ class StatisticsUserBaseProgram(AdminProgram):
     def _conf(self, bg_color):
         self.bg_color = bg_color
 
-    def __conf_font(self, n: int = 1):
+    def __conf_font(self, n: int = Config.tk_zoom):
         self.btn_font_size = int(14 * n)
 
     def conf_gui(self, n: int = 1):
-        self.__conf_font(n)
+        self.__conf_font(n * Config.tk_zoom)
         btn_font = make_font(size=self.btn_font_size)
 
         self.figure_frame['bg'] = self.bg_color

+ 2 - 2
tk_ui/ranking.py

@@ -228,7 +228,7 @@ class RankingStation(RankingStationBase):
         self.rank_var = [tk.StringVar() for _ in range(self.rank_count)]
         self.rank_btn = [tk.Button(self.rank_frame) for _ in range(3)]  # prev, auto, next
 
-    def __conf_font_size(self, n: Union[int, float] = 1):
+    def __conf_font_size(self, n: Union[int, float] = Config.tk_zoom):
         self._rank_font_title_size = int(24 * n)
         self._rank_font_size = int(16 * n)
         self._rank_font_btn_size = int(16 * n)
@@ -270,7 +270,7 @@ class RankingStation(RankingStationBase):
         self.height = self.window.winfo_height()
 
         n = min((self.height / height), (self.width / width))  # 因为横和纵不是平均放大, 因此取倍数小的
-        self.__conf_font_size(n)
+        self.__conf_font_size(n * Config.tk_zoom)
         self.__conf_tk()
         self.show_rank_first(self.rank_count)
 

+ 2 - 2
tk_ui/station.py

@@ -638,7 +638,7 @@ class GarbageStation(GarbageStationBase):
         self._loading_title: Tuple[tk.Label, tk.Variable] = (tk.Label(self._loading_frame), tk.StringVar())
         self._loading_pro = ttk.Progressbar(self._loading_frame)
 
-    def __conf_font_size(self, n: Union[int, float] = 1):
+    def __conf_font_size(self, n: Union[int, float] = Config.tk_zoom):
         """
         设置字体大小
         :param n: 缩放因子, 1为不缩放
@@ -737,7 +737,7 @@ class GarbageStation(GarbageStationBase):
         self._win_height = self._window.winfo_height()
 
         n = ((self._win_height / height) + (self._win_width / width)) / 2  # 平均放大倍数
-        self.__conf_font_size(n)
+        self.__conf_font_size(n * Config.tk_zoom)
         self.__conf_tk()
 
     def __set_windows_overrideredirect(self, show: bool = False):