use PlotDescription
This commit is contained in:
@ -1,17 +1,22 @@
|
||||
import numpy as np
|
||||
from plotdesc import PlotDescription
|
||||
|
||||
|
||||
X = np.arange(100) / 10
|
||||
|
||||
exampledata = {
|
||||
exampledata_raw = {
|
||||
"sine": [X, np.sin(X)],
|
||||
"cosine": [X, np.cos(X)],
|
||||
"exp": [X, np.exp(X)],
|
||||
"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
|
||||
|
||||
|
||||
|
||||
|
22
mainwin.py
22
mainwin.py
@ -5,19 +5,20 @@ import assets
|
||||
from dictlist import DictList
|
||||
from mdi import MDIArea, MDISubPlot
|
||||
from rpcserverthread import RPCServerThread
|
||||
from plotdesc import PlotDescription
|
||||
from exampledata import exampledata
|
||||
|
||||
|
||||
class MainWindow(QMainWindow):
|
||||
|
||||
sig_make_new_plot = pyqtSignal(str, list)
|
||||
sig_make_new_plot = pyqtSignal(str, PlotDescription)
|
||||
|
||||
def __init__(self, *args, title="grum", **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.setWindowTitle(title)
|
||||
self.setWindowIcon(assets.icon())
|
||||
|
||||
self.lst = lst = DictList(exampledata)
|
||||
self.lst = lst = DictList(exampledata, factory=PlotDescription)
|
||||
lst.setAlternatingRowColors(True)
|
||||
lst.doubleClicked.connect(self.on_select_list_item)
|
||||
self.setCentralWidget(lst)
|
||||
@ -40,19 +41,24 @@ class MainWindow(QMainWindow):
|
||||
|
||||
|
||||
def append(self, name, xy):
|
||||
pd = PlotDescription(title=name)
|
||||
x, y, pd.xlabel, pd.ylabel = xy
|
||||
|
||||
lst = self.lst
|
||||
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():
|
||||
if sub.windowTitle() == name:
|
||||
data = lst.data[name]
|
||||
data = list(zip(*data))
|
||||
sub.plot.setData(*data)
|
||||
pd = lst.data[name]
|
||||
sub.plot.setData(pd.xs, pd.ys)
|
||||
|
||||
if show_it:
|
||||
data = lst.data[name]
|
||||
self.sig_make_new_plot.emit(name, data)
|
||||
ps = lst.data[name]
|
||||
self.sig_make_new_plot.emit(name, pd)
|
||||
|
||||
|
||||
def on_select_list_item(self, index):
|
||||
|
7
mdi.py
7
mdi.py
@ -65,7 +65,7 @@ class MDIArea(QMdiArea):
|
||||
|
||||
class MDISubPlot(QMdiSubWindow):
|
||||
|
||||
def __init__(self, title, data, *args, **kwargs):
|
||||
def __init__(self, title, desc, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.setWindowTitle(title)
|
||||
self.setWindowIcon(assets.char())
|
||||
@ -73,11 +73,8 @@ class MDISubPlot(QMdiSubWindow):
|
||||
# without this, the SubWindow is not removed from the subWindowList
|
||||
self.setAttribute(Qt.WA_DeleteOnClose)
|
||||
|
||||
data = zip(*data)
|
||||
style = pg_plot_style()
|
||||
|
||||
plt = pg.PlotWidget()
|
||||
self.plot = plt.plot(*data, **style)
|
||||
self.plot = desc.make_plot(plt)
|
||||
self.setWidget(plt)
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user