示例#1
0
    def __init__(self, *args, **kwargs):
        """
        :param parent: (wx.Window) parent window
        :param id: (int) button id (optional)
        :param bitmap: (wx.Bitmap) default button face. Use `SetBitmaps` to set
                the other faces (e.g. hover, active)
        :param pos: (int, int)) button position
        :param size: (int, int) button size

        :param background_parent: (wx.Window) any parent higher up in the
                hierarchy from which to pick the background colour. (optional)
        :param label_delta: (int) the number of pixels to move button text down
                and to the right when it is pressed, to create an indentation
                effect. (This is used by subclasses that allow text to be
                displayed)

        """
        kwargs['style'] = wx.NO_BORDER
        self.labelDelta = kwargs.pop('label_delta', 0)
        self.background_parent = kwargs.pop('background_parent', None)

        # Fit the bmp if needed
        # Resizing should always be minimal, so distortion is minimum

        # If the bmp arg is provided (which is the 3rd one: parent, id, bmp)

        bmp = args[2] if len(args) >= 3 else kwargs.get('bitmap', None)
        size = args[4] if len(args) >= 5 else kwargs.get('size', None)

        if bmp:
            if size and size != (-1, -1):
                args = list(args)
                # Resize and replace original bmp
                if len(args) >= 3:
                    args[2] = resize_bmp(size, bmp)
                else:
                    kwargs['bitmap'] = resize_bmp(size, bmp)
            else:
                # Set the size of the button to match the bmp
                if len(args) >= 5:
                    args[4] = bmp.GetSize()
                else:
                    kwargs['size'] = bmp.GetSize()

        GenBitmapToggleButton.__init__(self, *args, **kwargs)

        if self.background_parent:
            self.SetBackgroundColour(
                self.background_parent.GetBackgroundColour()
            )
        else:
            self.SetBackgroundColour(self.GetParent().GetBackgroundColour())

        self.bmpHover = None
        self.bmpSelectedHover = None
        self.hovering = False

        self.Bind(wx.EVT_ENTER_WINDOW, self.OnEnter)
        self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeave)
	def createButtons(self):
		self.buttonGroup = ButtonGroup()
		for name in self.commonComponentNameList.keys():
			button1 = GenBitmapToggleButton(self, id=wx.ID_ANY, bitmap=self.nameToBitmap[name],style=wx.BU_EXACTFIT)
			button1.typeName = name
			button1.isVariable = self.commonComponentNameList[name]
			self.buttonGroup.addButton(button1,name)
			self.bSizer.Add(button1,0,wx.ALL,5)
 def addToggleButton(self, toolname, tooltip=None):
         bitmap = self.bitmaps[toolname]
         size = (24, 24)
         togglebutton = GenBitmapToggleButton(self.parent, -1, bitmap, size=size)
         togglebutton.SetBezelWidth(3)
         if tooltip is not None:
                 togglebutton.SetToolTip(wx.ToolTip(tooltip))
         self.togglebuttons[toolname] = togglebutton
         return togglebutton
示例#4
0
 def __init__(
     self,
     parent,
     id=-1,
     bitmap=wx.NullBitmap,
     pos=wx.DefaultPosition,
     size=wx.DefaultSize,
     style=0,
     validator=wx.DefaultValidator,
     name="bitmaptogglebutton",
 ):
     GenBitmapToggleButton.__init__(self, parent, id, bitmap, pos, size, style, validator, name)
 def __init__(self, imagepanel, sizer, bitmap, tooltip='', cursor=None,
                 untoggle=False, button=None):
         self.sizer = sizer
         self.imagepanel = imagepanel
         self.cursor = cursor
         if button is None:
                 self.button = GenBitmapToggleButton(self.imagepanel, -1, bitmap, size=(24, 24))
         else:
                 self.button = button
         self.untoggle = untoggle
         self.button.SetBezelWidth(3)
         if tooltip:
                 self.button.SetToolTip(wx.ToolTip(tooltip))
         self.sizer.Add(self.button, 0, wx.ALIGN_CENTER|wx.ALL, 3)
         self.button.Bind(wx.EVT_BUTTON, self.OnButton)
