Ejemplo n.º 1
0
    def __init__(self, parent=None):
        # print "StockDataWidgetForBigSingleTransactionData: init"
        super(TransactionDataWidgetForBigSingleTransactionData,
              self).__init__()

        # 创建本类管理的tab下的查询的参数
        self.__searchRefForBigSingleTransactionData = {}

        # 存放批量股票代码数据的列表
        self.__codeListForBigSingleTransactionData = []

        # 创建日历窗口,但是不显示
        self.__calenderForBigSingleTransactionData = Calendar()

        # 当点击起始时间,结束时间lineEdit的时候,弹出日历
        self.lineEditTransactionTimeForBigSingleTransactionData.LineEditClicked.connect(
            self.onLineEditStartTimeForBigSingleTransactionDataClicked)

        # 勾选上股票代码的时候,再显示是否显示需要输入具体的信息
        self.onChkBoxBulkModeForBigSingleTransactionDataClicked()
        self.chkBoxBulkModeForBigSingleTransactionData.clicked.connect(
            self.onChkBoxBulkModeForBigSingleTransactionDataClicked)

        # 批量导入按钮的信号与槽函数
        self.btnBulkModeForBigSingleTransactionData.clicked.connect(
            self.onBtnBulkModeForBigSingleTransactionDataClicked)

        # 保存路径
        self.btnSavePathForBigSingleTransactionData.clicked.connect(
            self.onBtnSavePathForBigSingleTransactionDataClicked)
Ejemplo n.º 2
0
    def __init__(self, parent=None):
        # print "StockDataWidgetForHistoricalTick: init"
        super(TransactionDataWidgetForHistoricalTick, self).__init__()

        # 创建本类管理的tab下的查询的参数
        self.__searchRefForHistoricalTick = {}

        # 存放批量股票代码数据的列表
        self.__codeListForHistoricalTick = []

        # 创建日历窗口,但是不显示
        self.__calenderForHistoricalTick = Calendar()

        # 当点击起始时间,结束时间lineEdit的时候,弹出日历
        self.lineEditTickTimeForHistoricalTick.LineEditClicked.connect(self.onLineEditTickTimeForHistoricalTickClicked)

        # 点击复选框,是否显示“批量导入按钮”
        self.onChkBoxBulkModeForHistoricalTickClicked()
        self.chkBoxBulkModeForHistoricalTick.clicked.connect(self.onChkBoxBulkModeForHistoricalTickClicked)

        # 批量导入按钮的信号与槽函数
        self.btnBulkModeForHistoricalTick.clicked.connect(self.onBtnBulkModeForHistoricalTickClicked)

        # 保存路径
        self.btnSavePathForHistoricalTick.clicked.connect(self.onBtnSavePathForHistoricalTickClicked)
Ejemplo n.º 3
0
    def __init__(self, parent=None):
        QtWidgets.QWidget.__init__(self, parent)
        self.setupUi(self)

        # 用户需要查询那些数据(记录那些checkbox被选中)
        self.__marketDataSourceList = []

        # 查询数据的传参字典
        self.__refDict = {}

        # 创建日历窗口,但是不显示
        self.__calender = Calendar()

        # 当点击起始时间,结束时间lineEdit的时候,弹出日历
        self.lineEditStartTime.LineEditClicked.connect(
            self.onLineEditStartTimeClicked)
        self.lineEditEndTime.LineEditClicked.connect(
            self.onLineEditEndTimeClicked)

        # 所有的chkbox的点击事件
        self.chkBoxSH.clicked.connect(self.onChkBoxChicked)  # 中金所
        self.chkBoxSZ.clicked.connect(self.onChkBoxChicked)  # 郑商所
        self.chkBoxHS300.clicked.connect(self.onChkBoxChicked)  # 上期所
        self.chkBoxSZ50.clicked.connect(self.onChkBoxChicked)  # 大商所

        # 所有的按钮事件
        self.btnSelectSavePath.clicked.connect(self.onBtnSelectSavePathClicked)
        self.btnSaveToCSV.clicked.connect(self.onBtnSaveClicked)
        self.btnSaveToExcel.clicked.connect(self.onBtnSaveClicked)
        self.btnSaveToHDF5.clicked.connect(self.onBtnSaveClicked)
        self.btnSaveToJSON.clicked.connect(self.onBtnSaveClicked)
        self.btnSaveToMySQL.clicked.connect(self.onBtnSaveClicked)
        self.btnSaveToMongoDB.clicked.connect(self.onBtnSaveClicked)
Ejemplo n.º 4
0
    def __init__(self, parent=None):
        QtWidgets.QWidget.__init__(self, parent)
        self.setupUi(self)

        # 创建日历窗口,但是不显示
        self.__calender = Calendar()

        # 当点击创建时间,修改时间lineEdit的时候,弹出日历
        self.lineEditCreateTime.LineEditClicked.connect(self.onLineEditCreateTimeClicked)
        self.lineEditModifyTime.LineEditClicked.connect(self.onLineEditModifyTimeClicked)
Ejemplo n.º 5
0
class StrategyMgrWidget(QtWidgets.QWidget, Ui_strategyMgrWidget):
    def __init__(self, parent=None):
        QtWidgets.QWidget.__init__(self, parent)
        self.setupUi(self)

        # 创建日历窗口,但是不显示
        self.__calender = Calendar()

        # 当点击创建时间,修改时间lineEdit的时候,弹出日历
        self.lineEditCreateTime.LineEditClicked.connect(self.onLineEditCreateTimeClicked)
        self.lineEditModifyTime.LineEditClicked.connect(self.onLineEditModifyTimeClicked)

    @QtCore.pyqtSlot()
    def onLineEditCreateTimeClicked(self):
        # 设置要修改的文本编辑窗口
        self.__calender.setLineEditObj(self.lineEditCreateTime)

        # 显示日历窗口
        self.__calender.show()

    @QtCore.pyqtSlot()
    def onLineEditModifyTimeClicked(self):
        # 设置要修改的文本编辑窗口
        self.__calender.setLineEditObj(self.lineEditModifyTime)

        # 显示日历窗口
        self.__calender.show()
