def set_root_path(self, path, hide_extra_columns=True): """ Sets the root path to watch :param path: root path - str :param hide_extra_columns: Hide extra column (size, paths,...) """ self._hide_extra_colums = hide_extra_columns if os.path.isfile(path): path = os.path.abspath(os.path.join(path, os.pardir)) self._fs_model_source = QtWidgets.QFileSystemModel() self._fs_model_source.setFilter(QtCore.QDir.Dirs | QtCore.QDir.Files | QtCore.QDir.NoDotAndDotDot | QtCore.QDir.Hidden) self._fs_model_source.setIconProvider(self._icon_provider) self._fs_model_proxy = self.FilterProxyModel() for item in self._ignored_patterns: self._fs_model_proxy.ignored_patterns.append(item) self._fs_model_proxy.setSourceModel(self._fs_model_source) self._fs_model_proxy.set_root_path(path) # takes parent of the root path, filter will keep only `path`, that # way `path` appear as the top level node of the tree self._root_path = os.path.dirname(path) self.root_path = path self._fs_model_source.directoryLoaded.connect(self._on_path_loaded) self._fs_model_source.setRootPath(self._root_path)
def set_root_path(self, path, hide_extra_columns=True): """ Sets the root path to watch :param path: root path - str :param hide_extra_columns: Hide extra column (size, paths,...) """ if os.path.isfile(path): path = os.path.abspath(os.path.join(path, os.pardir)) self._fs_model_source = QtWidgets.QFileSystemModel() self._fs_model_proxy = self.FilterProxyModel() for item in self._ignored_directories: self._fs_model_proxy.ignored_directories.append(item) for item in self._ignored_extensions: self._fs_model_proxy.ignored_extensions.append(item) self._fs_model_proxy.setSourceModel(self._fs_model_source) self.setModel(self._fs_model_proxy) self._fs_model_proxy.set_root_path(path) self.root_path = os.path.dirname(path) file_root_index = self._fs_model_source.setRootPath(self.root_path) root_index = self._fs_model_proxy.mapFromSource(file_root_index) self.setRootIndex(root_index) # Expand first entry (project name) file_parent_index = self._fs_model_source.index(path) self.setExpanded(self._fs_model_proxy.mapFromSource( file_parent_index), True) if hide_extra_columns: self.setHeaderHidden(True) for i in range(1, 4): self.hideColumn(i)
def set_root_path(self, path, hide_extra_columns=True): """ Sets the root path to watch :param path: root path - str :param hide_extra_columns: Hide extra column (size, paths,...) """ if not self.isVisible(): self._path_to_set = path self._hide_extra_colums = hide_extra_columns return if sys.platform == 'win32' and os.path.splitunc(path)[0]: mdl = QtGui.QStandardItemModel(1, 1) item = QtGui.QStandardItem( QtGui.QIcon.fromTheme( 'dialog-warning', QtGui.QIcon(':/pyqode-icons/rc/dialog-warning.png')), 'UNC pathnames not supported.') mdl.setItem(0, 0, item) self.setModel(mdl) self.root_path = None return self._hide_extra_colums = hide_extra_columns if os.path.isfile(path): path = os.path.abspath(os.path.join(path, os.pardir)) self._fs_model_source = QtWidgets.QFileSystemModel() self._fs_model_source.setFilter(QtCore.QDir.Dirs | QtCore.QDir.Files | QtCore.QDir.NoDotAndDotDot | QtCore.QDir.Hidden) self._fs_model_source.setIconProvider(self._icon_provider) self._fs_model_proxy = self.FilterProxyModel() for item in self._ignored_patterns: self._fs_model_proxy.ignored_patterns.append(item) self._fs_model_proxy.setSourceModel(self._fs_model_source) self._fs_model_proxy.set_root_path(path) # takes parent of the root path, filter will keep only `path`, that # way `path` appear as the top level node of the tree self._root_path = os.path.dirname(path) self.root_path = path self._fs_model_source.directoryLoaded.connect(self._on_path_loaded) self._fs_model_source.setRootPath(self._root_path)