Пример #1
0
    def test_click_each_button(self, qtbot, dataModel):
        widget = DataTableWidget()
        qtbot.addWidget(widget)
        widget.show()

        widget.setViewModel(dataModel)

        buttons = widget.findChildren(QtGui.QToolButton)
        for btn in buttons:
            if btn.isEnabled:
                qtbot.mouseClick(btn, QtCore.Qt.LeftButton)
                break

        for btn in buttons:
            if btn.objectName() == 'editbutton':
                continue

            if btn.objectName() in ['addcolumnbutton', 'removecolumnbutton']:
                qtbot.mouseClick(btn, QtCore.Qt.LeftButton)
                dlg = widget.findChildren(QtGui.QDialog)[-1]

                dlg_buttons = dlg.findChildren(QtGui.QPushButton)

                for b in dlg_buttons:
                    if b.text() == 'Cancel':
                        qtbot.mouseClick(b, QtCore.Qt.LeftButton)
                        break
            else:
                qtbot.mouseClick(btn, QtCore.Qt.LeftButton)
Пример #2
0
    def test_removeColumns(self, qtbot, dataModel2):
        widget = DataTableWidget()
        qtbot.addWidget(widget)
        widget.show()

        widget.setViewModel(dataModel2)

        df = dataModel2.dataFrame().copy()

        buttons = widget.findChildren(QtGui.QToolButton)
        for btn in buttons:
            if btn.isEnabled:
                qtbot.mouseClick(btn, QtCore.Qt.LeftButton)
                break

        for btn in buttons:
            if btn.objectName() == 'removecolumnbutton':
                qtbot.mouseClick(btn, QtCore.Qt.LeftButton)
                dlg = widget.findChildren(QtGui.QDialog)[-1]

                listview = dlg.findChildren(QtGui.QListView)[-1]

                listview.selectAll()

                dlg_buttons = dlg.findChildren(QtGui.QPushButton)

                for b in dlg_buttons:
                    if b.text() == 'OK':
                        qtbot.mouseClick(b, QtCore.Qt.LeftButton)
                        break

        assert widget.view().model().columnCount() == 0
Пример #3
0
    def test_addColumn(self, qtbot, dataModel):
        widget = DataTableWidget()
        qtbot.addWidget(widget)
        widget.show()

        widget.setViewModel(dataModel)

        buttons = widget.findChildren(QtGui.QToolButton)
        for btn in buttons:
            if btn.isEnabled:
                qtbot.mouseClick(btn, QtCore.Qt.LeftButton)
                break

        columns = []
        addButton = None
        for btn in buttons:
            if btn.objectName == 'addcolumnbutton':
                addbutton = btn
                qtbot.mouseClick(btn, QtCore.Qt.LeftButton)
                dlg = widget.findChildren(QtGui.QDialog)[-1]
                dlg_buttons = dlg.findChildren(QtGui.QPushButton)
                comboBox = dlg.findChildren(QtGui.QComboBox)[-1]

                for i in xrange(comboBox.count()):
                    columns.append(comboBox.itemText(i))

                for b in dlg_buttons:
                    if b.text() == 'Cancel':
                        qtbot.mouseClick(b, QtCore.Qt.LeftButton)
                        break
                break

        columnCountBeforeInsert = widget.view().model().columnCount()
        for index, column in enumerate(columns):
            qtbot.mouseClick(addbutton, QtCore.Qt.LeftButton)
            dlg = widget.findChildren(QtGui.QDialog)[-1]

            textedits = dlg.findChildren(QtGui.QLineEdit)
            qtbot.keyClicks(textedits[0], column)

            comboBox = dlg.findChildren(QtGui.QComboBox)[-1]
            comboBox.setCurrentIndex(index)

            dlg_buttons = dlg.findChildren(QtGui.QPushButton)

            for b in dlg_buttons:
                if b.text() == 'OK':
                    qtbot.mouseClick(b, QtCore.Qt.LeftButton)
                    break

            assert widget.view().model().columnCount() == columnCountBeforeInsert + 1 + index