Ejemplo n.º 6
0
    def __init__(self, parent=None):
        # print "StockDataWidgetForSameDayHistoricalTick: init"
        super(TransactionDataWidgetForSameDayHistoricalTick, self).__init__()

        # 创建本类管理的tab下的查询的参数
        self.__searchRefForSameDayHistoricalTick = {}

        # 存放批量股票代码数据的列表
        self.__codeListForSameDayHistoricalTick = []

        # 创建日历窗口,但是不显示
        self.__calenderForSameDayHistoricalTick = Calendar()

        # 勾选上股票代码的时候,再显示是否显示需要输入具体的信息
        self.onChkBoxBulkModeForSameDayHistoricalTickClicked()
        self.chkBoxBulkModeForSameDayHistoricalTick.clicked.connect(
            self.onChkBoxBulkModeForSameDayHistoricalTickClicked)

        # 批量导入按钮的信号与槽函数
        self.btnBulkModeForSameDayHistoricalTick.clicked.connect(
            self.onBtnBulkModeForSameDayHistoricalTickClicked)

        # 保存路径
        self.btnSavePathForSameDayHistoricalTick.clicked.connect(
            self.onBtnSavePathForSameDayHistoricalTickClicked)
    def __init__(self, parent=None):
        # print "StockDataWidgetForRealTimeTick: init"
        super(TransactionDataWidgetForRealTimeTick, self).__init__()

        # 创建本类管理的tab下的查询的参数
        self.__searchRefForRealTimeTick = {}

        # 存放批量股票代码数据的列表
        self.__codeListForRealTimeTick = []

        # 创建日历窗口,但是不显示
        self.__calenderForRealTimeTick = Calendar()

        # 统一管理所有的复选框
        self.__chkBoxDictForRealTimeTick = {}
        self.__chkBoxDictForRealTimeTick[self.chkBoxSHForRealTimeTick] = "sh"
        self.__chkBoxDictForRealTimeTick[self.chkBoxSZForRealTimeTick] = "sz"
        self.__chkBoxDictForRealTimeTick[self.chkBoxHS300ForRealTimeTick] = "hs300"
        self.__chkBoxDictForRealTimeTick[self.chkBoxSZ50ForRealTimeTick] = "sz50"
        self.__chkBoxDictForRealTimeTick[self.chkBoxZXBForRealTimeTick] = "zxb"
        self.__chkBoxDictForRealTimeTick[self.chkBoxCYBForRealTimeTick] = "cyb"

        # 勾选上股票代码的时候,再显示是否显示需要输入具体的信息
        self.isShowTheStockCodeInputForRealTimeTick()
        self.chkBoxStockCodeForRealTimeTick.clicked.connect(self.isShowTheStockCodeInputForRealTimeTick)
        self.chkBoxBulkModeForRealTimeTick.clicked.connect(self.onChkBoxBulkModeForRealTimeTickClicked)

        # 批量导入按钮的信号与槽函数
        self.btnBulkModeForRealTimeTick.clicked.connect(self.onBtnBulkModeForRealTimeTickClicked)

        # 保存路径
        self.btnSavePathForRealTimeTick.clicked.connect(self.onBtnSavePathForRealTimeTickClicked)
Ejemplo n.º 8
0
    def __init__(self, parent=None):
        # QtGui.QWidget.__init__(self, parent)
        # self.setupUi(self)

        # 创建本类管理的tab下的查询的参数
        self.__searchRefForHistoricalQuotation = {}

        # 存放批量股票代码数据的列表
        self.__codeList = []

        # 创建日历窗口,但是不显示
        self.__calenderForHistoricalQuotation = Calendar()

        # 勾选上股票代码的时候,再显示是否显示需要输入具体的信息
        self.isShowTheStockCodeInput()

        # 统一管理所有的复选框
        self.__chkBoxDict = {}
        self.__chkBoxDict[self.chkBoxSH] = "sh"
        self.__chkBoxDict[self.chkBoxSZ] = "sz"
        self.__chkBoxDict[self.chkBoxHS300] = "hs300"
        self.__chkBoxDict[self.chkBoxSZ50] = "sz50"
        self.__chkBoxDict[self.chkBoxZXB] = "zxb"
        self.__chkBoxDict[self.chkBoxCYB] = "cyb"

        # 所有的checkBox的信号和槽函数
        self.chkBoxSH.clicked.connect(self.onChkBoxClicked)
        self.chkBoxSZ.clicked.connect(self.onChkBoxClicked)
        self.chkBoxHS300.clicked.connect(self.onChkBoxClicked)
        self.chkBoxSZ50.clicked.connect(self.onChkBoxClicked)
        self.chkBoxZXB.clicked.connect(self.onChkBoxClicked)
        self.chkBoxCYB.clicked.connect(self.onChkBoxClicked)
        self.chkBoxStockCode.clicked.connect(self.onChkBoxClicked)

        self.chkBoxBulkModeForHistoricalQuotation.clicked.connect(
            self.onChkBoxBulkModeForHistoricalQuotationClicked)

        # 当点击起始时间,结束时间lineEdit的时候,弹出日历
        self.lineEditStartTimeForHistoricalQuotation.LineEditClicked.connect(
            self.onLineEditStartTimeForHistoricalQuotationClicked)
        self.lineEditEndTimeForHistoricalQuotation.LineEditClicked.connect(
            self.onLineEditEndTimeForHistoricalQuotationClicked)

        # 批量导入按钮的信号与槽函数
        self.btnBulkModeForHistoricalQuotation.clicked.connect(
            self.onBtnBulkModeForHistoricalQuotationClicked)
    def __init__(self, parent=None):
        # 调用父类方法
        # print "StockDataWidgetForHistoricalQuotation: init"
        super(TransactionDataWidgetForHistoricalQuotation, self).__init__()

        # 创建本类管理的tab下的查询的参数
        self.__searchRefForHistoricalQuotation = {}

        # 存放批量股票代码数据的列表
        self.__codeListForHistoricalQuotation = []

        # 创建日历窗口,但是不显示
        self.__calenderForHistoricalQuotation = Calendar()

        # 勾选上股票代码的时候,再显示是否显示需要输入具体的信息
        self.isShowTheStockCodeInputForHistoricalQuotation()

        # 统一管理所有的复选框
        self.__chkBoxDictForHistoricalQuotation = {}
        self.__chkBoxDictForHistoricalQuotation[self.chkBoxSH] = "sh"
        self.__chkBoxDictForHistoricalQuotation[self.chkBoxSZ] = "sz"
        self.__chkBoxDictForHistoricalQuotation[self.chkBoxHS300] = "hs300"
        self.__chkBoxDictForHistoricalQuotation[self.chkBoxSZ50] = "sz50"
        self.__chkBoxDictForHistoricalQuotation[self.chkBoxZXB] = "zxb"
        self.__chkBoxDictForHistoricalQuotation[self.chkBoxCYB] = "cyb"

        # 所有的checkBox的信号和槽函数
        self.chkBoxSH.clicked.connect(self.onChkBoxClicked)
        self.chkBoxSZ.clicked.connect(self.onChkBoxClicked)
        self.chkBoxHS300.clicked.connect(self.onChkBoxClicked)
        self.chkBoxSZ50.clicked.connect(self.onChkBoxClicked)
        self.chkBoxZXB.clicked.connect(self.onChkBoxClicked)
        self.chkBoxCYB.clicked.connect(self.onChkBoxClicked)
        self.chkBoxStockCode.clicked.connect(self.onChkBoxClicked)

        self.chkBoxBulkModeForHistoricalQuotation.clicked.connect(self.onChkBoxBulkModeForHistoricalQuotationClicked)

        # 当点击起始时间,结束时间lineEdit的时候,弹出日历
        self.lineEditStartTimeForHistoricalQuotation.LineEditClicked.connect(self.onLineEditStartTimeForHistoricalQuotationClicked)
        self.lineEditEndTimeForHistoricalQuotation.LineEditClicked.connect(self.onLineEditEndTimeForHistoricalQuotationClicked)

        # 批量导入按钮的信号与槽函数
        self.btnBulkModeForHistoricalQuotation.clicked.connect(self.onBtnBulkModeForHistoricalQuotationClicked)

        # 保存路径
        self.btnSavePathForHistoricalQuotation.clicked.connect(self.onBtnSavePathForHistoricalQuotationClicked)
Ejemplo n.º 10
0
    def __init__(self, parent=None):
        # 先实例化界面,然后调用各个父类的实例化方法
        QtGui.QWidget.__init__(self, parent)
        self.setupUi(self)
        super(StockDataWidget,self).__init__()

        # 查询数据的传参字典
        self.__refDict = {}

        # 创建日历窗口,但是不显示
        self.__calender = Calendar()

        # 所有的按钮事件
        self.btnShowData.clicked.connect(self.onBtnShowDataClicked)
        self.btnSaveToCSV.clicked.connect(self.onBtnSaveClicked)
        self.btnSaveToExcel.clicked.connect(self.onBtnSaveClicked)
        self.btnSaveToHDF5.clicked.connect(self.onBtnSaveClicked)
        self.btnSaveToJSON.clicked.connect(self.onBtnSaveClicked)
        self.btnSaveToMySQL.clicked.connect(self.onBtnSaveClicked)
        self.btnSaveToMongoDB.clicked.connect(self.onBtnSaveClicked)
