Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. from PySide2 import QtCore, QtGui, QtWidgets
  2.  
  3. import os
  4.  
  5. file = 'template'
  6. path_dir = r'D:templates'
  7.  
  8. class Ui_Form(object):
  9.  
  10. def setupUi(self, Form):
  11. Form.setObjectName("Form")
  12. Form.resize(1266, 798)
  13. self.treeView = QtWidgets.QTreeView(Form)
  14. self.treeView.setGeometry(QtCore.QRect(40, 70, 611, 241))
  15. self.treeView.setObjectName("treeView")
  16. #-------------
  17. # ? self.treeView.QFileSystemModel.directoryLoaded('D:testqt')
  18. #-------------
  19. self.pushButton = QtWidgets.QPushButton(Form)
  20. self.pushButton.setGeometry(QtCore.QRect(670, 70, 131, 41))
  21. self.pushButton.setObjectName("pushButton")
  22. self.pushButton.clicked.connect(self.save_file)
  23.  
  24. self.label = QtWidgets.QLabel(Form)
  25. self.label.setGeometry(QtCore.QRect(40, 42, 541, 21))
  26. self.label.setObjectName("label")
  27.  
  28. self.retranslateUi(Form)
  29. QtCore.QMetaObject.connectSlotsByName(Form)
  30.  
  31. def retranslateUi(self, Form):
  32. Form.setWindowTitle(QtWidgets.QApplication.translate("Form", "Form", None, -1))
  33. self.pushButton.setText(QtWidgets.QApplication.translate("Form", "PushButton", None, -1))
  34. self.label.setText(QtWidgets.QApplication.translate("Form", "TextLabel", None, -1))
  35.  
  36. def save_file(self):
  37. print('File', file , 'saved in: ' , path_dir, '!')
  38.  
  39.  
  40. class Widget(QtWidgets.QWidget, Ui_Form):
  41. def __init__(self, parent=None):
  42. super(Widget, self).__init__(parent)
  43.  
  44. self.setupUi(self)
  45.  
  46. self.resize(1266, 798)
  47. layout = QtWidgets.QHBoxLayout(self)
  48. # layout.addWidget(self.label)
  49. # layout.addWidget(self.treeView)
  50. # layout.addWidget(self.pushButton)
  51. self.model = QtWidgets.QFileSystemModel()
  52. self.model.setFilter(QtCore.QDir.AllEntries | QtCore.QDir.Hidden | QtCore.QDir.NoDot)
  53. self.path = os.path.expanduser('D:') # <-- ('D:/test/qt')
  54. self.parentIndex = self.model.setRootPath(self.path)
  55. self.treeView.setModel(self.model)
  56. self.treeView.setRootIndex(self.model.index(self.path))
  57. self.model.directoryLoaded.connect(self._loaded)
  58.  
  59. self.dirictory = QtWidgets.QDirModel()
  60. self.dirictory.index(self.path)
  61. self.dirictory.filePath(self.dirictory.index(self.path))
  62. print(self.dirictory.filePath(self.dirictory.index(self.path)))
  63.  
  64.  
  65.  
  66. def _loaded(self, path):
  67. print('_loaded', self.path)
  68. print('++loaded', self.dirictory.filePath(self.dirictory.index(self.path)))
  69.  
  70.  
  71. if __name__ == "__main__":
  72. import sys
  73. app = QtWidgets.QApplication(sys.argv)
  74. # Form = QtWidgets.QWidget()
  75. # ui = Ui_Form()
  76. # ui.setupUi(Form)
  77. # Form.show()
  78. w = Widget()
  79. w.show()
  80. sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement