use PlotDescription

This commit is contained in:
2022-12-19 11:32:31 +01:00
parent fdea41fad4
commit e930e35c6f
3 changed files with 24 additions and 16 deletions

View File

@ -1,17 +1,22 @@
import numpy as np import numpy as np
from plotdesc import PlotDescription
X = np.arange(100) / 10 X = np.arange(100) / 10
exampledata = { exampledata_raw = {
"sine": [X, np.sin(X)], "sine": [X, np.sin(X)],
"cosine": [X, np.cos(X)], "cosine": [X, np.cos(X)],
"exp": [X, np.exp(X)], "exp": [X, np.exp(X)],
"log": [X, np.log(X+1)] "log": [X, np.log(X+1)]
} }
# due to the appending of xy pairs, data needs to be transposed
exampledata = {k: zip(*v) for k, v in exampledata.items()} exampledata = {}
for k, v in exampledata_raw.items():
pd = PlotDescription(title=k, xlabel="x", ylabel="y")
pd.xs, pd.ys = v
exampledata[k] = pd

View File

@ -5,19 +5,20 @@ import assets
from dictlist import DictList from dictlist import DictList
from mdi import MDIArea, MDISubPlot from mdi import MDIArea, MDISubPlot
from rpcserverthread import RPCServerThread from rpcserverthread import RPCServerThread
from plotdesc import PlotDescription
from exampledata import exampledata from exampledata import exampledata
class MainWindow(QMainWindow): class MainWindow(QMainWindow):
sig_make_new_plot = pyqtSignal(str, list) sig_make_new_plot = pyqtSignal(str, PlotDescription)
def __init__(self, *args, title="grum", **kwargs): def __init__(self, *args, title="grum", **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.setWindowTitle(title) self.setWindowTitle(title)
self.setWindowIcon(assets.icon()) self.setWindowIcon(assets.icon())
self.lst = lst = DictList(exampledata) self.lst = lst = DictList(exampledata, factory=PlotDescription)
lst.setAlternatingRowColors(True) lst.setAlternatingRowColors(True)
lst.doubleClicked.connect(self.on_select_list_item) lst.doubleClicked.connect(self.on_select_list_item)
self.setCentralWidget(lst) self.setCentralWidget(lst)
@ -40,19 +41,24 @@ class MainWindow(QMainWindow):
def append(self, name, xy): def append(self, name, xy):
pd = PlotDescription(title=name)
x, y, pd.xlabel, pd.ylabel = xy
lst = self.lst lst = self.lst
show_it = (name not in lst.data) show_it = (name not in lst.data)
lst.append(name, xy) if show_it:
lst.add(name, pd)
lst.append(name, (x, y))
for sub in self.mdi.subWindowList(): for sub in self.mdi.subWindowList():
if sub.windowTitle() == name: if sub.windowTitle() == name:
data = lst.data[name] pd = lst.data[name]
data = list(zip(*data)) sub.plot.setData(pd.xs, pd.ys)
sub.plot.setData(*data)
if show_it: if show_it:
data = lst.data[name] ps = lst.data[name]
self.sig_make_new_plot.emit(name, data) self.sig_make_new_plot.emit(name, pd)
def on_select_list_item(self, index): def on_select_list_item(self, index):

7
mdi.py
View File

@ -65,7 +65,7 @@ class MDIArea(QMdiArea):
class MDISubPlot(QMdiSubWindow): class MDISubPlot(QMdiSubWindow):
def __init__(self, title, data, *args, **kwargs): def __init__(self, title, desc, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.setWindowTitle(title) self.setWindowTitle(title)
self.setWindowIcon(assets.char()) self.setWindowIcon(assets.char())
@ -73,11 +73,8 @@ class MDISubPlot(QMdiSubWindow):
# without this, the SubWindow is not removed from the subWindowList # without this, the SubWindow is not removed from the subWindowList
self.setAttribute(Qt.WA_DeleteOnClose) self.setAttribute(Qt.WA_DeleteOnClose)
data = zip(*data)
style = pg_plot_style()
plt = pg.PlotWidget() plt = pg.PlotWidget()
self.plot = plt.plot(*data, **style) self.plot = desc.make_plot(plt)
self.setWidget(plt) self.setWidget(plt)