def end(self): try: SweepController.end(self) except AssertionError: return # In case the sweep is too fast, ensure that the user has some time to see the dialog. span = time() - self.sweep_start_time if span < self.stall_time: sleep(self.stall_time - span) wx.CallAfter(self.timer.Stop) wx.CallAfter(self.Destroy)
def dwell(self): result = SweepController.dwell(self) # Prevent the GUI from locking up. sleep(0.005) return result
def __init__(self, parent, resources, variables, num_items, measurement_resources, measurement_variables, condition_resources, condition_variables, pulse_config, continuous=False, *args, **kwargs): kwargs['style'] = kwargs.get('style', wx.DEFAULT_DIALOG_STYLE) | wx.RESIZE_BORDER Dialog.__init__(self, parent, title='Sweeping...', *args, **kwargs) SweepController.__init__(self, resources, variables, num_items, measurement_resources, measurement_variables, condition_resources, condition_variables, pulse_config, continuous=continuous) self.parent = parent # Show only elapsed time in continuous mode. self.show_remaining_time = not self.continuous self.last_checked_time = -1 self.elapsed_time = 0 # us self.timer = wx.Timer(self) self.Bind(wx.EVT_TIMER, self.OnTimer, self.timer) self.cancelling = False def write_callback(pos, i, value): self.value_outputs[pos][i].Value = str(value)[:self.max_value_len] self.write_callback = partial(wx.CallAfter, write_callback) def read_callback(i, value): self.value_inputs[i].Value = str(value)[:self.max_value_len] self.read_callback = partial(wx.CallAfter, read_callback) self.general_exception_handler = partial(wx.CallAfter, self._general_exception_handler) self.resource_exception_handler = partial(wx.CallAfter, self._resource_exception_handler) # Dialog. dialog_box = wx.BoxSizer(wx.VERTICAL) ## Progress. progress_box = wx.BoxSizer(wx.HORIZONTAL) dialog_box.Add(progress_box, flag=wx.EXPAND|wx.ALL, border=5) ### Message. self.progress_percent = wx.StaticText(self, label='', size=(40, -1)) progress_box.Add(self.progress_percent, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT|wx.ALL, border=5) ### Bar. self.progress_bar = wx.Gauge(self, range=num_items, style=wx.GA_HORIZONTAL) progress_box.Add(self.progress_bar, proportion=1) ## Status. self.status_message_output = wx.TextCtrl(self, style=wx.TE_READONLY) self.status_message_output.BackgroundColour = wx.LIGHT_GREY dialog_box.Add(self.status_message_output, flag=wx.EXPAND) ## Values. self.values_box = wx.FlexGridSizer(rows=len(self.variables), cols=2, hgap=20) self.values_box.AddGrowableCol(1, 1) dialog_box.Add(self.values_box, flag=wx.EXPAND|wx.ALL, border=5) self.value_outputs = [] for group in self.variables: group_outputs = [] for var in group: output = wx.TextCtrl(self, style=wx.TE_READONLY) output.BackgroundColour = wx.LIGHT_GREY group_outputs.append(output) self.values_box.Add(wx.StaticText(self, label=var.name), flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT) self.values_box.Add(output, flag=wx.EXPAND) self.value_outputs.append(group_outputs) # Spacer. for _ in range(2): self.values_box.Add((-1, 15)) # Separator. for _ in range(2): self.values_box.Add(wx.StaticLine(self), flag=wx.EXPAND|wx.ALL, border=5) self.value_inputs = [] for var in self.measurement_variables: input = wx.TextCtrl(self, style=wx.TE_READONLY) input.BackgroundColour = wx.LIGHT_GREY self.value_inputs.append(input) self.values_box.Add(wx.StaticText(self, label=var.name), flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT) self.values_box.Add(input, flag=wx.EXPAND) ## Times. times_box = wx.FlexGridSizer(rows=2 if self.show_remaining_time else 1, cols=2, hgap=5) dialog_box.Add(times_box, proportion=1, flag=wx.CENTER|wx.ALL, border=15) ### Elapsed. times_box.Add(wx.StaticText(self, label='Elapsed time:')) self.elapsed_time_output = wx.StaticText(self, label='---:--:--') times_box.Add(self.elapsed_time_output) ### Remaining. if self.show_remaining_time: times_box.Add(wx.StaticText(self, label='Remaining time:')) self.remaining_time_output = wx.StaticText(self, label='---:--:--') times_box.Add(self.remaining_time_output) ## Last continuous. if self.continuous: self.last_continuous_input = wx.CheckBox(self, label='Last loop of continuous sweep') dialog_box.Add(self.last_continuous_input, flag=wx.CENTER) ## End button. button_box = wx.BoxSizer(wx.HORIZONTAL) dialog_box.Add(button_box, flag=wx.CENTER) self.cancel_button = wx.Button(self, label='Cancel') self.Bind(wx.EVT_BUTTON, self.OnCancel, self.cancel_button) button_box.Add(self.cancel_button) self.SetSizerAndFit(dialog_box) # Try to cancel cleanly instead of giving up. self.Bind(wx.EVT_CLOSE, self.OnCancel)
def __init__(self, parent, resources, variables, num_items, measurement_resources, measurement_variables, pulse_config, continuous=False, *args, **kwargs): kwargs['style'] = kwargs.get('style', wx.DEFAULT_DIALOG_STYLE) | wx.RESIZE_BORDER Dialog.__init__(self, parent, title='Sweeping...', *args, **kwargs) SweepController.__init__(self, resources, variables, num_items, measurement_resources, measurement_variables, pulse_config, continuous=continuous) self.parent = parent # Show only elapsed time in continuous mode. self.show_remaining_time = not self.continuous self.last_checked_time = -1 self.elapsed_time = 0 # us self.timer = wx.Timer(self) self.Bind(wx.EVT_TIMER, self.OnTimer, self.timer) self.cancelling = False def write_callback(pos, i, value): self.value_outputs[pos][i].Value = str(value)[:self.max_value_len] self.write_callback = partial(wx.CallAfter, write_callback) def read_callback(i, value): self.value_inputs[i].Value = str(value)[:self.max_value_len] self.read_callback = partial(wx.CallAfter, read_callback) self.general_exception_handler = partial(wx.CallAfter, self._general_exception_handler) self.resource_exception_handler = partial(wx.CallAfter, self._resource_exception_handler) # Dialog. dialog_box = wx.BoxSizer(wx.VERTICAL) ## Progress. progress_box = wx.BoxSizer(wx.HORIZONTAL) dialog_box.Add(progress_box, flag=wx.EXPAND|wx.ALL, border=5) ### Message. self.progress_percent = wx.StaticText(self, label='', size=(40, -1)) progress_box.Add(self.progress_percent, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT|wx.ALL, border=5) ### Bar. self.progress_bar = wx.Gauge(self, range=num_items, style=wx.GA_HORIZONTAL) progress_box.Add(self.progress_bar, proportion=1) ## Status. self.status_message_output = wx.TextCtrl(self, style=wx.TE_READONLY) self.status_message_output.BackgroundColour = wx.LIGHT_GREY dialog_box.Add(self.status_message_output, flag=wx.EXPAND) ## Values. self.values_box = wx.FlexGridSizer(rows=len(self.variables), cols=2, hgap=20) self.values_box.AddGrowableCol(1, 1) dialog_box.Add(self.values_box, flag=wx.EXPAND|wx.ALL, border=5) self.value_outputs = [] for group in self.variables: group_outputs = [] for var in group: output = wx.TextCtrl(self, style=wx.TE_READONLY) output.BackgroundColour = wx.LIGHT_GREY group_outputs.append(output) self.values_box.Add(wx.StaticText(self, label=var.name), flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT) self.values_box.Add(output, flag=wx.EXPAND) self.value_outputs.append(group_outputs) # Spacer. for _ in xrange(2): self.values_box.Add((-1, 15)) # Separator. for _ in xrange(2): self.values_box.Add(wx.StaticLine(self), flag=wx.EXPAND|wx.ALL, border=5) self.value_inputs = [] for var in self.measurement_variables: input = wx.TextCtrl(self, style=wx.TE_READONLY) input.BackgroundColour = wx.LIGHT_GREY self.value_inputs.append(input) self.values_box.Add(wx.StaticText(self, label=var.name), flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT) self.values_box.Add(input, flag=wx.EXPAND) ## Times. times_box = wx.FlexGridSizer(rows=2 if self.show_remaining_time else 1, cols=2, hgap=5) dialog_box.Add(times_box, proportion=1, flag=wx.CENTER|wx.ALL, border=15) ### Elapsed. times_box.Add(wx.StaticText(self, label='Elapsed time:')) self.elapsed_time_output = wx.StaticText(self, label='---:--:--') times_box.Add(self.elapsed_time_output) ### Remaining. if self.show_remaining_time: times_box.Add(wx.StaticText(self, label='Remaining time:')) self.remaining_time_output = wx.StaticText(self, label='---:--:--') times_box.Add(self.remaining_time_output) ## Last continuous. if self.continuous: self.last_continuous_input = wx.CheckBox(self, label='Last loop of continuous sweep') dialog_box.Add(self.last_continuous_input, flag=wx.CENTER) ## End button. button_box = wx.BoxSizer(wx.HORIZONTAL) dialog_box.Add(button_box, flag=wx.CENTER) self.cancel_button = wx.Button(self, label='Cancel') self.Bind(wx.EVT_BUTTON, self.OnCancel, self.cancel_button) button_box.Add(self.cancel_button) self.SetSizerAndFit(dialog_box) # Try to cancel cleanly instead of giving up. self.Bind(wx.EVT_CLOSE, self.OnCancel)