aboutsummaryrefslogtreecommitdiff
path: root/qolab/gui/web.py
diff options
context:
space:
mode:
Diffstat (limited to 'qolab/gui/web.py')
-rw-r--r--qolab/gui/web.py47
1 files changed, 42 insertions, 5 deletions
diff --git a/qolab/gui/web.py b/qolab/gui/web.py
index b6ac9d7..e03e0e1 100644
--- a/qolab/gui/web.py
+++ b/qolab/gui/web.py
@@ -23,18 +23,20 @@ class QOLPushButtonNoUndo(QOLPushButton):
self.set_classes('bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-4 rounded-full')
class QOLParamHeader(jp.Div):
- def __init__(self, label='NameNotSet', **kwargs):
+ def __init__(self, label='NameNotSet', value=None, **kwargs):
super().__init__(**kwargs)
root = self
root.label=label
root.set_classes(label_div_classes)
root.data[label]=None
jp.Span(text=f'{label}: ', classes=labelnames_classes, a=root)
+ self.setValue(value)
def getValue(self):
return self.data[self.label]
def setValue(self, val):
+ print(f'setting {self.label} to {val}')
self.data[self.label]=val
class QOLParamReadOnly(QOLParamHeader):
@@ -71,17 +73,44 @@ class QOLTimeLog(jp.Div):
super().__init__(**kwargs)
root = self
root.traces = None; # log must have 'plot' and 'clear_data' methods
+ root.getNextDataFile = None
root.set_classes(panel_div_classes)
dcontrols = jp.Div(a=root)
dcontrols.set_classes(controls_div_classes)
bclear = QOLPushButtonNoUndo(a=dcontrols, text='Clear log', click=self._clear_data)
breplot = QOLPushButton(a=dcontrols, text='Replot', click=self._replot)
- save_controls = QOLSaveControls(a=dcontrols)
+ self.save_controls = QOLSaveControls(a=dcontrols)
+ self.save_controls.save.on('click', self._save)
+ self.save_controls.next_file.on('click', self._next_file)
+
self.update_interval = QOLParamReadOnly(label='UpdateInterval',value=5,a=dcontrols)
self.autosave_interval = QOLParamReadOnly(label='AutoSaveInterval',value=10,a=dcontrols)
self.chart = jp.Matplotlib(a=root)
self.plot()
+
+ async def _next_file(self, msg):
+ print('asked for _next_file')
+ self.next_file()
+ await self.update()
+
+ def next_file(self):
+ if self.getNextDataFile is not None:
+ fname = self.getNextDataFile()
+ self.save_controls.file_name.setValue( fname )
+ async def _save(self, msg):
+ self.save()
+
+ def save(self):
+ print('asked to save')
+ fname = self.save_controls.file_name.getValue()
+ print(fname)
+ if fname is None:
+ return
+ if self.traces is None:
+ return
+ self.traces.save(fname)
+
async def _clear_data(self, msg):
self.clear_data()
await self.update()
@@ -96,12 +125,20 @@ class QOLTimeLog(jp.Div):
self.plot()
await self.update()
- async def update_loop(self, update_interval=4):
- update_interval=5
+ async def update_loop(self, update_interval=None):
+ if update_interval is not None:
+ self.update_interval.setValue(update_interval)
while True:
+ print(f'update interval {self.update_interval.getValue()}')
self.plot()
+ try:
+ strwtime = self.update_interval.getValue()
+ wtime = float(strwtime)
+ except ValueError:
+ wtime =2
+ print(f'Warning cannot convert {strwtime} setting to {wtime}')
await self.update()
- await asyncio.sleep(update_interval)
+ await asyncio.sleep(wtime)
def plot(self):
traces = self.traces