Skip to content

Commit cea4eb4

Browse files
committed
WIP table work
1 parent c825d57 commit cea4eb4

File tree

2 files changed

+78
-3
lines changed

2 files changed

+78
-3
lines changed

bluesky_widgets/examples/ipy_qt_figures.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,25 @@
55
66
In [1]: %run -m bluesky_widgets.examples.ipy_qt_figures
77
"""
8+
import pandas as pd
9+
810
from bluesky import RunEngine
911
from bluesky.plans import scan
1012
from ophyd.sim import motor, det
1113

1214
from bluesky_widgets.utils.streaming import stream_documents_into_runs
15+
from bluesky_widgets.models.utils import call_or_eval
1316
from bluesky_widgets.models.auto_plot_builders import AutoLines
1417
from bluesky_widgets.qt.figures import QtFigures
1518
from bluesky_widgets.examples.utils.generate_msgpack_data import get_catalog
1619

20+
from bluesky.callbacks.core import LiveTable
21+
22+
import matplotlib.pyplot as plt
23+
24+
plt.plot(range(5))
25+
plt.close("all")
26+
1727
model = AutoLines(max_runs=3)
1828
view = QtFigures(model.figures)
1929
view.show()
@@ -32,4 +42,35 @@ def plan():
3242
yield from scan([det], motor, -1, 1, 1 + 2 * i)
3343

3444

35-
RE(plan())
45+
catch = []
46+
47+
48+
def test(run):
49+
catch.append(run)
50+
51+
def handle_stream(evt):
52+
catch.append(evt)
53+
if evt.name != "primary":
54+
return
55+
count = 0
56+
run = evt.run
57+
cols = {f"col{j}": k for j, k in enumerate(run.primary.read())}
58+
59+
def handle_data(evt):
60+
nonlocal count
61+
62+
catch.append(evt)
63+
d = call_or_eval(cols, run, ["primary"])
64+
df = pd.DataFrame({k: v[count:] for k, v in d.items()})
65+
# print(df)
66+
count += len(df)
67+
68+
run.events.new_data.connect(handle_data)
69+
lt = LiveTable(list(cols.values()))
70+
lt("start", run.metadata["start"])
71+
run.events.new_doc.connect(lambda event: lt(event.name, event.doc))
72+
73+
run.events.new_stream.connect(handle_stream)
74+
75+
76+
RE(plan(), stream_documents_into_runs(test))

bluesky_widgets/models/plot_specs.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import uuid as uuid_module
1111

1212
from bluesky_live.event import EmitterGroup, Event
13-
from ..utils.list import EventedList
13+
from bluesky_live.list import ListModel as EventedList
1414
from ..utils.dict_view import UpdateOnlyDict, DictView
1515

1616

@@ -66,7 +66,41 @@ def __repr__(self):
6666

6767

6868
class TableContainer(Container):
69-
...
69+
__slots__ = ("_tables",)
70+
71+
72+
class Table(BaseSpec):
73+
__slots__ = (
74+
"_live",
75+
"_label",
76+
"_parent",
77+
"_fields"
78+
)
79+
80+
def __init__(self, *, label, fields, live=True, uuid=None, parent=None):
81+
self._label = label
82+
self._live = live
83+
self._fields = tuple(fields)
84+
self.events = EmitterGroup(
85+
source=self,
86+
label=Event,
87+
new_data=Event,
88+
completed=Event,
89+
style_updated=Event,
90+
)
91+
92+
@property
93+
def label(self):
94+
return self._label
95+
96+
@label.setter
97+
def label(self, value):
98+
self._label = value
99+
self.events.label(value=value)
100+
101+
@property
102+
def fields(self, value):
103+
return self._fields
70104

71105

72106
class Figure(Container):

0 commit comments

Comments
 (0)