def __init__(self, repoTreeModel, collector, parent=None): """ Constructor. :param parent: """ super(RepoWidget, self).__init__(parent=parent) self.detailDockPanes = [] self.mainLayout = QtWidgets.QVBoxLayout() self.mainLayout.setSpacing(DOCK_SPACING) self.mainLayout.setContentsMargins(DOCK_MARGIN, DOCK_MARGIN, DOCK_MARGIN, DOCK_MARGIN) self.setLayout(self.mainLayout) self.mainSplitter = QtWidgets.QSplitter(orientation=Qt.Vertical) self.mainLayout.addWidget(self.mainSplitter) self.repoTreeView = RepoTreeView(repoTreeModel, collector) self.mainSplitter.addWidget(self.repoTreeView) self.mainSplitter.setCollapsible(0, False) self.tabWidget = QtWidgets.QTabWidget() self.mainSplitter.addWidget(self.tabWidget) self.mainSplitter.setCollapsible(1, True) self.propertiesPane = self.addDetailsPane( PropertiesPane(self.repoTreeView)) self.attributesPane = self.addDetailsPane( AttributesPane(self.repoTreeView)) self.repoTreeView.sigRepoItemChanged.connect(self.repoItemChanged) self.tabWidget.currentChanged.connect(self.tabChanged) self.tabWidget.setCurrentIndex( 1) # Show attributes the first time the program runs
def __init__(self, label, registry, parent=None): """ Constructor """ super(PluginsDialog, self).__init__(parent=parent) check_class(registry, BaseRegistry) self._label = label self._orgRegistry = registry self._registry = copy.deepcopy(registry) # make copy so changes can be canceled self._tableModel = self._registry.createTableModel(parent=self) self.mapper = QtWidgets.QDataWidgetMapper(parent=self) self.mapper.setModel(self._tableModel) self.setWindowTitle("Argos {} Plugins".format(label)) layout = QtWidgets.QVBoxLayout(self) self.verSplitter = QtWidgets.QSplitter(Qt.Vertical) #self.verSplitter.setCollapsible(1, False) self.verSplitter.setChildrenCollapsible(False) layout.addWidget(self.verSplitter) self.tableWidget = TableEditWidget(self._tableModel) self.verSplitter.addWidget(self.tableWidget) self._tableView = self.tableWidget.tableView self._tableView.installEventFilter(self) # Form self.horSplitter = QtWidgets.QSplitter(Qt.Horizontal) self.horSplitter.setChildrenCollapsible(False) self.verSplitter.addWidget(self.horSplitter) self.formWidget = QtWidgets.QWidget() self.formLayout = QtWidgets.QFormLayout() self.formLayout.setContentsMargins(0, 0, 0, 0) self.formWidget.setLayout(self.formLayout) self.horSplitter.addWidget(self.formWidget) self._editWidgets = [] itemCls = registry.ITEM_CLASS assert len(itemCls.LABELS) == len(itemCls.TYPES), \ "Regtype Mismatch: {} != {}".format(len(itemCls.LABELS), len(itemCls.TYPES)) for col, (label, regType) in enumerate(zip(itemCls.LABELS, itemCls.TYPES)): if regType == RegType.String: editWidget = QtWidgets.QLineEdit() self.mapper.addMapping(editWidget, col) elif regType == RegType.ShortCut: editWidget = ShortCutEditor() self.mapper.addMapping(editWidget, col) elif regType == RegType.ColorStr: editWidget = ColorSelectWidget() self.mapper.addMapping(editWidget.lineEditor, col) else: raise AssertionError("Unexpected regType: {}".format(regType)) editWidget.installEventFilter(self) self.formLayout.addRow(label, editWidget) self._editWidgets.append(editWidget) # Detail info widget font = QtGui.QFont() font.setFamily(MONO_FONT) font.setFixedPitch(True) font.setPointSize(FONT_SIZE) self.editor = QtWidgets.QTextEdit() self.editor.setReadOnly(True) #self.editor.setFocusPolicy(Qt.NoFocus) # Allow focus so that user can copy text from it. #self.editor.setFont(font) self.editor.setWordWrapMode(QtGui.QTextOption.WordWrap) self.editor.clear() self.horSplitter.addWidget(self.editor) self.horSplitter.setStretchFactor(0, 2) self.horSplitter.setStretchFactor(1, 3) self.verSplitter.setSizes([300, 150]) # Reset/Cancel/Save Buttons self.saveButton = QtWidgets.QPushButton("Save") self.saveButton.clicked.connect(self.accept) self.cancelButton = QtWidgets.QPushButton("Cancel") self.cancelButton.clicked.connect(self.reject) self.resetButton = QtWidgets.QPushButton("Reset Table to Defaults...") self.resetButton.clicked.connect(self.resetToDefaults) self.resetButton.setIcon(QtGui.QIcon(os.path.join(icons_directory(), 'reset-l.svg'))) # We use a button layout instead of a QButtonBox because there always will be a default # button (e.g. the Save button) that will light up, even if another widget has the focus. # From https://doc.qt.io/archives/qt-4.8/qdialogbuttonbox.html#details # However, if there is no default button set and to preserve which button is the default # button across platforms when using the QPushButton::autoDefault property, the first # push button with the accept role is made the default button when the QDialogButtonBox # is shown, self.buttonLayout = QtWidgets.QHBoxLayout() self.buttonLayout.addWidget(self.resetButton) self.buttonLayout.addStretch() if sys.platform == 'darwin': self.buttonLayout.addWidget(self.cancelButton) self.buttonLayout.addWidget(self.saveButton) else: self.buttonLayout.addWidget(self.saveButton) self.buttonLayout.addWidget(self.cancelButton) layout.addLayout(self.buttonLayout) # Connect signals and populate self.tableWidget.tableView.selectionModel().currentChanged.connect(self.currentItemChanged) self.tableWidget.tableView.model().sigItemChanged.connect(self._updateEditor) self.resize(QtCore.QSize(1100, 700)) self.tableWidget.tableView.setFocus(Qt.NoFocusReason) self.tryImportAllPlugins()
def __init__(self, registry, parent=None, attrNames=None, headerNames=None, headerSizes=None, onlyShowImported=False, importOnSelect=True): """ Constructor. If onlyShowImported is True, regItems that are not (successfully) imported are filtered from the table. By default onlyShowImported is False. If importOnSelect is True (the default), the item is imported if the user selects it. """ super(RegistryTab, self).__init__(parent=parent) self._importOnSelect = importOnSelect self._onlyShowImported = onlyShowImported self._registry = registry attrNames = [] if attrNames is None else attrNames headerNames = attrNames if headerNames is None else headerNames headerSizes = [] if headerSizes is None else headerSizes if headerSizes is None: headerSizes = [] else: assert len(headerSizes) == len(attrNames), \ "Size mismatch {} != {}".format(len(headerSizes), len(attrNames)) layout = QtWidgets.QVBoxLayout(self) statusLayout = QtWidgets.QHBoxLayout() layout.addLayout(statusLayout) self.statusLabel = QtWidgets.QLabel("") statusLayout.addWidget(self.statusLabel) statusLayout.setStretch(0, 1) self.loadAllButton = QtWidgets.QPushButton("Load all") self.loadAllButton.setFocusPolicy(Qt.ClickFocus) self.loadAllButton.clicked.connect(self.tryImportAllPlugins) statusLayout.addWidget(self.loadAllButton) statusLayout.setStretch(1, 0) splitter = QtWidgets.QSplitter(Qt.Vertical) layout.addWidget(splitter) # Table tableModel = RegistryTableModel(self._registry, attrNames=attrNames, parent=self) proxyTableModel = RegistryTableProxyModel(parent=self, onlyShowImported=self._onlyShowImported) proxyTableModel.setSourceModel(tableModel) self.tableView = RegistryTableView(proxyTableModel, onlyShowImported=self.onlyShowImported) tableHeader = self.tableView.horizontalHeader() for col, headerSize in enumerate(headerSizes): if headerSize: tableHeader.resizeSection(col, headerSize) selectionModel = self.tableView.selectionModel() selectionModel.currentRowChanged.connect(self.currentItemChanged) splitter.addWidget(self.tableView) splitter.setCollapsible(0, False) # Detail info widget font = QtGui.QFont() font.setFamily(MONO_FONT) font.setFixedPitch(True) font.setPointSize(FONT_SIZE) self.editor = QtWidgets.QTextEdit() self.editor.setReadOnly(True) self.editor.setFont(font) self.editor.setWordWrapMode(QtGui.QTextOption.NoWrap) self.editor.clear() splitter.addWidget(self.editor) splitter.setCollapsible(1, False) splitter.setSizes([300, 150]) self.tableView.setFocus(Qt.NoFocusReason)