Ejemplo n.º 11
0
class StockDataWidgetForHistoricalQuotation(QtGui.QWidget, Ui_stockDataWidget):
    '''历史行情tab'''
    def __init__(self, parent=None):
        # QtGui.QWidget.__init__(self, parent)
        # self.setupUi(self)

        # 创建本类管理的tab下的查询的参数
        self.__searchRefForHistoricalQuotation = {}

        # 存放批量股票代码数据的列表
        self.__codeList = []

        # 创建日历窗口,但是不显示
        self.__calenderForHistoricalQuotation = Calendar()

        # 勾选上股票代码的时候,再显示是否显示需要输入具体的信息
        self.isShowTheStockCodeInput()

        # 统一管理所有的复选框
        self.__chkBoxDict = {}
        self.__chkBoxDict[self.chkBoxSH] = "sh"
        self.__chkBoxDict[self.chkBoxSZ] = "sz"
        self.__chkBoxDict[self.chkBoxHS300] = "hs300"
        self.__chkBoxDict[self.chkBoxSZ50] = "sz50"
        self.__chkBoxDict[self.chkBoxZXB] = "zxb"
        self.__chkBoxDict[self.chkBoxCYB] = "cyb"

        # 所有的checkBox的信号和槽函数
        self.chkBoxSH.clicked.connect(self.onChkBoxClicked)
        self.chkBoxSZ.clicked.connect(self.onChkBoxClicked)
        self.chkBoxHS300.clicked.connect(self.onChkBoxClicked)
        self.chkBoxSZ50.clicked.connect(self.onChkBoxClicked)
        self.chkBoxZXB.clicked.connect(self.onChkBoxClicked)
        self.chkBoxCYB.clicked.connect(self.onChkBoxClicked)
        self.chkBoxStockCode.clicked.connect(self.onChkBoxClicked)

        self.chkBoxBulkModeForHistoricalQuotation.clicked.connect(
            self.onChkBoxBulkModeForHistoricalQuotationClicked)

        # 当点击起始时间,结束时间lineEdit的时候,弹出日历
        self.lineEditStartTimeForHistoricalQuotation.LineEditClicked.connect(
            self.onLineEditStartTimeForHistoricalQuotationClicked)
        self.lineEditEndTimeForHistoricalQuotation.LineEditClicked.connect(
            self.onLineEditEndTimeForHistoricalQuotationClicked)

        # 批量导入按钮的信号与槽函数
        self.btnBulkModeForHistoricalQuotation.clicked.connect(
            self.onBtnBulkModeForHistoricalQuotationClicked)

    def getRefDictForHistoricalQuotation(self):
        """获取历史行情参数字典"""

        # 获取数据源
        mode, code = self.getRefDateSource()
        if mode is not None:
            self.__searchRefForHistoricalQuotation["mode"] = mode
            self.__searchRefForHistoricalQuotation["code"] = code
        else:
            return None

        # 如果是查询单只股票
        if self.__searchRefForHistoricalQuotation["mode"] == "singleCode":
            # 获取参数,创建传参字典
            if self.getRefSingleStockCode() is not None:
                self.__searchRefForHistoricalQuotation[
                    "code"] = self.getRefSingleStockCode()
            else:
                return None

        # 如果是查询多只股票
        if self.__searchRefForHistoricalQuotation["mode"] == "multiCode":
            # 获取参数,创建传参字典
            if self.getRefMultiStockCode() is not None:
                self.__searchRefForHistoricalQuotation[
                    "code"] = self.getRefMultiStockCode()
            else:
                return None

        # 获取时间
        start, end = self.getRefDateTime()
        if start is not None and end is not None:
            self.__searchRefForHistoricalQuotation["start"] = start
            self.__searchRefForHistoricalQuotation["end"] = end
        else:
            return None

        # 获取数据类型
        self.__searchRefForHistoricalQuotation["ktype"] = ktypeList[
            self.comboBoxDataType.currentIndex()]

        # 回返一个参数字典
        return self.__searchRefForHistoricalQuotation

    def getRefDateSource(self):
        """获取数据源"""

        # 判断哪个复选框被选中
        for chkBox in self.__chkBoxDict:
            if chkBox.isChecked():
                return "index", self.__chkBoxDict[chkBox]

        # 如果用户选择为“股票代码”, 进一步判断是否为批量模式
        if self.chkBoxStockCode.isChecked(
        ) and not self.chkBoxBulkModeForHistoricalQuotation.isChecked():
            return "singleCode", None
        elif self.chkBoxStockCode.isChecked(
        ) and not self.chkBoxBulkModeForHistoricalQuotation.isChecked():
            return "multiCode", None

        # 如果没有复选框被选中
        QtGui.QMessageBox.warning(self, u"错误!", u"请选择一个数据源",
                                  QtGui.QMessageBox.Cancel)
        return None, None

    def getRefDateTime(self):
        """获取时间"""

        # 判断是否选择了时间
        if self.lineEditStartTimeForHistoricalQuotation.text().isEmpty(
        ) or self.lineEditEndTimeForHistoricalQuotation.text().isEmpty():
            QtGui.QMessageBox.warning(self, u"错误!", u"请填写完整日期!",
                                      QtGui.QMessageBox.Cancel)
            return None, None

        # 起始和终止时间需要合法
        startDate = datetime.datetime.strptime(
            unicode(
                self.lineEditStartTimeForHistoricalQuotation.text().toUtf8(),
                'utf-8', 'ignore'), '%Y-%m-%d')
        endDate = datetime.datetime.strptime(
            unicode(self.lineEditEndTimeForHistoricalQuotation.text().toUtf8(),
                    'utf-8', 'ignore'), '%Y-%m-%d')
        if startDate >= endDate:
            QtGui.QMessageBox.warning(self, u"错误!", u"日期非法!",
                                      QtGui.QMessageBox.Cancel)
            return None, None

        # 获取参数
        start = unicode(
            self.lineEditStartTimeForHistoricalQuotation.text().toUtf8(),
            'utf-8', 'ignore')
        end = unicode(
            self.lineEditEndTimeForHistoricalQuotation.text().toUtf8(),
            'utf-8', 'ignore')

        return start, end

    def getRefSingleStockCode(self):
        """获取单只股票数据参数"""

        # 判断输入的股票代码是否合法
        if self.lineEditStockCodeForHistoricalQuotation.text().isEmpty():
            QtGui.QMessageBox.warning(self, u"错误!", u"请填写股票代码",
                                      QtGui.QMessageBox.Cancel)
            return None
        try:
            int(
                unicode(
                    self.lineEditStockCodeForHistoricalQuotation.text().toUtf8(
                    ), 'utf-8', 'ignore'))
        except:
            QtGui.QMessageBox.warning(self, u"错误!", u"股票代码须为6位数字",
                                      QtGui.QMessageBox.Cancel)
            return None
        if 6 != self.lineEditStockCodeForHistoricalQuotation.text().toUtf8(
        ).length():
            QtGui.QMessageBox.warning(self, u"错误!", u"股票代码长度须为6",
                                      QtGui.QMessageBox.Cancel)
            return None

        # 创建传参字典
        return unicode(
            self.lineEditStockCodeForHistoricalQuotation.text().toUtf8(),
            'utf-8', 'ignore')

    def getRefMultiStockCode(self):
        """获取单只股票数据参数"""

        # 判断输入的股票代码是否合法
        if 0 == len(self.__codeList) or self.__codeList is None:
            QtGui.QMessageBox.warning(self, u"错误!", u"请导入股票代码文件",
                                      QtGui.QMessageBox.Cancel)
            return None
        for stockCode in self.__codeList:
            if 6 == len(stockCode):
                QtGui.QMessageBox.warning(self, u"错误!", u"股票代码长度须为6",
                                          QtGui.QMessageBox.Cancel)
                return None

        # 创建传参字典
        return self.__codeList

    def isShowTheStockCodeInput(self):
        """检查是否需要显示股票代码输入接口"""
        if self.chkBoxStockCode.isChecked():
            self.labStockCodeForHistoricalQuotation.show()  # 显示股票代码输入标签
            self.lineEditStockCodeForHistoricalQuotation.show()  # 显示股票代码输入栏
            self.chkBoxBulkModeForHistoricalQuotation.show()  # 显示批量输入复选框
        else:
            self.labStockCodeForHistoricalQuotation.hide()  # 隐藏股票代码输入标签
            self.lineEditStockCodeForHistoricalQuotation.hide()  # 隐藏股票代码输入栏
            self.chkBoxBulkModeForHistoricalQuotation.hide()  # 隐藏批量输入复选框

        self.onChkBoxBulkModeForHistoricalQuotationClicked()

    @QtCore.pyqtSlot()
    def onLineEditStartTimeForHistoricalQuotationClicked(self):
        # 设置要修改的文本编辑窗口
        self.__calenderForHistoricalQuotation.setLineEditObj(
            self.lineEditStartTimeForHistoricalQuotation)

        # 显示日历窗口
        self.__calenderForHistoricalQuotation.show()

    @QtCore.pyqtSlot()
    def onLineEditEndTimeForHistoricalQuotationClicked(self):
        # 设置要修改的文本编辑窗口
        self.__calenderForHistoricalQuotation.setLineEditObj(
            self.lineEditEndTimeForHistoricalQuotation)

        # 显示日历窗口
        self.__calenderForHistoricalQuotation.show()

    @QtCore.pyqtSlot()
    def onChkBoxClicked(self):
        # 是否显示批接口控件
        self.isShowTheStockCodeInput()

    @QtCore.pyqtSlot()
    def onChkBoxBulkModeForHistoricalQuotationClicked(self):
        """检查是否需要调用批接口,显示批接口数据导入按钮"""

        # 检测“批量模式”复选框是否被选中,如果选中,显示“批量导入”按钮
        if self.chkBoxBulkModeForHistoricalQuotation.isChecked():
            self.btnBulkModeForHistoricalQuotation.show()
        else:
            self.btnBulkModeForHistoricalQuotation.hide()

            # 清空lineEdit
            self.lineEditStockCodeForHistoricalQuotation.clear()

        # 清空股票代码列表
        self.__codeList = []

    @QtCore.pyqtSlot()
    def onBtnBulkModeForHistoricalQuotationClicked(self):
        """批量导入按钮的槽函数"""

        # 清空lineEdit
        self.lineEditStockCodeForHistoricalQuotation.clear()

        # 获取用户设置的批量股票代码的Excel文件
        qFilePathName = QtGui.QFileDialog.getOpenFileName(
            self, u'导入股票列表', './', "excel(*.xls *.xlsx)")

        # 如果获取的文件名为空,或者用户点击了取消,直接退出本方法
        if qFilePathName.isEmpty():
            return

        # 将QString转换为string
        filePathName = unicode(qFilePathName.toUtf8(), 'utf-8', 'ignore')

        # 循环遍历该Excel文件中所有的数据表
        workbook = xlrd.open_workbook(filePathName)
        for sheet_name in workbook.sheets():
            # 读取该工作表中有多少列数据
            ncols = sheet_name.ncols
            for index in xrange(ncols):
                # 如果数据有非法值,报错
                try:
                    stockCodeList = map(str,
                                        map(int, sheet_name.col_values(index)))
                    self.__codeList += stockCodeList
                except:
                    QtGui.QMessageBox.warning(self, "错误!", "导入的股票代码表存在非法值",
                                              QtGui.QMessageBox.Cancel)
                    self.__codeList = []
                    return

        # 将股票列表的代码号填写到linEdit中
        for stockCode in self.__codeList:
            self.lineEditStockCodeForHistoricalQuotation.insert("\"%s\", " %
                                                                stockCode)
