Ejemplo n.º 1
0
    def startDrag(self, index):
        """start a drag operation with a PandasCellPayload on defined index.
        
        Args:
            index (QModelIndex): model index you want to start the drag operation.
        """

        if not index.isValid():
            return

        dataFrame = self.model().dataFrame()

        # get all infos from dataFrame
        dfindex = dataFrame.iloc[[index.row()]].index
        columnName = dataFrame.columns[index.column()]
        dtype = dataFrame[columnName].dtype
        value = dataFrame[columnName][dfindex]

        # create the mime data
        mimePayload = PandasCellPayload(dfindex, columnName, value, dtype,
                                        hex(id(self.model())))
        mimeData = MimeData()
        mimeData.setData(mimePayload)

        # create the drag icon and start drag operation
        drag = QtGui.QDrag(self)
        drag.setMimeData(mimeData)
        pixmap = QtGui.QPixmap(":/icons/insert-table.png")
        drag.setHotSpot(QtCore.QPoint(pixmap.width() / 3, pixmap.height() / 3))
        drag.setPixmap(pixmap)
        result = drag.start(Qt.MoveAction)
Ejemplo n.º 2
0
    def initUI(self):
        self.setGeometry(100, 100, 300, 300)

        self.vlayout = QtGui.QVBoxLayout(self)

        self.imgContainer = QtGui.QLabel(self)
        img = QtGui.QPixmap(':/europe.png')
        self.imgContainer.setPixmap(img)
        size = img.size()
        self.imgContainer.resize(size.width(), self.height())

        self.vlayout.addWidget(self.imgContainer)
        self.vlayout.addWidget(QtGui.QLabel('FOOO', self))

        threads = []

        worker1 = ExampleWorker('foo', 10)
        worker2 = ExampleWorker('bar', 13)
        worker3 = ExampleWorker('spam', 25)

        workers = [worker1, worker2, worker3]
        for worker in workers:
            thread = createThread(self, worker)
            threads.append(thread)
            worker.finished.connect(self.debugPrint)

        self.pgFrame = OverlayProgressWidget(self.imgContainer,
                                             workers=workers)

        for t in threads:
            t.start()
