def openMenu(self, position): """ Creates the contextmenu of the treeview at a given position. The contents of the contextmenu depend on whether the selected item is a file or a directory. Parameters ---------- position : QPoint The position to place the contextmenu. """ index = self.selectedIndexes() path = [self.dirmodel.filePath(x) for x in index] menu = QtWidgets.QMenu() if len(path) == 1: if self.dirmodel.isDir(index[0]): menu.addAction("Load Directory", lambda: self.father.loadData(path)) else: menu.addAction("Load File", lambda: self.father.loadData(path)) menu.addAction("Open File Externally", lambda: self.openExtAct(path)) menu.addAction("Open in File Browser", lambda: self.openBrowser(path)) else: menu.addAction("Load Selection", lambda: self.father.loadData(path)) menu.exec_(self.viewport().mapToGlobal(position))
def openMenu(self, position): index = self.selectedIndexes() path = [self.dirmodel.filePath(x) for x in index] menu = QtWidgets.QMenu() if len(path) == 1: if self.dirmodel.isDir(index[0]): menu.addAction("Load Directory", lambda: self.loadAct(path)) else: menu.addAction("Load File", lambda: self.loadAct(path)) else: menu.addAction("Load Selection", lambda: self.loadAct(path)) menu.exec_(self.viewport().mapToGlobal(position))