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