]>
Commit | Line | Data |
---|---|---|
8b7fa2d9 RD |
1 | |
2 | import wx | |
3 | import images | |
4 | ||
28ff70c2 RD |
5 | #import wx.lib.buttons |
6 | #wx.BitmapButton = wx.lib.buttons.GenBitmapButton | |
7 | ||
8b7fa2d9 RD |
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) | |
d7403ad2 | 25 | mask = wx.Mask(bmp, wx.BLUE) |
8b7fa2d9 RD |
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() | |
d7403ad2 | 32 | mask = wx.Mask(bmp, wx.BLUE) |
8b7fa2d9 RD |
33 | |
34 | bmp.SetMask(mask) | |
02b800ce | 35 | b = wx.BitmapButton(self, -1, bmp, (20, 20), |
8b7fa2d9 RD |
36 | (bmp.GetWidth()+10, bmp.GetHeight()+10)) |
37 | b.SetToolTipString("This is a bitmap button.") | |
38 | self.Bind(wx.EVT_BUTTON, self.OnClick, b) | |
02b800ce RD |
39 | |
40 | b = wx.BitmapButton(self, -1, bmp, (20, 120), | |
28ff70c2 RD |
41 | style = wx.NO_BORDER) |
42 | ||
43 | # hide a little surprise in the button... | |
44 | b.SetBitmapSelected(images.getRobinBitmap()) | |
45 | ||
7748c15c | 46 | b.SetToolTipString("This is a bitmap button with \nwx.NO_BORDER style.") |
02b800ce | 47 | self.Bind(wx.EVT_BUTTON, self.OnClick, b) |
8b7fa2d9 RD |
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> | |
3c8ad70a | 64 | <h2>BitmapButton</h2> |
8b7fa2d9 | 65 | |
3c8ad70a | 66 | <p>A BitmapButton control displays a bitmap. It can have a separate bitmap for each button state: normal, selected, disabled.</p> |
8b7fa2d9 RD |
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 |