]>
Commit | Line | Data |
---|---|---|
1 | # 11/20/2003 - Jeff Grimmett (grimmtooth@softhome.net) | |
2 | # | |
3 | # o Updated for wx namespace | |
4 | # | |
5 | # 11/30/2003 - Jeff Grimmett (grimmtooth@softhome.net) | |
6 | # | |
7 | # o Is it just me or are the graphics for the control not lining up right? | |
8 | # | |
9 | # 12/20/2003 - Jeff Grimmett (grimmtooth@softhome.net) | |
10 | # | |
11 | # o wxPopupControl -> PopupControl | |
12 | # | |
13 | ||
14 | import wx | |
15 | import wx.lib.popupctl as pop | |
16 | import wx.calendar as cal | |
17 | ||
18 | class TestDateControl(pop.PopupControl): | |
19 | def __init__(self,*_args,**_kwargs): | |
20 | apply(pop.PopupControl.__init__,(self,) + _args,_kwargs) | |
21 | ||
22 | self.win = wx.Window(self,-1,pos = (0,0),style = 0) | |
23 | self.cal = cal.CalendarCtrl(self.win,-1,pos = (0,0)) | |
24 | ||
25 | bz = self.cal.GetBestSize() | |
26 | self.win.SetSize(bz) | |
27 | ||
28 | # This method is needed to set the contents that will be displayed | |
29 | # in the popup | |
30 | self.SetPopupContent(self.win) | |
31 | ||
32 | # Event registration for date selection | |
33 | self.cal.Bind(cal.EVT_CALENDAR_DAY, self.OnCalSelected) | |
34 | ||
35 | # Method called when a day is selected in the calendar | |
36 | def OnCalSelected(self,evt): | |
37 | self.PopDown() | |
38 | date = self.cal.GetDate() | |
39 | ||
40 | # Format the date that was selected for the text part of the control | |
41 | self.SetValue('%02d/%02d/%04d' % (date.GetDay(), | |
42 | date.GetMonth()+1, | |
43 | date.GetYear())) | |
44 | evt.Skip() | |
45 | ||
46 | # Method overridden from PopupControl | |
47 | # This method is called just before the popup is displayed | |
48 | # Use this method to format any controls in the popup | |
49 | def FormatContent(self): | |
50 | # I parse the value in the text part to resemble the correct date in | |
51 | # the calendar control | |
52 | txtValue = self.GetValue() | |
53 | dmy = txtValue.split('/') | |
54 | didSet = False | |
55 | ||
56 | if len(dmy) == 3: | |
57 | date = self.cal.GetDate() | |
58 | d = int(dmy[0]) | |
59 | m = int(dmy[1]) - 1 | |
60 | y = int(dmy[2]) | |
61 | ||
62 | if d > 0 and d < 31: | |
63 | if m >= 0 and m < 12: | |
64 | if y > 1000: | |
65 | self.cal.SetDate(wx.DateTimeFromDMY(d,m,y)) | |
66 | didSet = True | |
67 | ||
68 | if not didSet: | |
69 | self.cal.SetDate(wx.DateTime_Today()) | |
70 | ||
71 | ||
72 | #--------------------------------------------------------------------------- | |
73 | ||
74 | class TestPanel(wx.Panel): | |
75 | def __init__(self, parent, log): | |
76 | self.log = log | |
77 | wx.Panel.__init__(self, parent, -1) | |
78 | date = TestDateControl(self, -1, pos = (30,30), size = (100,22)) | |
79 | ||
80 | #---------------------------------------------------------------------- | |
81 | ||
82 | def runTest(frame, nb, log): | |
83 | win = TestPanel(nb, log) | |
84 | return win | |
85 | ||
86 | #---------------------------------------------------------------------- | |
87 | ||
88 | overview = """<html><body> | |
89 | <h2><center>PopupControl</center></h2> | |
90 | ||
91 | PopupControl is a class that can display a value and has a button | |
92 | that will popup another window similar to how a wxComboBox works. The | |
93 | popup window can contain whatever is needed to edit the value. This | |
94 | example uses a wxCalendarCtrl. | |
95 | ||
96 | <p>Currently a wxDialog is used for the popup. Eventually a | |
97 | wxPopupWindow should be used... | |
98 | ||
99 | </body></html> | |
100 | """ | |
101 | ||
102 | ||
103 | if __name__ == '__main__': | |
104 | import sys,os | |
105 | import run | |
106 | run.main(['', os.path.basename(sys.argv[0])]) | |
107 |