def OnToggleBackground(self, event):
     """Toggle the backgroundBitmap"""
     if self.GetBackgroundColour() == wx.WHITE:
         bgBmp = wx.Bitmap(gImgDir + os.sep + 'seamless' + os.sep + 'metalgriddark506x264.png', wx.BITMAP_TYPE_PNG)
         self.SetBackgroundColour('#2C2C2C')
     else:
         bgBmp = wx.Bitmap(gImgDir + os.sep + 'seamless' + os.sep + 'transparentbackground32.png', wx.BITMAP_TYPE_PNG)
         self.SetBackgroundColour(wx.WHITE)
     self.backgroundBitmap = SBB.MakeDisplaySizeBackgroundBitmap(bgBmp)
     [child.SetParentBackgroundBitmap(self.backgroundBitmap)
         for child in self.GetChildren() if isinstance(child, SBB.ShapedBitmapButton)]
     self.Refresh()
    def __init__(self, parent, id=wx.ID_ANY,
                 pos=wx.DefaultPosition, size=wx.DefaultSize,
                 style=wx.BORDER_SUNKEN, name='panel'):
        wx.Panel.__init__(self, parent, id, pos, size, style, name)

        # Drawing performance is faster with a tilable bitmap about
        # the same size as what you are going to tile(In this case, the panel).
        # It also helps to optimize the images(reduce size/retain quality)
        # with a application such as FileOptimizer
        ## bgBmp = wx.Bitmap(gImgDir + os.sep + 'seamless' + os.sep + 'metalgriddark46x24.png', wx.BITMAP_TYPE_PNG)
        bgBmp = wx.Bitmap(gImgDir + os.sep + 'seamless' + os.sep + 'metalgriddark506x264.png', wx.BITMAP_TYPE_PNG)
        self.backgroundBitmap = SBB.MakeDisplaySizeBackgroundBitmap(bgBmp)
        # Slight flicker is less noticable at the edge when resizing if you use
        # a colour used most/close in the bitmap.
        self.SetBackgroundColour('#2C2C2C')
        ## self.SetBackgroundColour(wx.BLACK)

        ## self.backgroundBitmap = wx.Bitmap(gImgDir + os.sep + 'seamless' + os.sep + 'transparentbackground32.png', wx.BITMAP_TYPE_PNG)
        ## self.SetBackgroundColour(wx.WHITE)

        ## self.SetDoubleBuffered(True)

        s1, s2 = 32, 32
        img1 = wx.Image(gImgDir + os.sep + 'shapedbutton-normal.png').Rescale(s1, s2)
        img2 = wx.Image(gImgDir + os.sep + 'shapedbutton-pressed.png').Rescale(s1, s2)
        img3 = wx.Image(gImgDir + os.sep + 'shapedbutton-hover.png').Rescale(s1, s2)
        img4 = wx.Image(gImgDir + os.sep + 'shapedbutton-disabled.png').Rescale(s1, s2)
        bmp1 = img1.ConvertToBitmap()
        bmp2 = img2.ConvertToBitmap()
        bmp3 = img3.ConvertToBitmap()
        bmp4 = img4.ConvertToBitmap()

        self.Bind(wx.EVT_PAINT, self.OnPaint)

        p = 1
        b = 5
        flags = wx.EXPAND | wx.ALL

        hbSizer = wx.BoxSizer(wx.HORIZONTAL)
        for i in range(10):
            btn = SBB.ShapedBitmapButton(self, -1,
                bitmap=bmp1,
                pressedBmp=bmp2,
                hoverBmp=bmp3,
                disabledBmp=bmp4,
                parentBgBmp=self.backgroundBitmap
                )
            btn.Bind(wx.EVT_BUTTON, self.OnToggleBackground)
            hbSizer.Add(btn, p, flags, b)

        self.SetSizer(hbSizer)
