Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, path='', parent=None, iconFactory=None):
'''Initialise with root *path*.'''
super(Filesystem, self).__init__(parent=parent)
self.root = ItemFactory(path)
self.columns = ['Name', 'Size', 'Type', 'Date Modified']
if iconFactory is None:
# Local import to circumvent circular dependency.
import riffle.icon_factory
iconFactory = riffle.icon_factory.IconFactory()
self.iconFactory = iconFactory
# Ensure children for each segment in path are loaded.
segments = self._segmentPath(path)
for segment in reversed(segments):
pathIndex = model.pathIndex(segment)
model.fetchMore(pathIndex)
self._filesystemWidget.setRootIndex(model.pathIndex(path))
self._locationWidget.clear()
# Add history entry for each segment.
for segment in segments:
index = model.pathIndex(segment)
if not index.isValid():
# Root item.
icon = model.iconFactory.icon(
riffle.icon_factory.IconType.Computer
)
self._locationWidget.addItem(
icon, model.root.path or model.root.name, model.root.path
)
else:
icon = model.icon(index)
self._locationWidget.addItem(icon, segment, segment)
if self._locationWidget.count() > 1:
self._upButton.setEnabled(True)
self._upShortcut.setEnabled(True)
else:
self._upButton.setEnabled(False)
self._upShortcut.setEnabled(False)