Пример #4
0
def display_query(selcols):
    ## setup a new empty model
    model1 = DataFrameModel()
    ## setup an application and create a table view widget
    app = QtGui.QApplication([])
    widget1 = DataTableWidget()
    widget1.resize(1600, 800)
    widget1.show()
    ## asign the created model
    widget1.setViewModel(model1)
    ## fill the model with data
    model1.setDataFrame(selcols)
    ## start the app"""
    app.exec_()
    return
Пример #5
0
    def test_setModel(self, qtbot, dataModel):
        widget = DataTableWidget()
        qtbot.addWidget(widget)
        widget.show()

        widget.setViewModel(dataModel)

        assert widget.view().model() is not None
        assert widget.view().model() == dataModel

        buttons = widget.findChildren(QtGui.QToolButton)
        for btn in buttons:
            if btn.isEnabled:
                qtbot.mouseClick(btn, QtCore.Qt.LeftButton)
                assert widget.view().model().editable

                qtbot.mouseClick(btn, QtCore.Qt.LeftButton)
                assert not widget.view().model().editable

                break
Пример #6
0
class TestWidget(QtGui.QWidget):
    def __init__(self, parent=None):
        super(TestWidget, self).__init__(parent)
        self.resize(1680, 756)
        self.move(0, 0)

        self.df = pandas.DataFrame()
        self.dataModel = None

        #  init the data view's
        self.dataTableView = DataTableWidget(self)
        # self.dataTableView.setSortingEnabled(True)
        # self.dataTableView.setAlternatingRowColors(True)

        self.dataListView = QtGui.QListView(self)
        self.dataListView.setAlternatingRowColors(True)

        self.dataComboBox = QtGui.QComboBox(self)

        # make combobox to choose the model column for dataComboBox and dataListView
        self.chooseColumnComboBox = QtGui.QComboBox(self)

        self.buttonCsvData = QtGui.QPushButton("load csv data")
        self.buttonRandomData = QtGui.QPushButton("load random data")
        importDialog = CSVImportDialog(self)
        importDialog.load.connect(self.updateModel)
        self.buttonCsvData.clicked.connect(lambda: importDialog.show())
        self.buttonRandomData.clicked.connect(
            lambda: self.setDataFrame(getRandomData(rows=100, columns=100)))

        self.exportDialog = CSVExportDialog(self)

        self.buttonCSVExport = QtGui.QPushButton("export to csv")
        self.buttonCSVExport.clicked.connect(self._exportModel)
        self.buttonLayout = QtGui.QHBoxLayout()
        self.buttonLayout.addWidget(self.buttonCsvData)
        self.buttonLayout.addWidget(self.buttonCSVExport)
        self.buttonLayout.addWidget(self.buttonRandomData)

        self.mainLayout = QtGui.QVBoxLayout()
        self.setLayout(self.mainLayout)
        self.mainLayout.addLayout(self.buttonLayout)

        self.mainLayout.addWidget(self.dataTableView)

        self.spinbox = QtGui.QSpinBox()
        self.mainLayout.addWidget(self.spinbox)
        self.spinbox.setMaximum(99999999999)
        self.spinbox.setValue(99999999999)

        self.rightLayout = QtGui.QVBoxLayout()
        self.chooseColumLayout = QtGui.QHBoxLayout()
        self.mainLayout.addLayout(self.rightLayout)
        self.rightLayout.addLayout(self.chooseColumLayout)
        self.chooseColumLayout.addWidget(QtGui.QLabel("Choose column:"))
        self.chooseColumLayout.addWidget(self.chooseColumnComboBox)
        self.rightLayout.addWidget(self.dataListView)
        self.rightLayout.addWidget(self.dataComboBox)

        self.tableViewColumnDtypes = QtGui.QTableView(self)
        self.rightLayout.addWidget(QtGui.QLabel('dtypes'))
        self.rightLayout.addWidget(self.tableViewColumnDtypes)
        self.buttonGoToColumn = QtGui.QPushButton("go to column")
        self.rightLayout.addWidget(self.buttonGoToColumn)
        self.buttonGoToColumn.clicked.connect(self.goToColumn)

        self.buttonSetFilter = QtGui.QPushButton("set filter")
        self.rightLayout.addWidget(self.buttonSetFilter)
        self.buttonSetFilter.clicked.connect(self.setFilter)
        self.buttonClearFilter = QtGui.QPushButton("clear filter")
        self.rightLayout.addWidget(self.buttonClearFilter)
        self.buttonClearFilter.clicked.connect(self.clearFilter)
        self.lineEditFilterCondition = QtGui.QLineEdit("freeSearch('am')")
        self.rightLayout.addWidget(self.lineEditFilterCondition)

        self.chooseColumnComboBox.currentIndexChanged.connect(
            self.setModelColumn)

        self.dataListView.mouseReleaseEvent = self.mouseReleaseEvent

        self.dropLineEdit = DropLineEdit("drop data from table here", self)
        self.rightLayout.addWidget(self.dropLineEdit)

        self.dropWidget = ComplexDropWidget(self)
        self.dropWidget.dropRecieved.connect(self.processDataDrops)
        self.rightLayout.addWidget(self.dropWidget)

    @Slot('QMimeData')
    def processDataDrops(self, mimeData):
        """if you have more complicated stuff to do and you want to match some models, might be possible like that"""
        mimeDataPayload = mimeData.data()
        if isinstance(mimeDataPayload, PandasCellPayload):
            if self.dataModel is not None:
                if hex(id(self.dataModel)) == mimeDataPayload.parentId:
                    self.dropWidget.setText(
                        "complex stuff done after drop event. {0}".format(
                            mimeDataPayload.column))

    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)

    @Slot()
    def _exportModel(self):
        model = self.dataTableView.view().model()
        self.exportDialog.setExportModel(model)
        self.exportDialog.show()

    @Slot('QAbstractItemModel')
    def updateModel(self, model):
        self.dataModel = model
        self.dataListView.setModel(model)
        self.dataTableView.setViewModel(model)
        self.dataComboBox.setModel(model)

        self.tableViewColumnDtypes.setModel(model.columnDtypeModel())

    def setModelColumn(self, index):
        self.dataListView.setModelColumn(index)
        self.dataComboBox.setModelColumn(index)

    def goToColumn(self):
        print "go to column 7"
        index = self.dataTableView.view().model().index(7, 0)
        self.dataTableView.view().setCurrentIndex(index)

    def changeColumnValue(self, columnName, index, dtype):
        print "failed to change", columnName, "to", dtype
        print index.data(), index.isValid()
        self.dataTableView.view().setCurrentIndex(index)

    def setFilter(self):
        #filterIndex = eval(self.lineEditFilterCondition.text())
        search = DataSearch("Test", self.lineEditFilterCondition.text())
        self.dataTableView.view().model().setFilter(search)
        #raise NotImplementedError

    def clearFilter(self):
        self.dataTableView.view().model().clearFilter()
