82 lines
2.1 KiB
Python
82 lines
2.1 KiB
Python
from PyQt5.QtCore import Qt, pyqtSignal
|
|
from PyQt5.QtWidgets import QMainWindow, QSplitter
|
|
|
|
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, PlotDescription)
|
|
|
|
def __init__(self, *args, title="grum", **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
self.setWindowTitle(title)
|
|
self.setWindowIcon(assets.icon())
|
|
|
|
self.lst = lst = DictList(exampledata, factory=PlotDescription)
|
|
lst.setAlternatingRowColors(True)
|
|
lst.doubleClicked.connect(self.on_select_list_item)
|
|
self.setCentralWidget(lst)
|
|
|
|
bar = self.menuBar()
|
|
self.mdi = mdi = MDIArea(bar)
|
|
|
|
splitter = QSplitter(Qt.Horizontal)
|
|
splitter.addWidget(lst)
|
|
splitter.addWidget(mdi)
|
|
splitter.setSizes([100, 1000])
|
|
|
|
self.setCentralWidget(splitter)
|
|
|
|
rst = RPCServerThread("localhost", 8000)
|
|
rst.start()
|
|
rst.server.register_function(self.append)
|
|
|
|
self.sig_make_new_plot.connect(self.make_new_plot)
|
|
|
|
|
|
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)
|
|
|
|
if show_it:
|
|
lst.add(name, pd)
|
|
|
|
lst.append(name, (x, y))
|
|
for sub in self.mdi.subWindowList():
|
|
if sub.windowTitle() == name:
|
|
pd = lst.data[name]
|
|
sub.plot.setData(pd.xs, pd.ys)
|
|
|
|
if show_it:
|
|
ps = lst.data[name]
|
|
self.sig_make_new_plot.emit(name, pd)
|
|
|
|
|
|
def on_select_list_item(self, index):
|
|
key, value = self.lst.get(index)
|
|
|
|
for sub in self.mdi.subWindowList():
|
|
if sub.windowTitle() == key:
|
|
self.mdi.setActiveSubWindow(sub)
|
|
return
|
|
|
|
self.make_new_plot(key, value)
|
|
|
|
|
|
def make_new_plot(self, key, value):
|
|
sub = MDISubPlot(key, value)
|
|
self.mdi.addSubWindow(sub)
|
|
sub.show()
|
|
|
|
|
|
|