示例#6
0
 def __init__(self, parent, label_bitmap=None, selected_bitmap=None, toggled=False):
     # An image toggle button
     GenBitmapToggleButton.__init__(self, parent, id=-1, bitmap=None)
     
     if label_bitmap <> None:
         mask = wx.Mask(label_bitmap, wx.BLUE)
         label_bitmap.SetMask(mask)
         self.SetBitmapLabel(label_bitmap)
     
     if selected_bitmap <> None:
         mask = wx.Mask(selected_bitmap, wx.BLUE)
         selected_bitmap.SetMask(mask)
         self.SetBitmapSelected(selected_bitmap)
     
     self.SetToggle(toggled)
     self.SetInitialSize()
示例#7
0
    def AddSimpleTool(self,
                      wid,
                      bitmap,
                      shortHelpString='',
                      longHelpString='',
                      isToggle=0):
        """
		A method for adding a tool to the toolbar
		"""
        if not isToggle:
            #btn = wx.BitmapButton(self,id,bitmap,size=self.toolSize)
            btn = GenBitmapButton(self,
                                  wid,
                                  bitmap,
                                  style=wx.BORDER_NONE,
                                  size=self.toolSize)
        else:
            btn = GenBitmapToggleButton(self,
                                        wid,
                                        bitmap,
                                        size=(-1, self.toolSize[1]))

        btn.Bind(wx.EVT_BUTTON, self.onToolButton)
        btn.SetToolTipString(longHelpString)
        #self.sizer.Add(btn,(self.y,self.x))
        self.ctrls.append(btn)
        self.idToTool[wid] = btn
        self.sizes.append(btn.GetSize()[0])
        self.x += 1
示例#8
0
    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 _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
示例#10
0
 def SetToggle(self, toggle):
     # Avoid wxPyDeadObject errors. Investigate further. Probably needs to
     # be handled in VigilantAttributeConnector. See comments there.
     if isinstance(self, ImageToggleButton):
         GenBitmapToggleButton.SetToggle(self, toggle)
示例#11
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()
示例#12
0
    def __init__(self, parent=None):
        wx.Panel.__init__(self, parent)
        self.isEditable = True

        bmp = wx.Image(os.path.join(resourcePath, 'gui/icons/16x16/add.png'),
                       wx.BITMAP_TYPE_PNG).ConvertToBitmap()
        self.insert = wx.BitmapButton(self, -1, bmp)
        if sys.platform in ('win32', 'win64'):
            bmp = wx.Image(
                os.path.join(resourcePath, 'gui/icons/16x16/addDisabled.png'),
                wx.BITMAP_TYPE_PNG).ConvertToBitmap()
            self.insert.SetBitmapDisabled(bmp)
        self.insert.SetToolTip(wx.ToolTip('Insert a row.'))

        bmp = wx.Image(
            os.path.join(resourcePath, 'gui/icons/16x16/cancel.png'),
            wx.BITMAP_TYPE_PNG).ConvertToBitmap()
        self.delete = wx.BitmapButton(self, -1, bmp)
        if sys.platform in ('win32', 'win64'):
            bmp = wx.Image(
                os.path.join(resourcePath,
                             'gui/icons/16x16/cancelDisabled.png'),
                wx.BITMAP_TYPE_PNG).ConvertToBitmap()
            self.delete.SetBitmapDisabled(bmp)
        self.delete.SetToolTip(wx.ToolTip('Delete selected rows.'))

        bmp = wx.Image(os.path.join(resourcePath, 'gui/icons/16x16/up.png'),
                       wx.BITMAP_TYPE_PNG).ConvertToBitmap()
        self.moveUp = wx.BitmapButton(self, -1, bmp)
        if sys.platform in ('win32', 'win64'):
            bmp = wx.Image(
                os.path.join(resourcePath, 'gui/icons/16x16/upDisabled.png'),
                wx.BITMAP_TYPE_PNG).ConvertToBitmap()
            self.moveUp.SetBitmapDisabled(bmp)
        self.moveUp.SetToolTip(
            wx.ToolTip(
                'Left click to move row up. Right click to move row to top.'))

        bmp = wx.Image(os.path.join(resourcePath, 'gui/icons/16x16/down.png'),
                       wx.BITMAP_TYPE_PNG).ConvertToBitmap()
        self.moveDown = wx.BitmapButton(self, -1, bmp)
        if sys.platform in ('win32', 'win64'):
            bmp = wx.Image(
                os.path.join(resourcePath, 'gui/icons/16x16/downDisabled.png'),
                wx.BITMAP_TYPE_PNG).ConvertToBitmap()
            self.moveDown.SetBitmapDisabled(bmp)
        self.moveDown.SetToolTip(
            wx.ToolTip(
                'Left click to move row down. Right click to move row to bottom.'
            ))

        bmp = wx.Image(os.path.join(resourcePath, 'gui/icons/16x16/sort.png'),
                       wx.BITMAP_TYPE_PNG).ConvertToBitmap()
        self.sort = wx.BitmapButton(self, -1, bmp)
        if sys.platform in ('win32', 'win64'):
            bmp = wx.Image(
                os.path.join(resourcePath, 'gui/icons/16x16/sortDisabled.png'),
                wx.BITMAP_TYPE_PNG).ConvertToBitmap()
            self.sort.SetBitmapDisabled(bmp)
        self.sort.SetToolTip(
            wx.ToolTip(
                'Left click to sort in ascending order. Right click for descending order.'
            ))

        bmp = wx.Image(os.path.join(resourcePath, 'gui/icons/16x16/scale.png'),
                       wx.BITMAP_TYPE_PNG).ConvertToBitmap()
        self.autoSize = wx.BitmapButton(self, -1, bmp)
        if sys.platform in ('win32', 'win64'):
            bmp = wx.Image(
                os.path.join(resourcePath,
                             'gui/icons/16x16/scaleDisabled.png'),
                wx.BITMAP_TYPE_PNG).ConvertToBitmap()
            self.autoSize.SetBitmapDisabled(bmp)
        self.autoSize.SetToolTip(wx.ToolTip('Auto size cells.'))

        bmp = wx.Image(
            os.path.join(resourcePath, 'gui/icons/16x16/system-search.png'),
            wx.BITMAP_TYPE_PNG).ConvertToBitmap()
        self.expand = GenBitmapToggleButton(self,
                                            -1,
                                            bmp,
                                            size=self.autoSize.GetSize())
        self.expand.SetToolTip(wx.ToolTip('Show/hide optional fields.'))

        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(self.insert)
        sizer.Add(self.delete)
        sizer.Add(self.moveUp)
        sizer.Add(self.moveDown)
        sizer.Add(self.sort)
        sizer.Add(self.autoSize)
        sizer.Add(self.expand)
        self.SetSizer(sizer)
        self.setCellSelectedState()
