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) bmp1 = wx.Bitmap(gImgDir + os.sep + 'shapedbutton-normal64x40.png') bmp2 = wx.Bitmap(gImgDir + os.sep + 'shapedbutton-pressed64x40.png') bmp3 = wx.Bitmap(gImgDir + os.sep + 'shapedbutton-hover64x40.png') bmp4 = None p = 1 b = 5 flags = wx.EXPAND | wx.ALL try: hbSizer = wx.WrapSizer(wx.HORIZONTAL) except Exception: hbSizer = wx.BoxSizer(wx.HORIZONTAL) for i in range(49): btn = SBB.ShapedBitmapButton(self, -1, bitmap=bmp1, pressedBmp=bmp2, hoverBmp=bmp3, disabledBmp=bmp4) btn.Bind(wx.EVT_BUTTON, self.OnToggleBackground) hbSizer.Add(btn, p, flags, b) self.SetSizer(hbSizer)
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) bmp1 = wx.Bitmap(gImgDir + os.sep + 'snakey_outline128.png') bmp2 = wx.Bitmap(gImgDir + os.sep + 'snakey_outline_pressed128.png') bmp3 = wx.Bitmap(gImgDir + os.sep + 'snakey_outline_hover128.png') bmp4 = wx.Bitmap(gImgDir + os.sep + 'snakey_skin96.png') bmp5 = wx.Bitmap(gImgDir + os.sep + 'snakey_skin_pressed96.png') bmp6 = wx.Bitmap(gImgDir + os.sep + 'snakey_skin_hover96.png') # bmp4 = wx.Bitmap(gImgDir + os.sep + 'arrowcenterdot32.png') # bmp5 = wx.Bitmap(gImgDir + os.sep + 'arrowcenterdot32-pressed.png') # bmp6 = wx.Bitmap(gImgDir + os.sep + 'arrowcenterdot32-hover.png') btn1 = SBB.ShapedBitmapButton(self, -1, bitmap=bmp1, pressedBmp=bmp2, hoverBmp=bmp3, pos=(50, 50), style=wx.BORDER_SIMPLE) btn1.Bind(wx.EVT_BUTTON, self.OnToggleBackground) btn1.MakeChildBmp() btn2 = SBB.ShapedBitmapButton(btn1, -1, bitmap=bmp4, pressedBmp=bmp5, hoverBmp=bmp6, pos=(16, 16)) # Don't btn2.Bind(wx.EVT_BUTTON, self.OnToggleBackground) # btn1 = SBB.ShapedBitmapButton(self, -1, bitmap=bmp1) # btn1.Bind(wx.EVT_BUTTON, self.OnToggleBackground) self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
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) 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 + 'arrowcenterdot32.png') bmp5 = wx.Bitmap(gImgDir + os.sep + 'arrowcenterdot32-pressed.png') bmp6 = wx.Bitmap(gImgDir + os.sep + 'arrowcenterdot32-hover.png') btn1 = SBB.ShapedBitmapButton(self, -1, bitmap=bmp1, pressedBmp=bmp2, hoverBmp=bmp3, pos=(50, 50)) btn1.Bind(wx.EVT_BUTTON, self.OnToggleBackground) btn1.MakeChildBmp() btn2 = SBB.ShapedBitmapButton(btn1, -1, bitmap=bmp4, pressedBmp=bmp5, hoverBmp=bmp6, pos=(50, 50)) btn2.Bind(wx.EVT_BUTTON, self.OnClick) btn3 = SBB.ShapedBitmapButton(btn1, -1, bitmap=bmp4, pressedBmp=bmp5, hoverBmp=bmp6, pos=(10, 10)) btn3.Bind(wx.EVT_BUTTON, self.OnClick)
def __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition, size=(512, 160), style=wx.BORDER_SUNKEN, name='panel'): wx.Panel.__init__(self, parent, id, pos, size, style, name) sBmp = wx.Bitmap(gImgDir + os.sep + 'bigx128.png') sz = self.GetSize() button1 = SBB.ShapedBitmapButton( self, -1, bitmap=sBmp, pressedBmp=wx.Bitmap(gImgDir + os.sep + 'bigx128-pressed.png'), hoverBmp=wx.Bitmap(gImgDir + os.sep + 'bigx128-hover.png'), disabledBmp=wx.Bitmap(gImgDir + os.sep + 'bigx128-disabled.png'), pos=(sz[0] // 3, sz[1] // 2 - sBmp.GetHeight() // 2), size=(128, 128)) button1.SetToolTip(wx.ToolTip('%s' % self.__doc__)) button2 = SBB.ShapedBitmapButton( self, -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'), pos=(45, 25), style=wx.NO_BORDER | wx.WANTS_CHARS) button1.Bind(wx.EVT_BUTTON, self.OnButton) button2.Bind(wx.EVT_BUTTON, self.OnButton) # self.Bind(wx.EVT_CONTEXT_MENU, self.OnRightUp) self.Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
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)
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)
def __init__(self, parent, log): self.log = log wx.Frame.__init__(self, parent, -1, "Shaped Window", style=wx.FRAME_SHAPED | wx.FRAME_NO_TASKBAR | wx.STAY_ON_TOP) self.hasShape = False self.delta = (0, 0) self.Bind(wx.EVT_LEFT_DCLICK, self.OnDoubleClick) self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown) self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp) self.Bind(wx.EVT_MOTION, self.OnMouseMove) self.Bind(wx.EVT_RIGHT_UP, self.OnExit) self.Bind(wx.EVT_PAINT, self.OnPaint) self.bmp = wx.Bitmap(gImgDir + os.sep + 'shapedframe.png', wx.BITMAP_TYPE_PNG) w, h = self.bmp.GetWidth(), self.bmp.GetHeight() self.SetClientSize((w, h)) if wx.Platform != "__WXMAC__": # wxMac clips the tooltip to the window shape, YUCK!!! self.SetToolTip( wx.ToolTip( "Right-click to close the window\n" "Double-click the image to set/unset the window shape")) if wx.Platform == "__WXGTK__": # wxGTK requires that the window be created before you can # set its shape, so delay the call to SetWindowShape until # this event. self.Bind(wx.EVT_WINDOW_CREATE, self.SetWindowShape) else: # On wxMSW and wxMac the window has already been created, so go for it. self.SetWindowShape() dc = wx.ClientDC(self) dc.DrawBitmap(self.bmp, 0, 0, True) #----- Start ShapedBitmapButton Stuff -----# bmp1 = wx.Bitmap(gImgDir + os.sep + 'shapedbutton-normal64x40.png') bmp2 = wx.Bitmap(gImgDir + os.sep + 'shapedbutton-pressed64x40.png') bmp3 = wx.Bitmap(gImgDir + os.sep + 'shapedbutton-hover64x40.png') sbbtn1 = SBB.ShapedBitmapButton(self, -1, bitmap=bmp1, pressedBmp=bmp2, hoverBmp=bmp3, disabledBmp=None, parentBgBmp=self.bmp, pos=(104, 10)) img1 = wx.Image(gImgDir + os.sep + 'shapedbutton-hover64x40.png').Rotate90().Mirror(True) img2 = wx.Image(gImgDir + os.sep + 'shapedbutton-normal64x40.png').Rotate90().Mirror(True) img3 = wx.Image(gImgDir + os.sep + 'shapedbutton-pressed64x40.png').Rotate90().Mirror( True) bmp1 = img1.ConvertToBitmap() bmp2 = img2.ConvertToBitmap() bmp3 = img3.ConvertToBitmap() sbbtn2 = SBB.ShapedBitmapButton(self, -1, bitmap=bmp1, pressedBmp=bmp2, hoverBmp=bmp3, disabledBmp=None, parentBgBmp=self.bmp, pos=(10, 104)) sbbtn3 = SBB.ShapedBitmapButton( 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.bmp, pos=(48, 200), # style=wx.BORDER_SIMPLE | wx.WANTS_CHARS ) sbbtn4 = SBB.ShapedBitmapButton( self, -1, bitmap=wx.Bitmap(gImgDir + os.sep + 'shapedbutton-normal.png'), pressedBmp=wx.Bitmap(gImgDir + os.sep + 'shapedbutton-pressed.png'), hoverBmp=wx.Bitmap(gImgDir + os.sep + 'shapedbutton-hover.png'), disabledBmp=wx.Bitmap(gImgDir + os.sep + 'shapedbutton-disabled.png'), parentBgBmp=self.bmp, label='New Widget', # labelColour=wx.WHITE, labelRotation=27.0, labelPosition=(4, 68), labelFont=wx.Font(11, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD), pos=(192, 200), # style=wx.BORDER_SIMPLE ) sbbtn4.SetToolTip(wx.ToolTip('This is a ShapedBitmapButton.')) sbbtn4.Bind(wx.EVT_TIMER, self.OnTimer) sbbtn4.timer = wx.Timer(sbbtn4) sbbtn4.timer.Start(500) # Every half a second. sbbtn5 = SBB.ShapedBitmapButton( self, wx.ID_CLOSE, bitmap=wx.Bitmap(gImgDir + os.sep + 'bigx128.png'), pressedBmp=wx.Bitmap(gImgDir + os.sep + 'bigx128-pressed.png'), hoverBmp=wx.Bitmap(gImgDir + os.sep + 'bigx128-hover.png'), disabledBmp=wx.Bitmap(gImgDir + os.sep + 'bigx128-disabled.png'), parentBgBmp=self.bmp, pos=(336, 200), # style=wx.BORDER_SIMPLE ) sbbtn6 = SBB.ShapedBitmapButton( self, -1, bitmap=wx.Bitmap(gImgDir + os.sep + 'shapedbitmapbutton_text_normal.png'), pressedBmp=wx.Bitmap(gImgDir + os.sep + 'shapedbitmapbutton_text_pressed.png'), hoverBmp=wx.Bitmap(gImgDir + os.sep + 'shapedbitmapbutton_text_hover.png'), parentBgBmp=self.bmp, pos=(176, 68), # style=wx.BORDER_SIMPLE ) # Lets bind all the ShapedBitmapButtons. for child in self.GetChildren(): child.Bind(wx.EVT_BUTTON, self.OnButton) self.Centre()
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) self.SetBackgroundColour(wx.GREEN) button1 = SBB.ShapedBitmapButton( self, -1, bitmap=wx.Bitmap(gImgDir + os.sep + 'shapedbutton-normal.png'), pressedBmp=wx.Bitmap(gImgDir + os.sep + 'shapedbutton-pressed.png'), hoverBmp=None, disabledBmp=wx.Bitmap(gImgDir + os.sep + 'shapedbutton-disabled.png'), style=wx.NO_BORDER | wx.WANTS_CHARS) button2 = SBB.ShapedBitmapButton( self, -1, bitmap=wx.Bitmap(gImgDir + os.sep + 'shapedbutton-normal.png'), pressedBmp=wx.Bitmap(gImgDir + os.sep + 'shapedbutton-pressed.png'), hoverBmp=wx.Bitmap(gImgDir + os.sep + 'shapedbutton-hover.png'), disabledBmp=wx.Bitmap(gImgDir + os.sep + 'shapedbutton-disabled.png'), label='Hello World!', labelPosition=(5, 67), labelRotation=24.0, labelFont=wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD), style=wx.BORDER_SIMPLE | wx.WANTS_CHARS) button3 = SBB.ShapedBitmapButton( self, -1, bitmap=wx.Bitmap(gImgDir + os.sep + 'shapedbutton-normal.png'), pressedBmp=wx.Bitmap(gImgDir + os.sep + 'shapedbutton-pressed.png'), hoverBmp=None, disabledBmp=wx.Bitmap(gImgDir + os.sep + 'shapedbutton-disabled.png'), style=wx.BORDER_NONE) button3.Disable() button4 = SBB.ShapedBitmapButton( self, -1, bitmap=wx.Bitmap(gImgDir + os.sep + 'shapedbutton-normal.png'), pressedBmp=wx.Bitmap(gImgDir + os.sep + 'shapedbutton-pressed.png'), hoverBmp=None, disabledBmp=None) button4.Disable() hbSizer = wx.BoxSizer(wx.HORIZONTAL) for btn in self.GetChildren(): btn.Bind(wx.EVT_BUTTON, self.OnRandomBackgroundColour) hbSizer.Add(btn, 1, wx.EXPAND | wx.ALL, 5) self.SetSizer(hbSizer)