Skip to content

Instantly share code, notes, and snippets.

@altendky
Created April 19, 2018 18:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save altendky/67326961ff26c95148d2c2340a2d2c0e to your computer and use it in GitHub Desktop.
Save altendky/67326961ff26c95148d2c2340a2d2c0e to your computer and use it in GitHub Desktop.
import sys
import os
from PyQt5.Qt import * # noqa
def main():
class Foo(QMainWindow):
def __init__(self):
super().__init__()
self.model_files = QFileSystemModel(self)
self.model_files.setFilter(QDir.Files)
self.file_view = QTableView()
self.file_view.setModel(self.model_files)
self.setCentralWidget(self.file_view)
self.timer = QTimer.singleShot(2000, lambda: self.first(os.getcwd()))
self.timer = QTimer.singleShot(4000, lambda: self.first(os.path.join(os.getcwd(), '..')))
def first(self, path):
basedir = os.path.dirname(path) if os.path.isfile(path) else path
index = self.model_files.setRootPath(str(basedir))
self.file_view.setRootIndex(index)
app = QApplication(sys.argv)
foo = Foo()
foo.setMinimumSize(1024, 480)
foo.show()
sys.exit(app.exec_())
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment