示例#1
0
    def setDataFrame(self, dataFrame):
        self.df = dataFrame
        dataModel = DataFrameModel()
        dataModel.setDataFrame(self.df)

        self.dataModel = dataModel

        self.dataListView.setModel(dataModel)
        self.dataTableView.setViewModel(dataModel)
        self.dataComboBox.setModel(dataModel)

        # self.dataTableView.resizeColumnsToContents()

        # create a simple item model for our choosing combobox
        columnModel = QtGui.QStandardItemModel()
        for column in self.df.columns:
            columnModel.appendRow(QtGui.QStandardItem(column))
        self.chooseColumnComboBox.setModel(columnModel)

        self.tableViewColumnDtypes.setModel(dataModel.columnDtypeModel())
        self.tableViewColumnDtypes.horizontalHeader().setDefaultSectionSize(
            200)
        self.tableViewColumnDtypes.setItemDelegateForColumn(
            1, DtypeComboDelegate(self.tableViewColumnDtypes))
        dataModel.changingDtypeFailed.connect(self.changeColumnValue)
示例#2
0
    def test_editing(self, dataframe, qtbot):
        model = ColumnDtypeModel(dataFrame=dataframe)

        model.setEditable(True)

        tableView = QtGui.QTableView()
        qtbot.addWidget(tableView)

        tableView.setModel(model)
        delegate = DtypeComboDelegate(tableView)
        tableView.setItemDelegateForColumn(1, delegate)
        tableView.show()

        index = model.index(0, 1)
        preedit_data = index.data(DTYPE_ROLE)

        tableView.edit(index)
        editor = tableView.findChildren(QtGui.QComboBox)[0]
        selectedIndex = editor.currentIndex()
        editor.setCurrentIndex(selectedIndex+1)
        postedit_data = index.data(DTYPE_ROLE)

        assert preedit_data != postedit_data
示例#3
0
    def _initUI(self):
        """Initiates the user interface with a grid layout and several widgets.

        """
        self.setModal(self._modal)
        self.setWindowTitle(self._windowTitle)

        layout = QtWidgets.QGridLayout()

        self._filenameLabel = QtWidgets.QLabel(u'Choose File', self)
        self._filenameLineEdit = QtWidgets.QLineEdit(self)
        self._filenameLineEdit.textEdited.connect(self._updateFilename)
        chooseFileButtonIcon = QtGui.QIcon(
            QtGui.QPixmap(':/icons/document-open.png'))
        self._chooseFileAction = QtWidgets.QAction(self)
        self._chooseFileAction.setIcon(chooseFileButtonIcon)
        self._chooseFileAction.triggered.connect(self._openFile)

        self._chooseFileButton = QtWidgets.QToolButton(self)
        self._chooseFileButton.setDefaultAction(self._chooseFileAction)

        layout.addWidget(self._filenameLabel, 0, 0)
        layout.addWidget(self._filenameLineEdit, 0, 1, 1, 2)
        layout.addWidget(self._chooseFileButton, 0, 3)

        self._encodingLabel = QtWidgets.QLabel(u'File Encoding', self)

        encoding_names = map(lambda x: x.upper(),
                             sorted(list(set(_encodings.viewvalues()))))
        self._encodingComboBox = QtWidgets.QComboBox(self)
        self._encodingComboBox.addItems(encoding_names)
        self._encodingComboBox.activated.connect(self._updateEncoding)

        layout.addWidget(self._encodingLabel, 1, 0)
        layout.addWidget(self._encodingComboBox, 1, 1, 1, 1)

        self._hasHeaderLabel = QtWidgets.QLabel(u'Header Available?', self)
        self._headerCheckBox = QtWidgets.QCheckBox(self)
        self._headerCheckBox.toggled.connect(self._updateHeader)

        layout.addWidget(self._hasHeaderLabel, 2, 0)
        layout.addWidget(self._headerCheckBox, 2, 1)

        self._delimiterLabel = QtWidgets.QLabel(u'Column Delimiter', self)
        self._delimiterBox = DelimiterSelectionWidget(self)
        self._delimiter = self._delimiterBox.currentSelected()
        self._delimiterBox.delimiter.connect(self._updateDelimiter)

        layout.addWidget(self._delimiterLabel, 3, 0)
        layout.addWidget(self._delimiterBox, 3, 1, 1, 3)

        self._tabWidget = QtWidgets.QTabWidget(self)
        self._previewTableView = QtWidgets.QTableView(self)
        self._datatypeTableView = QtWidgets.QTableView(self)
        self._tabWidget.addTab(self._previewTableView, u'Preview')
        self._tabWidget.addTab(self._datatypeTableView, u'Change Column Types')
        layout.addWidget(self._tabWidget, 4, 0, 3, 4)

        self._datatypeTableView.horizontalHeader().setDefaultSectionSize(200)
        self._datatypeTableView.setItemDelegateForColumn(
            1, DtypeComboDelegate(self._datatypeTableView))

        self._loadButton = QtWidgets.QPushButton(u'Load Data', self)
        #self.loadButton.setAutoDefault(False)

        self._cancelButton = QtWidgets.QPushButton(u'Cancel', self)
        # self.cancelButton.setDefault(False)
        # self.cancelButton.setAutoDefault(True)

        self._buttonBox = QtWidgets.QDialogButtonBox(self)
        self._buttonBox.addButton(self._loadButton,
                                  QtWidgets.QDialogButtonBox.AcceptRole)
        self._buttonBox.addButton(self._cancelButton,
                                  QtWidgets.QDialogButtonBox.RejectRole)
        self._buttonBox.accepted.connect(self.accepted)
        self._buttonBox.rejected.connect(self.rejected)
        layout.addWidget(self._buttonBox, 9, 2, 1, 2)
        self._loadButton.setDefault(False)
        self._filenameLineEdit.setFocus()

        self._statusBar = QtWidgets.QStatusBar(self)
        self._statusBar.setSizeGripEnabled(False)
        layout.addWidget(self._statusBar, 8, 0, 1, 4)
        self.setLayout(layout)