Ejemplo n.º 12
0
class TransactionDataWidgetForBigSingleTransactionData(
        TransactionDataWidgetForMarketIndexList):
    def __init__(self, parent=None):
        # print "StockDataWidgetForBigSingleTransactionData: init"
        super(TransactionDataWidgetForBigSingleTransactionData,
              self).__init__()

        # 创建本类管理的tab下的查询的参数
        self.__searchRefForBigSingleTransactionData = {}

        # 存放批量股票代码数据的列表
        self.__codeListForBigSingleTransactionData = []

        # 创建日历窗口,但是不显示
        self.__calenderForBigSingleTransactionData = Calendar()

        # 当点击起始时间,结束时间lineEdit的时候,弹出日历
        self.lineEditTransactionTimeForBigSingleTransactionData.LineEditClicked.connect(
            self.onLineEditStartTimeForBigSingleTransactionDataClicked)

        # 勾选上股票代码的时候,再显示是否显示需要输入具体的信息
        self.onChkBoxBulkModeForBigSingleTransactionDataClicked()
        self.chkBoxBulkModeForBigSingleTransactionData.clicked.connect(
            self.onChkBoxBulkModeForBigSingleTransactionDataClicked)

        # 批量导入按钮的信号与槽函数
        self.btnBulkModeForBigSingleTransactionData.clicked.connect(
            self.onBtnBulkModeForBigSingleTransactionDataClicked)

        # 保存路径
        self.btnSavePathForBigSingleTransactionData.clicked.connect(
            self.onBtnSavePathForBigSingleTransactionDataClicked)

    @QtCore.pyqtSlot()
    def onLineEditStartTimeForBigSingleTransactionDataClicked(self):
        # 设置要修改的文本编辑窗口
        self.__calenderForBigSingleTransactionData.setLineEditObj(
            self.lineEditTransactionTimeForBigSingleTransactionData)

        # 显示日历窗口
        self.__calenderForBigSingleTransactionData.show()

    @QtCore.pyqtSlot()
    def onChkBoxBulkModeForBigSingleTransactionDataClicked(self):
        """检查是否需要调用批接口,显示批接口数据导入按钮"""

        # 检测“批量模式”复选框是否被选中,如果选中,显示“批量导入”按钮,并设置模式
        if self.chkBoxBulkModeForBigSingleTransactionData.isChecked():
            self.btnBulkModeForBigSingleTransactionData.show()
            self.__searchRefForBigSingleTransactionData["mode"] = "multiCode"
        else:
            self.btnBulkModeForBigSingleTransactionData.hide()
            self.__searchRefForBigSingleTransactionData["mode"] = "singleCode"

            # 清空lineEdit
            self.lineEditStockCodeForBigSingleTransactionData.clear()

        # 清空股票代码列表
        self.__codeListForBigSingleTransactionData = []

    @QtCore.pyqtSlot()
    def onBtnBulkModeForBigSingleTransactionDataClicked(self):
        """批量导入按钮的槽函数"""

        # 清空lineEdit
        self.lineEditStockCodeForBigSingleTransactionData.clear()

        # 获取用户设置的批量股票代码的Excel文件
        qFilePathName, fileType = QtWidgets.QFileDialog.getOpenFileName(
            self, u'导入股票列表', './', "excel(*.xls *.xlsx)")

        # 如果获取的文件名为空,或者用户点击了取消,直接退出本方法
        if 0 == len(qFilePathName):
            return

        # 将QString转换为string
        filePathName = qFilePathName

        # 循环遍历该Excel文件中所有的数据表
        workbook = xlrd.open_workbook(filePathName)
        for sheet_name in workbook.sheets():
            # 读取该工作表中有多少列数据
            ncols = sheet_name.ncols
            for index in range(ncols):
                # 如果数据有非法值,报错
                try:
                    stockCodeList = map(str,
                                        map(int, sheet_name.col_values(index)))
                    self.__codeListForBigSingleTransactionData += stockCodeList
                except:
                    QtWidgets.QMessageBox.warning(self, "错误!", "导入的股票代码表存在非法值",
                                                  QtWidgets.QMessageBox.Cancel)
                    self.__codeListForBigSingleTransactionData = []
                    return

        # 将股票列表的代码号填写到linEdit中
        for stockCode in self.__codeListForBigSingleTransactionData:
            self.lineEditStockCodeForBigSingleTransactionData.insert(
                "\"%s\", " % stockCode)

    @QtCore.pyqtSlot()
    def onBtnSavePathForBigSingleTransactionDataClicked(self):
        """获取用户想要保存的数据路径"""

        # 打开对话框,获取需要保存的路径
        path = QtWidgets.QFileDialog.getExistingDirectory(
            self, u"数据保存路径", QtCore.QDir.currentPath())

        # 如果获取失败,退出函数
        if path is None:
            return

        # 将路径显示到界面上
        self.lineEditSavePathForBigSingleTransactionData.setText(path)

    def getRefSingleStockCodeForBigSingleTransactionData(self):
        """获取单只股票数据参数"""

        # 判断输入的股票代码是否合法
        if 0 == len(self.lineEditStockCodeForBigSingleTransactionData.text()):
            QtWidgets.QMessageBox.warning(self, u"错误!", u"请填写股票代码",
                                          QtWidgets.QMessageBox.Cancel)
            return None
        try:
            int(self.lineEditStockCodeForBigSingleTransactionData.text())
        except:
            QtWidgets.QMessageBox.warning(self, u"错误!", u"股票代码须为6位数字",
                                          QtWidgets.QMessageBox.Cancel)
            return None
        if 6 != len(self.lineEditStockCodeForBigSingleTransactionData.text()):
            QtWidgets.QMessageBox.warning(self, u"错误!", u"股票代码长度须为6",
                                          QtWidgets.QMessageBox.Cancel)
            return None

        # 创建传参字典
        return self.lineEditStockCodeForBigSingleTransactionData.text()

    def getRefMultiStockCodeForBigSingleTransactionData(self):
        """获取单只股票数据参数"""

        # 判断输入的股票代码是否合法
        if 0 == len(self.__codeListForBigSingleTransactionData
                    ) or self.__codeListForBigSingleTransactionData is None:
            QtWidgets.QMessageBox.warning(self, u"错误!", u"请导入股票代码文件",
                                          QtWidgets.QMessageBox.Cancel)
            return None
        for stockCode in self.__codeListForBigSingleTransactionData:
            if 6 == len(stockCode):
                QtWidgets.QMessageBox.warning(self, u"错误!", u"股票代码长度须为6",
                                              QtWidgets.QMessageBox.Cancel)
                return None

        # 返回股票代码列表
        return self.__codeListForBigSingleTransactionData

    def getRefDateTimeForBigSingleTransactionData(self):
        """获取时间"""

        # 判断是否选择了时间
        if 0 == len(
                self.lineEditTransactionTimeForBigSingleTransactionData.text()
        ) or 0 == len(self.lineEditTransactionTimeForBigSingleTransactionData.
                      text()):
            QtWidgets.QMessageBox.warning(self, u"错误!", u"请填写完整日期!",
                                          QtWidgets.QMessageBox.Cancel)
            return None

        # 获取参数
        date = self.lineEditTransactionTimeForBigSingleTransactionData.text()

        return date

    def getRefVolForBigSingleTransactionData(self):
        """获取手数"""

        # 判断是否输入了参数
        if 0 == len(self.lineEditLots.text()) or 0 == len(
                self.lineEditLots.text()):
            QtWidgets.QMessageBox.warning(self, u"错误!", u"请填写手数!",
                                          QtWidgets.QMessageBox.Cancel)
            return None

        # 获取参数
        vol = self.lineEditLots.text()

        # 判断参数是否合法
        try:
            assert int(vol) >= 0
        except:
            QtWidgets.QMessageBox.warning(self, u"错误!", u"手数需要填写一个正整数!",
                                          QtWidgets.QMessageBox.Cancel)
            return None

        return vol

    def getRefSavePathForBigSingleTransactionData(self):
        """获取文件保存路径"""

        # 容错
        if 0 == len(self.lineEditSavePathForBigSingleTransactionData.text()):
            QtWidgets.QMessageBox.warning(self, u"错误!", u"请设置保存路径",
                                          QtWidgets.QMessageBox.Cancel)
            return None

        return str(self.lineEditSavePathForBigSingleTransactionData.text())

    def getRefDictForBigSingleTransactionData(self):
        """获取历史行情参数字典"""

        # 如果是查询单只股票
        if self.__searchRefForBigSingleTransactionData["mode"] == "singleCode":
            # 获取参数,创建传参字典
            if self.getRefSingleStockCodeForBigSingleTransactionData(
            ) is not None:
                self.__searchRefForBigSingleTransactionData[
                    "code"] = self.getRefSingleStockCodeForBigSingleTransactionData(
                    )
            else:
                return None

        # 如果是查询多只股票
        if self.__searchRefForBigSingleTransactionData["mode"] == "multiCode":
            # 获取参数,创建传参字典
            if self.getRefMultiStockCodeForBigSingleTransactionData(
            ) is not None:
                self.__searchRefForBigSingleTransactionData[
                    "code"] = self.getRefMultiStockCodeForBigSingleTransactionData(
                    )
            else:
                return None

        # 获取日期
        date = self.getRefDateTimeForBigSingleTransactionData()
        if date is not None:
            self.__searchRefForBigSingleTransactionData["date"] = date
        else:
            return None

        # 获取手数
        vol = self.getRefVolForBigSingleTransactionData()
        if vol is not None:
            self.__searchRefForBigSingleTransactionData["vol"] = vol
        else:
            return None

        # 获取文件保存路径
        self.__searchRefForBigSingleTransactionData[
            "path"] = self.getRefSavePathForBigSingleTransactionData()

        # 回返一个参数字典
        return self.__searchRefForBigSingleTransactionData
