def _initialize_tool(self, param):
        """ Initialize the tool palette button. """

        wxid, label, bmp, kind, tooltip, longtip = param

        panel = self.control.FindWindowById(wxid)

        sizer = wx.BoxSizer(wx.VERTICAL)
        panel.SetSizer(sizer)
        panel.SetAutoLayout(True)
        panel.SetWindowStyleFlag(wx.CLIP_CHILDREN)

        from wx.lib.buttons import GenBitmapToggleButton, GenBitmapButton

        if kind == 'radio':
            button = GenBitmapToggleButton(panel,
                                           -1,
                                           None,
                                           size=self.button_size)

        else:
            button = GenBitmapButton(panel, -1, None, size=self.button_size)

        self.button_tool_map[button.GetId()] = wxid
        self.tool_id_to_button_map[wxid] = button
        wx.EVT_BUTTON(panel, button.GetId(), self._on_button)
        button.SetBitmapLabel(bmp)
        button.SetToolTipString(label)
        sizer.Add(button, 0, wx.EXPAND)

        return
Beispiel #2
0
class DataRangeSelectionPanel(wx.Panel):
    def __init__(self, parent, series):
        """
        Panel to allow the user to select ranges of data from a plot.
        
            * parent - the parent wx.Window for the panel
            * series - the avoplot series that the selection is to be made from
        """
        self.series = series
        self.parent = parent

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

        vsizer = wx.BoxSizer(wx.VERTICAL)

        hsizer = wx.BoxSizer(wx.HORIZONTAL)

        self.all_select_button = GenBitmapToggleButton(
            self, wx.ID_ANY,
            wx.ArtProvider.GetBitmap("avoplot_allselect", wx.ART_BUTTON))
        self.h_select_button = GenBitmapToggleButton(
            self, wx.ID_ANY,
            wx.ArtProvider.GetBitmap("avoplot_hselect", wx.ART_BUTTON))
        self.v_select_button = GenBitmapToggleButton(
            self, wx.ID_ANY,
            wx.ArtProvider.GetBitmap("avoplot_vselect", wx.ART_BUTTON))
        self.rect_select_button = GenBitmapToggleButton(
            self, wx.ID_ANY,
            wx.ArtProvider.GetBitmap("avoplot_rectselect", wx.ART_BUTTON))

        self.all_select_button.SetToolTipString("Entire series")
        self.h_select_button.SetToolTipString("Horizontal selection")
        self.v_select_button.SetToolTipString("Vertical selection")
        self.rect_select_button.SetToolTipString("Rectangular selection")

        hsizer.AddSpacer(5)
        hsizer.Add(self.all_select_button, 0)
        hsizer.Add(self.h_select_button, 0, wx.LEFT, border=2)
        hsizer.Add(self.v_select_button, 0, wx.LEFT, border=2)
        hsizer.Add(self.rect_select_button, 0, wx.LEFT, border=2)
        hsizer.AddSpacer(5)

        wx.EVT_BUTTON(self, self.all_select_button.GetId(), self.on_allselect)
        wx.EVT_BUTTON(self, self.h_select_button.GetId(), self.on_hselect)
        wx.EVT_BUTTON(self, self.v_select_button.GetId(), self.on_vselect)
        wx.EVT_BUTTON(self, self.rect_select_button.GetId(),
                      self.on_rectselect)

        self.all_select_button.SetValue(True)
        self.selection_tool = EntireSeriesSelectionTool(self.series)

        vsizer.AddSpacer(5)
        vsizer.Add(hsizer, 0, wx.ALIGN_CENTER_HORIZONTAL)

        self.SetSizer(vsizer)
        vsizer.Fit(self)

    def disable_selection(self):
        self.selection_tool.disable_selection()

    def enable_selection(self):
        self.selection_tool.enable_selection()

    def __disable_all_except(self, button_to_keep):
        """
        De-selects all the selection buttons except the one passed as an arg.
        """
        self.selection_tool.disable_selection()

        for b in [
                self.all_select_button, self.h_select_button,
                self.v_select_button, self.rect_select_button
        ]:

            if b != button_to_keep:
                b.SetValue(False)

    def get_selection(self):
        """
        Returns a numpy array which is a mask where 0 == data not selected and 
        1 == data selected. The length of the mask will be equal to that of the
        series.
        """
        return self.selection_tool.get_current_selection()

    def on_allselect(self, evnt):
        """
        Callback handler for the "select all" button.
        """
        self.__disable_all_except(self.all_select_button)
        self.selection_tool = EntireSeriesSelectionTool(self.series)
        self.selection_tool.enable_selection()

    def on_hselect(self, evnt):
        """
        Callback handler for the "horizontal select" button.
        """
        if not self.h_select_button.GetValue():
            self.all_select_button.SetValue(True)
            self.on_allselect(None)
            return

        self.__disable_all_except(self.h_select_button)
        self.selection_tool = HorizontalSelectionTool(self.series)
        self.selection_tool.enable_selection()

    def on_vselect(self, evnt):
        """
        Callback handler for the "vertical select" button.
        """
        if not self.v_select_button.GetValue():
            self.all_select_button.SetValue(True)
            self.on_allselect(None)
            return

        self.__disable_all_except(self.v_select_button)
        self.selection_tool = VerticalSelectionTool(self.series)
        self.selection_tool.enable_selection()

    def on_rectselect(self, evnt):
        """
        Callback handler for the "rectangular select" button.
        """
        if not self.rect_select_button.GetValue():
            self.all_select_button.SetValue(True)
            self.on_allselect(None)
            return

        self.__disable_all_except(self.rect_select_button)
        self.selection_tool = RectSelectionTool(self.series)
        self.selection_tool.enable_selection()