]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/BitmapButton.py
wxGTK2: gtk_signal_disconnect_by_func isn't used anywhere anymore. Nuke prototype...
[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.Mask(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.Mask(bmp, wx.BLUE)
30
31 bmp.SetMask(mask)
32 b = wx.BitmapButton(self, -1, 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 b = wx.BitmapButton(self, -1, bmp, (20, 120),
38 (bmp.GetWidth()+10, bmp.GetHeight()+10),
39 style = wx.NO_BORDER)
40 b.SetToolTipString("This is a bitmap button with \nwx.NO_BORDER style.")
41 self.Bind(wx.EVT_BUTTON, self.OnClick, b)
42
43
44 def OnClick(self, event):
45 self.log.write("Click! (%d)\n" % event.GetId())
46
47
48 #----------------------------------------------------------------------
49
50 def runTest(frame, nb, log):
51 win = TestPanel(nb, log)
52 return win
53
54 #----------------------------------------------------------------------
55
56
57 overview = """<html><body>
58 <h2>BitmapButton</h2>
59
60 <p>A BitmapButton control displays a bitmap. It can have a separate bitmap for each button state: normal, selected, disabled.</p>
61
62 <p>The bitmaps to be displayed should have a small number of colours, such as 16,
63 to avoid palette problems.</p>
64
65 <p>A bitmap can be derived from most image formats using the wx.Image class.</p>
66
67 </body></html>
68 """
69
70
71
72 if __name__ == '__main__':
73 import sys,os
74 import run
75 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
76