示例#3
0
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, -1)

        self.backgroundBitmap = SBB.MakeDisplaySizeBackgroundBitmap(seamless.GetBitmap())

        gSizer = wx.GridSizer(rows=2, cols=3, vgap=15, hgap=15)

        for i in range(3):
            sButton = SBB.ShapedBitmapButton(self, -1,
                bitmap=shapedbitmapbutton_normal.GetBitmap(),
                pressedBmp=shapedbitmapbutton_pressed.GetBitmap(),
                hoverBmp=shapedbitmapbutton_hover.GetBitmap(),
                parentBgBmp=self.backgroundBitmap,
                label='Undo', labelForeColour=wx.WHITE,
                labelRotation=27.0, labelPosition=(2, 14),
                labelFont=wx.Font(11, wx.FONTFAMILY_DEFAULT,
                                     wx.FONTSTYLE_NORMAL,
                                     wx.FONTWEIGHT_BOLD),
                # style=wx.BORDER_SIMPLE # Show the Rect
                    # | wx.WANTS_CHARS # Don't Eat Enter/Return Key
                    )

            # sButton = wx.Button(self, -1, 'Button %s' % i, style=wx.BORDER_SIMPLE|wx.WANTS_CHARS)
            if i == 1:
                sButton.Rotate180()
                sButton.SetLabel('Redo')
                sButton.SetLabelPosition((20, 22))
            if i == 2:
                sButton.SetLabel('Timer')
                sButton.SetLabelPosition((2, 16))

            sButton.Bind(wx.EVT_BUTTON, self.OnButton)
            sButton.Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
            gSizer.Add(sButton, 0, wx.ALIGN_CENTER | wx.ALL, 15)

        sButton.Bind(wx.EVT_TIMER, self.OnTimer)
        sButton.timer = wx.Timer(sButton)
        sButton.timer.Start(500)  # Every half a second.

        for i in range(3):
            sButton = SBB.ShapedBitmapButton(self, -1,
                bitmap=shapedbitmapbutton_normal.GetBitmap(),
                pressedBmp=shapedbitmapbutton_pressed.GetBitmap(),
                hoverBmp=shapedbitmapbutton_hover.GetBitmap(),
                parentBgBmp=self.backgroundBitmap,
                # style=wx.BORDER_SIMPLE # Show the Rect
                    # | wx.WANTS_CHARS # Don't Eat Enter/Return Key
                    )

            if i == 0:
                sButton.Mirror()
            if i == 1:
                sButton.Rotate90()
            if i == 2:
                sButton.SetToolTip(wx.ToolTip('I have a ToolTip!'))

            sButton.Bind(wx.EVT_BUTTON, self.OnButton)
            sButton.Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
            gSizer.Add(sButton, 0, wx.ALIGN_CENTER | wx.ALL, 15)

        self.SetSizer(gSizer)
        self.Fit()
        # self.SetAutoLayout(True)

        # wx.CallAfter(sButton.SetSize, (32, 128))

        self.Bind(wx.EVT_PAINT, self.OnPaint)
        self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
