def __init__(self, parent, main_data, shid): xrcprogress_dialog.__init__(self, parent) # ProgressiveFuture for the ongoing calibration self._main_data = main_data self._shid = shid self.calib_future = None self._calib_future_connector = None self._started = False self.cancel_btn.Bind(wx.EVT_BUTTON, self.on_cancel) self.Bind(wx.EVT_CLOSE, self.on_close) self.info_txt.SetLabel("Calibration of the sample holder in progress") self.calib_future = DelphiCalibration(main_data) self._calib_future_connector = ProgressiveFutureConnector( self.calib_future, self.gauge, self.time_txt) self.calib_future.add_done_callback(self.on_calib_done) self.Fit()
def __init__(self, parent, main_data, shid): xrcprogress_dialog.__init__(self, parent) # ProgressiveFuture for the ongoing calibration self._main_data = main_data self._shid = shid self.calib_future = None self._calib_future_connector = None self._started = False self.cancel_btn.Bind(wx.EVT_BUTTON, self.on_cancel) self.Bind(wx.EVT_CLOSE, self.on_close) self.info_txt.SetLabel("Calibration of the sample holder in progress") self.calib_future = DelphiCalibration(main_data) self._calib_future_connector = ProgressiveFutureConnector(self.calib_future, self.gauge, self.time_txt) self.calib_future.add_done_callback(self.on_calib_done) self.Fit()
class CalibrationProgressDialog(xrcprogress_dialog): """ Wrapper class responsible for the connection between delphi calibration future and the xrcprogress_dialog. """ def __init__(self, parent, main_data, shid): xrcprogress_dialog.__init__(self, parent) # ProgressiveFuture for the ongoing calibration self._main_data = main_data self._shid = shid self.calib_future = None self._calib_future_connector = None self._started = False self.cancel_btn.Bind(wx.EVT_BUTTON, self.on_cancel) self.Bind(wx.EVT_CLOSE, self.on_close) self.info_txt.SetLabel("Calibration of the sample holder in progress") self.calib_future = DelphiCalibration(main_data) self._calib_future_connector = ProgressiveFutureConnector(self.calib_future, self.gauge, self.time_txt) self.calib_future.add_done_callback(self.on_calib_done) self.Fit() def Fit(self): # On a wxFrame, it typically does nothing => adjust to panel child = self.Children[0] child.Layout() child.Fit() self.ClientSize = child.BestSize def on_close(self, evt): """ Close event handler that executes various cleanup actions """ if self.calib_future: msg = "Cancelling calibration due to closing the calibration window" logging.info(msg) self.calib_future.cancel() self.Destroy() def on_cancel(self, evt): """ Handle calibration cancel button click """ if not self.calib_future: logging.warning("Tried to cancel calibration while it was not started") return logging.debug("Cancel button clicked, stopping calibration") self.calib_future.cancel() # all the rest will be handled by on_acquisition_done() def on_run_manual(self, evt): """ Handle the "Run" manual calibration button """ ManualCalibration() self.Destroy() @call_in_wx_main def on_calib_done(self, future): """ Callback called when the calibration is finished (either successfully or cancelled) """ # bind button back to direct closure self.info_txt.SetLabel("Calibration of the sample holder ended") self.cancel_btn.Bind(wx.EVT_BUTTON, self.on_close) # Eject the sample holder self._main_data.chamberState.value = model.CHAMBER_VENTING try: shcalib = future.result(1) # timeout is just for safety except CancelledError: # hide progress bar (+ put pack estimated time) self.time_txt.SetLabel("Calibration cancelled.") self.cancel_btn.SetLabel("Close") self.gauge.Hide() self.Fit() return except Exception as e: # Suggest to the user to run the semi-manual calibration self.calib_future.cancel() self.time_txt.SetLabel("Automatic calibration failed:\n" "%s\n\n" "Please follow the manual calibration procedure. \n" "Press Run to start." % (e,)) self.cancel_btn.SetLabel("Run") self.cancel_btn.Bind(wx.EVT_BUTTON, self.on_run_manual) self.Fit() return # Update the calibration file calibconf = get_calib_conf() calibconf.set_sh_calib(self._shid, *shcalib) # self.update_calibration_time(0) self.time_txt.SetLabel("Calibration completed.") # As the action is complete, rename "Cancel" to "Close" self.cancel_btn.SetLabel("Close")