# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'data_import_model.ui'
#
# Created by: PyQt5 UI code generator 5.15.0
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again.  Do not edit this file unless you know what you are doing.

from PySide2 import QtCore, QtGui, QtWidgets
#from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_Form(object):
    def __init__(self):
        self.IconPath = ""
    ##### 动态生成参数模块的部分
    def addForm(self, obj, objType, name, setText = ""):
        obj.setMinimumSize(QtCore.QSize(150, 25))
        obj.setMaximumSize(QtCore.QSize(100, 16777215))
        obj.setObjectName(objType + "_" + name)
        obj.objName = name
        obj.setHidden(True)
        if setText:
            obj.setText(self.translate("Form", str(setText)))
        return(obj)

    def addForm_checkBox(self, tagName, objName, setItem = [""]):
        """添加复选项组件"""
        model = QtWidgets.QCheckBox(self.groupBox_importparam)
        model.setChecked(setItem[0])
        model = self.addForm(obj = model, objType = "checkBox", name = objName, setText = tagName)
        model.tagName = tagName
        return(model)

    def addForm_lineEdit(self, tagName, objName, setItem = ""):
        """添加行文本组件"""
        model = QtWidgets.QLineEdit(self.groupBox_importparam)
        model = self.addForm(obj = model, objType = "lineEdit", name = objName, setText = setItem)
        model.tagName = tagName
        return(model)

    def addForm_comboBox(self, tagName, objName, setItem = [""]):
        """添加组合框组件"""
        model = QtWidgets.QComboBox(self.groupBox_importparam)
        model = self.updateForm_ComboBox(model, setItem)
        model = self.addForm(obj = model, objType = "combBox", name = objName)
        model.tagName = tagName
        return(model)

    def updateForm_ComboBox(self, obj, setItem = [""]):
        """更新ComboBox的内容"""
        obj.clear()
        for i, item_i in enumerate(setItem):
            obj.addItem("")
            obj.setItemText(i, self.translate("Form", str(item_i)))
        return(obj)

    def createUiFormAPI(self):
        """
            创建所有API
            如果对API有特殊处理需求，则需要在各自的模块中进行定义
        """
        self.checkBox_ifColumns = self.addForm_checkBox("首行列名", "ifColumns", [True])
        self.checkBox_ifColIndex = self.addForm_checkBox("首列行号", "ifColIndex", [False])
        self.checkBox_asDataFrame = self.addForm_checkBox("数据框格式", "asDataFrame", [True])
        self.checkBox_asString = self.addForm_checkBox("文本格式", "asString", [True])
        self.checkBox_allDataImport = self.addForm_checkBox("全部导入", "allDataImport", [True])

        self.lineEdit_datasetName = self.addForm_lineEdit("数据集名", "datasetname", "")
        self.lineEdit_limitRow = self.addForm_lineEdit("行数限制", "linelimit", "全部")
        self.lineEdit_skipRow = self.addForm_lineEdit("跳过行数", "skipRows", "0")

        self.comboBox_encode = self.addForm_comboBox("字符类型", "encodetype", [""])
        self.comboBox_separator = self.addForm_comboBox("分割符号", "separator", [""])
        self.comboBox_sheetname = self.addForm_comboBox("页面名称", "sheetname", [""])
        self.comboBox_varname = self.addForm_comboBox("变量名称", "varname", [""])

    def horizontalLayoutAddUI(self, obj):
        """添加水平控件位置"""
        obj.setHidden(False)
        self.horizontalLayout_checkBox.addWidget(obj)

    def verticalLayoutAddUI(self, obj, type):
        """添加竖直控件位置"""
        ui = QtWidgets.QHBoxLayout()
        ui.setContentsMargins(0, 0, 0, 0)
        ui.setObjectName("horizontalLayout_" + obj.objName)
        label = QtWidgets.QLabel(self.groupBox_importparam)
        label.setMinimumSize(QtCore.QSize(0, 25))
        label.setObjectName("lable_" + obj.objName)
        label.setText(self.translate("Form", str(obj.tagName)))
        spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        ui.addWidget(label)
        obj.setHidden(False)
        ui.addWidget(obj)
        ui.addItem(spacerItem)
        if type == "left":
            self.verticalLayout_left.addLayout(ui)
        elif type == "right":
            self.verticalLayout_right.addLayout(ui)
        else:
            pass
    ###### 动态生成参数模块

    def publicUIFormActivity(self):
        # 导入窗口的相关事件
        # 在"导入"窗口，打开选择文件
        self.pushButton_choosefile.clicked.connect(self.chooseFileButton)

        # 帮助
        self.pushButton_help.clicked.connect(self.showHelp)

        # 按键更新数据
        self.pushButton_preview.clicked.connect(self.previewButton)  # 预览
        self.pushButton_ok.clicked.connect(self.importDatasetButton)  # 导入
        self.pushButton_cancel.clicked.connect(self.close)  # 取消

    def chooseFileButton(self):
        pass
    def showHelp(self):
        pass
    def previewButton(self):
        pass
    def importDatasetButton(self):
        pass

    def setupUi(self, Form):
        # 公共模块
        Form.resize(800, 630)
        Form.setObjectName("Form")
        Form.setMinimumSize(QtCore.QSize(800, 630))
        Form.setMaximumSize(QtCore.QSize(16777215, 16777215))

        # 头部图片UI
        if self.IconPath:
            icon = QtGui.QIcon()
            icon.addPixmap(QtGui.QPixmap(self.IconPath), QtGui.QIcon.Normal, QtGui.QIcon.Off)
            Form.setWindowIcon(icon)

        # 选择文件路径
        self.widget_chooseFile = QtWidgets.QWidget(Form)
        self.widget_chooseFile.setGeometry(QtCore.QRect(10, 10, 779, 27))
        self.widget_chooseFile.setObjectName("widget_chooseFile")
        self.horizontalLayout_chooseFile = QtWidgets.QHBoxLayout(self.widget_chooseFile)
        self.horizontalLayout_chooseFile.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout_chooseFile.setObjectName("horizontalLayout_chooseFile")
        # 标签：选择文件
        self.label_chooseFile = QtWidgets.QLabel(self.widget_chooseFile)
        self.label_chooseFile.setMinimumSize(QtCore.QSize(0, 25))
        self.label_chooseFile.setObjectName("label_chooseFile")
        # 输入路径窗口
        self.lineEdit_filePath = QtWidgets.QLineEdit(self.widget_chooseFile)
        self.lineEdit_filePath.setMinimumSize(QtCore.QSize(0, 25))
        self.lineEdit_filePath.setObjectName("lineEdit_filePath")
        # 预览按钮
        self.pushButton_choosefile = QtWidgets.QPushButton(self.widget_chooseFile)
        self.pushButton_choosefile.setMinimumSize(QtCore.QSize(0, 25))
        self.pushButton_choosefile.setObjectName("pushButton_choosefile")

        # 添加入窗口
        self.horizontalLayout_chooseFile.addWidget(self.label_chooseFile)
        self.horizontalLayout_chooseFile.addWidget(self.lineEdit_filePath)
        self.horizontalLayout_chooseFile.addWidget(self.pushButton_choosefile)

        # 标签：文件预览
        self.label = QtWidgets.QLabel(Form)
        self.label.setGeometry(QtCore.QRect(10, 40, 100, 20))
        self.label.setObjectName("label")

        # 表格视图
        self.tableWidget_previewData = QtWidgets.QTableWidget(Form)
        self.tableWidget_previewData.setEnabled(True)
        self.tableWidget_previewData.setGeometry(QtCore.QRect(10, 60, 779, 341))
        self.tableWidget_previewData.setObjectName("tableWidget_previewData")
        self.tableWidget_previewData.setColumnCount(0)
        self.tableWidget_previewData.setRowCount(0)

        # 下方界面
        self.widget_importButton = QtWidgets.QWidget(Form)
        self.widget_importButton.setGeometry(QtCore.QRect(10, 590, 779, 27))
        self.widget_importButton.setObjectName("widget_importButton")
        self.horizontalLayout_import = QtWidgets.QHBoxLayout(self.widget_importButton)
        self.horizontalLayout_import.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout_import.setObjectName("horizontalLayout_8")
        # 帮助按钮
        self.pushButton_help = QtWidgets.QPushButton(self.widget_importButton)
        self.pushButton_help.setMinimumSize(QtCore.QSize(0, 25))
        self.pushButton_help.setObjectName("pushButton_help")
        # 中间空余区域
        spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        # 预览按钮
        self.pushButton_preview = QtWidgets.QPushButton(self.widget_importButton)
        self.pushButton_preview.setMinimumSize(QtCore.QSize(0, 25))
        self.pushButton_preview.setObjectName("pushButton_preview")
        # 导入按钮
        self.pushButton_ok = QtWidgets.QPushButton(self.widget_importButton)
        self.pushButton_ok.setMinimumSize(QtCore.QSize(0, 25))
        self.pushButton_ok.setObjectName("pushButton_ok")
        # 取消按钮
        self.pushButton_cancel = QtWidgets.QPushButton(self.widget_importButton)
        self.pushButton_cancel.setMinimumSize(QtCore.QSize(0, 25))
        self.pushButton_cancel.setObjectName("pushButton_cancel")

        # 添加控件
        self.horizontalLayout_import.addWidget(self.pushButton_help)     # 帮助
        self.horizontalLayout_import.addItem(spacerItem)                 # 留白
        self.horizontalLayout_import.addWidget(self.pushButton_preview)  # 预览
        self.horizontalLayout_import.addWidget(self.pushButton_ok)       # 导入
        self.horizontalLayout_import.addWidget(self.pushButton_cancel)   # 取消

        # =================================动态UI部分============================================ #
        # 导入参数区域
        self.groupBox_importparam = QtWidgets.QGroupBox(Form)
        self.groupBox_importparam.setGeometry(QtCore.QRect(10, 410, 779, 171))
        self.groupBox_importparam.setObjectName("groupBox_importparam")

        # 整体布局，分成上下部分，上部分为选择参数，下班部分为输入参数
        self.verticalLayout_param = QtWidgets.QVBoxLayout(self.groupBox_importparam)
        self.verticalLayout_param.setObjectName("verticalLayout_param")

        # 勾选项区域
        self.horizontalLayout_checkBox = QtWidgets.QHBoxLayout()
        self.horizontalLayout_checkBox.setObjectName("horizontalLayout_checkBox")

        # 添加一个弹簧避免控件居中
        spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)

        self.param_checkbox_part = QtWidgets.QHBoxLayout()
        self.param_checkbox_part.setObjectName("horizontalLayout_checkBox")
        self.param_checkbox_part.addLayout(self.horizontalLayout_checkBox)
        self.param_checkbox_part.addItem(spacerItem)
        self.verticalLayout_param.addLayout(self.param_checkbox_part)

        # 输入参数区域
        self.param_import_part = QtWidgets.QFormLayout()
        self.param_import_part.setObjectName("formLayout")
        # 参数区域 - 左边
        self.verticalLayout_left = QtWidgets.QVBoxLayout()
        self.verticalLayout_left.setObjectName("verticalLayout_left")
        # 参数区域 - 右边
        self.verticalLayout_right = QtWidgets.QVBoxLayout()
        self.verticalLayout_right.setObjectName("verticalLayout_right")
        # 添加区域
        self.param_import_part.setLayout(0, QtWidgets.QFormLayout.LabelRole, self.verticalLayout_left)
        self.param_import_part.setLayout(0, QtWidgets.QFormLayout.FieldRole, self.verticalLayout_right)
        self.verticalLayout_param.addLayout(self.param_import_part)

        self.verticalLayout_global = QtWidgets.QVBoxLayout(Form)
        self.verticalLayout_global.setObjectName("verticalLayout_global")
        self.verticalLayout_global.addWidget(self.widget_chooseFile)
        self.verticalLayout_global.addWidget(self.label)
        self.verticalLayout_global.addWidget(self.tableWidget_previewData)
        self.verticalLayout_global.addWidget(self.groupBox_importparam)
        self.verticalLayout_global.addWidget(self.widget_importButton)

        self.retranslateUi(Form)
        self.createUiFormAPI()
        QtCore.QMetaObject.connectSlotsByName(Form)

    def retranslateUi(self, Form):
        _translate = QtCore.QCoreApplication.translate
        self.translate = _translate
        Form.setWindowTitle(_translate("Form", "导入文本数据"))
        self.pushButton_help.setText(_translate("Form", "帮助"))
        self.pushButton_preview.setText(_translate("Form", "预览"))
        self.pushButton_ok.setText(_translate("Form", "确定"))
        self.pushButton_cancel.setText(_translate("Form", "取消"))
        self.groupBox_importparam.setTitle(_translate("Form", "导入参数配置"))
        self.label.setText(_translate("Form", "文件预览"))
        self.label_chooseFile.setText(_translate("Form", "选择数据集："))
        self.pushButton_choosefile.setText(_translate("Form", "浏览"))
# import pyqtsource_rc

if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    Form = QtWidgets.QWidget()
    ui = Ui_Form()
    ui.setupUi(Form)
    Form.show()
    sys.exit(app.exec_())