def _load_scripts(self): """ Loads all relevant scripts/devices from filesystem""" # Load scripts with configuraitons script_dir = os.path.join(get_config_directory(), 'scripts') if os.path.isdir(script_dir): model = QtWidgets.QFileSystemModel() model.setRootPath(script_dir) self.main_window.scripts.setModel(model) self.main_window.scripts.setRootIndex(model.index(script_dir)) self.main_window.scripts.hideColumn(1) self.main_window.scripts.hideColumn(2) self.main_window.scripts.hideColumn(3) self.main_window.scripts.doubleClicked.connect(self._script_clicked) # Load device config files device_dir = os.path.join(get_config_directory(), 'devices') if os.path.isdir(device_dir): model = QtWidgets.QFileSystemModel() model.setRootPath(device_dir) self.main_window.devices.setModel(model) self.main_window.devices.setRootIndex(model.index(device_dir)) self.main_window.devices.hideColumn(1) self.main_window.devices.hideColumn(2) self.main_window.devices.hideColumn(3) self.main_window.devices.doubleClicked.connect(self._device_clicked)
def __init__(self): super(Mywindow,self).__init__() self.new=Ui_MainWindow() self.new.setupUi(self) self.dirtree = QtWidgets.QFileSystemModel() #左上目录树形图 dir='::{20D04FE0-3AEA-1069-A2D8-08002B30309D}' self.dirtree.setRootPath(dir) self.new.treeView.setModel(self.dirtree) self.new.treeView.setRootIndex(self.dirtree.index(dir)) self.new.treeView.resizeColumnToContents(0) self.new.treeView.clicked.connect(self.treeView_double_click) self.new.comboBox_2.activated.connect(self.continueActivated) #combobox信号触发,右上目录树显示 self.dirtree2 = QtWidgets.QFileSystemModel() #左下目录树形图 self.new.treeView.customContextMenuRequested[QtCore.QPoint].connect(self.myListWidgetContext) self.new.comboBox_3.activated.connect(self.handleActivated) #combobox信号触发,右上目录树显示 self.dirtree3 = QtWidgets.QFileSystemModel() self.new.treeView_2.clicked.connect(self.treeView_2_double_click) self.dirtree4 = QtWidgets.QFileSystemModel()
def __init__(self, *args, **kwargs): QWidget.__init__(self, *args, **kwargs) self.c = ComputeMI() path = ".\\results" hlay = QHBoxLayout(self) self.treeview = QTreeView() self.listview = QListView() hlay.addWidget(self.treeview) hlay.addWidget(self.listview) self.dirModel = QtWidgets.QFileSystemModel() self.dirModel.setRootPath(QDir.rootPath()) self.dirModel.setFilter(QDir.NoDotAndDotDot | QDir.AllDirs) self.fileModel = QtWidgets.QFileSystemModel() self.fileModel.setFilter(QDir.NoDotAndDotDot | QDir.Files) self.treeview.setModel(self.dirModel) self.listview.setModel(self.fileModel) self.treeview.setRootIndex(self.dirModel.index(path)) self.listview.setRootIndex(self.fileModel.index(path)) self.treeview.clicked.connect(self.onClicked) self.treeview.setFixedSize(720, 480) self.treeview.setColumnWidth(0, 500)
def treeVeListBagla(self): self.lokalDirModel = QtWidgets.QFileSystemModel() self.lokalDirModel.setRootPath("") self.lokalDirList.setModel(self.lokalDirModel) self.lokalDirList.verticalHeader().hide() self.lokalDirList.setSortingEnabled(True) self.lokalTreeModel = QtWidgets.QFileSystemModel() self.lokalTreeModel.setRootPath("") self.lokalTreeModel.setFilter(QtCore.QDir.AllDirs | QtCore.QDir.NoDotAndDotDot) self.lokalTree.setModel(self.lokalTreeModel) for i in range(1, self.lokalTreeModel.columnCount()): self.lokalTree.hideColumn(i)
def newFileSystemModel(self): fileSystemModel = QtWidgets.QFileSystemModel() fileSystemModel.setRootPath(QtCore.QDir.rootPath()) fileSystemModel.setNameFilterDisables(False) fileSystemModel.setIconProvider(self.iconProvider) return fileSystemModel
def __init__(self): super(ChangePathExcelInterface, self).__init__() self.resize(700, 400) self.setWindowTitle("Change Excel path") self.show() '''Font settings''' font = QtGui.QFont() font.setPointSize(13) self.setFont(font) '''Button settings''' self.button = QtWidgets.QPushButton("Save") self.button.setStyleSheet("background-color: #8b0000; color: white; height:50; border-radius:10") self.button.setFont(font) '''TreeView''' self.treeView = QtWidgets.QTreeView() '''File System''' self.fileSystemModel = QtWidgets.QFileSystemModel(self.treeView) self.fileSystemModel.setReadOnly(True) self.fileSystemModel.setRootPath(os.path.realpath('')) self.treeView.setModel(self.fileSystemModel) '''Vertical layout''' vbox = QtWidgets.QVBoxLayout(self) vbox.addWidget(self.treeView) vbox.addWidget(self.button) '''Tree and Button clicked''' self.treeView.clicked.connect(self.on_select) self.button.clicked.connect(self.on_button_clicked)
def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(566, 594) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.treeView = QtWidgets.QTreeView(self.centralwidget) self.treeView.setGeometry(QtCore.QRect(0, 0, 256, 551)) self.treeView.setObjectName("treeView") model = QtWidgets.QFileSystemModel() model.setRootPath("/") self.treeView.setModel(model) self.treeView.hideColumn(1) self.treeView.hideColumn(2) self.treeView.hideColumn(3) self.treeView.doubleClicked.connect(self.fileOpen) self.lineEdit = QtWidgets.QLineEdit(self.centralwidget) self.lineEdit.setGeometry(QtCore.QRect(270, 0, 291, 20)) self.lineEdit.setObjectName("lineEdit") MainWindow.setCentralWidget(self.centralwidget) self.menubar = QtWidgets.QMenuBar(MainWindow) self.menubar.setGeometry(QtCore.QRect(0, 0, 566, 21)) self.menubar.setObjectName("menubar") MainWindow.setMenuBar(self.menubar) self.statusbar = QtWidgets.QStatusBar(MainWindow) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow)
def __init__(self): super(MyFileBrowser, self).__init__() self.model = QtWidgets.QFileSystemModel() self.setupUi(self) self.treeView.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self.treeView.customContextMenuRequested.connect(self.context_menu) self.populate()
def initFileTree(self): self.file_tree = QtWidgets.QTreeView() self.fs_model = QtWidgets.QFileSystemModel(self.file_tree) self.fs_model.setNameFilterDisables(False) self.fs_model.setRootPath(str(self.proc_log_path)) self.file_tree.setModel(self.fs_model) self.file_tree.hideColumn(1) self.file_tree.hideColumn(2) self.file_tree.setColumnWidth(0, 200) self.file_tree.setSelectionMode( QtGui.QAbstractItemView.ExtendedSelection) self.file_tree.selectionModel().selectionChanged.connect( self.loadSelection) self.fs_model.setNameFilters(["*.txt"]) # self.fs_model self.showDir(str(self.proc_log_path)) self.file_tree.setSortingEnabled(True) self.file_tree.sortByColumn(3, 0)
def __init__(self): super(FileView, self).__init__() self.current_path = IMAGE_DIR # file system model self.model = QtWidgets.QFileSystemModel() self.model.setNameFilters(IMAGE_FILE_FILTER) # tree view self.tree = QtWidgets.QTreeView() self.tree.setModel(self.model) self.tree.setRootIndex(self.model.setRootPath(self.current_path)) self.tree.setColumnHidden(1, True) self.tree.setColumnHidden(2, True) self.tree.setColumnHidden(3, True) self.tree.setAnimated(False) self.tree.setIndentation(20) self.tree.setSortingEnabled(True) self.tree.sortByColumn(0, Qt.AscendingOrder) # buttons self.button_change = QtWidgets.QPushButton('change directory') self.button_change.setSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed) self.button_change.clicked.connect(self.change_directory) # layout _layout = QtWidgets.QVBoxLayout() _layout.addWidget(self.tree) _layout.addWidget(self.button_change) self.setLayout(_layout)
def browse(self): path = "csv_dataset/" self.model = QtWidgets.QFileSystemModel() self.model.setRootPath((QtCore.QDir.rootPath())) self.treeView.setModel(self.model) self.treeView.setRootIndex(self.model.index(path)) self.treeView.setSortingEnabled(True)
def _update_logfile_status(self): """ Updates the status of whether or not we are using a logfile """ if self.main_window.log_file_button.isChecked(): # Enable and show file browser self.main_window.file_viewer.setEnabled(True) self.main_window.file_viewer.setHidden(False) self.main_window.logfile_status_button.setEnabled(True) self.main_window.logfile_status_button.setHidden(False) self.main_window.log_previous.setEnabled(True) self.main_window.log_previous.setHidden(False) # Assign a file system model if we're not already logging if not self.main_window.logfile_status_button.isChecked(): model = QtWidgets.QFileSystemModel() model.setRootPath(QtCore.QDir.rootPath()) self.main_window.file_viewer.setModel(model) self.main_window.file_viewer.setRootIndex( model.index(QtCore.QDir.homePath())) self.main_window.file_viewer.setColumnWidth(0, 200) else: # Disable and hide file browser self.main_window.file_viewer.setHidden(True) self.main_window.file_viewer.setEnabled(False) self.main_window.logfile_status_button.setHidden(True) self.main_window.logfile_status_button.setEnabled(False) self.main_window.log_previous.setEnabled(False) self.main_window.log_previous.setHidden(True)
def __init__(self, parent, x: int, y: int, w: int, h: int, func, rootPath=QtCore.QDir.currentPath()): super().__init__(parent) self.setGeometry(x, y, w, h); self.fileSystem = QtWidgets.QFileSystemModel(self) self.fileSystem.setRootPath(QtCore.QDir.currentPath()) self.tree = QtWidgets.QTreeView() self.tree.setModel(self.fileSystem) self.tree.setRootIndex(self.fileSystem.index(rootPath)) self.tree.move(200, 0) self.tree.setAnimated(False) self.tree.setIndentation(5) self.tree.setSortingEnabled(True) self.tree.setHeaderHidden(True) self.tree.setStyleSheet(""" color: white; background-color: black; """) self.windowLayout = QtWidgets.QVBoxLayout() self.windowLayout.addWidget(self.tree) self.setLayout(self.windowLayout) self.tree.doubleClicked.connect(func)
def __init__(self, parent=None): QtWidgets.QWidget.__init__(self, parent) self.settings = QtCore.QSettings('Maxlab', 'EmittanceMeterViewer') self.image_width = 240 self.image_height = 240 self.px = 5.0 / self.image_width self.scan_n_pos = None self.scan_pos = None self.file_model = QtWidgets.QFileSystemModel() self.file_model.setFilter(QtCore.QDir.NoDotAndDotDot | QtCore.QDir.Files) self.path = os.path.join(os.path.curdir, "data") self.file_model.setRootPath(self.path) self.dataset_model = QtGui.QStandardItemModel() self.dataset_name_init = None self.charge_plot = None self.line_plot = None self.xp_plot = None self.xp2_plot = None self.image_autorange = True self.ui = Ui_Dialog() self.ui.setupUi(self) self.setup_layout() self.em_ana = EmittanceMeterAnalysis() self.parse_directory(self.ui.dir_select_edit.text())
def populate(self): path = "/Users/trannam" self.model = QtWidgets.QFileSystemModel() self.model.setRootPath((QtCore.QDir.rootPath())) self.fileBrower.setModel(self.model) self.fileBrower.setRootIndex(self.model.index(path)) self.fileBrower.setSortingEnabled(True)
def populate(self): path = r"/home/masterubunto/M2_gitprojects/historical_dictionary-/data/corpus" self.model = QtWidgets.QFileSystemModel() self.model.setRootPath((QtCore.QDir.rootPath())) self.treeView.setModel(self.model) self.treeView.setRootIndex(self.model.index(path)) self.treeView.setSortingEnabled(True)
def populate(self): path = "/home/" + getpass.getuser() + "/" self.model = QtWidgets.QFileSystemModel() self.model.setRootPath((QtCore.QDir.rootPath())) self.treeView.setModel(self.model) self.treeView.setRootIndex(self.model.index(path)) self.treeView.setSortingEnabled(True)
def __init__(self, useData, FILE_EXPLORER_SHORTCUTS, messagesWidget, editorTabWidget, parent=None): QtWidgets.QTreeView.__init__(self, parent) self.setAcceptDrops(True) self.setAnimated(True) self.setAutoScroll(True) self.activated.connect(self.treeItemActivated) self.setObjectName("sidebarItem") self.fileSystemModel = QtWidgets.QFileSystemModel() self.fileSystemModel.setRootPath(QtCore.QDir.rootPath()) self.fileSystemModel.setNameFilterDisables(False) self.setModel(self.fileSystemModel) self.setColumnWidth(0, 300) self.useData = useData self.FILE_EXPLORER_SHORTCUTS = FILE_EXPLORER_SHORTCUTS self.messagesWidget = messagesWidget self.editorTabWidget = editorTabWidget self.manageShortcuts = ManageShortcuts( useData, self.FILE_EXPLORER_SHORTCUTS, self) self.manageShortcuts.updateShortcuts.connect( self.updateShortcutsActionGroup) editorTabWidget.addToolWidget(self.manageShortcuts) self.createActions() self.shortcutsMenu = QtWidgets.QMenu("Shortcuts") self.updateShortcutsActionGroup()
def populate(self): path = "C:\Windows" self.model = QtWidgets.QFileSystemModel() self.model.setRootPath((QtCore.QDir.rootPath())) self.treeView.setModel(self.model) self.treeView.setRootIndex(self.model.index(path)) self.treeView.setSortingEnabled(True)
def populate(self): """Load file browser model on tree view""" self.model = QtWidgets.QFileSystemModel() self.model.setRootPath((QtCore.QDir.rootPath())) self.treeView.setModel(self.model) self.treeView.setColumnWidth(0, 350) self.treeView.setSortingEnabled(1)
def __init__(self, *args, **kwargs): QtWidgets.QDialog.__init__(self, *args, **kwargs) self.completer = QtWidgets.QCompleter() self.completer_model = QtWidgets.QFileSystemModel(self.completer) self.completer.setModel(self.completer_model) self.completer.setMaxVisibleItems(8) loadUi(get_resource("dialog_config.ui"), self) self.ok_button.released.connect(self.setAttributes) self.ok_button.released.connect(self.close) self.apply_button.released.connect(self.setAttributes) self.vector_color_picker = QtWidgets.QColorDialog(self) self.vector_color_picker.setCurrentColor( QtGui.QColor(*getConfig().vector_color)) self.vector_color_picker.setOption( self.vector_color_picker.ShowAlphaChannel) self.vector_color_picker.colorSelected.connect(self.updateVectorColor) self.vector_color_picker.setModal(True) self.vector_color.clicked.connect(self.vector_color_picker.show) self.vector_color.setValue = self.setButtonColor self.vector_color.value = self.getButtonColor self.chooseStoreDirButton.released.connect(self.chooseStoreDir) self.completer_model.setRootPath("") self.completer.setParent(self.default_gf_dir) self.default_gf_dir.setCompleter(self.completer) self.getAttributes()
def __init__(self, parent=None): super(Widget, self).__init__(parent) le = QtWidgets.QLineEdit(textChanged=self.on_textChanged) self.lv = QtWidgets.QListView() self._dirpath = '/home/vbert/tmp' # QtCore.QDir.homePath() print("\n-----------------------------") print(QtCore.QDir.homePath()) print("-----------------------------\n") # file = str(QtWidgets.QFileDialog.getExistingDirectory( # self, "Wybierz katalog")) # print(file) self.file_model = QtWidgets.QFileSystemModel() # self.file_model.setRootPath(QtCore.QDir.rootPath()) self.file_model.setRootPath('') self.file_model.setFilter(QtCore.QDir.NoDotAndDotDot | QtCore.QDir.AllEntries | QtCore.QDir.Dirs | QtCore.QDir.Files) self.proxy_model = QtCore.QSortFilterProxyModel( recursiveFilteringEnabled=True, filterRole=QtWidgets.QFileSystemModel.FileNameRole) self.proxy_model.setSourceModel(self.file_model) self.lv.setModel(self.proxy_model) self.adjust_root_index() lay = QtWidgets.QVBoxLayout(self) lay.addWidget(le) lay.addWidget(self.lv)
def setDirectory(self, dir=''): # Handle filesystem self.model = QtWidgets.QFileSystemModel() self.model.setRootPath(QtCore.QDir.rootPath()) # Get root path self.treeView.setModel(self.model) self.treeView.setRootIndex( self.model.index(dir)) # Choose directory to display
def populateTreeView(self): self.filesystemmodel = QtWidgets.QFileSystemModel(self) self.filesystemmodel.setRootPath("") self.filesystemmodel.setNameFilters(["*.jpg"]) self.filesystemmodel.setNameFilterDisables(False) self.treeView.setModel(self.filesystemmodel) self.treeView.setRootIndex(self.filesystemmodel.index("")) path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "examples") #print("PATH=",path) path = self.filesystemmodel.index(path) self.treeView.setCurrentIndex(path) self.treeView.scrollTo(path) #self.treeView.scrollTo(self.filesystemmodel.index("/home/marian/programming/leafarea/examples")) self.treeView.hideColumn(1) self.treeView.hideColumn(2) self.treeView.hideColumn(3) self.treeView.setWindowTitle("Dir View") self.selectFolder() #self.treeView.setCurrentIndex(QtWidgets.QFileSystemModel.index()) return
def __init__(self): super(MainWindow, self).__init__() self.ui = mainwindow.Ui_MainWindow() self.ui.setupUi(self) self.ui.searchInLE.setText(QtCore.QDir.currentPath()) self.ui.recurseCB.setChecked(True) # Create a text completer for searchInLE dircompleter = QtWidgets.QCompleter(self.ui.searchInLE) dircompleterfsmodel = QtWidgets.QFileSystemModel(dircompleter) dircompleterfsmodel.setRootPath(QtCore.QDir.currentPath()) dircompleterfsmodel.setFilter(QtCore.QDir.AllDirs | QtCore.QDir.NoDotAndDotDot) dircompleter.setModel(dircompleterfsmodel) dircompleter.setCaseSensitivity(QtCore.Qt.CaseInsensitive) self.ui.searchInLE.setCompleter(dircompleter) # Setup the model for the table view self.tablemodel = QtGui.QStandardItemModel() self.tablemodel.setHorizontalHeaderLabels(self.tableheader) self.ui.resultsWidget.setModel(self.tablemodel) self.ui.resultsWidget.setSortingEnabled(True) self.ui.resultsWidget.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers) self.ui.dirBtn.clicked.connect(self.dirBtnClicked) self.ui.searchBtn.clicked.connect(self.searchBtnClicked)
def populate(self): #windowDirectory self.modelWindowDirectory = QtWidgets.QFileSystemModel() self.modelWindowDirectory.setRootPath((QtCore.QDir.rootPath())) self.windowDirectory.setModel(self.modelWindowDirectory) self.windowDirectory.setSortingEnabled(True) self.windowDirectory.setColumnWidth(0, 270) #windowSelected self.modelWindowSelected = QtGui.QStandardItemModel() self.windowSelected.setModel(self.modelWindowSelected) self.windowSelected.clicked[QtCore.QModelIndex].connect( self.clicked_windowSelected) #windowFoundPrimary self.modelWindowFoundPrimary = QtGui.QStandardItemModel() self.modelWindowFoundPrimary.setColumnCount(1) self.windowFoundPrimary.setModel(self.modelWindowFoundPrimary) self.windowFoundPrimary.clicked[QtCore.QModelIndex].connect( self.clicked_windowFoundPrimary) self.selModWindowFoundPrimary = self.windowFoundPrimary.selectionModel( ) self.selModWindowFoundPrimary.currentChanged.connect( self.primaryChanged) self.resized.connect(self.resize_event) #windowFoundDuplicates self.modelWindowFoundDuplicates = QtGui.QStandardItemModel() self.windowFoundDuplicates.setModel(self.modelWindowFoundDuplicates) self.windowFoundDuplicates.clicked[QtCore.QModelIndex].connect( self.clicked_windowFoundDuplicates) self.selModWindowFoundDuplicates = self.windowFoundDuplicates.selectionModel( )
def klik(self): self.model = QtWidgets.QFileSystemModel() self.model.setNameFilters(("*.py", "*.txt")) self.model.setNameFilterDisables(0) self.model.setRootPath("/home/jani") self.treeView.setModel(self.model) self.treeView.setRootIndex(self.model.index("/home/jani"))
def __init__(self, parent, double_click_func, create_file_func, create_dir_func, delete_file_func, delete_dir_func): super().__init__(parent) # Signal Functions self.double_click_func = double_click_func self.create_file_func = create_file_func self.create_dir_func = create_dir_func self.delete_file_func = delete_file_func self.delete_dir_func = delete_dir_func # Directory view self.model = QtWidgets.QFileSystemModel() self.model.setRootPath(QtCore.QDir.rootPath()) self.model.setReadOnly(False) self.setSortingEnabled(True) self.setDragEnabled(True) self.setDropIndicatorShown(True) self.setDragDropMode(QtWidgets.QAbstractItemView.InternalMove) self.viewport().setAcceptDrops( True) # Enables dragging within the scrollable area self.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows) self.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self.setEditTriggers(QtWidgets.QTreeView.NoEditTriggers) self.setModel(self.model) self.header().setSectionResizeMode(0, QtWidgets.QHeaderView.Stretch) # Create and use a custom icon provider to override tree icons self.model.setIconProvider(FileSystemIconProvider()) self.customContextMenuRequested.connect(self.CreateContextMenu) self.doubleClicked.connect(self.ItemDoubleClicked)
def __init__(self, **kwargs): """ Constructs an FileBrowser instance Keyword Args: parent: The parent widget mode: (int) The TreeView mode. Possible values: TREE_MODE, DIR_MODE navigate: (Boolean) If True, the user can navigate through the directories rootPath: (str) Initial root path selectedPath: (str) The selected path """ TreeModelView.__init__(self, **kwargs) self._mode = kwargs.get('mode', TreeModelView.TREE_MODE) self._navigate = True self._model = None self.setModel(kwargs.get('model', qtw.QFileSystemModel(self))) self.header().setSectionResizeMode(0, qtw.QHeaderView.ResizeToContents) rootPath = kwargs.get('rootPath', qtc.QDir.rootPath()) self._model.setRootPath(qtc.QDir.rootPath()) rootIndex = self._model.index(rootPath) self.setRootIndex(rootIndex) self.setCurrentIndex(rootIndex) self.selectPath(kwargs.get('selectedPath')) self._navigate = kwargs.get('navigate', True)
def __init__(self): super(MyApp, self).__init__() self.setupUi(self) self.pushButton.clicked.connect(self.browse_folder) self.model = QtWidgets.QFileSystemModel() fig = Figure() self.canvasPlot(fig)