Ejemplo n.º 13
0
class FutureDataWidget(QtWidgets.QWidget, Ui_futureDataWidget):
    def __init__(self, parent=None):
        QtWidgets.QWidget.__init__(self, parent)
        self.setupUi(self)

        # 用户需要查询那些数据(记录那些checkbox被选中)
        self.__marketDataSourceList = []

        # 查询数据的传参字典
        self.__refDict = {}

        # 创建日历窗口,但是不显示
        self.__calender = Calendar()

        # 当点击起始时间,结束时间lineEdit的时候,弹出日历
        self.lineEditStartTime.LineEditClicked.connect(
            self.onLineEditStartTimeClicked)
        self.lineEditEndTime.LineEditClicked.connect(
            self.onLineEditEndTimeClicked)

        # 所有的chkbox的点击事件
        self.chkBoxSH.clicked.connect(self.onChkBoxChicked)  # 中金所
        self.chkBoxSZ.clicked.connect(self.onChkBoxChicked)  # 郑商所
        self.chkBoxHS300.clicked.connect(self.onChkBoxChicked)  # 上期所
        self.chkBoxSZ50.clicked.connect(self.onChkBoxChicked)  # 大商所

        # 所有的按钮事件
        self.btnSelectSavePath.clicked.connect(self.onBtnSelectSavePathClicked)
        self.btnSaveToCSV.clicked.connect(self.onBtnSaveClicked)
        self.btnSaveToExcel.clicked.connect(self.onBtnSaveClicked)
        self.btnSaveToHDF5.clicked.connect(self.onBtnSaveClicked)
        self.btnSaveToJSON.clicked.connect(self.onBtnSaveClicked)
        self.btnSaveToMySQL.clicked.connect(self.onBtnSaveClicked)
        self.btnSaveToMongoDB.clicked.connect(self.onBtnSaveClicked)

    def getRefDict(self):
        """获取用户选择的数据,如果数据有误,返回False"""

        # 判断参数是否正确
        if 0 == len(self.__marketDataSourceList):
            QtWidgets.QMessageBox.warning(self, u"错误!", u"请选择数据来源!",
                                          QtWidgets.QMessageBox.Cancel)
            return False

        # 需要有起始和终止时间
        if 0 == len(self.lineEditStartTime.text()) or 0 == len(
                self.lineEditEndTime.text()):
            QtWidgets.QMessageBox.warning(self, u"错误!", u"请填写完整日期!",
                                          QtWidgets.QMessageBox.Cancel)
            return False

        # 起始和终止时间需要合法
        startDate = datetime.datetime.strptime(self.lineEditStartTime.text(),
                                               '%Y-%m-%d')
        endDate = datetime.datetime.strptime(self.lineEditEndTime.text(),
                                             '%Y-%m-%d')
        if startDate >= endDate:
            QtWidgets.QMessageBox.warning(self, u"错误!", u"日期非法!",
                                          QtWidgets.QMessageBox.Cancel)
            return False

        # 创建传参字典
        self.__refDict["market"] = self.__marketDataSourceList
        self.__refDict["startTime"] = str(self.lineEditStartTime.text())
        self.__refDict["endTime"] = str(self.lineEditEndTime.text())
        return True

    def appendDataSourceToList(self, chkBox, ref):
        """判断数据源列表中需要添加还是删除数据"""

        # 容错
        if chkBox is None:
            return

        # 判断参数的添加与删除
        if chkBox.isChecked():
            self.__marketDataSourceList.append(ref)
        else:
            self.__marketDataSourceList.remove(ref)

    @QtCore.pyqtSlot()
    def onBtnSelectSavePathClicked(self):
        """获取用户想要保存的数据路径"""

        # 打开对话框,获取需要保存的路径
        path = QtWidgets.QFileDialog.getExistingDirectory(
            self, u"数据保存路径", QtCore.QDir.currentPath())

        # 如果获取失败,退出函数
        if path is None:
            return

        # 将路径显示到界面上
        self.lineEditSavePath.setText(path)

    @QtCore.pyqtSlot()
    def onBtnSaveClicked(self):
        """各个保存按钮按下的时候的槽函数"""

        # 先获取一下需要传递的参数,如果数据有误,退出函数
        if not self.getRefDict():
            return

        # 获取用户想要保存的数据路径
        if 0 == len(self.lineEditSavePath.text()) or 0 == len(
                self.lineEditSavePath.text()):
            QtWidgets.QMessageBox.warning(self, u"错误!", u"请输入保存路径!",
                                          QtWidgets.QMessageBox.Cancel)
            return
        self.__refDict["path"] = str(self.lineEditSavePath.text())

        print(self.__refDict)

        # 调取数据模块的接口
        if self.btnSaveToCSV == self.sender():
            print(self.__refDict)
            for market in self.__refDict["market"]:
                DataBasic.get_futures(self.__refDict["startTime"],
                                      self.__refDict["endTime"], market)

        elif self.btnSaveToExcel == self.sender():
            pass  # todo
        elif self.btnSaveToHDF5 == self.sender():
            pass  # todo
        elif self.btnSaveToJSON == self.sender():
            pass  # todo
        elif self.btnSaveToMySQL == self.sender():
            pass  # todo
        elif self.btnSaveToMongoDB == self.sender():
            pass  # todo
        else:
            return

    @QtCore.pyqtSlot()
    def onChkBoxChicked(self):
        """当复选框被选中的时候"""

        # 中金所
        if self.chkBoxSH == self.sender():
            self.appendDataSourceToList(self.sender(), 'CFFEX')
        # 郑商所
        elif self.chkBoxSZ == self.sender():
            self.appendDataSourceToList(self.sender(), "CZCE")
        # 上期所
        elif self.chkBoxHS300 == self.sender():
            self.appendDataSourceToList(self.sender(), "SHFE")
        # 大商所
        elif self.chkBoxSZ50 == self.sender():
            self.appendDataSourceToList(self.sender(), "DCE")

    @QtCore.pyqtSlot()
    def onLineEditStartTimeClicked(self):
        # 设置要修改的文本编辑窗口
        self.__calender.setLineEditObj(self.lineEditStartTime)

        # 显示日历窗口
        self.__calender.show()

    @QtCore.pyqtSlot()
    def onLineEditEndTimeClicked(self):
        # 设置要修改的文本编辑窗口
        self.__calender.setLineEditObj(self.lineEditEndTime)

        # 显示日历窗口
        self.__calender.show()
