class SpinSetting(wxSetting): def __init__(self, name, default, min, max, label=None, help=None, group=None, increment=0.1): super(SpinSetting, self).__init__(name, default, label, help, group) self.min = min self.max = max self.increment = increment def get_specific_widget(self, parent): from wx.lib.agw.floatspin import FloatSpin self.widget = FloatSpin(parent, -1, min_val=self.min, max_val=self.max, digits=0) self.widget.SetValue(self.value) orig = self.widget.GetValue self.widget.GetValue = lambda: int(orig()) return self.widget
class singleFloat: def __init__(self, parent, parameter): self.parent = parent self.HorizontalOneParam = wx.BoxSizer(wx.HORIZONTAL) self.parameter = parameter paramName = self.parameter.getName() paramType = self.parameter.getType() paramUnit = self.parameter.getUnit() self.parNameLabel = wx.Button(parent.PNL_PARAM_EDIT, label=(paramName + '\n in ' + paramUnit)) self.parValueCtrl = FloatSpin(parent.PNL_PARAM_EDIT) # setup the limits and value for the float control [upperLimit, lowerLimit, allowedList] = self.parameter.getLimits() self.parValueCtrl.SetRange(lowerLimit, upperLimit) self.parValueCtrl.SetFormat(fmt='%e') self.parValueCtrl.SetDigits(digits=3) paramValue = self.parameter.getValue() if not paramValue == None: self.parValueCtrl.SetValue(paramValue) try: increment = (upperLimit - lowerLimit) / 10.0 except: increment = 1 self.parValueCtrl.SetIncrement(increment) # setup the limits and value for the float control if there is list of allowed values if not allowedList == None: self.parValueCtrl.Destroy() self.parValueCtrl = wx.Choice(parent.PNL_PARAM_EDIT) for value in allowedList: item = ('%8.3e' % value) self.parValueCtrl.Append(item) paramValue = self.parameter.getValue() paramValueItem = ('%8.3e' % paramValue) #print paramValueItem if not paramValue == None: idXDefault = self.parValueCtrl.FindString(paramValueItem) self.parValueCtrl.Select(idXDefault) else: self.parValueCtrl.Select(0) #self.parTypeLabel = wx.StaticText(parent.PNL_PARAM_EDIT, label=paramType[0]) #self.HorizontalOneParam.Add(self.parNameLabel, 0, wx.ALL, 5) self.HorizontalOneParam.Add( wx.StaticLine(parent.PNL_PARAM_EDIT, style=wx.LI_VERTICAL), 0, wx.ALL | wx.EXPAND, 5) self.HorizontalOneParam.Add(self.parValueCtrl, 1, wx.ALL | wx.EXPAND, 5) #self.HorizontalOneParam.Add(self.parTypeLabel,0, wx.ALL, 5) parent.paramVSizer.Add(self.parNameLabel, 0, wx.ALIGN_LEFT) parent.paramVSizer.Add(self.HorizontalOneParam, 0, wx.ALIGN_LEFT) # binding events parent.Bind(wx.EVT_BUTTON, self.OnDescribeBTN, source=self.parNameLabel) # decire if it is an choice or it is FloatSpin try: self.parValueCtrl.GetSelection() parent.Bind(wx.EVT_CHOICE, self.OnEditParam, source=self.parValueCtrl) except: self.parValueCtrl.Bind(EVT_FLOATSPIN, self.OnEditParam, source=self.parValueCtrl) return def OnEditParam(self, event): """ Update the given parameter according to control """ floatValue = 'No value found' try: value = event.GetString() floatValue = float(value) except: floatValue = self.parValueCtrl.GetValue() pass #print floatValue self.parameter.setValue(floatValue) acutalValue = self.parameter.getValue() try: self.parValueCtrl.SetValue(acutalValue) except: pass self.parent._update_description_box(( 'Parameter "%(name)s" updated to %(value)s (%(unit)s)' % \ {'name':self.parameter.getName(), 'value':str(acutalValue), 'unit':self.parameter.getUnit() })) return def OnDescribeBTN(self, event): """ Gives hint about the parameter """ parDescribe = self.parameter.getDescription() self.parent._update_description_box(parDescribe)
class RingSettingsPanel(wx.Panel): def __init__(self, *args, **kwds): # XXX Support several rings. Plot radial distribution somewhere # (not here), but maybe distribution along ring. Drop-down menu # for ring center, and button to reset to beam center. super(RingSettingsPanel, self).__init__(*args, **kwds) # Needed to draw and delete the rings. XXX Applies to # calibration_frame as well? self._pyslip = self.GetParent().GetParent().pyslip sizer = wx.BoxSizer(wx.VERTICAL) self.SetSizer(sizer) # Number of decimal digits for distances. self.digits = 2 # Distance control XXX probably does not belong here # print "DISTANCE",self.GetParent().GetParent().viewer._img # box = wx.BoxSizer(wx.HORIZONTAL) # from wxtbx.phil_controls.floatctrl import FloatCtrl # from wxtbx.phil_controls import EVT_PHIL_CONTROL # self.distance_ctrl = FloatCtrl(self, pos=(300,180), size=(80,-1), # value=80.00, # name="Detector Distance") # self.distance_ctrl.SetMax(1000) # self.distance_ctrl.SetMin(5) # self.distance_ctrl.SetOptional(False) # box.Add(self.distance_ctrl, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5) # txtd = wx.StaticText(self, label="Detector Distance") # box.Add(txtd, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5) # s.Add(box) from wx.lib.agw.floatspin import EVT_FLOATSPIN, FloatSpin # XXX Should really make value be in Aangstroem resolution, and # have a non-linear slider. self._radius = 100 self._center = [0, 0] radius_max = 2000 radius_min = 10 # Radius controls. box = wx.BoxSizer(wx.HORIZONTAL) self.slider = wx.Slider(self, maxValue=radius_max, minValue=radius_min, size=(250, -1), style=wx.SL_AUTOTICKS | wx.SL_HORIZONTAL, value=self._radius) box.Add(self.slider, 0, wx.RIGHT | wx.TOP | wx.BOTTOM | wx.ALIGN_CENTER_VERTICAL, 5) self.Bind(wx.EVT_SLIDER, self.OnSlide, self.slider) self.spinner = FloatSpin(self, digits=self.digits, max_val=radius_max, min_val=radius_min, value=self._radius) box.Add(self.spinner, 0, wx.RIGHT | wx.TOP | wx.BOTTOM | wx.ALIGN_CENTER_VERTICAL, 5) self.Bind(EVT_FLOATSPIN, self.OnSpin, self.spinner) self.auto = wx.Button(self, label="Auto fit") self.Bind(wx.EVT_BUTTON, self.OnAutoFit, self.auto) box.Add(self.auto, 0, wx.RIGHT | wx.TOP | wx.BOTTOM | wx.ALIGN_CENTER_VERTICAL, 5) sizer.Add(box) # Centering controls. box = wx.BoxSizer(wx.HORIZONTAL) self.spinner_fast = FloatSpin(self, digits=self.digits, name="fast_ctrl", value=self._center[0]) box.Add(self.spinner_fast, 0, wx.RIGHT | wx.TOP | wx.BOTTOM | wx.ALIGN_CENTER_VERTICAL, 5) box.Add(wx.StaticText(self, label="Center fast"), 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5) self.Bind(EVT_FLOATSPIN, self.OnSpinCenter, self.spinner_fast) self.spinner_slow = FloatSpin(self, digits=self.digits, name="slow_ctrl", value=self._center[1]) box.Add(self.spinner_slow, 0, wx.RIGHT | wx.TOP | wx.BOTTOM | wx.ALIGN_CENTER_VERTICAL, 5) box.Add(wx.StaticText(self, label="Center slow"), 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5) self.Bind(EVT_FLOATSPIN, self.OnSpinCenter, self.spinner_slow) sizer.Add(box) self.DrawRing() def __del__(self): if (hasattr(self, "_ring_layer") and self._ring_layer is not None): self._pyslip.DeleteLayer(self._ring_layer) def OnSlide(self, event): # Keep slider and spinner synchronized. obj = event.EventObject # XXX Is this construct sane? See below # and in calibration_frame, too! self._radius = obj.GetValue() self.spinner.SetValue(self._radius) self.DrawRing() def OnAutoFit(self, event): import math jitter = 6 detector = self._pyslip.tiles.raw_image.get_detector() beam = self._pyslip.tiles.raw_image.get_beam() # FIXME assumes all detector elements use the same millimeter-to-pixel convention if detector[0].get_distance() > 0: if len(detector) > 1: h = detector.hierarchy() if len(h) > 0: beam_pixel_fast, beam_pixel_slow = detector[ 0].millimeter_to_pixel( detector.hierarchy().get_beam_centre( beam.get_s0())) else: beam_pixel_fast, beam_pixel_slow = detector[ 0].millimeter_to_pixel(detector[0].get_beam_centre( beam.get_s0())) else: beam_pixel_fast, beam_pixel_slow = detector[ 0].millimeter_to_pixel(detector[0].get_beam_centre( beam.get_s0())) avg_distance = -sum([p.get_distance() for p in detector]) / len(detector) beam_pixel_fast += self._center[0] beam_pixel_slow += self._center[1] def PointsOnCircle(center, radius, count): for r in range(count): t = (r / count) * 2 * math.pi yield (center[0] + (radius * math.cos(t)), center[1] + (radius * math.sin(t))) best = float("-inf") bestc = [self._center[0], self._center[1]] bestr = self._radius raw_data = self._pyslip.tiles.raw_image.get_raw_data() if not isinstance(raw_data, tuple): raw_data = (raw_data, ) for j in range(-jitter, jitter, 1): j /= 2 for i in range(-jitter, jitter, 1): i /= 2 for r in range(-jitter, jitter, 1): r /= 2 total = 0.0 for point in PointsOnCircle( (beam_pixel_fast + i, beam_pixel_slow + j), self._radius + r, 360): mm = detector[0].pixel_to_millimeter(point) mm = (mm[0], mm[1], avg_distance) pid = detector.get_panel_intersection(mm) if pid >= 0: px = detector[pid].get_ray_intersection_px(mm) px = [int(round(px[0])), int(round(px[1]))] data = raw_data[pid] if px[0] >= 0 and px[0] < data.focus( )[1] and px[1] >= 0 and px[1] < data.focus()[0]: total += data[px[1], px[0]] if total > best: best = total bestc = [self._center[0] + i, self._center[1] + j] bestr = self._radius + r print("r: % 3.1f, i: % 3.1f, j: % 3.1f, best: %f" % (r, i, j, best)) print("DONE", bestc, bestr) self._radius = bestr self._center = bestc self.spinner.SetValue(bestr) self.spinner_fast.SetValue(bestc[0]) self.spinner_slow.SetValue(bestc[1]) self.DrawRing() def OnSpin(self, event): # Keep slider and spinner synchronized. XXX OnSpinRadius()? obj = event.EventObject self._radius = obj.GetValue() self.slider.SetValue(self._radius) self.DrawRing() def OnSpinCenter(self, event): obj = event.EventObject name = obj.GetName() if (name == "fast_ctrl"): self._center[0] = obj.GetValue() elif (name == "slow_ctrl"): self._center[1] = obj.GetValue() self.DrawRing() def _draw_ring_layer(self, dc, data, map_rel): """Draw a points layer. dc the device context to draw on data an iterable of point tuples: (x, y, place, radius, colour, x_off, y_off, pdata) map_rel points relative to map if True, MUST BE TRUE for lightweight Assumes all points are the same colour, saving 100's of ms. """ assert map_rel is True if len(data) == 0: return (lon, lat, place, radius, colour, x_off, y_off, pdata) = data[0] scale = 2**self._pyslip.tiles.zoom_level # Draw points on map/view, using transparency if implemented. try: dc = wx.GCDC(dc) except NotImplementedError: pass dc.SetPen(wx.Pen(colour)) dc.SetBrush(wx.Brush(colour, wx.TRANSPARENT)) for (lon, lat, place, radius, colour, x_off, y_off, pdata) in data: (x, y) = self._pyslip.ConvertGeo2View((lon, lat)) dc.DrawCircle(x, y, radius * scale) def DrawRing(self): detector = self._pyslip.tiles.raw_image.get_detector() beam = self._pyslip.tiles.raw_image.get_beam() xrayframe = self.GetParent().GetParent() panel_id, beam_pixel_fast, beam_pixel_slow = xrayframe.get_beam_center_px( ) if len(detector) > 1: beam_pixel_slow, beam_pixel_fast = xrayframe.pyslip.tiles.flex_image.tile_readout_to_picture( panel_id, beam_pixel_slow - 0.5, beam_pixel_fast - 0.5) center = self._pyslip.tiles.picture_fast_slow_to_map_relative( beam_pixel_fast + self._center[0], beam_pixel_slow + self._center[1]) # XXX Transparency? ring_data = [(center[0], center[1], { "colour": "red", "radius": self._radius })] # Remove the old ring layer, and draw a new one. XXX Why # disappears at highest levels? if (hasattr(self, "_ring_layer") and self._ring_layer is not None): self._pyslip.DeleteLayer(self._ring_layer) self._ring_layer = None self._ring_layer = self._pyslip.AddPointLayer( ring_data, map_rel=True, visible=True, show_levels=[-3, -2, -1, 0, 1, 2, 3, 4, 5], renderer=self._draw_ring_layer, name="<ring_layer>")
class VoltageSourceTunerDialog(Dialog): """ A dialog for tuning a voltage source port. """ def __init__(self, parent, global_store, ok_callback, port, *args, **kwargs): Dialog.__init__(self, parent, title='Port {0} tuning'.format(port.num)) self.global_store = global_store self.ok_callback = ok_callback self.port = port # Dialog. dialog_box = wx.BoxSizer(wx.VERTICAL) ## Self-calibration. calibration_static_box = wx.StaticBox(self, label='DAC self-calibration') calibration_box = wx.StaticBoxSizer(calibration_static_box, wx.VERTICAL) dialog_box.Add(calibration_box, flag=wx.EXPAND | wx.ALL, border=5) self.calibrate_button = wx.Button(self, label='Self-calibrate') self.Bind(wx.EVT_BUTTON, self.OnCalibrate, self.calibrate_button) calibration_box.Add(self.calibrate_button, flag=wx.EXPAND) ## Tuning. tuning_static_box = wx.StaticBox(self, label='Tuning') tuning_box = wx.StaticBoxSizer(tuning_static_box, wx.VERTICAL) dialog_box.Add(tuning_box, flag=wx.EXPAND) ### Autotune. autotuning_static_box = wx.StaticBox(self, label='Autotuning') autotuning_box = wx.StaticBoxSizer(autotuning_static_box, wx.VERTICAL) tuning_box.Add(autotuning_box, flag=wx.EXPAND | wx.ALL, border=5) autotuning_sizer = wx.FlexGridSizer(rows=3, cols=2, hgap=5) autotuning_box.Add(autotuning_sizer, flag=wx.CENTER) autotuning_sizer.Add(wx.StaticText(self, label='Resource name:'), flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT) self.resource_name_input = wx.TextCtrl(self, size=(300, -1)) autotuning_sizer.Add(self.resource_name_input) autotuning_sizer.Add(wx.StaticText(self, label='Max:'), flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT) self.automax_input = FloatSpin(self, value=1, min_val=-10, max_val=10, increment=1, digits=5) autotuning_sizer.Add(self.automax_input) autotuning_sizer.Add(wx.StaticText(self, label='Min:'), flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT) self.automin_input = FloatSpin(self, value=-1, min_val=-10, max_val=10, increment=1, digits=5) autotuning_sizer.Add(self.automin_input) self.autotune_button = wx.Button(self, label='Autotune') self.Bind(wx.EVT_BUTTON, self.OnAutotune, self.autotune_button) autotuning_box.Add(self.autotune_button, flag=wx.EXPAND) ### Manual tune. tuning_sizer = wx.FlexGridSizer(rows=2, cols=2, hgap=5) tuning_box.Add(tuning_sizer, flag=wx.CENTER) tuning_sizer.Add(wx.StaticText(self, label='Gain:'), flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT) self.gain_input = FloatSpin(self, value=0, min_val=-1e6, max_val=1e6, increment=1, digits=5) tuning_sizer.Add(self.gain_input) tuning_sizer.Add(wx.StaticText(self, label='Offset:'), flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT) self.offset_input = FloatSpin(self, value=0, min_val=-1e6, max_val=1e6, increment=1, digits=5) tuning_sizer.Add(self.offset_input) ## End buttons. button_box = wx.BoxSizer(wx.HORIZONTAL) dialog_box.Add(button_box, flag=wx.CENTER | wx.ALL, border=5) ok_button = wx.Button(self, wx.ID_OK) self.Bind(wx.EVT_BUTTON, self.OnOk, ok_button) button_box.Add(ok_button) cancel_button = wx.Button(self, wx.ID_CANCEL) button_box.Add(cancel_button) self.SetSizerAndFit(dialog_box) def autotune(self, resource): gain, offset = self.port.autotune( resource, set_result=False, min_value=self.automin_input.GetValue(), max_value=self.automax_input.GetValue()) wx.CallAfter(self.gain_input.SetValue, gain) wx.CallAfter(self.offset_input.SetValue, offset) wx.CallAfter(self.autotune_button.Enable) def self_calbrate(self): self.port.apply_settings(calibrate=True) sleep(self.port.calibration_delay) wx.CallAfter(self.calibrate_button.Enable) def SetValue(self, gain, offset): self.gain_input.SetValue(gain) self.offset_input.SetValue(offset) def GetValue(self): return (self.gain_input.GetValue(), self.offset_input.GetValue()) def OnAutotune(self, evt=None): name = self.resource_name_input.Value if not name: MessageDialog(self, 'No resource provided').Show() return try: resource = self.global_store.resources[name] except KeyError: MessageDialog(self, name, 'Missing resource').Show() return if not resource.readable: MessageDialog(self, name, 'Unreadable resource').Show() return self.autotune_button.Disable() thr = Thread(target=self.autotune, args=(resource, )) thr.daemon = True thr.start() def OnCalibrate(self, evt=None): self.calibrate_button.Disable() thr = Thread(target=self.self_calbrate) thr.daemon = True thr.start() def OnOk(self, evt=None): self.ok_callback(self) self.Destroy()
class PageOne(wx.Panel): def __init__(self, parent, hw_ver, frame): self.frame = frame self.multiplier_list = [1, 2, 4, 5, 8, 10, 16, 20] wx.Panel.__init__(self, parent) self.hw_ver = hw_ver main_sizer = wx.BoxSizer(wx.HORIZONTAL) grid = wx.GridBagSizer(hgap=5, vgap=5) grid_2 = wx.GridBagSizer(hgap=5, vgap=5) horizontal_sizer_2 = wx.BoxSizer(wx.HORIZONTAL) horizontal_sizer = wx.BoxSizer(wx.VERTICAL) plot_sizer = wx.BoxSizer(wx.VERTICAL) self.input_label = wx.StaticBox(self, -1, 'Analog input') self.input_sizer = wx.StaticBoxSizer(self.input_label, wx.HORIZONTAL) self.sample_list = [] for i in range(1, 9): self.sample_list.append("A" + str(i)) self.label_ch_1 = wx.StaticText(self, label="Ch+") grid.Add(self.label_ch_1, pos=(0, 0)) self.edit_ch_1 = wx.ComboBox(self, size=(95, -1), choices=self.sample_list, style=wx.CB_READONLY) self.edit_ch_1.SetSelection(0) grid.Add(self.edit_ch_1, pos=(0, 1)) if self.hw_ver == 1: self.sample_list = ("AGND", "VREF", "A5", "A6", "A7", "A8") else: if self.hw_ver == 2: self.sample_list = ("AGND", "A2") self.label_ch_2 = wx.StaticText(self, label="Ch-") grid.Add(self.label_ch_2, pos=(1, 0)) self.edit_ch_2 = wx.ComboBox(self, size=(95, -1), choices=self.sample_list, style=wx.CB_READONLY) self.edit_ch_2.SetSelection(0) grid.Add(self.edit_ch_2, pos=(1, 1)) self.Bind(wx.EVT_COMBOBOX, self.edit_ch_1_change, self.edit_ch_1) self.Bind(wx.EVT_COMBOBOX, self.edit_ch_2_change, self.edit_ch_2) if self.hw_ver == 1: self.sample_list = ("+-12 V", "+-4 V", "+-2 V", "+-0.4 V", "+-0.04 V") self.label_range = wx.StaticText(self, label="Range") else: if self.hw_ver == 2: self.sample_list = ("x1", "x2", "x4", "x5", "x8", "x10", "x16", "x20") self.label_range = wx.StaticText(self, label="Multiplier") grid.Add(self.label_range, pos=(2, 0)) self.edit_range = wx.ComboBox(self, size=(95, -1), choices=self.sample_list, style=wx.CB_READONLY) self.edit_range.SetSelection(0) grid.Add(self.edit_range, pos=(2, 1)) if self.hw_ver == 2: self.edit_range.Enable(False) self.label_rate = wx.StaticText(self, label="Rate(s)") grid.Add(self.label_rate, pos=(3, 0)) self.edit_rate = (FloatSpin(self, value=1, min_val=0.1, max_val=65.535, increment=0.1, digits=1)) grid.Add(self.edit_rate, pos=(3, 1)) self.button_play = wx.Button(self, label="Play", size=(95, 25)) self.Bind(wx.EVT_BUTTON, self.play_event, self.button_play) self.button_stop = wx.Button(self, label="Stop", size=(95, 25)) self.Bind(wx.EVT_BUTTON, self.stop_event, self.button_stop) self.button_stop.Enable(False) grid.Add(self.button_play, pos=(4, 0)) grid.Add(self.button_stop, pos=(4, 1)) self.label_value = wx.StaticText(self, label="Last value (V)") grid.Add(self.label_value, pos=(5, 0)) self.input_value = wx.TextCtrl(self, style=wx.TE_READONLY, size=(95, 25)) grid.Add(self.input_value, pos=(5, 1)) self.input_sizer.Add(grid, 0, wx.ALL, border=10) self.output_label = wx.StaticBox(self, -1, 'Analog output') self.output_sizer = wx.StaticBoxSizer(self.output_label, wx.HORIZONTAL) if hw_ver == 1: self.edit_value = FloatSpin(self, value=0, min_val=-4.0, max_val=4.0, increment=0.1, digits=3) elif hw_ver == 2: self.edit_value = FloatSpin(self, value=0, min_val=0, max_val=4.0, increment=0.1, digits=3) self.Bind(wx.lib.agw.floatspin.EVT_FLOATSPIN, self.slider_change, self.edit_value) self.lblDAC = wx.StaticText(self, label="DAC value (V)") grid_2.Add(self.lblDAC, pos=(0, 0)) grid_2.Add(self.edit_value, pos=(0, 3)) self.output_sizer.Add(grid_2, 0, wx.ALL, border=10) self.export_label = wx.StaticBox(self, -1, 'Export') self.export_sizer = wx.StaticBoxSizer(self.export_label, wx.HORIZONTAL) self.png = wx.Button(self, label="As PNG file...", size=(98, 25)) self.Bind(wx.EVT_BUTTON, self.save_as_png_event, self.png) self.csv = wx.Button(self, label="As CSV file...", size=(98, 25)) self.Bind(wx.EVT_BUTTON, self.save_as_csv_event, self.csv) horizontal_sizer_2.Add(self.png, 0, wx.ALL) horizontal_sizer_2.Add(self.csv, 0, wx.ALL) self.export_sizer.Add(horizontal_sizer_2, 0, wx.ALL, border=10) self.figure = Figure(facecolor='#ece9d8') self.axes = self.figure.add_subplot(111) self.canvas = FigureCanvas(self, -1, self.figure) self.axes.set_xlabel("Time (s)", fontsize=12) self.axes.set_ylabel("Voltage (mV)", fontsize=12) self.canvas.SetInitialSize(size=(600, 600)) self.add_toolbar() self.cidUpdate = self.canvas.mpl_connect('motion_notify_event', self.UpdateStatusBar) plot_sizer.Add(self.toolbar, 0, wx.CENTER) plot_sizer.Add(self.canvas, 0, wx.ALL) horizontal_sizer.Add(self.input_sizer, 0, wx.CENTRE) horizontal_sizer.Add(self.output_sizer, 0, wx.EXPAND) horizontal_sizer.Add(self.export_sizer, 0, wx.EXPAND) main_sizer.Add(horizontal_sizer, 0, wx.ALL, border=10) main_sizer.Add(plot_sizer, 0, wx.ALL) self.SetSizerAndFit(main_sizer) self.data_packet = [] self.x = [] self.y = [] # Create a publisher receiver pub.subscribe(self.new_data, "newdata") pub.subscribe(self.clear_canvas, "clearcanvas") def new_data(self, msg): data = msg.data if isinstance(msg.data, float): self.input_value.Clear() self.input_value.AppendText(str(data)) if (self.toolbar.mode == "pan/zoom"): return if (self.toolbar.mode == "zoom rect"): return self.canvas.mpl_disconnect(self.frame.page_1.cidUpdate) self.axes.cla() self.axes.grid(color='gray', linestyle='dashed') self.axes.plot(self.y, self.x) self.canvas.draw() self.cidUpdate = self.frame.page_1.canvas.mpl_connect( 'motion_notify_event', self.frame.page_1.UpdateStatusBar) def clear_canvas(self, msg): self.input_value.Clear() self.axes.cla() self.axes.grid(color='gray', linestyle='dashed') self.axes.plot(self.y, self.x) self.canvas.draw() def UpdateStatusBar(self, event): if event.inaxes: x, y = event.xdata, event.ydata self.frame.status_bar.SetStatusText( ("x= " + "%.4g" % x + " y=" + "%.4g" % y), 1) def add_toolbar(self): self.toolbar = MyCustomToolbar(self.canvas) self.toolbar.Realize() # On Windows platform, default window size is incorrect, so set # toolbar width to figure width. tw, th = self.toolbar.GetSizeTuple() fw, fh = self.canvas.GetSizeTuple() # By adding toolbar in sizer, we are able to put it at the bottom # of the frame - so appearance is closer to GTK version. # As noted above, doesn't work for Mac. self.toolbar.SetSize(wx.Size(fw, th)) #self.main_sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND) # update the axes menu on the toolbar self.toolbar.update() def save_as_png_event(self, event): self.directory_name = '' dlg = wx.FileDialog(self, "Choose a file", self.directory_name, "", "*.png", wx.OPEN) if dlg.ShowModal() == wx.ID_OK: self.file_name = dlg.GetFilename() self.directory_name = dlg.GetDirectory() self.figure.savefig(self.directory_name + "\\" + self.file_name) dlg.Destroy() def save_as_csv_event(self, event): self.directory_name = '' dlg = wx.FileDialog(self, "Choose a file", self.directory_name, "", "*.odq", wx.OPEN) if dlg.ShowModal() == wx.ID_OK: self.file_name = dlg.GetFilename() self.directory_name = dlg.GetDirectory() with open(self.directory_name + "\\" + self.file_name, 'wb') as file: spamwriter = csv.writer(file, quoting=csv.QUOTE_MINIMAL) for i in range(len(self.frame.comunication_thread.data)): spamwriter.writerow([ self.frame.comunication_thread.x[i], self.frame.comunication_thread.y[i] ]) dlg.Destroy() def zoom_up(self, event): pass def play_event(self, event): self.data_packet = [] self.x = [] self.y = [] self.ch_1 = self.edit_ch_1.GetCurrentSelection() self.ch_2 = self.edit_ch_2.GetCurrentSelection() self.range = self.edit_range.GetCurrentSelection() self.rate = self.edit_rate.GetValue() * 1000 self.edit_rate.SetValue(self.edit_rate.GetValue()) self.edit_value.SetValue(self.edit_value.GetValue()) if self.ch_1 == -1: self.frame.show_error_parameters() return if self.ch_2 == -1: self.frame.show_error_parameters() return if self.range == -1: self.frame.show_error_parameters() return if self.hw_ver == 2 and self.ch_2 == 1: self.ch_2 = self.edit_ch_2.GetValue() self.ch_2 = self.ch_2[1] if self.hw_ver == 1: if self.ch_2 == 1: self.ch_2 = 25 elif self.ch_2 > 1: self.ch_2 += 3 self.frame.comunication_thread.config(self.ch_1, int(self.ch_2), self.range, self.rate) self.button_play.Enable(False) self.button_stop.Enable(True) self.edit_ch_1.Enable(False) self.edit_ch_2.Enable(False) self.edit_range.Enable(False) self.edit_rate.Enable(False) self.frame.daq.set_led(3) wx.CallAfter(pub.sendMessage, "clearcanvas", None) if self.frame.comunication_thread.is_alive(): self.frame.comunication_thread.restart() else: self.frame.comunication_thread.start() self.frame.comunication_thread.stop() self.play_event(0) def stop_event(self, event): self.button_play.Enable(True) self.button_stop.Enable(False) self.edit_ch_1.Enable(True) self.edit_ch_2.Enable(True) self.edit_rate.Enable(True) if (self.hw_ver == 1 or (self.hw_ver == 2 and self.edit_ch_2.GetValue() != "AGND")): self.edit_range.Enable(True) self.frame.daq.set_led(1) self.frame.comunication_thread.stop() def slider_change(self, event): dac_value = self.edit_value.GetValue() self.frame.daq.set_analog(dac_value) def edit_ch_1_change(self, event): if self.hw_ver == 1: return value = self.edit_ch_1.GetValue() self.edit_ch_2.Clear() self.edit_ch_2.Append("AGND") if (int(value[1]) % 2) == 0: self.edit_ch_2.Append("A" + str(int(value[1]) - 1)) else: self.edit_ch_2.Append("A" + str(int(value[1]) + 1)) self.edit_ch_2.SetSelection(0) self.edit_range.SetSelection(0) self.edit_range.Enable(False) def edit_ch_2_change(self, event): if self.hw_ver == 1: return if self.edit_ch_2.GetValue() == "AGND": self.edit_range.Enable(False) self.edit_range.SetSelection(0) else: self.edit_range.Enable(True)
class ExampleSettingsPanel(wx.Panel): def __init__(self, *args, **kwds): super(ExampleSettingsPanel, self).__init__(*args, **kwds) # Needed to draw and delete the overlay self._pyslip = self.GetParent().GetParent().pyslip sizer = wx.BoxSizer(wx.VERTICAL) self.SetSizer(sizer) # Number of decimal digits self.digits = 2 from wx.lib.agw.floatspin import EVT_FLOATSPIN, FloatSpin # Set initial values self._radius = 100 self._center = [0, 0] radius_max = 2000 radius_min = 10 # Bind data to controls -- duplicate this section for each control box = wx.BoxSizer(wx.HORIZONTAL) self.slider = wx.Slider( self, maxValue=radius_max, minValue=radius_min, size=(250, -1), style=wx.SL_AUTOTICKS | wx.SL_HORIZONTAL, value=self._radius, ) box.Add( self.slider, 0, wx.RIGHT | wx.TOP | wx.BOTTOM | wx.ALIGN_CENTER_VERTICAL, 5 ) self.Bind(wx.EVT_SLIDER, self.OnSlide, self.slider) self.spinner = FloatSpin( self, digits=self.digits, max_val=radius_max, min_val=radius_min, value=self._radius, ) box.Add( self.spinner, 0, wx.RIGHT | wx.TOP | wx.BOTTOM | wx.ALIGN_CENTER_VERTICAL, 5 ) self.Bind(EVT_FLOATSPIN, self.OnSpin, self.spinner) sizer.Add(box) # end duplicate section # Update self.DrawRing() def __del__(self): # Delete layer method if hasattr(self, "_ring_layer") and self._ring_layer is not None: self._pyslip.DeleteLayer(self._ring_layer) def OnSlide(self, event): # Keep slider and spinner synchronized obj = event.EventObject self._radius = obj.GetValue() self.spinner.SetValue(self._radius) self.DrawRing() def OnSpin(self, event): # Keep slider and spinner synchronized obj = event.EventObject self._radius = obj.GetValue() self.slider.SetValue(self._radius) self.DrawRing() def _draw_ring_layer(self, dc, data, map_rel): """Draw a points layer. dc the device context to draw on data an iterable of point tuples: (x, y, place, radius, colour, x_off, y_off, pdata) map_rel points relative to map if True, MUST BE TRUE for lightweight Assumes all points are the same colour, saving 100's of ms. """ assert map_rel is True if len(data) == 0: return (lon, lat, place, radius, colour, x_off, y_off, pdata) = data[0] scale = 2 ** self._pyslip.tiles.zoom_level # Draw points on map/view, using transparency if implemented. try: dc = wx.GCDC(dc) except NotImplementedError: pass dc.SetPen(wx.Pen(colour)) dc.SetBrush(wx.Brush(colour, wx.TRANSPARENT)) for (lon, lat, place, radius, colour, x_off, y_off, pdata) in data: (x, y) = self._pyslip.ConvertGeo2View((lon, lat)) dc.DrawCircle(x, y, radius * scale) def DrawRing(self): detector = self._pyslip.tiles.raw_image.get_detector() beam = self._pyslip.tiles.raw_image.get_beam() if len(detector) > 1: beam_pixel_fast, beam_pixel_slow = detector[ 0 ].millimeter_to_pixel( # FIXME assumes all detector elements use the same detector.hierarchy().get_beam_centre(beam.get_s0()) ) # millimeter-to-pixel convention else: beam_pixel_fast, beam_pixel_slow = detector[0].millimeter_to_pixel( detector[0].get_beam_centre(beam.get_s0()) ) center = self._pyslip.tiles.picture_fast_slow_to_map_relative( beam_pixel_fast + self._center[0], beam_pixel_slow + self._center[1] ) ring_data = [(center[0], center[1], {"colour": "red", "radius": self._radius})] # Remove the old ring layer, and draw a new one. if hasattr(self, "_ring_layer") and self._ring_layer is not None: self._pyslip.DeleteLayer(self._ring_layer) self._ring_layer = None self._ring_layer = self._pyslip.AddPointLayer( ring_data, map_rel=True, visible=True, show_levels=[-3, -2, -1, 0, 1, 2, 3, 4, 5], renderer=self._draw_ring_layer, name="<ring_layer>", )
class GraphOptions(wx.Dialog): """Graph options for plot in main window""" #---------------------------------------------------------------------- def __init__(self,parent=None,extended=True): """Constructor""" wx.Dialog.__init__(self, parent, wx.ID_ANY, "Graph Options", size = (600,450), ) self.parent = parent colors=["blue","black","green","red","yellow","orange","pink","purple","brown", "gray","darkblue","silver","darkgreen","darkred","gold"] styles=["-","-.",":","steps","--","_"] #axis self.xlabel = "Depth [mm]" self.ylabel = "Force [N]" self.xlim = (0,300) self.auto_x = True self.ylim = (-1,41) self.auto_y = True self.xticks = 10 self.auto_xticks = True self.yticks = 10 self.auto_yticks = True self.mirrorx = False self.mirrory = False self.plot_title = "SMP Measurement" self.logscale = False #data self.color = colors[0] self.style = styles[0] self.width = 1 self.sampling = 1 #gradient self.grad_color = colors[3] self.grad_style = styles[2] self.grad_width = 1 self.grad_sampling = 100 #median self.median_color = colors[9] self.median_style = styles[0] self.median_width = 1 self.median_sampling = 100 panel = wx.Panel(self) notebook = Tabs(panel,extended) confirm = wx.Button(panel, wx.ID_OK) self.Bind(wx.EVT_BUTTON,self.onOK,confirm) cancel = wx.Button(panel, wx.ID_CANCEL) self.Bind(wx.EVT_BUTTON,self.onCancel,cancel) apply = wx.Button(panel, wx.ID_APPLY) self.Bind(wx.EVT_BUTTON,self.onApply,apply) vsizer = wx.BoxSizer(wx.VERTICAL) vsizer.Add(notebook, 1, wx.ALL|wx.EXPAND) hsizer = wx.BoxSizer(wx.HORIZONTAL) hsizer.Add(cancel) hsizer.Add(apply) hsizer.Add(confirm) vsizer.Add(hsizer,0,wx.ALIGN_RIGHT) panel.SetSizer(vsizer) self.Layout() #axis self.box_autox = wx.CheckBox(notebook.tabAxis, -1 ,'Auto X') self.Bind(wx.EVT_CHECKBOX,self.onUpdate,self.box_autox) self.box_autoy = wx.CheckBox(notebook.tabAxis, -1 ,'Auto Y') self.Bind(wx.EVT_CHECKBOX,self.onUpdate,self.box_autoy) self.box_autox_tick = wx.CheckBox(notebook.tabAxis, -1 ,'Auto X ticks') self.Bind(wx.EVT_CHECKBOX,self.onUpdate,self.box_autox_tick) self.box_autoy_tick = wx.CheckBox(notebook.tabAxis, -1 ,'Auto Y ticks') self.Bind(wx.EVT_CHECKBOX,self.onUpdate,self.box_autoy_tick) self.box_mirrorx = wx.CheckBox(notebook.tabAxis, -1 ,'Mirror X') self.box_mirrory = wx.CheckBox(notebook.tabAxis, -1 ,'Mirror Y') self.xmin = FloatSpin(notebook.tabAxis,-1,value=self.xlim[0],min_val=-100.00,max_val=1800.00,increment=1,digits=3) label_xmin = wx.StaticText(notebook.tabAxis,-1, 'X min') self.ymin = FloatSpin(notebook.tabAxis,-1,value=self.ylim[0],min_val=-100.00,max_val=1800.00,increment=1,digits=3) label_ymin = wx.StaticText(notebook.tabAxis,-1, 'Y min') self.xmax = FloatSpin(notebook.tabAxis,-1,value=self.xlim[1],min_val=-100.00,max_val=1800.00,increment=1,digits=3) label_xmax = wx.StaticText(notebook.tabAxis,-1, 'X max') self.ymax = FloatSpin(notebook.tabAxis,-1,value=self.ylim[1],min_val=-100.00,max_val=1800.00,increment=1,digits=3) label_ymax = wx.StaticText(notebook.tabAxis,-1, 'Y max') self.xlabel_ctrl = wx.TextCtrl(notebook.tabAxis,-1,size=(200,-1),value=self.xlabel) label_xlabel = wx.StaticText(notebook.tabAxis,-1, 'X label') self.ylabel_ctrl = wx.TextCtrl(notebook.tabAxis,-1,size=(200,-1),value=self.ylabel) label_ylabel = wx.StaticText(notebook.tabAxis,-1, 'Y label') label_xticks = wx.StaticText(notebook.tabAxis,-1, 'X ticks') self.xticks_ctrl = wx.SpinCtrl(notebook.tabAxis,-1,size=(100,-1),min=1,max=100,initial=self.xticks,name="X ticks") label_yticks = wx.StaticText(notebook.tabAxis,-1, 'Y ticks') self.yticks_ctrl = wx.SpinCtrl(notebook.tabAxis,-1,size=(100,-1),min=1,max=100,initial=self.yticks,name="Y ticks") self.scale_ctrl = wx.CheckBox(notebook.tabAxis, -1, "Log Scale") self.box_autox.SetValue(True) self.xmin.Enable(False) self.xmax.Enable(False) self.box_autoy.SetValue(True) self.ymin.Enable(False) self.ymax.Enable(False) self.xticks_ctrl.Enable(False) self.yticks_ctrl.Enable(False) self.box_autox_tick.SetValue(True) self.box_autoy_tick.SetValue(True) self.box_mirrorx.SetValue(self.mirrorx) self.box_mirrory.SetValue(self.mirrory) self.scale_ctrl.SetValue(self.logscale) font = wx.Font(14,wx.DEFAULT, wx.NORMAL,wx.BOLD,True) #graph label_data = wx.StaticText(notebook.tabGraph, -1, "Data Plot") label_sampling = wx.StaticText(notebook.tabGraph,-1, 'Down sampling Factor') self.sampling_ctrl = wx.SpinCtrl(notebook.tabGraph,-1,size=(100,-1),min=0,max=1000,initial=self.sampling,name="Sampling") label_color = wx.StaticText(notebook.tabGraph,-1, 'Line Color') self.color_ctrl = wx.ComboBox(notebook.tabGraph, -1, size=(150, -1), choices=colors, style=wx.CB_READONLY,value=self.color) label_style = wx.StaticText(notebook.tabGraph,-1, 'Line Style') self.style_ctrl = wx.ComboBox(notebook.tabGraph, -1, size=(150, -1), choices=styles, style=wx.CB_READONLY,value=self.style) label_width = wx.StaticText(notebook.tabGraph,-1, 'Line Width') self.width_ctrl = wx.SpinCtrl(notebook.tabGraph, -1,name="Width",initial=1,min=0.5,max=10,pos=(325,135),size=(50,-1)) #gradient label_grad = wx.StaticText(notebook.tabGraph, -1, "Gradient") label_grad_sampling = wx.StaticText(notebook.tabGraph,-1, 'Down sampling Factor') self.grad_sampling_ctrl = wx.SpinCtrl(notebook.tabGraph,-1,size=(100,-1),min=0,max=1000,initial=self.grad_sampling,name="Sampling") label_grad_color = wx.StaticText(notebook.tabGraph,-1, 'Line Color') self.grad_color_ctrl = wx.ComboBox(notebook.tabGraph, -1, size=(150, -1), choices=colors, style=wx.CB_READONLY,value=self.grad_color) label_grad_style = wx.StaticText(notebook.tabGraph,-1, 'Line Style') self.grad_style_ctrl = wx.ComboBox(notebook.tabGraph, -1, size=(150, -1), choices=styles, style=wx.CB_READONLY,value=self.grad_style) label_grad_width = wx.StaticText(notebook.tabGraph,-1, 'Line Width') self.grad_width_ctrl = wx.SpinCtrl(notebook.tabGraph, -1,name="Width",initial=1,min=0.5,max=10,pos=(325,135),size=(50,-1)) #median label_median = wx.StaticText(notebook.tabGraph, -1, "Median") label_median_sampling = wx.StaticText(notebook.tabGraph,-1, 'Window') self.median_sampling_ctrl = wx.SpinCtrl(notebook.tabGraph,-1,size=(100,-1),min=0,max=1000,initial=self.median_sampling,name="Sampling") label_median_color = wx.StaticText(notebook.tabGraph,-1, 'Line Color') self.median_color_ctrl = wx.ComboBox(notebook.tabGraph, -1, size=(150, -1), choices=colors, style=wx.CB_READONLY,value=self.median_color) label_median_style = wx.StaticText(notebook.tabGraph,-1, 'Line Style') self.median_style_ctrl = wx.ComboBox(notebook.tabGraph, -1, size=(150, -1), choices=styles, style=wx.CB_READONLY,value=self.median_style) label_median_width = wx.StaticText(notebook.tabGraph,-1, 'Line Width') self.median_width_ctrl = wx.SpinCtrl(notebook.tabGraph, -1,name="Width",initial=1,min=0.5,max=10,pos=(325,135),size=(50,-1)) vert1 = wx.BoxSizer(wx.VERTICAL) vert2 = wx.BoxSizer(wx.VERTICAL) hor1 = wx.BoxSizer(wx.HORIZONTAL) hor1.Add(self.box_autoy,0,wx.ALIGN_CENTER|wx.ALL) hor1.Add(self.scale_ctrl,0,wx.ALIGN_CENTER|wx.ALL) vert1.Add(self.box_autox,0,wx.ALIGN_CENTER|wx.ALL,10) vert2.Add(hor1,0,wx.ALIGN_CENTER|wx.ALL,10) vert1.Add(label_xmin,0,wx.ALIGN_CENTER|wx.RIGHT,10) vert1.Add(self.xmin,0,wx.ALIGN_CENTER|wx.ALL,10) vert2.Add(label_ymin,0,wx.ALIGN_CENTER|wx.RIGHT,10) vert2.Add(self.ymin,0,wx.ALIGN_CENTER|wx.ALL,10) vert1.Add(label_xmax,0,wx.ALIGN_CENTER|wx.RIGHT,10) vert1.Add(self.xmax,0,wx.ALIGN_CENTER|wx.ALL,10) vert2.Add(label_ymax,0,wx.ALIGN_CENTER|wx.RIGHT,10) vert2.Add(self.ymax,0,wx.ALIGN_CENTER|wx.ALL,10) vert1.Add(label_xlabel,0,wx.ALIGN_CENTER|wx.RIGHT,10) vert1.Add(self.xlabel_ctrl,0,wx.ALIGN_CENTER|wx.ALL,10) vert2.Add(label_ylabel,0,wx.ALIGN_CENTER|wx.RIGHT,10) vert2.Add(self.ylabel_ctrl,0,wx.ALIGN_CENTER|wx.ALL,10) vert1.Add(self.box_autox_tick,0,wx.ALIGN_CENTER|wx.ALL,10) vert1.Add(label_xticks,0,wx.ALIGN_CENTER|wx.RIGHT,10) vert1.Add(self.xticks_ctrl,0,wx.ALIGN_CENTER|wx.ALL,10) vert1.Add(self.box_mirrorx,0,wx.ALIGN_CENTER|wx.ALL,10) vert2.Add(self.box_autoy_tick,0,wx.ALIGN_CENTER|wx.ALL,10) vert2.Add(label_yticks,0,wx.ALIGN_CENTER|wx.RIGHT,10) vert2.Add(self.yticks_ctrl,0,wx.ALIGN_CENTER|wx.ALL,10) vert2.Add(self.box_mirrory,0,wx.ALIGN_CENTER|wx.ALL,10) sizer = wx.BoxSizer(wx.HORIZONTAL) sizer.Add(vert1,wx.ALIGN_CENTER) sizer.Add(wx.StaticLine(notebook.tabAxis,style=wx.LI_VERTICAL,size=(-1,600))) sizer.Add(vert2,wx.ALIGN_CENTER) notebook.tabAxis.SetSizer(sizer) vert1 = wx.BoxSizer(wx.VERTICAL) vert2 = wx.BoxSizer(wx.VERTICAL) vert3 = wx.BoxSizer(wx.VERTICAL) vert1.Add(label_data,0,wx.ALIGN_CENTER|wx.ALL,20) vert1.Add(label_sampling,0,wx.ALIGN_CENTER|wx.RIGHT,10) vert1.Add(self.sampling_ctrl,0,wx.ALIGN_CENTER|wx.ALL,10) vert1.Add(label_color,0,wx.ALIGN_CENTER|wx.RIGHT,10) vert1.Add(self.color_ctrl,0,wx.ALIGN_CENTER|wx.ALL,10) vert1.Add(label_width,0,wx.ALIGN_CENTER|wx.RIGHT,10) vert1.Add(self.width_ctrl,0,wx.ALIGN_CENTER|wx.ALL,10) vert1.Add(label_style,0,wx.ALIGN_CENTER|wx.RIGHT,10) vert1.Add(self.style_ctrl,0,wx.ALIGN_CENTER|wx.ALL,10) vert2.Add(label_grad,0,wx.ALIGN_CENTER|wx.ALL,20) vert2.Add(label_grad_sampling,0,wx.ALIGN_CENTER|wx.RIGHT,10) vert2.Add(self.grad_sampling_ctrl,0,wx.ALIGN_CENTER|wx.ALL,10) vert2.Add(label_grad_color,0,wx.ALIGN_CENTER|wx.RIGHT,10) vert2.Add(self.grad_color_ctrl,0,wx.ALIGN_CENTER|wx.ALL,10) vert2.Add(label_grad_width,0,wx.ALIGN_CENTER|wx.RIGHT,10) vert2.Add(self.grad_width_ctrl,0,wx.ALIGN_CENTER|wx.ALL,10) vert2.Add(label_grad_style,0,wx.ALIGN_CENTER|wx.RIGHT,10) vert2.Add(self.grad_style_ctrl,0,wx.ALIGN_CENTER|wx.ALL,10) vert3.Add(label_median,0,wx.ALIGN_CENTER|wx.ALL,20) vert3.Add(label_median_sampling,0,wx.ALIGN_CENTER|wx.RIGHT,10) vert3.Add(self.median_sampling_ctrl,0,wx.ALIGN_CENTER|wx.ALL,10) vert3.Add(label_median_color,0,wx.ALIGN_CENTER|wx.RIGHT,10) vert3.Add(self.median_color_ctrl,0,wx.ALIGN_CENTER|wx.ALL,10) vert3.Add(label_median_width,0,wx.ALIGN_CENTER|wx.RIGHT,10) vert3.Add(self.median_width_ctrl,0,wx.ALIGN_CENTER|wx.ALL,10) vert3.Add(label_median_style,0,wx.ALIGN_CENTER|wx.RIGHT,10) vert3.Add(self.median_style_ctrl,0,wx.ALIGN_CENTER|wx.ALL,10) label_data.SetFont(font) label_grad.SetFont(font) label_median.SetFont(font) sizer = wx.BoxSizer(wx.HORIZONTAL) sizer.Add(vert1,wx.ALIGN_CENTER|wx.ALIGN_BOTTOM) sizer.Add(wx.StaticLine(notebook.tabGraph,style=wx.LI_VERTICAL,size=(-1,600))) sizer.Add(vert2,wx.ALIGN_CENTER|wx.ALIGN_BOTTOM) sizer.Add(wx.StaticLine(notebook.tabGraph,style=wx.LI_VERTICAL,size=(-1,600))) sizer.Add(vert3,wx.ALIGN_CENTER|wx.ALIGN_BOTTOM) notebook.tabGraph.SetSizer(sizer) def onOK(self,e): """OK button event""" self.onApply(e) self.Hide() def onApply(self,e): """Apply button event""" self.color = self.color_ctrl.GetValue() self.style = self.style_ctrl.GetValue() self.width = self.width_ctrl.GetValue() self.xlabel = self.xlabel_ctrl.GetValue() self.ylabel = self.ylabel_ctrl.GetValue() self.xlim = (self.xmin.GetValue(),self.xmax.GetValue()) self.ylim = (self.ymin.GetValue(),self.ymax.GetValue()) self.sampling = self.sampling_ctrl.GetValue() self.auto_x = self.box_autox.GetValue() self.auto_y = self.box_autoy.GetValue() self.xticks = self.xticks_ctrl.GetValue() self.auto_xticks = self.box_autox_tick.GetValue() self.yticks = self.yticks_ctrl.GetValue() self.auto_yticks = self.box_autoy.GetValue() self.mirrorx = self.box_mirrorx.GetValue() self.mirrory = self.box_mirrory.GetValue() self.grad_color = self.grad_color_ctrl.GetValue() self.grad_style = self.grad_style_ctrl.GetValue() self.grad_width = self.grad_width_ctrl.GetValue() self.grad_sampling = self.grad_sampling_ctrl.GetValue() self.logscale = self.scale_ctrl.GetValue() self.median_color = self.median_color_ctrl.GetValue() self.median_style = self.median_style_ctrl.GetValue() self.median_width = self.median_width_ctrl.GetValue() self.median_sampling = self.median_sampling_ctrl.GetValue() self.parent.draw_figure(autozoom=False) def onCancel(self,e): """cancel button event""" self.color_ctrl.SetValue(self.color) self.style_ctrl.SetValue(self.style) self.width_ctrl.SetValue(self.width) self.xlabel_ctrl.SetValue(self.xlabel) self.ylabel_ctrl.SetValue(self.ylabel) self.xmin.SetValue(self.xlim[0]) self.xmax.SetValue(self.xlim[1]) self.ymin.SetValue(self.ylim[0]) self.ymax.SetValue(self.ylim[1]) self.sampling_ctrl.SetValue(self.sampling) self.box_autox.SetValue(self.auto_x) self.box_autoy.SetValue(self.auto_y) self.xticks_ctrl.SetValue(self.xticks) self.box_autox_tick.SetValue(self.auto_xticks) self.yticks_ctrl.SetValue(self.yticks) self.box_autoy_tick.SetValue(self.auto_yticks) self.box_mirrorx.SetValue(self.mirrorx) self.box_mirrory.SetValue(self.mirrory) self.grad_color_ctrl.SetValue(self.grad_color) self.grad_style_ctrl.SetValue(self.grad_style) self.grad_width_ctrl.SetValue(self.grad_width) self.grad_sampling_ctrl.SetValue(self.grad_sampling) self.scale_ctrl.SetValue(self.logscale) self.median_color_ctrl.SetValue(self.median_color) self.median_style_ctrl.SetValue(self.median_style) self.median_width_ctrl.SetValue(self.median_width) self.median_sampling_ctrl.SetValue(self.median_sampling) self.Hide() def onUpdate(self,e): xlim = not self.box_autox.GetValue() self.xmax.Enable(xlim) self.xmin.Enable(xlim) ylim = not self.box_autoy.GetValue() self.ymax.Enable(ylim) self.ymin.Enable(ylim) xtick = not self.box_autox_tick.GetValue() self.xticks_ctrl.Enable(xtick) ytick = not self.box_autoy_tick.GetValue() self.yticks_ctrl.Enable(ytick)
class ScalingSettingsDialog(Dialog): def __init__(self, parent, ok_callback, *args, **kwargs): Dialog.__init__(self, parent, title='Scaling settings') self.ok_callback = ok_callback # Dialog. dialog_box = wx.BoxSizer(wx.VERTICAL) ## Settings. settings_box = wx.FlexGridSizer(rows=3, cols=2, hgap=5) dialog_box.Add(settings_box, flag=wx.EXPAND|wx.ALL, border=5) ### Linear scale. settings_box.Add(wx.StaticText(self, label='Linear scale:'), flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT) self.linear_scale_input = FloatSpin(self, value=0, min_val=-1e9, max_val=1e9, increment=1, digits=5) settings_box.Add(self.linear_scale_input, flag=wx.EXPAND) ### Exponential scale. settings_box.Add(wx.StaticText(self, label='Exponential scale:'), flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT) self.exponential_scale_input = FloatSpin(self, value=0, min_val=-100, max_val=100, increment=1, digits=2) settings_box.Add(self.exponential_scale_input, flag=wx.EXPAND) ### Offset. settings_box.Add(wx.StaticText(self, label='Offset:'), flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT) self.offset_input = FloatSpin(self, value=0, min_val=-1e9, max_val=1e9, increment=1, digits=5, size=(200, -1)) settings_box.Add(self.offset_input, flag=wx.EXPAND) ## End buttons. button_box = wx.BoxSizer(wx.HORIZONTAL) dialog_box.Add(button_box, flag=wx.CENTER|wx.ALL, border=5) ok_button = wx.Button(self, wx.ID_OK) self.Bind(wx.EVT_BUTTON, self.OnOk, ok_button) button_box.Add(ok_button) cancel_button = wx.Button(self, wx.ID_CANCEL) button_box.Add(cancel_button) self.SetSizerAndFit(dialog_box) def GetValue(self): result = ScalingSettings() result.linear_scale = self.linear_scale_input.GetValue() result.exponential_scale = self.exponential_scale_input.GetValue() result.offset = self.offset_input.GetValue() return result def SetValue(self, value): self.linear_scale_input.SetValue(value.linear_scale) self.exponential_scale_input.SetValue(value.exponential_scale) self.offset_input.SetValue(value.offset) def OnOk(self, evt=None): self.ok_callback(self) self.Destroy()