示例#4
0
    def __init__(self, parent, log=sys.stdout):
        self.log = log
        wx.Panel.__init__(self, parent, -1)
        self.SetDoubleBuffered(True)

        self.SetBackgroundColour(wx.WHITE)
        # self.SetBackgroundColour(wx.BLUE)
        # bgBmp = wx.Bitmap(gImgDir + os.sep + 'seamless' + os.sep + 'transparentbackground32.png', wx.BITMAP_TYPE_PNG)
        bgBmp = wx.Bitmap(
            gImgDir + os.sep + 'seamless' + os.sep + 'metalgriddark46x24.png',
            wx.BITMAP_TYPE_PNG)
        self.backgroundBitmap = SBB.MakeDisplaySizeBackgroundBitmap(bgBmp)

        #self.Refresh()
        bmp1 = wx.Bitmap(gImgDir + os.sep + 'shapedbutton-normal.png')
        bmp2 = wx.Bitmap(gImgDir + os.sep + 'shapedbutton-pressed.png')
        bmp3 = wx.Bitmap(gImgDir + os.sep + 'shapedbutton-hover.png')
        bmp4 = wx.Bitmap(gImgDir + os.sep + 'shapedbutton-disabled.png')
        fnt = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
        fnt.SetWeight(wx.FONTWEIGHT_BOLD)
        fnt.SetStyle(wx.FONTSTYLE_ITALIC)
        fnt.SetPointSize(11)
        print(
            'WillLabelTextFitInsideButton',
            SBB.ShapedBitmapButtonAdv.WillLabelTextFitInsideButton(
                bmp1, 'Test' * 10))
        self.ctrl1 = SBB.ShapedBitmapButtonAdv(
            self,
            -1,
            bitmap=bmp1,
            pressedBmp=bmp2,
            hoverBmp=bmp3,
            disabledBmp=bmp4,
            parentBgBmp=self.backgroundBitmap,
            label='>-Arrow->',
            # label='Multi\nLine\nlabel',
            # labelRotation=20,
            # labelPosition=(5, 64),
            labelFont=fnt,
            # labelBackgroundMode=wx.SOLID,
            name='arrow')

        self.ctrl1cld = SBB.ShapedBitmapButtonAdv(
            self.ctrl1,
            -1,
            bitmap=wx.Bitmap(gImgDir + os.sep + 'arrowcenterdot32.png'),
            pressedBmp=wx.Bitmap(gImgDir + os.sep +
                                 'arrowcenterdot32-pressed.png'),
            hoverBmp=wx.Bitmap(gImgDir + os.sep +
                               'arrowcenterdot32-hover.png'),
            disabledBmp=wx.Bitmap(gImgDir + os.sep +
                                  'arrowcenterdot32-disabled.png'),
            # parentBgBmp=self.backgroundBitmap
            pos=(50, 50),
            name='dot')

        # bgColor = wx.CallAfter(self.GetBackgroundColour)
        # wx.CallAfter(self.ctrl.SetBackgroundColour, bgColor)
        # wx.CallAfter(self.ctrl.Refresh)
        # wx.CallAfter(self.ctrl.UpdateBackgroundColourFromParent)

        # self.ctrl2 = wx.Button(self, -1, "AnimatedMove Ctrl To Pos", (50, 50))
        # self.ctrl2 = wx.StaticBitmap(self, -1, wx.Bitmap(gImgDir + os.sep + "phoenix128.png"), (150, 150))
        self.ctrl2 = SBB.ShapedBitmapButtonAdv(
            self,
            -1,
            bitmap=wx.Bitmap(gImgDir + os.sep + "phoenix128.png"),
            #pressedBmp=bmp2,
            hoverBmp=wx.Bitmap(gImgDir + os.sep + "phoenix128-hover.png"),
            #disabledBmp=bmp4,
            parentBgBmp=self.backgroundBitmap,
            pos=(100, 75),
            name='phoenix')
        self.ctrl2.SetLabelsList(
            labelsList=['wxPython %s' % wx.version(), 'rotated', 'test'],
            coords=[(0, 0), (64, 64), (0, 100)],
            foregrounds=[wx.RED, wx.BLUE, wx.GREEN],
            backgrounds=[
                wx.LIGHT_GREY, wx.TransparentColour,
                wx.Colour(255, 128, 0)
            ],
            fonts=[fnt, fnt, fnt],
            rotations=[0.0, 45.0, 0.0])

        self.ctrl3 = SBB.ShapedBitmapButtonAdv(
            self,
            -1,
            bitmap=wx.Bitmap(gImgDir + os.sep + "bigcheck128.png"),
            pressedBmp=wx.Bitmap(gImgDir + os.sep + "bigcheck128-pressed.png"),
            hoverBmp=wx.Bitmap(gImgDir + os.sep + "bigcheck128-hover.png"),
            disabledBmp=wx.Bitmap(gImgDir + os.sep +
                                  "bigcheck128-disabled.png"),
            parentBgBmp=self.backgroundBitmap,
            pos=(100, 200),
            name='bigcheck',
            ## style=wx.BORDER
        )

        # mdc = wx.MemoryDC(wx.EmptyBitmap(100, 32))
        # mdc.Clear()
        # transBmp = mdc.GetAsBitmap(wx.Rect(0, 0, 100, 32))
        self.ctrl4 = SBB.ShapedBitmapButtonAdv(
            self,
            -1,
            # bitmap=wx.Bitmap(gImgDir + os.sep + "transparentpixel.png").ConvertToImage().Rescale(100, 32).ConvertToBitmap(),
            bitmap=wx.Bitmap(gImgDir + os.sep +
                             "transparent16.png").ConvertToImage().Rescale(
                                 100, 32).ConvertToBitmap(),
            # pressedBmp=wx.Bitmap(gImgDir + os.sep + "bigcheck128-pressed.png"),
            hoverBmp=wx.Bitmap(gImgDir + os.sep +
                               "menu_hover16.png").ConvertToImage().Rescale(
                                   100, 32).ConvertToBitmap(),
            # disabledBmp=wx.Bitmap(gImgDir + os.sep + "bigcheck128-disabled.png"),
            parentBgBmp=self.backgroundBitmap,
            pos=(250, 200),
            label='File',
            labelForeColour=wx.BLUE,
            name='file menu',
            ## style=wx.BORDER
        )

        self.ctrl1.Bind(wx.EVT_BUTTON, self.OnButton)
        self.ctrl2.Bind(wx.EVT_BUTTON, self.OnButton)
        self.ctrl3.Bind(wx.EVT_BUTTON, self.OnButton)
        self.ctrl1.SetDoubleBuffered(True)
        self.ctrl2.SetDoubleBuffered(True)
        self.ctrl3.SetDoubleBuffered(True)

        self.Bind(wx.EVT_LEFT_UP, self.AnimatedMoveCtrlToPos)
        self.Bind(wx.EVT_MIDDLE_UP, self.AnimatedMoveCtrlToPos)
        self.Bind(wx.EVT_RIGHT_UP, self.AnimatedMoveCtrlToPos)
        self.Bind(wx.EVT_PAINT, self.OnPaint)

        # Tests to see events passing through the alpha region in the shapedbitmapbuttons
        self_Bind = self.Bind
        # self_Bind(wx.EVT_MOTION, self.OnMotion)
        self_Bind(wx.EVT_MOUSEWHEEL, self.OnMouseWheel)
        self_Bind(wx.EVT_MIDDLE_DOWN, self.OnMiddleDown)