from PyQt4.uic import loadUiType
from PyQt4.Qt import*
from pyqtgraph.Qt import QtGui, QtCore
import numpy as np
import pyqtgraph as pg
Ui_MainWindow, QMainWindow = loadUiType('window.ui')
class Main(QMainWindow, Ui_MainWindow):
def __init__(self):
super(Main, self).__init__()
self.setupUi(self)
self.fig_dict = {}
self.plot_dict = {}
print self.fig_dict.values()
pw = pg.PlotWidget(name='Plot')
self.mplVl.addWidget(pw)
xd = np.arange(10)
yd = np.arange(10)
p1 = pw.plot()
p1.setData(y=yd, x=xd)
p1.setPen((200,200,100))
self.mplFigs.itemClicked.connect(self.clicked_fig)
self.mplFigs.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)
'''
x1 = np.arange(10),
y1 = np.sin(x1)
plot = pw.plot()
plot.setData(x=x1, y=y1)
plot.setPen((200,200,100))
pw.addItem(plot)'''
openFile = QtGui.QAction('&Open File', self)
openFile.setShortcut('Ctrl+O')
openFile.setStatusTip('Open File')
openFile.triggered.connect(self.open_file)
mainMenu = self.menuBar()
fileMenu = mainMenu.addMenu('&File')
fileMenu.addAction(openFile)
def open_file(self):
self.open = QtGui.QFileDialog.getOpenFileNames(self, 'Select the files of one type of measurement')
n=1
b=0
fig=0
for path in self.open:
file = open(path, 'r')
text = np.genfromtxt(file)
x = text[:,0]
a = text[:,1]
b = b + a
y = b / n
n=n+1
fig = np.column_stack((x, y))
# print fig
# fig1 = Figure()
# ax1f1 = fig1.add_subplot(111)
# ax1f1.plot(x, y)
self.add_fig(raw_input('name: '), fig)
def clicked_fig(self):
return True
def change_fig(self, item):
text = item.text()
self.rm_mpl()
self.add_mpl(self.fig_dict[text])
def add_fig(self, name, fig):
self.fig_dict[name] = fig
self.mplFigs.addItem(name)
def add_mpl(self, fig):
self.canvas = FigureCanvas(fig)
self.mplVl.addWidget(self.canvas)
self.canvas.draw()
self.toolbar = NavigationToolbar(self.canvas,
self.mplWindow,
coordinates=True)
self.mplVl.addWidget(self.toolbar)
def rm_mpl(self):
self.mplVl.removeWidget(self.canvas)
self.canvas.close()
self.mplVl.removeWidget(self.toolbar)
self.toolbar.close()
if __name__ == '__main__':
import sys
from PyQt4 import QtGui
app = QtGui.QApplication(sys.argv)
main = Main()
main.show()
sys.exit(app.exec_())