class IPFSHashExplorerToolBox(GalacteekTab): """ Organizes IPFSHashExplorerWidgets with a QToolBox """ def __init__(self, gWindow, hashRef, maxItems=16, parent=None): super(IPFSHashExplorerToolBox, self).__init__(gWindow) self.rootHash = hashRef self.maxItems = maxItems self.toolbox = QToolBox() self.exLayout = QVBoxLayout() self.exLayout.addWidget(self.toolbox) self.vLayout.addLayout(self.exLayout) if self.rootHash: self.viewHash(self.rootHash) @property def itemsCount(self): return self.toolbox.count() def viewHash(self, hashRef, addClose=False, autoOpenFolders=False): w = self.lookup(hashRef) if w: self.toolbox.setCurrentWidget(w) return True if self.itemsCount > self.maxItems: return False view = IPFSHashExplorerWidget(hashRef, parent=self, addClose=addClose, autoOpenFolders=autoOpenFolders) view.closeRequest.connect(functools.partial(self.remove, view)) view.directoryOpenRequest.connect( lambda cid: self.viewHash(cid, addClose=True)) idx = self.toolbox.addItem(view, getIconIpfsWhite(), hashRef) self.toolbox.setCurrentIndex(idx) view.reFocus() return True def lookup(self, hashRef): for idx in range(self.itemsCount): if self.toolbox.itemText(idx) == hashRef: return self.toolbox.widget(idx) def remove(self, view): idx = self.toolbox.indexOf(view) if idx: self.toolbox.removeItem(idx) # Always display previous index in the stack if self.itemsCount > 0: rIdx = idx - 1 view = self.toolbox.widget(rIdx) if view: self.toolbox.setCurrentWidget(view) view.reFocus()