diff options
author | Eugeniy E. Mikhailov <evgmik@gmail.com> | 2021-06-13 12:54:14 -0400 |
---|---|---|
committer | Eugeniy E. Mikhailov <evgmik@gmail.com> | 2021-06-13 12:54:14 -0400 |
commit | 678c891c359716550d054a9d033084fa19693592 (patch) | |
tree | b3aa8745b433bd0d9b00df037db8eb1520c98c04 /eitControl.py | |
parent | 96a8cca1483e636da438b7496dc5db8f355028a7 (diff) | |
download | pyExpControl-678c891c359716550d054a9d033084fa19693592.tar.gz pyExpControl-678c891c359716550d054a9d033084fa19693592.zip |
draft of transition to pyqtgraph
Diffstat (limited to 'eitControl.py')
-rw-r--r-- | eitControl.py | 119 |
1 files changed, 55 insertions, 64 deletions
diff --git a/eitControl.py b/eitControl.py index 8785144..1f69944 100644 --- a/eitControl.py +++ b/eitControl.py @@ -1,6 +1,7 @@ -import tkinter as tk -from tkinter import * -from tkinter import ttk +from pyqtgraph.Qt import QtGui, QtCore +import pyqtgraph as pg +from pyqtgraph.dockarea import * + import platform import argparse @@ -33,8 +34,9 @@ class Experiment: self.channelsNames2plot={'adc0'} self.xChannelName='rfFreq' # can be also 'tic' or any of above self.xlabel='' - self.lines2plot={} + self.channelGraph={} self.clearData() + self.color = 1 self.guiSetup(root) self.guiSweeper = Sweeper(self.root, Npoints=2, SweepTime=1, onTicCallbacks=[self.updatePlot]) self.guiSweeper.cmdStart() @@ -65,50 +67,36 @@ class Experiment: self.hardware['rfGen'] = rf def guiSetup(self, root): - self.cntrlPannel=ttk.LabelFrame(root, text='controls') - self.cntrlPannel.pack() - - self.bAutoZoom=Button(self.cntrlPannel,text="AutoZoom",command=self.autoZoom,font=('Arial','24')) - self.bAutoZoom.pack(side='left') - - self.bRestart=Button(self.cntrlPannel,text="RESTART",command=self.restart,font=('Arial','24')) - self.bRestart.pack(side='left') - - self.bStart=Button(self.cntrlPannel,text="START",command=self.start,font=('Arial','24')) - self.bStart.pack(side='left') - - self.bStop=Button(self.cntrlPannel,text="STOP",command=self.stop,font=('Arial','24')) - self.bStop.pack(side='left') - - self.bSave=Button(self.cntrlPannel,text="SAVE",command=self.saveCmd,font=('Arial','24')) - self.bSave.pack(side='left') - - self.bExit=Button(self.cntrlPannel,text="EXIT",command=exit,font=('Arial','24')) - self.bExit.pack(side='left') - - self.dataDisplay=ttk.LabelFrame(root, text='data') - self.dataDisplay.pack() - - self.fig=plt.figure(figsize=[32, 24]) - - self.ax = self.fig.add_subplot(1,1,1) - # self.ax.set_xlim([0,20]) - # self.ax.set_ylim([0,20]) - # self.ax.plot([i for i in range(10)],[i for i in range(10)]) - self.line, = self.ax.plot(self.data['tic'], self.data['adc1'], '.') - - self.canvas = FigureCanvasTkAgg(self.fig, master = self.dataDisplay) - self.canvas.draw() - - # placing the canvas on the Tkinter window - # self.canvas.get_tk_widget().pack() - - # creating the Matplotlib toolbar - self.toolbar = NavigationToolbar2Tk(self.canvas, self.dataDisplay) - self.toolbar.update() - - # placing the toolbar on the Tkinter window - self.canvas.get_tk_widget().pack() + area = DockArea() + d1 = Dock("Controls", size=(5,1)) + d2 = Dock("Data", size=(100,100)) + area.addDock(d1, 'top') + area.addDock(d2, 'bottom', d1) + self.root.addWidget(area) + + self.dataPlot = pg.PlotWidget(name='Plot1') + d2.addWidget(self.dataPlot) + + w1 = pg.LayoutWidget() + bAutoZoom = QtGui.QPushButton('AutoZoom') + bAutoZoom.clicked.connect(self.autoZoom) + bRestart = QtGui.QPushButton('Restart') + bRestart.clicked.connect(self.restart) + bStart = QtGui.QPushButton('Start') + bStart.clicked.connect(self.start) + bStop = QtGui.QPushButton('Stop') + bStop.clicked.connect(self.stop) + bSave = QtGui.QPushButton('Save data') + bSave.clicked.connect(self.saveCmd) + bExit = QtGui.QPushButton('Exit') + bExit.clicked.connect(exit) + w1.addWidget(bAutoZoom, row=0, col=0) + w1.addWidget(bRestart, row=0, col=1) + w1.addWidget(bStart, row=0, col=2) + w1.addWidget(bStop, row=0, col=3) + w1.addWidget(bSave, row=0, col=4) + w1.addWidget(bExit, row=0, col=5) + d1.addWidget(w1) def clearData(self): self.data = {} @@ -205,29 +193,24 @@ class Experiment: if name not in self.data: continue y = self.data[name] - self.lines2plot[name], = self.ax.plot(x, y, '.', label=name) + # self.lines2plot[name], = self.ax.plot(x, y, '.', label=name) self.ax.legend() plt.xlabel(self.xlabel) self.canvas.draw() def updatePlot(self,swp=None): + self.color += 1 start = datetime.now() - # self.ax.cla() - # self.line, = self.ax.plot(self.data['tic'], self.data['adc1'], '.') - # t = Thread(target=self.canvas.draw) - # self.line.set_data([.1, .2, .3], [.1, .2, .3]) x = self.data['x'] for name in self.channelsNames2plot: if name not in self.data: continue y = self.data[name] - if name in self.lines2plot: - ln = self.lines2plot[name] - ln.set_data(x, y) - self.ax.draw_artist(ln) - # self.canvas.update() - self.canvas.draw() - self.fig.canvas.flush_events() + if name not in self.channelGraph: + color = (255,0,0) + self.channelGraph[name]=self.dataPlot.plot(x,y, pen=None, symbol='o', symbolPen=None, symbolBrush=color, symbolSize=5) + else: + self.channelGraph[name].setData(x,y) stop = datetime.now() runTime = (stop-start).seconds + float((stop-start).microseconds)/1000000 print("Replot took %s seconds to plot %s points." % (runTime, len(self.data['adc1'])) ) @@ -239,10 +222,18 @@ if __name__ == '__main__': help='test mode, use fake/dummy hardware') args = parser.parse_args() - root=Tk() - root.geometry("800x600") + app = QtGui.QApplication([]) + mw = QtGui.QMainWindow() + mw.setWindowTitle('pyqtgraph example: PlotWidget') + mw.resize(800,800) + cw = QtGui.QWidget() + mw.setCentralWidget(cw) + l = QtGui.QVBoxLayout() + cw.setLayout(l) + + mw.show() - experiment=Experiment(root, args) + experiment=Experiment(l, args) + app.exec() - root.mainloop() |