def __init__(self, parent): QtGui.QScrollArea.__init__(self, parent) # Init the scroll area self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded) self.setWidgetResizable(True) self.setFrameShape(QtGui.QFrame.NoFrame) # Create widget and a layout self._content = QtGui.QWidget(parent) self._formLayout = QtGui.QFormLayout(self._content) # Collect classes of widgets to instantiate classes = [] for t in self.INFO_KEYS: className = 'ShellInfo_' + t.key cls = globals()[className] classes.append((t, cls)) # Instantiate all classes self._shellInfoWidgets = {} for t, cls in classes: # Instantiate and store instance = cls(self._content) self._shellInfoWidgets[t.key] = instance # Create label label = QtGui.QLabel(t, self._content) label.setToolTip(t.tt) # Add to layout self._formLayout.addRow(label, instance) # Add delete button t = translate('shell', 'Delete ::: Delete this shell configuration') label = QtGui.QLabel('', self._content) instance = QtGui.QPushButton(pyzo.icons.cancel, t, self._content) instance.setToolTip(t.tt) instance.setAutoDefault(False) instance.clicked.connect(self.parent().parent().onTabClose) deleteLayout = QtGui.QHBoxLayout() deleteLayout.addWidget(instance, 0) deleteLayout.addStretch(1) # Add to layout self._formLayout.addRow(label, deleteLayout) # Apply layout self._formLayout.setSpacing(15) self._content.setLayout(self._formLayout) self.setWidget(self._content)
def loadTool(self, toolId, splitWith=None): """ Load a tool by creating a dock widget containing the tool widget. """ # A tool id should always be lower case toolId = toolId.lower() # Close old one if toolId in self._activeTools: old = self._activeTools[toolId].widget() self._activeTools[toolId].setWidget(QtGui.QWidget(pyzo.main)) if old: old.close() old.deleteLater() # Get tool class (returns None on failure) toolClass = self.getToolClass(toolId) if toolClass is None: return # Already loaded? reload! if toolId in self._activeTools: self._activeTools[toolId].reload(toolClass) return # Obtain name from buffered list of names for toolDes in self._toolInfo: if toolDes.id == toolId: name = toolDes.name break else: name = toolId # Make sure there is a config entry for this tool if not hasattr(pyzo.config.tools, toolId): pyzo.config.tools[toolId] = ssdf.new() # Create dock widget and add in the main window dock = ToolDockWidget(pyzo.main, self) dock.setTool(toolId, name, toolClass) if splitWith and splitWith in self._activeTools: otherDock = self._activeTools[splitWith] pyzo.main.splitDockWidget(otherDock, dock, QtCore.Qt.Horizontal) else: pyzo.main.addDockWidget(QtCore.Qt.RightDockWidgetArea, dock) # Add to list self._activeTools[toolId] = dock self.updateToolInstances()
def setTabText(self, i, text): """ setTabText(i, text) Set the text for tab i. """ self.tabBar().setTabText(i, text) def tabText(self, i): """ tabText(i) Get the title of the tab at index i. """ return self.tabBar().tabText(i) if __name__ == '__main__': w = CompactTabWidget() w.show() w.addTab(QtGui.QWidget(w), 'aapenootjedopje') w.addTab(QtGui.QWidget(w), 'aapenootjedropje') w.addTab(QtGui.QWidget(w), 'noot en mies') w.addTab(QtGui.QWidget(w), 'boom bijv een iep') w.addTab(QtGui.QWidget(w), 'roosemarijnus') w.addTab(QtGui.QWidget(w), 'vis') w.addTab(QtGui.QWidget(w), 'vuurvuurvuur')
def __init__(self, parent=None, collection_filename=None): """ Initializes an assistance instance. When collection_file is none, it is determined from the appDataDir. """ from pyzolib.qt import QtHelp super().__init__(parent) self.setWindowTitle('Help') pyzoDir, appDataDir = getResourceDirs() if collection_filename is None: # Collection file is stored in pyzo data dir: collection_filename = os.path.join(appDataDir, 'tools', 'docs.qhc') self._engine = QtHelp.QHelpEngine(collection_filename) # Important, call setup data to load the files: self._engine.setupData() # If no files are loaded, register at least the pyzo docs: if len(self._engine.registeredDocumentations()) == 0: doc_file = os.path.join(pyzoDir, 'resources', 'pyzo.qch') ok = self._engine.registerDocumentation(doc_file) # The main players: self._content = self._engine.contentWidget() self._index = self._engine.indexWidget() self._indexTab = QtGui.QWidget() il = QtGui.QVBoxLayout(self._indexTab) filter_text = QtGui.QLineEdit() il.addWidget(filter_text) il.addWidget(self._index) self._helpBrowser = HelpBrowser(self._engine) self._searchEngine = self._engine.searchEngine() self._settings = Settings(self._engine) self._progress = QtGui.QWidget() pl = QtGui.QHBoxLayout(self._progress) bar = QtGui.QProgressBar() bar.setMaximum(0) pl.addWidget(QtGui.QLabel('Indexing')) pl.addWidget(bar) self._searchResultWidget = self._searchEngine.resultWidget() self._searchQueryWidget = self._searchEngine.queryWidget() self._searchTab = QtGui.QWidget() search_layout = QtGui.QVBoxLayout(self._searchTab) search_layout.addWidget(self._searchQueryWidget) search_layout.addWidget(self._searchResultWidget) tab = QtGui.QTabWidget() tab.addTab(self._content, "Contents") tab.addTab(self._indexTab, "Index") tab.addTab(self._searchTab, "Search") tab.addTab(self._settings, "Settings") splitter = QtGui.QSplitter(self) splitter.addWidget(tab) splitter.addWidget(self._helpBrowser) layout = QtGui.QVBoxLayout(self) layout.addWidget(splitter) layout.addWidget(self._progress) # Connect clicks: self._content.linkActivated.connect(self._helpBrowser.setSource) self._index.linkActivated.connect(self._helpBrowser.setSource) self._searchEngine.searchingFinished.connect(self.onSearchFinish) self._searchEngine.indexingStarted.connect(self.onIndexingStarted) self._searchEngine.indexingFinished.connect(self.onIndexingFinished) filter_text.textChanged.connect(self._index.filterIndices) self._searchResultWidget.requestShowLink.connect( self._helpBrowser.setSource) self._searchQueryWidget.search.connect(self.goSearch) # Always re-index on startup: self._searchEngine.reindexDocumentation() self._search_term = None # Show initial page: # self.showHelpForTerm('welcome to pyzo') self._helpBrowser.setHtml(help_help)