]>
Commit | Line | Data |
---|---|---|
1 | ||
2 | import wx | |
3 | ||
4 | #---------------------------------------------------------------------- | |
5 | ||
6 | class TestPanel(wx.Panel): | |
7 | def __init__(self, parent, log): | |
8 | self.log = log | |
9 | wx.Panel.__init__(self, parent, -1) | |
10 | ||
11 | box = wx.BoxSizer(wx.VERTICAL) | |
12 | title = wx.StaticText(self, -1, "Picker Controls") | |
13 | title.SetFont(wx.FFont(24, wx.FONTFAMILY_SWISS, wx.FONTFLAG_BOLD)) | |
14 | title.SetForegroundColour("navy") | |
15 | box.Add(title, 0, wx.ALIGN_CENTER|wx.ALL, 5) | |
16 | #print title.GetBestSize(), title.GetMinSize(), title.GetSize() | |
17 | ||
18 | box.Add(wx.StaticLine(self), 0, wx.EXPAND) | |
19 | ||
20 | fgs = wx.FlexGridSizer(cols=4, hgap=5, vgap=5) | |
21 | fgs.AddGrowableCol(3) | |
22 | fgs.Add((10,10)) # spacer | |
23 | lbl = wx.StaticText(self, -1, "default style") | |
24 | lbl.SetFont(wx.FFont(12, wx.FONTFAMILY_SWISS, wx.FONTFLAG_BOLD)) | |
25 | fgs.Add(lbl) | |
26 | fgs.Add((10,10)) # spacer | |
27 | lbl = wx.StaticText(self, -1, "with textctrl") | |
28 | lbl.SetFont(wx.FFont(12, wx.FONTFAMILY_SWISS, wx.FONTFLAG_BOLD)) | |
29 | fgs.Add(lbl, 0, wx.ALIGN_CENTER) | |
30 | ||
31 | fgs.Add(wx.StaticText(self, -1, "wx.ColourPickerCtrl:"), 0, wx.ALIGN_CENTER_VERTICAL) | |
32 | cp1 = wx.ColourPickerCtrl(self) | |
33 | fgs.Add(cp1, 0, wx.ALIGN_CENTER) | |
34 | fgs.Add((10,10)) # spacer | |
35 | cp2 = wx.ColourPickerCtrl(self, style=wx.CLRP_USE_TEXTCTRL) | |
36 | cp2.SetTextCtrlProportion(5) | |
37 | fgs.Add(cp2, 0, wx.EXPAND) | |
38 | self.Bind(wx.EVT_COLOURPICKER_CHANGED, self.OnPickColor, cp1) | |
39 | self.Bind(wx.EVT_COLOURPICKER_CHANGED, self.OnPickColor, cp2) | |
40 | ||
41 | fgs.Add(wx.StaticText(self, -1, "wx.DirPickerCtrl:"), 0, wx.ALIGN_CENTER_VERTICAL) | |
42 | dp1 = wx.DirPickerCtrl(self) | |
43 | fgs.Add(dp1, 0, wx.ALIGN_CENTER) | |
44 | fgs.Add((10,10)) # spacer | |
45 | dp2 = wx.DirPickerCtrl(self, style=wx.DIRP_USE_TEXTCTRL) | |
46 | dp2.SetTextCtrlProportion(2) | |
47 | fgs.Add(dp2, 0, wx.EXPAND) | |
48 | self.Bind(wx.EVT_DIRPICKER_CHANGED, self.OnPickFileDir, dp1) | |
49 | self.Bind(wx.EVT_DIRPICKER_CHANGED, self.OnPickFileDir, dp2) | |
50 | ||
51 | fgs.Add(wx.StaticText(self, -1, "wx.FilePickerCtrl:"), 0, wx.ALIGN_CENTER_VERTICAL) | |
52 | fp1 = wx.FilePickerCtrl(self) | |
53 | fgs.Add(fp1, 0, wx.ALIGN_CENTER) | |
54 | fgs.Add((10,10)) # spacer | |
55 | fp2 = wx.FilePickerCtrl(self, style=wx.FLP_USE_TEXTCTRL) | |
56 | fp2.SetTextCtrlProportion(2) | |
57 | fgs.Add(fp2, 0, wx.EXPAND) | |
58 | self.Bind(wx.EVT_FILEPICKER_CHANGED, self.OnPickFileDir, fp1) | |
59 | self.Bind(wx.EVT_FILEPICKER_CHANGED, self.OnPickFileDir, fp2) | |
60 | ||
61 | fgs.Add(wx.StaticText(self, -1, "wx.FontPickerCtrl:"), 0, wx.ALIGN_CENTER_VERTICAL) | |
62 | fnt1 = wx.FontPickerCtrl(self, style=wx.FNTP_FONTDESC_AS_LABEL) | |
63 | fgs.Add(fnt1, 0, wx.ALIGN_CENTER) | |
64 | fgs.Add((10,10)) # spacer | |
65 | fnt2 = wx.FontPickerCtrl(self, style=wx.FNTP_FONTDESC_AS_LABEL|wx.FNTP_USE_TEXTCTRL) | |
66 | fnt2.SetTextCtrlProportion(2) | |
67 | fgs.Add(fnt2, 0, wx.EXPAND) | |
68 | self.Bind(wx.EVT_FONTPICKER_CHANGED, self.OnPickFont, fnt1) | |
69 | self.Bind(wx.EVT_FONTPICKER_CHANGED, self.OnPickFont, fnt2) | |
70 | ||
71 | ||
72 | box.Add(fgs, 1, wx.EXPAND|wx.ALL, 5) | |
73 | self.SetSizer(box) | |
74 | ||
75 | ||
76 | def OnPickColor(self, evt): | |
77 | self.log.write("You chose: %s\n" % repr(evt.GetColour())) | |
78 | ||
79 | def OnPickFileDir(self, evt): | |
80 | self.log.write("You chose: %s\n" % repr(evt.GetPath())) | |
81 | ||
82 | def OnPickFont(self, evt): | |
83 | font = evt.GetFont() | |
84 | self.log.write("You chose: %s\n" % font.GetNativeFontInfoUserDesc()) | |
85 | ||
86 | #---------------------------------------------------------------------- | |
87 | ||
88 | def runTest(frame, nb, log): | |
89 | win = TestPanel(nb, log) | |
90 | return win | |
91 | ||
92 | #---------------------------------------------------------------------- | |
93 | ||
94 | ||
95 | ||
96 | overview = """<html><body> | |
97 | <h2><center>Picker Controls</center></h2> | |
98 | ||
99 | The Picker controls are either native or generic controls usually | |
100 | comprised of a button and with an optional text control next to it. | |
101 | The pickers enable the user to choose something using one of the | |
102 | common dialogs and then displays the result in some way. | |
103 | ||
104 | </body></html> | |
105 | """ | |
106 | ||
107 | ||
108 | ||
109 | if __name__ == '__main__': | |
110 | import sys,os | |
111 | import run | |
112 | run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:]) | |
113 |