File: Img2PyArtProvider.py

package info (click to toggle)
wxpython3.0 3.0.1.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 481,208 kB
  • ctags: 520,541
  • sloc: cpp: 2,126,470; python: 293,214; makefile: 51,927; ansic: 19,032; sh: 3,011; xml: 1,629; perl: 17
file content (98 lines) | stat: -rw-r--r-- 2,771 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98

import wx
from wx.lib.art import flagart, img2pyartprov

FlagArtProvider = None

#----------------------------------------------------------------------

class TestPanel(wx.Panel):
    def __init__(self, parent, log):
        self.log = log
        wx.Panel.__init__(self, parent, -1)
        
        sizer = wx.BoxSizer(wx.VERTICAL)
        self.SetSizer(sizer)
        
        title = wx.StaticText(self, -1, "Img2PyArtProvider")
        title.SetFont(wx.Font(18, wx.SWISS, wx.NORMAL, wx.BOLD))
        sizer.Add(title, 0, wx.ALIGN_CENTRE|wx.ALL, 5)

        line = wx.StaticLine(self, -1, size=(20,-1), style=wx.LI_HORIZONTAL)
        sizer.Add(line, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
        sizer.Add((20,20))

        box = wx.BoxSizer(wx.HORIZONTAL)
        ch = wx.ComboBox(self, -1, 'BLANK', choices=flagart.index,
                         style=wx.CB_DROPDOWN|wx.CB_READONLY)
        self.Bind(wx.EVT_COMBOBOX, self.OnSelectCountry, ch)
        box.Add(ch, 0,  wx.ALIGN_CENTER_VERTICAL)
        box.Add((50,10))

        bmp = wx.EmptyBitmap(32,22)
        self.bmpFlag = wx.StaticBitmap(self, -1, bmp)
        box.Add(self.bmpFlag, 0, wx.ALIGN_CENTER_VERTICAL)
        
        sizer.Add(box, 0, wx.CENTER|wx.ALL, 10)
        
        self.country = 'BLANK'
        global FlagArtProvider
        if FlagArtProvider is None:
            FlagArtProvider = img2pyartprov.Img2PyArtProvider(flagart,
                                                              artIdPrefix='wx.ART_')
            wx.ArtProvider.Push(FlagArtProvider)

        self.getArt()

        
    def OnSelectCountry(self, evt):
        self.log.write("OnSelectCountry\n")
        self.country = evt.GetString()
        self.getArt()


    def getArt(self):
        bmp = wx.ArtProvider.GetBitmap('wx.ART_'+self.country, wx.ART_OTHER, (32,22))
        if not bmp.Ok():
            bmp = wx.EmptyBitmap(32,22)
            self.clearBmp(bmp)
        self.bmpFlag.SetBitmap(bmp)
        

    def clearBmp(self, bmp):
        dc = wx.MemoryDC()
        dc.SelectObject(bmp)
        dc.SetBackground(wx.Brush("white"))
        dc.Clear()
 
#----------------------------------------------------------------------

def runTest(frame, nb, log):
    win = TestPanel(nb, log)
    return win

#----------------------------------------------------------------------



overview = """<html><body>
<h2><center>Img2PyArtProvider</center></h2>

Img2PyArtProvider is an ArtProvider class that publishes images from
modules generated by img2py.

<p>
This sample shows how to access the flag images in wx.lib.art.flagart
via the ArtProvider.


</body></html>
"""



if __name__ == '__main__':
    import sys,os
    import run
    run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])