Ejemplo n.º 3
0
    def initUi(self, edit_rows, edit_cols, edit_cells=False):
        """Initalizes the Uuser Interface with all sub widgets.

        """
        self.gridLayout = QtGui.QGridLayout(self)
        self.gridLayout.setContentsMargins(0, 0, 0, 0)

        self.buttonFrame = QtGui.QFrame(self)
        #self.buttonFrame.setMinimumSize(QtCore.QSize(250, 50))
        #self.buttonFrame.setMaximumSize(QtCore.QSize(250, 50))
        self.buttonFrame.setFrameShape(QtGui.QFrame.NoFrame)
        spacerItemButton = QtGui.QSpacerItem(40, 20,
                                             QtGui.QSizePolicy.Expanding,
                                             QtGui.QSizePolicy.Minimum)

        if edit_rows:

            self.addRowButton = QtGui.QToolButton(self.buttonFrame)
            self.addRowButton.setObjectName('addrowbutton')
            self.addRowButton.setText(self.tr(u'+row'))
            self.addRowButton.setToolTip(self.tr(u'add new row'))
            icon = QtGui.QIcon(
                QtGui.QPixmap(
                    _fromUtf8(':/icons/edit-table-insert-row-below.png')))

            self.addRowButton.setIcon(icon)
            self.addRowButton.toggled.connect(self.addRow)

            self.removeRowButton = QtGui.QToolButton(self.buttonFrame)
            self.removeRowButton.setObjectName('removerowbutton')
            self.removeRowButton.setText(self.tr(u'-row'))
            self.removeRowButton.setToolTip(self.tr(u'remove selected rows'))
            icon = QtGui.QIcon(
                QtGui.QPixmap(_fromUtf8(':/icons/edit-table-delete-row.png')))

            self.removeRowButton.setIcon(icon)
            self.removeRowButton.toggled.connect(self.removeRow)

            row_buttons = [self.addRowButton, self.removeRowButton]

        if edit_cols:

            self.addColumnButton = QtGui.QToolButton(self.buttonFrame)
            self.addColumnButton.setObjectName('addcolumnbutton')
            self.addColumnButton.setText(self.tr(u'+col'))
            self.addColumnButton.setToolTip(self.tr(u'add new column'))
            icon = QtGui.QIcon(
                QtGui.QPixmap(
                    _fromUtf8(':/icons/edit-table-insert-column-right.png')))

            self.addColumnButton.setIcon(icon)
            self.addColumnButton.toggled.connect(self.showAddColumnDialog)

            self.removeColumnButton = QtGui.QToolButton(self.buttonFrame)
            self.removeColumnButton.setObjectName('removecolumnbutton')
            self.removeColumnButton.setText(self.tr(u'-col'))
            self.removeColumnButton.setToolTip(self.tr(u'remove a column'))
            icon = QtGui.QIcon(
                QtGui.QPixmap(
                    _fromUtf8(':/icons/edit-table-delete-column.png')))

            self.removeColumnButton.setIcon(icon)
            self.removeColumnButton.toggled.connect(
                self.showRemoveColumnDialog)

            col_buttons = [self.addColumnButton, self.removeColumnButton]

        if edit_rows or edit_cols or edit_cells:

            self.buttonFrameLayout = QtGui.QGridLayout(self.buttonFrame)
            self.buttonFrameLayout.setContentsMargins(0, 0, 0, 0)

            self.editButton = QtGui.QToolButton(self.buttonFrame)
            self.editButton.setObjectName('editbutton')
            self.editButton.setText(self.tr(u'edit'))
            self.editButton.setToolTip(self.tr(u'toggle editing mode'))
            icon = QtGui.QIcon(
                QtGui.QPixmap(_fromUtf8(':/icons/document-edit.png')))

            self.editButton.setIcon(icon)
            self.editButton.toggled.connect(self.enableEditing)

            edit_buttons = [self.editButton]

            if edit_rows and edit_cols:

                for x in zip(row_buttons, col_buttons):
                    edit_buttons.extend(x)

            elif edit_rows:

                edit_buttons.extend(row_buttons)

            elif edit_cols:

                edit_buttons.extend(col_buttons)

            elif not edit_cells:

                errStr = "Ack! Ack! Ack!"
                raise SystemError(errStr)

            self.buttons = edit_buttons

            for index, button in enumerate(self.buttons):
                button.setMinimumSize(self._iconSize)
                button.setMaximumSize(self._iconSize)
                button.setIconSize(self._iconSize)
                button.setCheckable(True)
                self.buttonFrameLayout.addWidget(button, 0, index, 1, 1)
            self.buttonFrameLayout.addItem(spacerItemButton, 0, index + 1, 1,
                                           1)

            for button in self.buttons[1:]:
                button.setEnabled(False)

        else:

            self.buttons = None

        #self.tableView = QtGui.QTableView(self)
        self.tableView = DragTable(self)
        self.tableView.setAlternatingRowColors(True)
        self.tableView.setSortingEnabled(True)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding,
                                       QtGui.QSizePolicy.Expanding)
        self.tableView.setSizePolicy(sizePolicy)
        self.tableView.installEventFilter(self)

        self.gridLayout.addWidget(self.buttonFrame, 0, 0, 1, 1)
        self.gridLayout.addWidget(self.tableView, 1, 0, 1, 1)

        return
