Exemplo n.º 1
0
    def __init__(self,
                 parent,
                 pv=None,
                 deadTime=2500,
                 min_val=None,
                 max_val=None,
                 increment=1.0,
                 digits=-1,
                 **kw):
        """
        Most arguments are common with FloatSpin.

        Additional Arguments:
        pv = pv to set
        deadTime = delay (ms) between user typing a value into the field,
        and it being set to the PV

        """
        floatspin.FloatSpin.__init__(self,
                                     parent,
                                     increment=increment,
                                     min_val=min_val,
                                     max_val=max_val,
                                     digits=digits,
                                     **kw)
        PVCtrlMixin.__init__(self, pv=pv, font="", fg=None, bg=None)
        floatspin.EVT_FLOATSPIN(parent, self.GetId(), self.OnSpin)

        self.deadTimer = wx.Timer(self)
        self.deadTime = deadTime
        wx.EVT_TIMER(self, self.deadTimer.GetId(), self.OnTimeout)
Exemplo n.º 2
0
    def add_slider(self, name, caption, defaultval, minval, maxval, inc, handler):
        #create a label for the slider
        label = wx.StaticText(self, wx.ID_ANY, caption)
        self.Add(label, 0,
                 wx.LEFT | wx.RIGHT | wx.TOP | wx.ALIGN_CENTER_HORIZONTAL,
                 border=10)

        #create a frequency slider
        #self.slider = wx.Slider(self, wx.ID_ANY, value=0.01, minValue=0.01,
        #                        maxValue=2.0, style=wx.SL_LABELS)
        slider_ref = FS.FloatSpin(self, -1, min_val=minval, max_val=maxval,
                                 increment=inc, value=defaultval)
        slider_ref.SetFormat("%f")
        slider_ref.SetDigits(2)

        self.sliders[name] = slider_ref
        
        #add the slider to the control panel's sizer
        self.Add(self.sliders[name], 0, 
                 wx.ALL | wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, border=0)
        
        #register an event handler for slider change events
        FS.EVT_FLOATSPIN(self, self.sliders[name].GetId(), 
                                      handler)
