diff options
-rw-r--r-- | qolab/gui/web.py | 74 |
1 files changed, 32 insertions, 42 deletions
diff --git a/qolab/gui/web.py b/qolab/gui/web.py index 79a2d3a..e45af3c 100644 --- a/qolab/gui/web.py +++ b/qolab/gui/web.py @@ -73,52 +73,27 @@ 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) - 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.save_controls = QOLSaveControls(component_with_data=self.traces, a=dcontrols) 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.start_task() + def setTraces(self,component_with_data=None): + self.traces = component_with_data + self.save_controls.component_with_data=component_with_data + def start_task(self): jp.run_task( self.update_loop() ) def stop_tasks(self): pass - 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 ) - self.traces.clear_last_saved_pos() - - 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 - print(f'saving to {fname}') - self.traces.save(fname) - async def _clear_data(self, msg): self.clear_data() await self.update() @@ -159,27 +134,41 @@ class QOLTimeLog(jp.Div): class QOLSaveControls(jp.Div): - def __init__(self, **kwargs): + def __init__(self, component_with_data=None, **kwargs): super().__init__(**kwargs) root = self root.set_classes(controls_group_classes) - root.save=QOLPushButton(a=root, text='Save', name='Save', click=self._save) - root.next_file=QOLPushButton(a=root, text='Next file', name='NextFile', click=self._next_file) + root.component_with_data = component_with_data + root.getNextDataFile = None + root.bsave=QOLPushButton(a=root, text='Save', name='Save', click=self._save) + root.bnext_file=QOLPushButton(a=root, text='Next file', name='NextFile', click=self._next_file) self.autosave=QOLCheckbox(label='autosave', a=root ) + self.autosave_interval = QOLParamReadOnly(label='AutoSaveInterval', value=10, a=root) self.file_name=QOLParamReadOnly(label='FileName', a=root) - def _save(self, msg): - """ This is place holder: user should assign 'save' with a callback """ - print('Warning: `save` callback is not set') - pass + async def _save(self, msg): + self.save() - def _next_file(self, msg): - """ This is place holder: user should assign 'next_file' with a callback """ - print('Warning: `next_file` callback is not set') - pass + def save(self): + fname = self.file_name.getValue() + if fname is None: + return + if self.component_with_data is None: + return + print(f'saving to {fname}') + self.component_with_data.save(fname) - + async def _next_file(self, msg): + self.next_file() + await self.update() + + def next_file(self): + if self.getNextDataFile is not None: + fname = self.getNextDataFile() + self.file_name.setValue( fname ) + if self.component_with_data is not None: + self.component_with_data.clear_last_saved_pos() def gui_test(): return wp @@ -190,6 +179,7 @@ if __name__ == '__main__': rw.setValue(12345) log = QOLTimeLog(a=wp) + log.save_controls.getNextDataFile=lambda: "data.dat" def test(self, msg): print(rw.getValue()) |