Пример #7
0
class TestWidget(QtWidgets.QWidget):

    def __init__(self, parent=None):
        super(TestWidget, self).__init__(parent)
        self.resize(1680, 756)
        self.move(0, 0)


        self.df = pandas.DataFrame()
        #  init the data view's
        self.dataTableView = DataTableWidget(self)
        # self.dataTableView.setSortingEnabled(True)
        # self.dataTableView.setAlternatingRowColors(True)

        self.dataListView = QtWidgets.QListView(self)
        self.dataListView.setAlternatingRowColors(True)

        self.dataComboBox = QtWidgets.QComboBox(self)

        # make combobox to choose the model column for dataComboBox and dataListView
        self.chooseColumnComboBox = QtWidgets.QComboBox(self)

        self.buttonCsvData = QtWidgets.QPushButton("load csv data")
        self.buttonRandomData = QtWidgets.QPushButton("load random data")
        importDialog = CSVImportDialog(self)
        importDialog.load.connect(self.updateModel)
        self.buttonCsvData.clicked.connect(lambda: importDialog.show())
        self.buttonRandomData.clicked.connect(lambda: self.setDataFrame( getRandomData(rows=100, columns=100) ))

        self.exportDialog = CSVExportDialog(self)

        self.buttonCSVExport = QtWidgets.QPushButton("export to csv")
        self.buttonCSVExport.clicked.connect(self._exportModel)
        self.buttonLayout = QtWidgets.QHBoxLayout()
        self.buttonLayout.addWidget(self.buttonCsvData)
        self.buttonLayout.addWidget(self.buttonCSVExport)
        self.buttonLayout.addWidget(self.buttonRandomData)

        self.mainLayout = QtWidgets.QVBoxLayout()
        self.setLayout(self.mainLayout)
        self.mainLayout.addLayout(self.buttonLayout)

        self.mainLayout.addWidget(self.dataTableView)

        self.spinbox = QtWidgets.QSpinBox()
        self.mainLayout.addWidget(self.spinbox)
        self.spinbox.setMaximum(99999999999)
        self.spinbox.setValue(99999999999)

        self.rightLayout = QtWidgets.QVBoxLayout()
        self.chooseColumLayout = QtWidgets.QHBoxLayout()
        self.mainLayout.addLayout(self.rightLayout)
        self.rightLayout.addLayout(self.chooseColumLayout)
        self.chooseColumLayout.addWidget(QtWidgets.QLabel("Choose column:"))
        self.chooseColumLayout.addWidget(self.chooseColumnComboBox)
        self.rightLayout.addWidget(self.dataListView)
        self.rightLayout.addWidget(self.dataComboBox)

        self.tableViewColumnDtypes = QtWidgets.QTableView(self)
        self.rightLayout.addWidget(QtWidgets.QLabel('dtypes'))
        self.rightLayout.addWidget(self.tableViewColumnDtypes)
        self.buttonGoToColumn = QtWidgets.QPushButton("go to column")
        self.rightLayout.addWidget(self.buttonGoToColumn)
        self.buttonGoToColumn.clicked.connect(self.goToColumn)

        self.buttonSetFilter = QtWidgets.QPushButton("set filter")
        self.rightLayout.addWidget(self.buttonSetFilter)
        self.buttonSetFilter.clicked.connect(self.setFilter)
        self.buttonClearFilter = QtWidgets.QPushButton("clear filter")
        self.rightLayout.addWidget(self.buttonClearFilter)
        self.buttonClearFilter.clicked.connect(self.clearFilter)
        self.lineEditFilterCondition = QtWidgets.QLineEdit("freeSearch('am')")
        self.rightLayout.addWidget(self.lineEditFilterCondition)

        self.chooseColumnComboBox.currentIndexChanged.connect(self.setModelColumn)

        self.dataListView.mouseReleaseEvent = self.mouseReleaseEvent


    def setDataFrame(self, dataFrame):
        self.df = dataFrame
        dataModel = DataFrameModel()
        dataModel.setDataFrame(self.df)
        self.dataListView.setModel(dataModel)
        self.dataTableView.setViewModel(dataModel)
        self.dataComboBox.setModel(dataModel)

        for index, column in enumerate(dataModel.dataFrame().columns):
            dtype = dataModel.dataFrame()[column].dtype
            self.updateDelegates(index, dtype)
        #self.updateDelegates()

        # 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.dtypeChanged.connect(self.updateDelegates)
        dataModel.changingDtypeFailed.connect(self.changeColumnValue)

    @Slot()
    def _exportModel(self):
        model = self.dataTableView.view().model()
        self.exportDialog.setExportModel(model)
        self.exportDialog.show()

    @Slot('QAbstractItemModel')
    def updateModel(self, model):
        self.dataListView.setModel(model)
        self.dataTableView.setViewModel(model)
        self.dataComboBox.setModel(model)

        self.tableViewColumnDtypes.setModel(model.columnDtypeModel())

    def setModelColumn(self, index):
        self.dataListView.setModelColumn(index)
        self.dataComboBox.setModelColumn(index)

    @Slot(int, object)
    def updateDelegates(self, column, dtype):
        print "update delegate for column", column, dtype
        # as documented in the setDelegatesFromDtype function
        # we need to store all delegates, so going from
        # type A -> type B -> type A
        # would cause a segfault if not stored.
        view = self.dataTableView.tableView
        createDelegate(dtype, column, view)
        # dlg = self.delegates or {}
        # self.delegates = setDelegatesFromDtype(self.dataTableView.tableView, dlg)
        # print dlg

    def goToColumn(self):
        print "go to column 7"
        index = self.dataTableView.view().model().index(7, 0)
        self.dataTableView.view().setCurrentIndex(index)

    def changeColumnValue(self, columnName, index, dtype):
        print "failed to change", columnName, "to", dtype
        print index.data(), index.isValid()
        self.dataTableView.view().setCurrentIndex(index)

    def setFilter(self):
        #filterIndex = eval(self.lineEditFilterCondition.text())
        search = DataSearch("Test", self.lineEditFilterCondition.text())
        self.dataTableView.view().model().setFilter(search)
        #raise NotImplementedError

    def clearFilter(self):
        self.dataTableView.view().model().clearFilter()
