Merge branch 'new_structure' of ssh://git.gogao.top:2222/sfgrid into new_structure
# Conflicts: # config.py
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
import configparser
|
||||
from pathlib import Path
|
||||
import sys
|
||||
from typing import Any
|
||||
|
||||
miniQMTPath = r'D:\\Programs\\DTQMT\\userdata_mini' # miniQMT软件的安装路径
|
||||
# miniQMTPath = ''
|
||||
account_no:str = '99082560'
|
||||
console_log = True
|
||||
log_level = "INFO"
|
||||
|
||||
config : Any
|
||||
|
||||
def get_config_path() -> Path:
|
||||
"""获取配置文件的正确路径(兼容开发环境和打包后的可执行文件)"""
|
||||
if getattr(sys, 'frozen', False):
|
||||
# 打包后的可执行文件环境
|
||||
# sys._MEIPASS是PyInstaller解压临时文件的目录
|
||||
# 配置文件应该放在可执行文件同目录下
|
||||
base_path = Path(sys.executable).parent
|
||||
else:
|
||||
# 开发环境
|
||||
base_path = Path(__file__).resolve().parent
|
||||
|
||||
return base_path / 'config.ini'
|
||||
|
||||
def get_config(section:str, key:str):
|
||||
pass
|
||||
|
||||
def save_config(miniQmtPath:str, account_no:str):
|
||||
"""创建默认配置文件"""
|
||||
config = configparser.ConfigParser()
|
||||
config['config'] = {
|
||||
'miniQMTPath': miniQmtPath,
|
||||
'account_no': account_no
|
||||
}
|
||||
config_path = get_config_path()
|
||||
with open(config_path, 'w') as configfile:
|
||||
config.write(configfile)
|
||||
print(f'已创建默认配置文件: {config_path}')
|
||||
|
||||
def exist_config() -> bool:
|
||||
"""检查配置文件是否存在"""
|
||||
config_path = get_config_path()
|
||||
return config_path.exists()
|
||||
|
||||
def initConfig() -> bool:
|
||||
global miniQMTPath, account_no, log_level
|
||||
|
||||
# 获取配置文件路径
|
||||
config_path = get_config_path()
|
||||
|
||||
config = configparser.ConfigParser()
|
||||
config.read(config_path, encoding='utf-8')
|
||||
miniQMTPath = config.get('config','miniQMTPath')
|
||||
account_no = config.get('config','account_no')
|
||||
log_level = config.get('config','log_level')
|
||||
|
||||
# 判断miniQMTPath是否为空,并且目录是否存在
|
||||
if not miniQMTPath or not Path(miniQMTPath).exists():
|
||||
print('请先配置miniQMTPath')
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
+4
-4
@@ -39,7 +39,7 @@ class MainEntry:
|
||||
qmt_label = "QMT (已开启)" if self.qmt_enabled else "QMT (已关闭)"
|
||||
return [
|
||||
{
|
||||
"label": "交易大师",
|
||||
"label": "-- 交易大师 --",
|
||||
"items": [
|
||||
{"label": "交易复盘", "action": "handler", "enabled": True},
|
||||
{"label": "市场数据", "action": "handler", "enabled": True},
|
||||
@@ -47,7 +47,7 @@ class MainEntry:
|
||||
],
|
||||
},
|
||||
{
|
||||
"label": "策略交易",
|
||||
"label": "-- 策略交易 --",
|
||||
"items": [
|
||||
{"label": "交易看板", "action": "handler", "enabled": True},
|
||||
{"label": "策略中心", "action": None, "enabled": False},
|
||||
@@ -55,13 +55,13 @@ class MainEntry:
|
||||
],
|
||||
},
|
||||
{
|
||||
"label": "实时数据",
|
||||
"label": "-- 实时数据 --",
|
||||
"items": [
|
||||
{"label": qmt_label, "action": "marketDataSwitch", "enabled": True},
|
||||
],
|
||||
},
|
||||
{
|
||||
"label": "系统",
|
||||
"label": "-- 系统 --",
|
||||
"items": [
|
||||
{"label": "控制台", "action": "show_window", "enabled": True, "default": True},
|
||||
{"label": "设置", "action": "marketDataSwitch", "enabled": True},
|
||||
|
||||
Reference in New Issue
Block a user