Ejemplo n.º 14
0
class TransactionDataWidgetForHistoricalTick(TransactionDataWidgetForRealTimeQuotation):
    def __init__(self, parent=None):
        # print "StockDataWidgetForHistoricalTick: init"
        super(TransactionDataWidgetForHistoricalTick, self).__init__()

        # 创建本类管理的tab下的查询的参数
        self.__searchRefForHistoricalTick = {}

        # 存放批量股票代码数据的列表
        self.__codeListForHistoricalTick = []

        # 创建日历窗口,但是不显示
        self.__calenderForHistoricalTick = Calendar()

        # 当点击起始时间,结束时间lineEdit的时候,弹出日历
        self.lineEditTickTimeForHistoricalTick.LineEditClicked.connect(self.onLineEditTickTimeForHistoricalTickClicked)

        # 点击复选框,是否显示“批量导入按钮”
        self.onChkBoxBulkModeForHistoricalTickClicked()
        self.chkBoxBulkModeForHistoricalTick.clicked.connect(self.onChkBoxBulkModeForHistoricalTickClicked)

        # 批量导入按钮的信号与槽函数
        self.btnBulkModeForHistoricalTick.clicked.connect(self.onBtnBulkModeForHistoricalTickClicked)

        # 保存路径
        self.btnSavePathForHistoricalTick.clicked.connect(self.onBtnSavePathForHistoricalTickClicked)

    @QtCore.pyqtSlot()
    def onLineEditTickTimeForHistoricalTickClicked(self):
        # 设置要修改的文本编辑窗口
        self.__calenderForHistoricalTick.setLineEditObj(self.lineEditTickTimeForHistoricalTick)

        # 显示日历窗口
        self.__calenderForHistoricalTick.show()

    @QtCore.pyqtSlot()
    def onChkBoxBulkModeForHistoricalTickClicked(self):
        """检查是否需要显示批量输入按钮"""
        if self.chkBoxBulkModeForHistoricalTick.isChecked():
            self.btnBulkModeForHistoricalTick.show()  # 显示批量输入按钮
            self.__searchRefForHistoricalTick["mode"] = "multiCode"
        else:
            self.btnBulkModeForHistoricalTick.hide()  # 隐藏批量输入按钮
            self.__searchRefForHistoricalTick["mode"] = "singleCode"

    @QtCore.pyqtSlot()
    def onBtnBulkModeForHistoricalTickClicked(self):
        """批量导入按钮的槽函数"""

        # 清空lineEdit
        self.lineEditStockCodeForHistoricalTick.clear()

        # 获取用户设置的批量股票代码的Excel文件
        qFilePathName, fileType = QtWidgets.QFileDialog.getOpenFileName(self, u'导入股票列表', './', "excel(*.xls *.xlsx)")

        # 如果获取的文件名为空,或者用户点击了取消,直接退出本方法
        if 0 == len(qFilePathName):
            return

        # 将QString转换为string
        filePathName = qFilePathName

        # 循环遍历该Excel文件中所有的数据表
        workbook = xlrd.open_workbook(filePathName)
        for sheet_name in workbook.sheets():
            # 读取该工作表中有多少列数据
            ncols = sheet_name.ncols
            for index in range(ncols):
                # 如果数据有非法值,报错
                try:
                    stockCodeList = map(str, map(int, sheet_name.col_values(index)))
                    self.__codeListForHistoricalTick += stockCodeList
                except:
                    QtWidgets.QMessageBox.warning(self, "错误!", "导入的股票代码表存在非法值", QtWidgets.QMessageBox.Cancel)
                    self.__codeListForHistoricalTick = []
                    return

    @QtCore.pyqtSlot()
    def onBtnSavePathForHistoricalTickClicked(self):
        """获取用户想要保存的数据路径"""

        # 打开对话框,获取需要保存的路径
        path = QtWidgets.QFileDialog.getExistingDirectory(self, u"数据保存路径", QtCore.QDir.currentPath())

        # 如果获取失败,退出函数
        if path is None:
            return

        # 将路径显示到界面上
        self.lineEditSavePathForHistoricalTick.setText(path)

    def getRefSingleStockCodeForHistoricalTick(self):
        """获取单只股票数据参数"""

        # 判断输入的股票代码是否合法
        if 0 == len(self.lineEditStockCodeForHistoricalTick.text()):
            QtWidgets.QMessageBox.warning(self, u"错误!", u"请填写股票代码", QtWidgets.QMessageBox.Cancel)
            return None
        try:
            int(self.lineEditStockCodeForHistoricalTick.text())
        except:
            QtWidgets.QMessageBox.warning(self, u"错误!", u"股票代码须为6位数字", QtWidgets.QMessageBox.Cancel)
            return None
        if 6 != len(self.lineEditStockCodeForHistoricalTick.text()):
            QtWidgets.QMessageBox.warning(self, u"错误!", u"股票代码长度须为6", QtWidgets.QMessageBox.Cancel)
            return None

        # 返回股票代码
        return self.lineEditStockCodeForHistoricalTick.text()

    def getRefMultiStockCodeForHistoricalTick(self):
        """获取单只股票数据参数"""

        # 判断输入的股票代码是否合法
        if 0 == len(self.__codeListForHistoricalTick) or self.__codeListForHistoricalTick is None:
            QtWidgets.QMessageBox.warning(self, u"错误!", u"请导入股票代码文件", QtWidgets.QMessageBox.Cancel)
            return None
        for stockCode in self.__codeListForHistoricalTick:
            if 6 == len(stockCode):
                QtWidgets.QMessageBox.warning(self, u"错误!", u"股票代码长度须为6", QtWidgets.QMessageBox.Cancel)
                return None

        # 创建传参字典
        return self.__codeListForHistoricalTick

    def getRefDateTimeForHistoricalTick(self):
        """获取时间"""

        # 判断是否选择了时间
        if 0 == len(self.lineEditTickTimeForHistoricalTick.text()) or 0 == len(self.lineEditTickTimeForHistoricalTick.text()):
            QtWidgets.QMessageBox.warning(self, u"错误!", u"请填写完整日期!", QtWidgets.QMessageBox.Cancel)
            return None

        # 获取参数
        date = self.lineEditTickTimeForHistoricalTick.text()

        return date

    def getRefSavePathForHistoricalTick(self):
        """获取文件保存路径"""

        # 容错
        if 0 == len(self.lineEditSavePathForHistoricalTick.text()):
            QtWidgets.QMessageBox.warning(self, u"错误!", u"请设置保存路径", QtWidgets.QMessageBox.Cancel)
            return None

        return str(self.lineEditSavePathForHistoricalTick.text())

    def getRefDictForHistoricalTick(self):
        """获取复权数据参数字典"""

        # 如果是查询单只股票
        if self.__searchRefForHistoricalTick["mode"] == "singleCode":
            # 获取参数,创建传参字典
            if self.getRefSingleStockCodeForHistoricalTick() is not None:
                self.__searchRefForHistoricalTick["code"] = self.getRefSingleStockCodeForHistoricalTick()
            else:
                return None

        # 如果是查询多只股票
        if self.__searchRefForHistoricalTick["mode"] == "multiCode":
            # 获取参数,创建传参字典
            if self.getRefMultiStockCodeForHistoricalTick() is not None:
                self.__searchRefForHistoricalTick["code"] = self.getRefMultiStockCodeForHistoricalTick()
            else:
                return None

        # 获取时间
        date = self.getRefDateTimeForHistoricalTick()
        if date is not None:
            self.__searchRefForHistoricalTick["date"] = date
        else:
            return None

        # 获取文件保存路径
        self.__searchRefForHistoricalTick["path"] = self.getRefSavePathForHistoricalTick()

        # 回返一个参数字典
        return self.__searchRefForHistoricalTick