Пример #8
0
class TestWidget(QtWidgets.QWidget):
    def __init__(self, parent=None):
        super(TestWidget, self).__init__(parent)
        self.resize(1680, 756)
        self.move(0, 0)

        self.df = pandas.DataFrame()
        #  init the data view's
        self.dataTableView = DataTableWidget(self)
        # self.dataTableView.setSortingEnabled(True)
        # self.dataTableView.setAlternatingRowColors(True)

        self.dataListView = QtWidgets.QListView(self)
        self.dataListView.setAlternatingRowColors(True)

        self.dataComboBox = QtWidgets.QComboBox(self)

        # make combobox to choose the model column for dataComboBox and dataListView
        self.chooseColumnComboBox = QtWidgets.QComboBox(self)

        self.buttonCsvData = QtWidgets.QPushButton("load csv data")
        self.buttonRandomData = QtWidgets.QPushButton("load random data")
        importDialog = CSVImportDialog(self)
        importDialog.load.connect(self.updateModel)
        self.buttonCsvData.clicked.connect(lambda: importDialog.show())
        self.buttonRandomData.clicked.connect(
            lambda: self.setDataFrame(getRandomData(rows=100, columns=100)))

        self.exportDialog = CSVExportDialog(self)

        self.buttonCSVExport = QtWidgets.QPushButton("export to csv")
        self.buttonCSVExport.clicked.connect(self._exportModel)
        self.buttonLayout = QtWidgets.QHBoxLayout()
        self.buttonLayout.addWidget(self.buttonCsvData)
        self.buttonLayout.addWidget(self.buttonCSVExport)
        self.buttonLayout.addWidget(self.buttonRandomData)

        self.mainLayout = QtWidgets.QVBoxLayout()
        self.setLayout(self.mainLayout)
        self.mainLayout.addLayout(self.buttonLayout)

        self.mainLayout.addWidget(self.dataTableView)

        self.spinbox = QtWidgets.QSpinBox()
        self.mainLayout.addWidget(self.spinbox)
        self.spinbox.setMaximum(99999999999)
        self.spinbox.setValue(99999999999)

        self.rightLayout = QtWidgets.QVBoxLayout()
        self.chooseColumLayout = QtWidgets.QHBoxLayout()
        self.mainLayout.addLayout(self.rightLayout)
        self.rightLayout.addLayout(self.chooseColumLayout)
        self.chooseColumLayout.addWidget(QtWidgets.QLabel("Choose column:"))
        self.chooseColumLayout.addWidget(self.chooseColumnComboBox)
        self.rightLayout.addWidget(self.dataListView)
        self.rightLayout.addWidget(self.dataComboBox)

        self.tableViewColumnDtypes = QtWidgets.QTableView(self)
        self.rightLayout.addWidget(QtWidgets.QLabel('dtypes'))
        self.rightLayout.addWidget(self.tableViewColumnDtypes)
        self.buttonGoToColumn = QtWidgets.QPushButton("go to column")
        self.rightLayout.addWidget(self.buttonGoToColumn)
        self.buttonGoToColumn.clicked.connect(self.goToColumn)

        self.buttonSetFilter = QtWidgets.QPushButton("set filter")
        self.rightLayout.addWidget(self.buttonSetFilter)
        self.buttonSetFilter.clicked.connect(self.setFilter)
        self.buttonClearFilter = QtWidgets.QPushButton("clear filter")
        self.rightLayout.addWidget(self.buttonClearFilter)
        self.buttonClearFilter.clicked.connect(self.clearFilter)
        self.lineEditFilterCondition = QtWidgets.QLineEdit("freeSearch('am')")
        self.rightLayout.addWidget(self.lineEditFilterCondition)

        self.chooseColumnComboBox.currentIndexChanged.connect(
            self.setModelColumn)

        self.dataListView.mouseReleaseEvent = self.mouseReleaseEvent

    def setDataFrame(self, dataFrame):
        self.df = dataFrame
        dataModel = DataFrameModel()
        dataModel.setDataFrame(self.df)
        self.dataListView.setModel(dataModel)
        self.dataTableView.setViewModel(dataModel)
        self.dataComboBox.setModel(dataModel)

        for index, column in enumerate(dataModel.dataFrame().columns):
            dtype = dataModel.dataFrame()[column].dtype
            self.updateDelegates(index, dtype)
        #self.updateDelegates()

        # 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.dtypeChanged.connect(self.updateDelegates)
        dataModel.changingDtypeFailed.connect(self.changeColumnValue)

    @Slot()
    def _exportModel(self):
        model = self.dataTableView.view().model()
        self.exportDialog.setExportModel(model)
        self.exportDialog.show()

    @Slot('QAbstractItemModel')
    def updateModel(self, model):
        self.dataListView.setModel(model)
        self.dataTableView.setViewModel(model)
        self.dataComboBox.setModel(model)

        self.tableViewColumnDtypes.setModel(model.columnDtypeModel())

    def setModelColumn(self, index):
        self.dataListView.setModelColumn(index)
        self.dataComboBox.setModelColumn(index)

    @Slot(int, object)
    def updateDelegates(self, column, dtype):
        print "update delegate for column", column, dtype
        # as documented in the setDelegatesFromDtype function
        # we need to store all delegates, so going from
        # type A -> type B -> type A
        # would cause a segfault if not stored.
        view = self.dataTableView.tableView
        createDelegate(dtype, column, view)
        # dlg = self.delegates or {}
        # self.delegates = setDelegatesFromDtype(self.dataTableView.tableView, dlg)
        # print dlg

    def goToColumn(self):
        print "go to column 7"
        index = self.dataTableView.view().model().index(7, 0)
        self.dataTableView.view().setCurrentIndex(index)

    def changeColumnValue(self, columnName, index, dtype):
        print "failed to change", columnName, "to", dtype
        print index.data(), index.isValid()
        self.dataTableView.view().setCurrentIndex(index)

    def setFilter(self):
        #filterIndex = eval(self.lineEditFilterCondition.text())
        search = DataSearch("Test", self.lineEditFilterCondition.text())
        self.dataTableView.view().model().setFilter(search)
        #raise NotImplementedError

    def clearFilter(self):
        self.dataTableView.view().model().clearFilter()