Exemplo n.º 3
0
    def __init__(self,
                 parent,
                 mpl_lines,
                 update_command,
                 linestyles=all_available_lines):
        """
        Panel with controls to allow the user to change the style of a series
        line.
        """
        wx.Panel.__init__(self, parent, wx.ID_ANY)
        self.mpl_lines = mpl_lines
        self.parent = parent
        self.update_command = update_command
        self.__available_lines = linestyles

        self.__line_symbol_to_idx_map = {}
        self.__line_name_to_idx_map = {}
        for i, m in enumerate(self.__available_lines):
            self.__line_symbol_to_idx_map[m.mpl_symbol] = i
            self.__line_name_to_idx_map[m.name] = i

        line_ctrls_szr = wx.FlexGridSizer(cols=2, vgap=5, hgap=2)

        #line style
        line_ctrls_szr.Add(wx.StaticText(self, wx.ID_ANY, "Style:"), 0,
                           wx.ALIGN_CENTRE_VERTICAL | wx.ALIGN_RIGHT)
        self.linestyle_choice = wx.Choice(
            self, wx.ID_ANY, choices=[l.name for l in self.__available_lines])
        line_ctrls_szr.Add(self.linestyle_choice, 0,
                           wx.ALIGN_CENTRE_VERTICAL | wx.ALIGN_LEFT)
        wx.EVT_CHOICE(self, self.linestyle_choice.GetId(), self.on_linestyle)

        #line thickness
        self.line_weight_ctrl_txt = wx.StaticText(self, wx.ID_ANY,
                                                  "Thickness:")
        self.line_weight_ctrl = floatspin.FloatSpin(
            self,
            wx.ID_ANY,
            min_val=0.1,
            max_val=50.0,
            value=mpl_lines[0].get_linewidth(),
            increment=0.1,
            digits=2)
        line_ctrls_szr.Add(self.line_weight_ctrl_txt, 0,
                           wx.ALIGN_CENTRE_VERTICAL | wx.ALIGN_RIGHT)
        line_ctrls_szr.Add(self.line_weight_ctrl, 0,
                           wx.ALIGN_CENTRE_VERTICAL | wx.ALIGN_LEFT)
        floatspin.EVT_FLOATSPIN(self, self.line_weight_ctrl.GetId(),
                                self.on_linewidth)

        #line colour
        line_col = matplotlib.colors.colorConverter.to_rgb(
            mpl_lines[0].get_color())
        line_col = (255 * line_col[0], 255 * line_col[1], 255 * line_col[2])
        self.line_colour_picker_txt = wx.StaticText(self, wx.ID_ANY, "Colour:")
        self.line_colour_picker = wx.ColourPickerCtrl(self, -1, line_col)
        line_ctrls_szr.Add(self.line_colour_picker_txt, 0,
                           wx.ALIGN_CENTRE_VERTICAL | wx.ALIGN_RIGHT)
        line_ctrls_szr.Add(self.line_colour_picker, 0,
                           wx.ALIGN_CENTRE_VERTICAL | wx.ALIGN_LEFT)
        wx.EVT_COLOURPICKER_CHANGED(self, self.line_colour_picker.GetId(),
                                    self.on_line_colour_change)

        #line opacity
        line_alpha = mpl_lines[0].get_alpha()
        if not line_alpha:
            line_alpha = 1.0
        self.line_alpha_ctrl = floatspin.FloatSpin(self,
                                                   -1,
                                                   min_val=0.0,
                                                   max_val=1.0,
                                                   value=line_alpha,
                                                   increment=0.1,
                                                   digits=1)
        self.line_alpha_txt = wx.StaticText(self, wx.ID_ANY, "Opacity:")

        line_ctrls_szr.Add(self.line_alpha_txt, 0,
                           wx.ALIGN_CENTRE_VERTICAL | wx.ALIGN_RIGHT)
        line_ctrls_szr.Add(self.line_alpha_ctrl, 0,
                           wx.ALIGN_CENTRE_VERTICAL | wx.ALIGN_LEFT)

        floatspin.EVT_FLOATSPIN(self, self.line_alpha_ctrl.GetId(),
                                self.on_line_alpha_change)

        #set the line selection to that of the data
        #it is possible that the line will have been set to something that
        #avoplot does not yet support - if so, default to None and issue warning
        if self.__line_symbol_to_idx_map.has_key(mpl_lines[0].get_linestyle()):
            #everything is fine
            current_line_idx = self.__line_symbol_to_idx_map[
                mpl_lines[0].get_linestyle()]
        else:
            current_line_idx = 0
            warnings.warn("Data series has an unsupported line style. "
                          "Defaulting to a line style of \'%s\' instead." %
                          (self.__available_lines[0].name))

        #update the GUI appropriately for the current line selection
        self.linestyle_choice.SetSelection(current_line_idx)
        self.update_line_controls(self.__available_lines[current_line_idx])

        self.SetSizer(line_ctrls_szr)
        line_ctrls_szr.Fit(self)
        self.SetAutoLayout(True)
        self.parent.SendSizeEvent()
        self.parent.Refresh()
