def __init__(self, book):
"Book must be an associated notebook that this Browser is 'controlling'"
self.nb = book
QWidget.__init__(self)
self.lo = QVBoxLayout()
self.setLayout(self.lo)
#SEtup file system model
self.files = QFileSystemModel()
self.files.setReadOnly(False)
self.files.setNameFilters(supportedTypes)
if config.notespath:
self.files.setRootPath(config.notespath)
#Setup the view over that
self.fv = CustomTreeView()
self.fv.setModel(self.files)
self.fv.hideColumn(2)
self.fv.hideColumn(3)
self.fv.hideColumn(1)
self.fv.resizeColumnToContents(0)
self.fv.setAutoScroll(True)
#We pass it a reference so it can open things in the notebook
self.fv.nb=book
#I don't know what that line does, but it's important!!!!
self.fv.setRootIndex(self.files.setRootPath("/Users"))
#self.fv.doubleClicked.connect(self.dblclk)
self.fv.expanded.connect(lambda x: self.fv.resizeColumnToContents(0))
self.fv.clicked.connect(lambda x: self.fv.resizeColumnToContents(0))
self.fv.setDragEnabled(True)
self.fv.setDragDropMode(QAbstractItemView.DragDrop)
self.fv.setAcceptDrops(True)
self.lo.addWidget(self.fv)
#Credit to vahancho http://stackoverflow.com/questions/22198427/adding-a-right-click-menu-for-specific-items-in-qtreeview
self.fv.setContextMenuPolicy(Qt.CustomContextMenu);
self.fv.customContextMenuRequested.connect(self.onCustomContextMenu);
评论列表
文章目录