Пример #9
0
sys.excepthook = excepthook

# use QtGui from the compat module to take care if correct sip version, etc.
from pandasqt.compat import QtGui
from pandasqt.models.DataFrameModel import DataFrameModel
from pandasqt.views.DataTableView import DataTableWidget
from pandasqt.views._ui import icons_rc
"""setup a new empty model"""
model = DataFrameModel()
"""setup an application and create a table view widget"""
app = QtGui.QApplication([])
widget = DataTableWidget()
widget.resize(800, 600)
widget.show()
"""asign the created model"""
widget.setViewModel(model)
"""create some test data"""
data = {
    'A': [10, 11, 12],
    'B': [20, 21, 22],
    'C': ['Peter Pan', 'Cpt. Hook', 'Tinkerbell']
}
df = pandas.DataFrame(data)
"""convert the column to the numpy.int8 datatype to test the delegates in the table
int8 is limited to -128-127
"""
df['A'] = df['A'].astype(numpy.int8)
df['B'] = df['B'].astype(numpy.float16)
"""fill the model with data"""
model.setDataFrame(df)
"""start the app"""
Пример #10
0
class TestWidget(QtGui.QWidget):

    def __init__(self, parent=None):
        super(TestWidget, self).__init__(parent)
        self.resize(1680, 756)
        self.move(0, 0)

        self.df = pandas.DataFrame()
        self.dataModel = None

        #  init the data view's
        self.dataTableView = DataTableWidget(self)
        # self.dataTableView.setSortingEnabled(True)
        # self.dataTableView.setAlternatingRowColors(True)

        self.dataListView = QtGui.QListView(self)
        self.dataListView.setAlternatingRowColors(True)

        self.dataComboBox = QtGui.QComboBox(self)

        # make combobox to choose the model column for dataComboBox and dataListView
        self.chooseColumnComboBox = QtGui.QComboBox(self)

        self.buttonCsvData = QtGui.QPushButton("load csv data")
        self.buttonRandomData = QtGui.QPushButton("load random data")
        importDialog = CSVImportDialog(self)
        importDialog.load.connect(self.updateModel)
        self.buttonCsvData.clicked.connect(lambda: importDialog.show())
        self.buttonRandomData.clicked.connect(lambda: self.setDataFrame( getRandomData(rows=100, columns=100) ))

        self.exportDialog = CSVExportDialog(self)

        self.buttonCSVExport = QtGui.QPushButton("export to csv")
        self.buttonCSVExport.clicked.connect(self._exportModel)
        self.buttonLayout = QtGui.QHBoxLayout()
        self.buttonLayout.addWidget(self.buttonCsvData)
        self.buttonLayout.addWidget(self.buttonCSVExport)
        self.buttonLayout.addWidget(self.buttonRandomData)

        self.mainLayout = QtGui.QVBoxLayout()
        self.setLayout(self.mainLayout)
        self.mainLayout.addLayout(self.buttonLayout)

        self.mainLayout.addWidget(self.dataTableView)

        self.spinbox = QtGui.QSpinBox()
        self.mainLayout.addWidget(self.spinbox)
        self.spinbox.setMaximum(99999999999)
        self.spinbox.setValue(99999999999)

        self.rightLayout = QtGui.QVBoxLayout()
        self.chooseColumLayout = QtGui.QHBoxLayout()
        self.mainLayout.addLayout(self.rightLayout)
        self.rightLayout.addLayout(self.chooseColumLayout)
        self.chooseColumLayout.addWidget(QtGui.QLabel("Choose column:"))
        self.chooseColumLayout.addWidget(self.chooseColumnComboBox)
        self.rightLayout.addWidget(self.dataListView)
        self.rightLayout.addWidget(self.dataComboBox)

        self.tableViewColumnDtypes = QtGui.QTableView(self)
        self.rightLayout.addWidget(QtGui.QLabel('dtypes'))
        self.rightLayout.addWidget(self.tableViewColumnDtypes)
        self.buttonGoToColumn = QtGui.QPushButton("go to column")
        self.rightLayout.addWidget(self.buttonGoToColumn)
        self.buttonGoToColumn.clicked.connect(self.goToColumn)

        self.buttonSetFilter = QtGui.QPushButton("set filter")
        self.rightLayout.addWidget(self.buttonSetFilter)
        self.buttonSetFilter.clicked.connect(self.setFilter)
        self.buttonClearFilter = QtGui.QPushButton("clear filter")
        self.rightLayout.addWidget(self.buttonClearFilter)
        self.buttonClearFilter.clicked.connect(self.clearFilter)
        self.lineEditFilterCondition = QtGui.QLineEdit("freeSearch('am')")
        self.rightLayout.addWidget(self.lineEditFilterCondition)

        self.chooseColumnComboBox.currentIndexChanged.connect(self.setModelColumn)

        self.dataListView.mouseReleaseEvent = self.mouseReleaseEvent
        
        self.dropLineEdit = DropLineEdit("drop data from table here", self)
        self.rightLayout.addWidget(self.dropLineEdit)
        
        self.dropWidget = ComplexDropWidget(self)
        self.dropWidget.dropRecieved.connect(self.processDataDrops)
        self.rightLayout.addWidget(self.dropWidget)
        
    @Slot('QMimeData')
    def processDataDrops(self, mimeData):
        """if you have more complicated stuff to do and you want to match some models, might be possible like that"""
        mimeDataPayload = mimeData.data()
        if isinstance(mimeDataPayload, PandasCellPayload):
            if self.dataModel is not None:
                if hex(id(self.dataModel)) == mimeDataPayload.parentId:
                    self.dropWidget.setText("complex stuff done after drop event. {0}".format(mimeDataPayload.column))

    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)

    @Slot()
    def _exportModel(self):
        model = self.dataTableView.view().model()
        self.exportDialog.setExportModel(model)
        self.exportDialog.show()

    @Slot('QAbstractItemModel')
    def updateModel(self, model):
        self.dataModel = model
        self.dataListView.setModel(model)
        self.dataTableView.setViewModel(model)
        self.dataComboBox.setModel(model)

        self.tableViewColumnDtypes.setModel(model.columnDtypeModel())

    def setModelColumn(self, index):
        self.dataListView.setModelColumn(index)
        self.dataComboBox.setModelColumn(index)

    def goToColumn(self):
        print "go to column 7"
        index = self.dataTableView.view().model().index(7, 0)
        self.dataTableView.view().setCurrentIndex(index)

    def changeColumnValue(self, columnName, index, dtype):
        print "failed to change", columnName, "to", dtype
        print index.data(), index.isValid()
        self.dataTableView.view().setCurrentIndex(index)

    def setFilter(self):
        #filterIndex = eval(self.lineEditFilterCondition.text())
        search = DataSearch("Test", self.lineEditFilterCondition.text())
        self.dataTableView.view().model().setFilter(search)
        #raise NotImplementedError

    def clearFilter(self):
        self.dataTableView.view().model().clearFilter()
Пример #11
0
# use QtGui from the compat module to take care if correct sip version, etc.
from pandasqt.compat import QtGui
from pandasqt.models.DataFrameModel import DataFrameModel
from pandasqt.views.DataTableView import DataTableWidget
from pandasqt.views._ui import icons_rc

"""setup a new empty model"""
model = DataFrameModel()

"""setup an application and create a table view widget"""
app = QtGui.QApplication([])
widget = DataTableWidget()
widget.resize(800, 600)
widget.show()
"""asign the created model"""
widget.setViewModel(model)

"""create some test data"""
data = {
    'A': [10, 11, 12], 
    'B': [20, 21, 22], 
    'C': ['Peter Pan', 'Cpt. Hook', 'Tinkerbell']
}
df = pandas.DataFrame(data)
"""convert the column to the numpy.int8 datatype to test the delegates in the table
int8 is limited to -128-127
"""
df['A'] = df['A'].astype(numpy.int8)
df['B'] = df['B'].astype(numpy.float16)

"""fill the model with data"""