Exemplo n.º 4
0
    def __init__(self,
                 parent,
                 mpl_lines,
                 update_command,
                 markers=all_available_markers):
        """
        Panel with controls to allow the user to change the markers used to plot
        a data series.
        """

        wx.Panel.__init__(self, parent, wx.ID_ANY)

        self.__available_markers = markers
        self.parent = parent
        self.mpl_lines = mpl_lines
        self.update_command = update_command

        #build some mappings between marker properties and their indices in the list
        #of available markers
        self.__marker_symbol_to_idx_map = {}
        #self.__marker_name_to_idx_map = {}
        for i, m in enumerate(self.__available_markers):
            self.__marker_symbol_to_idx_map[m.mpl_symbol] = i
            #self.__marker_name_to_idx_map[m.name] = i

        marker_ctrls_szr = wx.FlexGridSizer(cols=2, vgap=5, hgap=2)

        #marker style
        #TODO - better way to include NullBitmap here (this is a quick hack for now)
        bitmaps = [
            wx.ArtProvider.GetBitmap(m.bitmap, size=wx.Size(16, 16))
            for m in self.__available_markers
        ]

        self.marker_style_choice = widgets.BitmapChoice(self,
                                                        choices=[""] *
                                                        len(bitmaps),
                                                        size=(80, -1),
                                                        style=wx.CB_READONLY,
                                                        bitmaps=bitmaps)

        marker_ctrls_szr.Add(wx.StaticText(self, wx.ID_ANY, "Style:"), 0,
                             wx.ALIGN_CENTRE_VERTICAL | wx.ALIGN_RIGHT)
        marker_ctrls_szr.Add(self.marker_style_choice, 0,
                             wx.ALIGN_CENTRE_VERTICAL | wx.ALIGN_LEFT)
        wx.EVT_COMBOBOX(self, self.marker_style_choice.GetId(), self.on_marker)

        #marker size
        self.marker_size_ctrl_txt = wx.StaticText(self, wx.ID_ANY, "Size:")
        self.marker_size_ctrl = floatspin.FloatSpin(
            self,
            wx.ID_ANY,
            min_val=0.1,
            max_val=50.0,
            value=mpl_lines[0].get_markersize(),
            increment=0.1,
            digits=2)
        marker_ctrls_szr.Add(self.marker_size_ctrl_txt, 0,
                             wx.ALIGN_CENTRE_VERTICAL | wx.ALIGN_RIGHT)
        marker_ctrls_szr.Add(self.marker_size_ctrl, 0,
                             wx.ALIGN_CENTRE_VERTICAL | wx.ALIGN_LEFT)
        floatspin.EVT_FLOATSPIN(self, self.marker_size_ctrl.GetId(),
                                self.on_markersize)

        #marker colour
        prev_col = matplotlib.colors.colorConverter.to_rgb(
            mpl_lines[0].get_markerfacecolor())
        prev_col = (255 * prev_col[0], 255 * prev_col[1], 255 * prev_col[2])
        self.marker_fillcolour_picker_txt = wx.StaticText(
            self, wx.ID_ANY, "Fill:")
        self.marker_fillcolour_picker = wx.ColourPickerCtrl(self, -1, prev_col)
        marker_ctrls_szr.Add(self.marker_fillcolour_picker_txt, 0,
                             wx.ALIGN_CENTRE_VERTICAL | wx.ALIGN_RIGHT)
        marker_ctrls_szr.Add(self.marker_fillcolour_picker, 0,
                             wx.ALIGN_CENTRE_VERTICAL | wx.ALIGN_LEFT)
        wx.EVT_COLOURPICKER_CHANGED(self,
                                    self.marker_fillcolour_picker.GetId(),
                                    self.on_marker_fillcolour)

        #marker edge colour
        prev_col = matplotlib.colors.colorConverter.to_rgb(
            mpl_lines[0].get_markeredgecolor())
        prev_col = (255 * prev_col[0], 255 * prev_col[1], 255 * prev_col[2])
        self.marker_edgecolour_picker_txt = wx.StaticText(
            self, wx.ID_ANY, "Edge:")
        self.marker_edgecolour_picker = wx.ColourPickerCtrl(self, -1, prev_col)
        marker_ctrls_szr.Add(self.marker_edgecolour_picker_txt, 0,
                             wx.ALIGN_CENTRE_VERTICAL | wx.ALIGN_RIGHT)
        marker_ctrls_szr.Add(self.marker_edgecolour_picker, 0,
                             wx.ALIGN_CENTRE_VERTICAL | wx.ALIGN_LEFT)
        wx.EVT_COLOURPICKER_CHANGED(self,
                                    self.marker_edgecolour_picker.GetId(),
                                    self.on_marker_edgecolour)

        #marker edge width
        self.marker_edgewidth_ctrl_txt = wx.StaticText(self, wx.ID_ANY,
                                                       "Edge width:")
        self.marker_edgewidth_ctrl = floatspin.FloatSpin(
            self,
            wx.ID_ANY,
            min_val=0.1,
            max_val=50.0,
            value=mpl_lines[0].get_markeredgewidth(),
            increment=0.1,
            digits=2)
        marker_ctrls_szr.Add(self.marker_edgewidth_ctrl_txt, 0,
                             wx.ALIGN_CENTRE_VERTICAL | wx.ALIGN_RIGHT)
        marker_ctrls_szr.Add(self.marker_edgewidth_ctrl, 0,
                             wx.ALIGN_CENTRE_VERTICAL | wx.ALIGN_LEFT)
        floatspin.EVT_FLOATSPIN(self, self.marker_edgewidth_ctrl.GetId(),
                                self.on_marker_edgewidth)

        #set the marker selection to that of the data
        #it is possible that the marker will have been set to something that
        #avoplot does not yet support - if so, default to None and issue warning
        if self.__marker_symbol_to_idx_map.has_key(mpl_lines[0].get_marker()):
            #everything is fine
            current_marker_idx = self.__marker_symbol_to_idx_map[
                mpl_lines[0].get_marker()]
        else:
            current_marker_idx = 0
            warnings.warn("Data series has an unsupported marker style. "
                          "Defaulting to a marker style of \'%s\' instead." %
                          (self.__available_markers[0].name))

        #update the GUI appropriately for the current marker selection
        self.marker_style_choice.SetSelection(current_marker_idx)
        self.update_marker_controls(
            self.__available_markers[current_marker_idx])

        self.SetSizer(marker_ctrls_szr)
        marker_ctrls_szr.Fit(self)
        self.SetAutoLayout(True)