# -*- 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 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
        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_param)
        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_param)
        for i, ui_i in enumerate(setItem):
            model.addItem("")
            model.setItemText(i, self.translate("Form", str(ui_i)))
        model = self.addForm(obj = model, objType = "combBox", name = objName)
        model.tagName = tagName
        return(model)

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

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

        self.comboBox_encode = self.addForm_comboBox("字符类型", "encodetype", [""])
        self.comboBox_separator = self.addForm_comboBox("分割符号", "separator", [""])



    def verticalLayoutAddUI(self, obj, type):
        ui = QtWidgets.QHBoxLayout(self.groupBox_param)
        ui.setContentsMargins(0, 0, 0, 0)
        ui.setObjectName("horizontalLayout" + obj.objName)
        label = QtWidgets.QLabel(self.groupBox_param)
        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)
        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 getParam(self):
        # 后续迁移到具体模块里头，getImportParam中调用
        param = {}
        param.update(
            filepath_or_buffer = self.lineEdit_filePath.text(),
            datasetname = self.lineEdit_datasetName.text(),
            engine = "python",
            header = 'infer' if self.checkBox_ifColumns.isChecked() else None,
            sep = self.comboBox_separator.currentText(),
            encoding = self.comboBox_encode.currentText(),
            nrows = self.lineEdit_limitRow.text()
        )
        print(param)

    def addUIActivition(self):
        # 该部分迁移到 importutils 里头，打开UI界面时候时候动态加载
        self.pushButton_choosefile.clicked.connect(self.setUIModel)
        # self.pushButton_preview.clicked.connect(self.getParam)
    
    def setupUi(self, Form):
        # 公共模块
        Form.setObjectName("Form")
        Form.setMinimumSize(QtCore.QSize(800, 600))
        Form.setMaximumSize(QtCore.QSize(16777215, 16777215))
        
        # 头部图片UI
        # icon = QtGui.QIcon()
        # icon.addPixmap(QtGui.QPixmap(":/color/source/theme/color/icons/txt.svg"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        # Form.setWindowIcon(icon)
        # 整体界面
        self.widget = QtWidgets.QWidget(Form)
        self.widget.setGeometry(QtCore.QRect(10, 560, 779, 39))
        self.widget.setMinimumSize(QtCore.QSize(50, 0))
        self.widget.setMaximumSize(QtCore.QSize(16777215, 16777215))
        self.widget.setObjectName("widget")

        # 下方模块
        # self.horizontalLayout_10 = QtWidgets.QHBoxLayout(self.widget)
        # self.horizontalLayout_10.setContentsMargins(0, 0, 0, 0)
        # self.horizontalLayout_10.setObjectName("horizontalLayout_10")

        self.horizontalLayout_8 = QtWidgets.QHBoxLayout(self.widget)
        self.horizontalLayout_8.setContentsMargins(0, 0, 0, 0)
        # self.horizontalLayout_8 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_8.setObjectName("horizontalLayout_8")
        # 帮助按钮
        self.pushButton_help = QtWidgets.QPushButton(self.widget)
        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)
        self.pushButton_preview.setMinimumSize(QtCore.QSize(0, 25))
        self.pushButton_preview.setObjectName("pushButton_preview")
        # 导入按钮
        self.pushButton_ok = QtWidgets.QPushButton(self.widget)
        self.pushButton_ok.setMinimumSize(QtCore.QSize(0, 25))
        self.pushButton_ok.setObjectName("pushButton_ok")
        # 取消按钮
        self.pushButton_cancel = QtWidgets.QPushButton(self.widget)
        self.pushButton_cancel.setMinimumSize(QtCore.QSize(0, 25))
        self.pushButton_cancel.setObjectName("pushButton_cancel")

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

        # 表格视图
        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.label = QtWidgets.QLabel(Form)
        self.label.setGeometry(QtCore.QRect(10, 40, 36, 16))
        self.label.setObjectName("label")

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

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

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

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

        # 输入参数区域
        self.formLayout_param = QtWidgets.QFormLayout()
        self.formLayout_param.setHorizontalSpacing(4)
        self.formLayout_param.setObjectName("formLayout_param")

        self.groupBox_param = QtWidgets.QGroupBox(self.groupBox_importparam)
        self.groupBox_param.setTitle("")
        self.groupBox_param.setObjectName("groupBox")
        # 参数区域结构
        self.formLayout = QtWidgets.QFormLayout(self.groupBox_param)
        self.formLayout.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.formLayout.setLayout(0, QtWidgets.QFormLayout.LabelRole, self.verticalLayout_left)
        self.formLayout.setLayout(0, QtWidgets.QFormLayout.FieldRole, self.verticalLayout_right)

        # 导入参数部分的留白区域
        spacerItem7 = QtWidgets.QSpacerItem(244, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)

        self.formLayout_param.setWidget(0, QtWidgets.QFormLayout.LabelRole, self.groupBox_param)
        self.formLayout_param.setItem(0, QtWidgets.QFormLayout.FieldRole, spacerItem7)


        # 输入选项部分
        self.formLayout_importparam = QtWidgets.QFormLayout(self.groupBox_importparam)
        self.formLayout_importparam.setObjectName("formLayout_importparam")
        # 勾选项部分
        self.formLayout_importparam.setLayout(1, QtWidgets.QFormLayout.FieldRole, self.horizontalLayout_checkBox)
        # 填写参数部分
        self.formLayout_importparam.setLayout(2, QtWidgets.QFormLayout.FieldRole, self.formLayout_param)
        self.retranslateUi(Form)
        self.addUIActivition()
        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", "浏览"))




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_())