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