Esempio n. 1
0
    def test_enableToolBar(self, qtbot):
        widget = DataTableWidget()
        qtbot.addWidget(widget)
        widget.show()

        assert widget.view().model() is None

        buttons = widget.findChildren(QtGui.QToolButton)

        exclude_button = None
        for btn in buttons:
            if btn.isEnabled:
                qtbot.mouseClick(btn, QtCore.Qt.LeftButton)
                exclude_button = btn
                assert btn.isChecked()
                break

        for button in buttons:
            assert button.isEnabled()

        qtbot.mouseClick(btn, QtCore.Qt.LeftButton)

        for button in buttons:
            if button == exclude_button:
                continue
            assert not button.isEnabled()
            assert not button.isChecked()
Esempio n. 2
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)
Esempio n. 3
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
Esempio n. 4
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
Esempio n. 5
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
Esempio n. 6
0
    def test_init(self, qtbot):
        widget = DataTableWidget()
        qtbot.addWidget(widget)
        widget.show()

        assert widget.view().model() is None

        buttons = widget.findChildren(QtGui.QToolButton)

        enabled_counter = 0
        for btn in buttons:
            assert not btn.isChecked()
            if btn.isEnabled():
                enabled_counter += 1

        assert enabled_counter == 1
Esempio n. 7
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
Esempio n. 8
0
    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)
Esempio n. 9
0
import pandas
import numpy
import sys
from pandasqt.excepthook import excepthook
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)