]>
Commit | Line | Data |
---|---|---|
13db99f1 RD |
1 | |
2 | import wx | |
3 | from wx.lib.art import flagart, img2pyartprov | |
4 | ||
5 | FlagArtProvider = None | |
6 | ||
7 | #---------------------------------------------------------------------- | |
8 | ||
9 | class TestPanel(wx.Panel): | |
10 | def __init__(self, parent, log): | |
11 | self.log = log | |
12 | wx.Panel.__init__(self, parent, -1) | |
13 | ||
14 | sizer = wx.BoxSizer(wx.VERTICAL) | |
15 | self.SetSizer(sizer) | |
16 | ||
17 | title = wx.StaticText(self, -1, "Img2PyArtProvider") | |
18 | title.SetFont(wx.Font(18, wx.SWISS, wx.NORMAL, wx.BOLD)) | |
19 | sizer.Add(title, 0, wx.ALIGN_CENTRE|wx.ALL, 5) | |
20 | ||
21 | line = wx.StaticLine(self, -1, size=(20,-1), style=wx.LI_HORIZONTAL) | |
22 | sizer.Add(line, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5) | |
23 | sizer.Add((20,20)) | |
24 | ||
25 | box = wx.BoxSizer(wx.HORIZONTAL) | |
26 | ch = wx.ComboBox(self, -1, 'BLANK', choices=flagart.index, | |
27 | style=wx.CB_DROPDOWN|wx.CB_READONLY) | |
28 | self.Bind(wx.EVT_COMBOBOX, self.OnSelectCountry, ch) | |
29 | box.Add(ch, 0, wx.ALIGN_CENTER_VERTICAL) | |
30 | box.Add((50,10)) | |
31 | ||
32 | bmp = wx.EmptyBitmap(32,22) | |
33 | self.bmpFlag = wx.StaticBitmap(self, -1, bmp) | |
34 | box.Add(self.bmpFlag, 0, wx.ALIGN_CENTER_VERTICAL) | |
35 | ||
36 | sizer.Add(box, 0, wx.CENTER|wx.ALL, 10) | |
37 | ||
38 | self.country = 'BLANK' | |
39 | global FlagArtProvider | |
40 | if FlagArtProvider is None: | |
41 | FlagArtProvider = img2pyartprov.Img2PyArtProvider(flagart, | |
42 | artIdPrefix='wx.ART_') | |
43 | wx.ArtProvider.Push(FlagArtProvider) | |
44 | ||
45 | self.getArt() | |
46 | ||
47 | ||
48 | def OnSelectCountry(self, evt): | |
49 | self.log.write("OnSelectCountry\n") | |
50 | self.country = evt.GetString() | |
51 | self.getArt() | |
52 | ||
53 | ||
54 | def getArt(self): | |
55 | bmp = wx.ArtProvider.GetBitmap('wx.ART_'+self.country, wx.ART_OTHER, (32,22)) | |
56 | if not bmp.Ok(): | |
57 | bmp = wx.EmptyBitmap(32,22) | |
58 | self.clearBmp(bmp) | |
59 | self.bmpFlag.SetBitmap(bmp) | |
60 | ||
61 | ||
62 | def clearBmp(self, bmp): | |
63 | dc = wx.MemoryDC() | |
64 | dc.SelectObject(bmp) | |
65 | dc.SetBackground(wx.Brush("white")) | |
66 | dc.Clear() | |
67 | ||
68 | #---------------------------------------------------------------------- | |
69 | ||
70 | def runTest(frame, nb, log): | |
71 | win = TestPanel(nb, log) | |
72 | return win | |
73 | ||
74 | #---------------------------------------------------------------------- | |
75 | ||
76 | ||
77 | ||
78 | overview = """<html><body> | |
79 | <h2><center>Img2PyArtProvider</center></h2> | |
80 | ||
81 | Img2PyArtProvider is an ArtProvider class that publishes images from | |
82 | modules generated by img2py. | |
83 | ||
84 | <p> | |
85 | This sample shows how to access the flag images in wx.lib.art.flagart | |
86 | via the ArtProvider. | |
87 | ||
88 | ||
89 | </body></html> | |
90 | """ | |
91 | ||
92 | ||
93 | ||
94 | if __name__ == '__main__': | |
95 | import sys,os | |
96 | import run | |
97 | run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:]) | |
98 |