示例#13
0
 def _addPrinterButton(self, image_name, next_page):
     printer = GenBitmapToggleButton(self, -1, getBitmap(image_name))
     self.GetSizer().Add(printer, pos=(2 + int(len(self._printers) / 2), len(self._printers) % 2))
     printer.Bind(wx.EVT_BUTTON, self._onPrinterSelect)
     printer.next_page = next_page
     self._printers.append(printer)
class ImageTool(object):
        def __init__(self, imagepanel, sizer, bitmap, tooltip='', cursor=None,
                        untoggle=False, button=None):
                self.sizer = sizer
                self.imagepanel = imagepanel
                self.cursor = cursor
                if button is None:
                        self.button = GenBitmapToggleButton(self.imagepanel, -1, bitmap, size=(24, 24))
                else:
                        self.button = button
                self.untoggle = untoggle
                self.button.SetBezelWidth(3)
                if tooltip:
                        self.button.SetToolTip(wx.ToolTip(tooltip))
                self.sizer.Add(self.button, 0, wx.ALIGN_CENTER|wx.ALL, 3)
                self.button.Bind(wx.EVT_BUTTON, self.OnButton)

        #--------------------
        def OnButton(self, evt):
                if self.button.GetToggle():
                        if self.untoggle:
                                self.imagepanel.UntoggleTools(self)
                        if self.cursor is not None:
                                self.imagepanel.panel.SetCursor(self.cursor)
                        self.OnToggle(True)
                else:
                        self.imagepanel.panel.SetCursor(self.imagepanel.defaultcursor)
                        self.OnToggle(False)

        #--------------------
        def OnToggle(self, value):
                pass

        #--------------------
        def OnLeftClick(self, evt):
                pass

        #--------------------
        def OnShiftLeftClick(self, evt):
                pass

        #--------------------
        def OnRightClick(self, evt):
                pass

        #--------------------
        def OnShiftRightClick(self, evt):
                pass

        #--------------------
        def OnShiftCtrlRightClick(self, evt):
                pass

        #--------------------
        def OnMotion(self, evt, dc):
                return False

        #--------------------
        def getToolTipStrings(self, x, y, value):
                return []

        #--------------------
        def Draw(self, dc):
                pass