#! /usr/bin/env python
#-*- encoding: utf-8 -*-
#author 元宵大师 本例程仅用于教学目的,严禁转发和用于盈利目的,违者必究
import wx
import wx.adv
import wx.grid
import wx.html2
import os
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import time
import webbrowser
from importlib import reload
from datetime import datetime
import threading
import queue
from ApiData.Tushare import basic_code_list
from MainlyGui.ElementGui.DefPanel import (
SubGraphs,
Sys_Panel
)
from MainlyGui.ElementGui.DefEchart import (
WebGraphs
)
from MainlyGui.ElementGui.DefTreelist import (
CollegeTreeListCtrl, CollegeTreeListCtrl2
)
from MainlyGui.ElementGui.DefGrid import (
GridTable
)
from MainlyGui.ElementGui.DefEchart import (
Pyechart_Drive
)
from MainlyGui.ElementGui.DefDialogs.CommDialog import MessageDialog, ImportFileDiag, ChoiceDialog
from MainlyGui.ElementGui.DefDialogs.SpecDialog import (
ScanDialog, UserDialog, GroupPctDiag, GroupTrendDiag, ProgressDialog, BrowserF10,
WebDialog, DouBottomDialog, RpsTop10Dialog, ViewGripDiag,
)
from MainlyGui.ElementGui.DefDialogs.ParaDialog import (MarketGraphDialog, BacktGraphDialog, PattenSelDialog)
from MainlyGui.ElementGui.DefProgress import ProgressBarDialog, ProgressBarThread
from MainlyGui.ElementGui.DefAnimation import AnimationDialog
from MainlyGui.ElementGui.DefListBox import ClassifySelectDiag
from ApiData.Tushare import (Tspro_Backend)
from ApiData.FromSql import (
ReadFundDatFromSql
)
from ApiData.CrawerDaily import CrawerDailyBackend
from ApiData.CrawerNorth import CrawerNorthBackend
from ApiData.EastmUpLimit import UpLimitBackend
from ApiData.Csvdata import (
Csv_Backend
)
# 分离控件事件中调用的子事件
from EventEngine.DefEvent import (
EventHandle
)
from StrategyGath.IndicateGath import Base_Indicate_Group
from StrategyGath.StrategyGath import Base_Strategy_Group
from StrategyGath.PattenGath import Base_Patten_Group
from CommIf.SysFile import Base_File_Oper
from CommIf.CodeTable import ManageCodeTable
from CommIf.CodePool import ManageSelfPool
from CommIf.PrintLog import SysLogIf, PatLogIf
from CommIf.RemoteInfo import auto_send_email
from CommIf.SqliteHandle import DataBase_Sqlite
from ApiData.HistoryOCHLV import HistoryOCHLV
plt.rcParams['font.sans-serif'] = ['SimHei'] # 用来正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False # 用来正常显示负号
# 创建本地存储路径
data_path = os.path.dirname(os.path.dirname(__file__)) + '/DataFiles/stock_history/'
q_codes = queue.Queue(5000)
q_results = queue.Queue(5000)
class CrawlerThread(threading.Thread):
"""爬虫类"""
def __init__(self, parent, taskif):
super(CrawlerThread, self).__init__()
self.parent = parent
self.taskif = taskif
self.setDaemon(True)
def run(self):
while not q_codes.empty():
para = q_codes.get()
results = self.taskif(para)
if q_results.full() != True:
q_results.put(results)
class UserFrame(wx.Frame):
def __init__(self, parent=None, id=-1, displaySize=(1600, 900), Fun_SwFrame=None):
# M1 与 M2 横向布局时宽度分割
self.M1_width = int(displaySize[0] * 0.1)
self.M2_width = int(displaySize[0] * 0.9)
# M1 纵向100%
self.M1_length = int(displaySize[1])
# M1中S1 S2 S3 纵向布局高度分割
self.M1S1_length = int(self.M1_length * 0.2)
self.M1S2_length = int(self.M1_length * 0.2)
self.M1S3_length = int(self.M1_length * 0.6)
# 默认样式wx.DEFAULT_FRAME_STYLE含
# wx.MINIMIZE_BOX | wx.MAXIMIZE_BOX | wx.RESIZE_BORDER | wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX | wx.CLIP_CHILDREN
wx.Frame.__init__(self, parent=None, title=u'my量化软件', size=displaySize, style=wx.DEFAULT_FRAME_STYLE)
# 用于量化工具集成到整体系统中
self.fun_swframe = Fun_SwFrame
# 多子图布局对象
self.FlexGridSizer = None
# 存储单个行情数据
self.stock_dat = pd.DataFrame()
# 存储单个回测数据
self.backt_dat = pd.DataFrame()
# 存储策略函数
self.function = ''
# 初始化事件调用接口
self.EventHandle = EventHandle()
self.call_method = self.EventHandle.call_method
self.event_task = self.EventHandle.event_task
# 添加参数布局
self.vbox_sizer_a = wx.BoxSizer(wx.VERTICAL) # 纵向box
#self.vbox_sizer_a.Add(self._init_treelist_ctrl(), proportion=3, flag=wx.EXPAND | wx.BOTTOM, border=5)
self.vbox_sizer_a.Add(self._init_text_log(), proportion=1, flag=wx.EXPAND | wx.BOTTOM, border=5)
self.vbox_sizer_a.Add(self._init_listbox_mult(), proportion=1, flag=wx.EXPAND | wx.BOTTOM, border=5)
self.vbox_sizer_a.Add(self._init_nav_notebook(), proportion=2, flag=wx.EXPAND | wx.BOTTOM, border=5)
#self.vbox_sizer_a.Add(self._init_grid_pl(), proportion=5, flag=wx.EXPAND | wx.BOTTOM, border=5)
# 加载配置文件
firm_para = Base_File_Oper.load_sys_para("firm_para.json")
back_para = Base_File_Oper.load_sys_para("back_para.json")
# 创建显示区面板
self.DispPanel = Sys_Panel(self, **firm_para['layout_dict']) # 自定义
self.BackMplPanel = Sys_Panel(self, **back_para['layout_dict']) # 自定义
self.DispPanelA = self.DispPanel
# 此处涉及windows和macos的区别
sys_para = Base_File_Oper.load_sys_para("sys_para.json")
if sys_para["operate_sys"] == "windows":
try:
# WIN环境下兼容WEB配置
import winreg
key = winreg.OpenKey(winreg.HKEY_CURRENT_USER,
r"SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION",
0, winreg.KEY_ALL_ACCESS) # 打开所有权限
# 设置注册表python.exe 值为 11000(IE11)
winreg.SetValueEx(key, 'python.exe', 0, winreg.REG_DWORD, 0x00002af8)
except:
# 设置出现错误
MessageDialog("WIN环境配置注册表中浏览器兼容显示出错,检查是否安装第三方库【winreg】")
# 创建wxGrid表格对象
self._init_grid_pk()
# 创建text日志对象
self._init_patten_log()
# 第二层布局
self.vbox_sizer_b = wx.BoxSizer(wx.VERTICAL) # 纵向box
self.vbox_sizer_b.Add(self._init_para_notebook(), proportion=1, flag=wx.EXPAND | wx.BOTTOM, border=5) # 添加行情参数布局
self.vbox_sizer_b.Add(self.patten_log_tx, proportion=10, flag=wx.EXPAND | wx.BOTTOM, border=5)
# 第一层布局
self.HBoxPanelSizer = wx.BoxSizer(wx.HORIZONTAL)
self.HBoxPanelSizer.Add(self.vbox_sizer_a, proportion=1, border=2, flag=wx.EXPAND | wx.ALL)
self.HBoxPanelSizer.Add(self.vbox_sizer_b, proportion=10, border=2, flag=wx.EXPAND | wx.ALL)
self.SetSizer(self.HBoxPanelSizer) # 使布局有效
# 初始化全部页面
self.switch_main_panel(self.patten_log_tx, self.grid_pk, False)
self.switch_main_panel(self.grid_pk, self.BackMplPanel, False)
self.switch_main_panel(self.BackMplPanel, self.DispPanel, True) # 等类型替换
################################### 辅助配置 ###################################
self.syslog = SysLogIf(self.sys_log_tx)
self.patlog = PatLogIf(self.patten_log_tx)
#self.timer = wx.Timer(self) # 创建定时器
#self.Bind(wx.EVT_TIMER, self.ev_int_timer, self.timer) # �
评论0