]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/BitmapButton.py
fix for self.root == None
[wxWidgets.git] / wxPython / demo / BitmapButton.py
1
2 import wx
3 import images
4
5 #----------------------------------------------------------------------
6
7 class 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)
22 mask = wx.MaskColour(bmp, wx.BLUE)
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()
29 mask = wx.MaskColour(bmp, wx.BLUE)
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
44 def runTest(frame, nb, log):
45 win = TestPanel(nb, log)
46 return win
47
48 #----------------------------------------------------------------------
49
50
51 overview = """<html><body>
52 <h2>BitmapButton</h2>
53
54 <p>A BitmapButton control displays a bitmap. It can have a separate bitmap for each button state: normal, selected, disabled.</p>
55
56 <p>The bitmaps to be displayed should have a small number of colours, such as 16,
57 to 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
66 if __name__ == '__main__':
67 import sys,os
68 import run
69 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
70