Использование PYQT5 для разделения окна на браузер файлов дерева и панель для отображения данных в текстовом файле, выбранном из браузера - PullRequest
0 голосов
/ 24 марта 2019

Так что мне нужно иметь одно окно с двумя панелями, в левом - браузер дерева папок и файлов на ПК, а в правом - график, на котором выбран файл .txt издерево браузер строится.Файлы .txt имеют формат двух столбцов, и мне нужно отобразить каждый столбец как временной ряд.Теперь у меня есть код, который разбивает окно и показывает древовидный браузер файлов и папок, но я не знаю, как встроить Matplotlib во вторую панель (которая в настоящее время также отображает древовидный браузер.

import sys

from PyQt5.QtWidgets import (QApplication, QColumnView, QFileSystemModel,
                     QSplitter, QTreeView, QPushButton)
from PyQt5.QtCore import QDir, Qt
from matplotlib.backends.backend_qt5agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
import numpy as np

if __name__ == '__main__':
    app = QApplication(sys.argv)
# Splitter to show 2 views in same widget easily.
    splitter = QSplitter()
# The model.
    model = QFileSystemModel()
# You can setRootPath to any path.
    model.setRootPath("/Users/mariamrakka/")
# List of views.
    views = []
    for ViewType in (QColumnView, QTreeView):
    # Create the view in the splitter.
        view = ViewType(splitter)
    # Set the model of the view.
        view.setModel(model)
    # Set the root index of the view as the user's home directory.
        view.setRootIndex(model.index(QDir.homePath()))
# Show the splitter.
    splitter.show()
# Maximize the splitter.
    splitter.setWindowState(Qt.WindowMaximized)
# Start the main loop.
    sys.exit(app.exec_())

##########I need to embed the below in the above code###############
#def MyUI(self):
#    
#    button= QPushButton("Plot",self)
#    button.move(100,450)
# 
#class Canvas(FigureCanvas):
#    def _init_(self,parent=None, width=5,height=5,dpi=100 ):
#        fig=Figure(figsize=(width,height),dpi=dpi)
#        self.axis=fig.add_subplot(111)
#        FigureCanvas.__init__(self,fig)
#        self.setParent(parent)
#    def plot(self):
#    f=open("p.txt")
#    lines = f.readlines()
#
#    x, y = [], []
#    for line in lines:
#        x.append(line.split()[0])
#        y.append(line.split()[1])
#    f.close()
#    x1=np.array(x)
#
#    import random
#    rand_items = [x[random.randrange(len(x))]
#              for item in range(50)]
#    plt.plot(rand_items)
#    rand_items2 = [y[random.randrange(len(y))]
#              for item in range(50)]
#    plt.plot(rand_items2)

#f=open("THE FILE I AM HIGHLIGHTING IN TREE BROWSE SEARCH")
#lines = f.readlines()
#
#x, y = [], []
#for line in lines:
#    x.append(line.split()[0])
#    y.append(line.split()[1])
#f.close()
#x1=np.array(x)
#
#import random
#rand_items = [x[random.randrange(len(x))]
#              for item in range(50)]
#plt.plot(rand_items)
#rand_items2 = [y[random.randrange(len(y))]
#              for item in range(50)]
#plt.plot(rand_items2)
...