PyQT使用QTreeView显示FTP服务器的内容

时间:2017-10-22 14:02:40

标签: python-3.x ftp pyqt

我正在编写FTP客户端GUI。我希望它看起来像这样,所以我可以在文件夹中移动,并右键单击文件或文件夹并将其下载到本地机器:

enter image description here

我想我需要做这样的事情,但我不知道如何将从服务器获取的文件添加到树中。那么,任何建议在哪里寻找信息?

def _print_list(self):
    if self.thread and self.thread.is_alive():
        return
    files = self._ftp.nlst().split('\r\n') 
      # all the folders and files in current directory

    path = self._ftp.extract_path_from_pwd_reply()
      # current directory

    widget = QWidget(self)
    self.setCentralWidget(widget)

    model = QFileSystemModel()

    #and here I want to do something like:
    for file in files:
        model.add(file)
        if os.path.isdir(file):
            # change directory and run again?

    tree = QTreeView()
    tree.setModel(model)

    tree.setAnimated(False)
    tree.setIndentation(20)
    tree.setSortingEnabled(True)

    windowLayout = QVBoxLayout()
    windowLayout.addWidget(tree)
    widget.setLayout(windowLayout)

0 个答案:

没有答案