Ejemplo n.º 4
0
    def _initUI(self):
        """Initiates the user interface with a grid layout and several widgets.

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

        layout = QtGui.QGridLayout()

        self._filenameLabel = QtGui.QLabel(u'Output File', self)
        self._filenameLineEdit = QtGui.QLineEdit(self)
        chooseFileButtonIcon = QtGui.QIcon(
            QtGui.QPixmap(':/icons/document-save-as.png'))
        self._chooseFileAction = QtGui.QAction(self)
        self._chooseFileAction.setIcon(chooseFileButtonIcon)
        self._chooseFileAction.triggered.connect(self._createFile)

        self._chooseFileButton = QtGui.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 = QtGui.QLabel(u'File Encoding', self)

        encoding_names = map(lambda x: x.upper(),
                             sorted(list(set(_encodings.viewvalues()))))
        self._encodingComboBox = QtGui.QComboBox(self)
        self._encodingComboBox.addItems(encoding_names)
        self._idx = encoding_names.index('UTF_8')
        self._encodingComboBox.setCurrentIndex(self._idx)
        #self._encodingComboBox.activated.connect(self._updateEncoding)

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

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

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

        self._delimiterLabel = QtGui.QLabel(u'Column Delimiter', self)
        self._delimiterBox = DelimiterSelectionWidget(self)

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

        self._exportButton = QtGui.QPushButton(u'Export Data', self)
        self._cancelButton = QtGui.QPushButton(u'Cancel', self)

        self._buttonBox = QtGui.QDialogButtonBox(self)
        self._buttonBox.addButton(self._exportButton,
                                  QtGui.QDialogButtonBox.AcceptRole)
        self._buttonBox.addButton(self._cancelButton,
                                  QtGui.QDialogButtonBox.RejectRole)

        self._buttonBox.accepted.connect(self.accepted)
        self._buttonBox.rejected.connect(self.rejected)

        layout.addWidget(self._buttonBox, 5, 2, 1, 2)
        self._exportButton.setDefault(False)
        self._filenameLineEdit.setFocus()

        self._statusBar = QtGui.QStatusBar(self)
        self._statusBar.setSizeGripEnabled(False)
        layout.addWidget(self._statusBar, 4, 0, 1, 4)
        self.setLayout(layout)
Ejemplo n.º 5
0
    def _initUI(self):
        """Initiates the user interface with a grid layout and several widgets.

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

        layout = QtGui.QGridLayout()

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

        self._chooseFileButton = QtGui.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 = QtGui.QLabel(u'File Encoding', self)

        encoding_names = map(lambda x: x.upper(),
                             sorted(list(set(_encodings.viewvalues()))))
        self._encodingComboBox = QtGui.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 = QtGui.QLabel(u'Header Available?', self)
        self._headerCheckBox = QtGui.QCheckBox(self)
        self._headerCheckBox.toggled.connect(self._updateHeader)

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

        self._delimiterLabel = QtGui.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 = QtGui.QTabWidget(self)
        self._previewTableView = QtGui.QTableView(self)
        self._datatypeTableView = QtGui.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 = QtGui.QPushButton(u'Load Data', self)
        #self.loadButton.setAutoDefault(False)

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

        self._buttonBox = QtGui.QDialogButtonBox(self)
        self._buttonBox.addButton(self._loadButton,
                                  QtGui.QDialogButtonBox.AcceptRole)
        self._buttonBox.addButton(self._cancelButton,
                                  QtGui.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 = QtGui.QStatusBar(self)
        self._statusBar.setSizeGripEnabled(False)
        layout.addWidget(self._statusBar, 8, 0, 1, 4)
        self.setLayout(layout)
Ejemplo n.º 6
0
    def initUi(self):
        """Initalizes the Uuser Interface with all sub widgets.

        """
        self.gridLayout = QtGui.QGridLayout(self)
        self.gridLayout.setContentsMargins(0, 0, 0, 0)

        self.buttonFrame = QtGui.QFrame(self)
        #self.buttonFrame.setMinimumSize(QtCore.QSize(250, 50))
        #self.buttonFrame.setMaximumSize(QtCore.QSize(250, 50))
        self.buttonFrame.setFrameShape(QtGui.QFrame.NoFrame)
        spacerItemButton = QtGui.QSpacerItem(40, 20,
                                             QtGui.QSizePolicy.Expanding,
                                             QtGui.QSizePolicy.Minimum)

        self.buttonFrameLayout = QtGui.QGridLayout(self.buttonFrame)
        self.buttonFrameLayout.setContentsMargins(0, 0, 0, 0)

        self.editButton = QtGui.QToolButton(self.buttonFrame)
        self.editButton.setObjectName('editbutton')
        self.editButton.setText(self.tr(u'edit'))
        self.editButton.setToolTip(self.tr(u'toggle editing mode'))
        icon = QtGui.QIcon(
            QtGui.QPixmap(_fromUtf8(':/icons/document-edit.png')))

        self.editButton.setIcon(icon)

        self.addColumnButton = QtGui.QToolButton(self.buttonFrame)
        self.addColumnButton.setObjectName('addcolumnbutton')
        self.addColumnButton.setText(self.tr(u'+col'))
        self.addColumnButton.setToolTip(self.tr(u'add new column'))
        icon = QtGui.QIcon(
            QtGui.QPixmap(
                _fromUtf8(':/icons/edit-table-insert-column-right.png')))

        self.addColumnButton.setIcon(icon)

        self.addRowButton = QtGui.QToolButton(self.buttonFrame)
        self.addRowButton.setObjectName('addrowbutton')
        self.addRowButton.setText(self.tr(u'+row'))
        self.addRowButton.setToolTip(self.tr(u'add new row'))
        icon = QtGui.QIcon(
            QtGui.QPixmap(
                _fromUtf8(':/icons/edit-table-insert-row-below.png')))

        self.addRowButton.setIcon(icon)

        self.removeColumnButton = QtGui.QToolButton(self.buttonFrame)
        self.removeColumnButton.setObjectName('removecolumnbutton')
        self.removeColumnButton.setText(self.tr(u'-col'))
        self.removeColumnButton.setToolTip(self.tr(u'remove a column'))
        icon = QtGui.QIcon(
            QtGui.QPixmap(_fromUtf8(':/icons/edit-table-delete-column.png')))

        self.removeColumnButton.setIcon(icon)

        self.removeRowButton = QtGui.QToolButton(self.buttonFrame)
        self.removeRowButton.setObjectName('removerowbutton')
        self.removeRowButton.setText(self.tr(u'-row'))
        self.removeRowButton.setToolTip(self.tr(u'remove selected rows'))
        icon = QtGui.QIcon(
            QtGui.QPixmap(_fromUtf8(':/icons/edit-table-delete-row.png')))

        self.removeRowButton.setIcon(icon)

        self.buttons = [
            self.editButton, self.addColumnButton, self.addRowButton,
            self.removeColumnButton, self.removeRowButton
        ]

        for index, button in enumerate(self.buttons):
            button.setMinimumSize(self._iconSize)
            button.setMaximumSize(self._iconSize)
            button.setIconSize(self._iconSize)
            button.setCheckable(True)
            self.buttonFrameLayout.addWidget(button, 0, index, 1, 1)
        self.buttonFrameLayout.addItem(spacerItemButton, 0, index + 1, 1, 1)

        for button in self.buttons[1:]:
            button.setEnabled(False)

        #self.tableView = QtGui.QTableView(self)
        self.tableView = DragTable(self)
        self.tableView.setAlternatingRowColors(True)
        self.tableView.setSortingEnabled(True)

        self.gridLayout.addWidget(self.buttonFrame, 0, 0, 1, 1)
        self.gridLayout.addWidget(self.tableView, 1, 0, 1, 1)

        self.editButton.toggled.connect(self.enableEditing)
        self.addColumnButton.toggled.connect(self.showAddColumnDialog)
        self.addRowButton.toggled.connect(self.addRow)
        self.removeRowButton.toggled.connect(self.removeRow)
        self.removeColumnButton.toggled.connect(self.showRemoveColumnDialog)