Giter Site home page Giter Site logo

treeview's Introduction

treeView

This python script is generated by ChatGPT

I looked for a tool to display directories and files. I saw an example using PyQT5 and had some ideas, so I asked ChatGPT to generate the code ;-)

The idea is to have a tool to visualize a directory tree like the tree command in the command line. It shall be possible to display the directory tree with or without the files inside the tree. So you can make a printscreen to include it in your documentation.

treeView treeView with files

Download

Precompiled executable

SW-Requirements

The PyQt5 package has to be installed using:

pip install PyQt5

To create a standalone executable you can use pyinstaller

pip install pyinstaller

pyinstaller.exe --onefile --windowed .\treeView.py

Description of the code given by ChatGPT

  1. First, we import the necessary modules from PyQt5:
  2. Next, we define a class called DirTreeView that inherits from QWidget. This class represents the main window of the GUI and contains all the widgets and functionality.
  3. In the init method of the DirTreeView class, we create a QFileSystemModel object, which will be used to display the directory tree. We also create a boolean flag called filter_directories_only, which determines whether to show only directories or both directories and files in the tree view. By default, we set this flag to True, so that only directories are displayed.
  4. We create a QTreeView widget, which is used to display the directory tree. We also create a QLabel widget, which will be used to display the selected directory path. We create a QPushButton widget to allow the user to select a directory using a file dialog. We create a QCheckBox widget to allow the user to toggle between showing only directories or both directories and files in the tree view. Finally, we create two more QPushButton widgets to allow the user to expand or collapse all folders in the tree view.
  5. We create a horizontal layout to hold the expand/collapse buttons and the checkbox.
  6. We create a vertical layout to hold the label, select directory button, expand/collapse buttons and checkbox, and the tree view. We add all the widgets to this layout, and then set it as the main layout for the DirTreeView widget.
  7. We initialize the file system model and tree view to show all available drives. We set the size of the first column of the tree view to 450 pixels, and resize the widget to the desired size.
  8. We define a method called update_filter that updates the filter used by the file system model to show or hide files based on the checkbox state. If the checkbox is checked, we show both directories and files. If the checkbox is unchecked, we show only directories.
  9. We define a method called select_directory that shows a file dialog to allow the user to select a directory. If the user selects a directory, we update the file system model and tree view to show the selected directory path, and update the path label to display the selected directory path.
  10. Finally, we create an instance of the DirTreeView class and show it using the QApplication.exec_() method. This starts the event loop and shows the GUI to the user.

Author

Marco Graf

treeview's People

Contributors

grafmar avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.