class TransactionDataWidgetForRehabilitationData(TransactionDataWidgetForHistoricalQuotation):
    '''复权数据tab'''

    def __init__(self, parent=None):
        # 调用父类方法
        # print "StockDataWidgetForRehabilitationData: init"
        super(TransactionDataWidgetForRehabilitationData, self).__init__()

        # 创建本类管理的tab下的查询的参数
        self.__searchRefForRehabilitationData = {}

        # 存放批量股票代码数据的列表
        self.__codeListForRehabilitationData = []

        # 创建日历窗口,但是不显示
        self.__calenderForRehabilitationData = Calendar()

        # 当点击起始时间,结束时间lineEdit的时候,弹出日历
        self.lineEditStartTimeForRehabilitationData.LineEditClicked.connect(self.onLineEditStartTimeForRehabilitationDataClicked)
        self.lineEditEndTimeForRehabilitationData.LineEditClicked.connect(self.onLineEditEndTimeForRehabilitationDataClicked)

        # 点击复选框,是否显示“批量导入按钮”
        self.onChkBoxBulkModeForRehabilitationDataClicked()
        self.chkBoxBulkModeForRehabilitationData.clicked.connect(self.onChkBoxBulkModeForRehabilitationDataClicked)

        # 批量导入按钮的信号与槽函数
        self.btnBulkModeForRehabilitationData.clicked.connect(self.onBtnBulkModeForRehabilitationDataClicked)

        # 保存路径
        self.btnSavePathForRehabilitationData.clicked.connect(self.onBtnSavePathForRehabilitationDataClicked)

    @QtCore.pyqtSlot()
    def onLineEditStartTimeForRehabilitationDataClicked(self):
        # 设置要修改的文本编辑窗口
        self.__calenderForRehabilitationData.setLineEditObj(self.lineEditStartTimeForRehabilitationData)

        # 显示日历窗口
        self.__calenderForRehabilitationData.show()

    @QtCore.pyqtSlot()
    def onLineEditEndTimeForRehabilitationDataClicked(self):
        # 设置要修改的文本编辑窗口
        self.__calenderForRehabilitationData.setLineEditObj(self.lineEditEndTimeForRehabilitationData)

        # 显示日历窗口
        self.__calenderForRehabilitationData.show()

    @QtCore.pyqtSlot()
    def onChkBoxBulkModeForRehabilitationDataClicked(self):
        """检查是否需要显示批量输入按钮"""
        if self.chkBoxBulkModeForRehabilitationData.isChecked():
            self.btnBulkModeForRehabilitationData.show()     # 显示批量输入按钮
            self.__searchRefForRehabilitationData["mode"] = "multiCode"
        else:
            self.btnBulkModeForRehabilitationData.hide()     # 隐藏批量输入按钮
            self.__searchRefForRehabilitationData["mode"] = "singleCode"

    @QtCore.pyqtSlot()
    def onBtnBulkModeForRehabilitationDataClicked(self):
        """批量导入按钮的槽函数"""

        # 清空lineEdit
        self.lineEditStockCodeForRehabilitationData.clear()

        # 获取用户设置的批量股票代码的Excel文件
        qFilePathName, fileType = QtWidgets.QFileDialog.getOpenFileName(self, u'导入股票列表', './', "excel(*.xls *.xlsx)")

        # 如果获取的文件名为空,或者用户点击了取消,直接退出本方法
        if 0 == len(qFilePathName):
            return

        # 将QString转换为string
        filePathName = qFilePathName

        # 循环遍历该Excel文件中所有的数据表
        workbook = xlrd.open_workbook(filePathName)
        for sheet_name in workbook.sheets():
            # 读取该工作表中有多少列数据
            ncols = sheet_name.ncols
            for index in range(ncols):
                # 如果数据有非法值,报错
                try:
                    stockCodeList = map(str, map(int, sheet_name.col_values(index)))
                    self.__codeListForRehabilitationData += stockCodeList
                except:
                    QtWidgets.QMessageBox.warning(self, "错误!", "导入的股票代码表存在非法值", QtWidgets.QMessageBox.Cancel)
                    self.__codeListForRehabilitationData = []
                    return

        # 将股票列表的代码号填写到linEdit中
        for stockCode in self.__codeListForRehabilitationData:
            self.lineEditStockCodeForRehabilitationData.insert("\"%s\", " % stockCode)

    @QtCore.pyqtSlot()
    def onBtnSavePathForRehabilitationDataClicked(self):
        """获取用户想要保存的数据路径"""

        # 打开对话框,获取需要保存的路径
        path = QtWidgets.QFileDialog.getExistingDirectory(self, u"数据保存路径", QtCore.QDir.currentPath())

        # 如果获取失败,退出函数
        if path is None:
            return

        # 将路径显示到界面上
        self.lineEditSavePathForRehabilitationData.setText(path)

    def getRefSingleStockCodeForRehabilitationData(self):
        """获取单只股票数据参数"""

        # 判断输入的股票代码是否合法
        if 0 == len(self.lineEditStockCodeForRehabilitationData.text()):
            QtWidgets.QMessageBox.warning(self, u"错误!", u"请填写股票代码", QtWidgets.QMessageBox.Cancel)
            return None
        try:
            int(self.lineEditStockCodeForRehabilitationData.text())
        except:
            QtWidgets.QMessageBox.warning(self, u"错误!", u"股票代码须为6位数字", QtWidgets.QMessageBox.Cancel)
            return None
        if 6 != len(self.lineEditStockCodeForRehabilitationData.text()):
            QtWidgets.QMessageBox.warning(self, u"错误!", u"股票代码长度须为6", QtWidgets.QMessageBox.Cancel)
            return None

        # 返回股票代码
        return self.lineEditStockCodeForRehabilitationData.text()

    def getRefMultiStockCodeForRehabilitationData(self):
        """获取单只股票数据参数"""

        # 判断输入的股票代码是否合法
        if 0 == len(self.__codeListForRehabilitationData) or self.__codeListForRehabilitationData is None:
            QtWidgets.QMessageBox.warning(self, u"错误!", u"请导入股票代码文件", QtWidgets.QMessageBox.Cancel)
            return None
        for stockCode in self.__codeListForRehabilitationData:
            if 6 == len(stockCode):
                QtWidgets.QMessageBox.warning(self, u"错误!", u"股票代码长度须为6", QtWidgets.QMessageBox.Cancel)
                return None

        # 创建传参字典
        return self.__codeListForRehabilitationData

    def getRefDateTimeForRehabilitationData(self):
        """获取时间"""

        # 都不填写,表示不需要时间
        if 0 == len(self.lineEditStartTimeForRehabilitationData.text()) and 0 == len(self.lineEditEndTimeForRehabilitationData.text()):
            return None, None

        # 判断是否选择了时间
        if 0 == len(self.lineEditStartTimeForRehabilitationData.text()) or 0 == len(self.lineEditEndTimeForRehabilitationData.text()):
            QtWidgets.QMessageBox.warning(self, u"错误!", u"请填写完整日期!", QtWidgets.QMessageBox.Cancel)
            return None, None

        # 起始和终止时间需要合法
        startDate = datetime.datetime.strptime(self.lineEditStartTimeForRehabilitationData.text(), '%Y-%m-%d')
        endDate = datetime.datetime.strptime(self.lineEditEndTimeForRehabilitationData.text(), '%Y-%m-%d')
        if startDate >= endDate:
            QtWidgets.QMessageBox.warning(self, u"错误!", u"日期非法!", QtWidgets.QMessageBox.Cancel)
            return None, None

        # 获取参数
        start = self.lineEditStartTimeForRehabilitationData.text()
        end = self.lineEditEndTimeForRehabilitationData.text()

        return start, end

    def getRefIndexForRehabilitationData(self):
        """判断是否是大盘数据"""

        # 如果两个都没有选中,默认选中“是”
        if not self.chkBoxYes.isChecked() and not self.chkBoxNo.isChecked():
            self.chkBoxYes.setChecked(True)

        # 判断用户选中了拿个选项
        if self.chkBoxYes.isChecked() and not self.chkBoxNo.isChecked():
            return True
        else:
            return False

    def getRefSavePathForRehabilitationData(self):
        """获取文件保存路径"""

        # 容错
        if 0 == len(self.lineEditSavePathForRehabilitationData.text()):
            QtWidgets.QMessageBox.warning(self, u"错误!", u"请设置保存路径", QtWidgets.QMessageBox.Cancel)
            return None

        return str(self.lineEditSavePathForRehabilitationData.text())

    def getRefDictForRehabilitationData(self):
        """获取复权数据参数字典"""

        # 如果是查询单只股票
        if self.__searchRefForRehabilitationData["mode"] == "singleCode":
            # 获取参数,创建传参字典
            if self.getRefSingleStockCodeForRehabilitationData() is not None:
                self.__searchRefForRehabilitationData["code"] = self.getRefSingleStockCodeForRehabilitationData()
            else:
                return None

        # 如果是查询多只股票
        if self.__searchRefForRehabilitationData["mode"] == "multiCode":
            # 获取参数,创建传参字典
            if self.getRefMultiStockCodeForRehabilitationData() is not None:
                self.__searchRefForRehabilitationData["code"] = self.getRefMultiStockCodeForRehabilitationData()
            else:
                return None

        # 获取时间
        start, end = self.getRefDateTimeForRehabilitationData()
        if start is not None and end is not None:
            self.__searchRefForRehabilitationData["start"] = start
            self.__searchRefForRehabilitationData["end"] = end
        else:
            return None

        # 获取复权类型
        self.__searchRefForRehabilitationData["autype"] = autypeList[self.comboBoxRehabilitationType.currentIndex()]

        # 是否是大盘指数
        self.__searchRefForRehabilitationData["index"] = self.getRefIndexForRehabilitationData()

        # 获取文件保存路径
        self.__searchRefForRehabilitationData["path"] = self.getRefSavePathForRehabilitationData()

        # 回返一个参数字典
        return self.__searchRefForRehabilitationData