11# coding:utf-8
2+ import json
3+ import os
24import sys
35from enum import Enum
46
57from PySide6 .QtCore import QLocale
68from qfluentwidgets import (qconfig , QConfig , ConfigItem , OptionsConfigItem , BoolValidator ,
79 OptionsValidator , Theme , ConfigSerializer , RangeConfigItem , RangeValidator )
810
9- from .setting import CONFIG_FILE
11+ from .setting import CONFIG_FILE , TRANS_CONFIG_FILE
1012from .constant import LANGUAGES
1113
12- models = ['google' , 'deepl' , 'gpt-3.5-turbo' , 'gpt-4' , 'gpt-4-turbo-2024-04-09' , 'gpt-4o' , 'gpt-4o-mini' , 'custom model' ]
13-
1414
1515class Language (Enum ):
1616 """ Language enumeration """
@@ -46,16 +46,6 @@ class Config(QConfig):
4646 """ Config of application """
4747 i18n_extract_cp = ConfigItem ("Translation" , "i18n_extract_cp" , False , BoolValidator ())
4848 i18n_source_flag = ConfigItem ("Translation" , "i18n_source_flag" , False , BoolValidator ())
49- trans_model = OptionsConfigItem ("Translation" , "trans_model" , "google" , OptionsValidator (models ))
50- ai_base_url = OptionsConfigItem ("Translation" , "ai_base_url" , "" )
51- trans_custom_model = OptionsConfigItem ("Translation" , "trans_custom_model" , "" )
52-
53- ai_batch_size = RangeConfigItem ("Translation" , "ai_batch_size" , 5 , RangeValidator (1 , 50 ))
54- thread_count = RangeConfigItem ("Translation" , "thread_count" , 5 , RangeValidator (1 , 20 ))
55- ai_prompt = ConfigItem ("Translation" , "ai_prompt" ,
56- "You are currently a professional Stardew Valley mod translator. " , None )
57- api_key = ConfigItem ("Translation" , "api_key" , "" , None )
58-
5949 source_language = OptionsConfigItem (
6050 "Translation" , "source_language" , LANGUAGES ['English' ], OptionsValidator (LANGUAGES .values ()), restart = False )
6151 to_language = OptionsConfigItem (
@@ -71,7 +61,29 @@ class Config(QConfig):
7161 # 本地字典界面每页显示条数
7262 localDictPageSize = ConfigItem ("LocalDict" , "pageSize" , 100 )
7363
64+ # 任务设置
65+ trans_platform = ConfigItem ("TaskSettings" , "trans_platform" , "google" , None )
66+ task_prompt = ConfigItem ("TaskSettings" , "prompt" , "You are currently a professional Stardew Valley mod translator." , None )
67+ task_split_mode = OptionsConfigItem ("TaskSettings" , "split_mode" , "token" , OptionsValidator (["token" , "count" ]))
68+ task_split_token_limit = RangeConfigItem ("TaskSettings" , "split_token_limit" , 3000 , RangeValidator (100 , 200000 ))
69+ task_token_reserve = RangeConfigItem ("TaskSettings" , "token_reserve" , 512 , RangeValidator (0 , 20000 ))
70+ task_split_count_limit = RangeConfigItem ("TaskSettings" , "split_count_limit" , 20 , RangeValidator (1 , 500 ))
71+ task_concurrency = RangeConfigItem ("TaskSettings" , "concurrency" , 0 , RangeValidator (0 , 100 ))
72+ task_request_timeout = RangeConfigItem ("TaskSettings" , "request_timeout" , 120 , RangeValidator (10 , 3600 ))
73+ task_max_rounds = RangeConfigItem ("TaskSettings" , "max_rounds" , 1 , RangeValidator (1 , 50 ))
74+
75+
76+ # 载入配置文件
77+ def load_config (path ) -> dict :
78+ config = {}
79+ if os .path .exists (path ):
80+ with open (path , "r" , encoding = "utf-8" ) as reader :
81+ config = json .load (reader )
82+ return config
83+
84+
85+ appConfig = Config ()
86+ appConfig .themeMode .value = Theme .AUTO
87+ qconfig .load (str (CONFIG_FILE .absolute ()), appConfig )
7488
75- cfg = Config ()
76- cfg .themeMode .value = Theme .AUTO
77- qconfig .load (str (CONFIG_FILE .absolute ()), cfg )
89+ # transConfig = load_config(str(TRANS_CONFIG_FILE.absolute()))
0 commit comments