]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/BitmapButton.py
updates
[wxWidgets.git] / wxPython / demo / BitmapButton.py
CommitLineData
8b7fa2d9
RD
1
2import wx
3import images
4
5#----------------------------------------------------------------------
6
7class TestPanel(wx.Panel):
8 def __init__(self, parent, log):
9 wx.Panel.__init__(self, parent, -1,
10 style=wx.NO_FULL_REPAINT_ON_RESIZE)
11 self.log = log
12
13 if 0: # a test case for catching wx.PyAssertionError
14
15 #wx.GetApp().SetAssertMode(wx.PYAPP_ASSERT_SUPPRESS)
16 #wx.GetApp().SetAssertMode(wx.PYAPP_ASSERT_EXCEPTION)
17 #wx.GetApp().SetAssertMode(wx.PYAPP_ASSERT_DIALOG)
18 #wx.GetApp().SetAssertMode(wx.PYAPP_ASSERT_EXCEPTION | wx.PYAPP_ASSERT_DIALOG)
19
20 try:
21 bmp = wx.Bitmap("nosuchfile.bmp", wx.BITMAP_TYPE_BMP)
d7403ad2 22 mask = wx.Mask(bmp, wx.BLUE)
8b7fa2d9
RD
23 except wx.PyAssertionError:
24 self.log.write("Caught wx.PyAssertionError! I will fix the problem.\n")
25 bmp = images.getTest2Bitmap()
26 mask = wx.MaskColour(bmp, wx.BLUE)
27 else:
28 bmp = images.getTest2Bitmap()
d7403ad2 29 mask = wx.Mask(bmp, wx.BLUE)
8b7fa2d9
RD
30
31 bmp.SetMask(mask)
32 b = wx.BitmapButton(self, 30, bmp, (20, 20),
33 (bmp.GetWidth()+10, bmp.GetHeight()+10))
34 b.SetToolTipString("This is a bitmap button.")
35 self.Bind(wx.EVT_BUTTON, self.OnClick, b)
36
37
38 def OnClick(self, event):
39 self.log.write("Click! (%d)\n" % event.GetId())
40
41
42#----------------------------------------------------------------------
43
44def runTest(frame, nb, log):
45 win = TestPanel(nb, log)
46 return win
47
48#----------------------------------------------------------------------
49
50
51overview = """<html><body>
3c8ad70a 52<h2>BitmapButton</h2>
8b7fa2d9 53
3c8ad70a 54<p>A BitmapButton control displays a bitmap. It can have a separate bitmap for each button state: normal, selected, disabled.</p>
8b7fa2d9
RD
55
56<p>The bitmaps to be displayed should have a small number of colours, such as 16,
57to avoid palette problems.</p>
58
59<p>A bitmap can be derived from most image formats using the wx.Image class.</p>
60
61</body></html>
62"""
63
64
65
66if __name__ == '__main__':
67 import sys,os
68 import run
69 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
70