]>
Commit | Line | Data |
---|---|---|
8fa876ca RD |
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 | # | |
d4b73b1b RD |
9 | # 12/20/2003 - Jeff Grimmett (grimmtooth@softhome.net) |
10 | # | |
11 | # o wxPopupControl -> PopupControl | |
12 | # | |
8fa876ca RD |
13 | |
14 | import wx | |
15 | import wx.lib.popupctl as pop | |
16 | import wx.calendar as cal | |
17 | ||
d4b73b1b | 18 | class TestDateControl(pop.PopupControl): |
1e4a197e | 19 | def __init__(self,*_args,**_kwargs): |
d4b73b1b | 20 | apply(pop.PopupControl.__init__,(self,) + _args,_kwargs) |
1e4a197e | 21 | |
8fa876ca RD |
22 | self.win = wx.Window(self,-1,pos = (0,0),style = 0) |
23 | self.cal = cal.CalendarCtrl(self.win,-1,pos = (0,0)) | |
1e4a197e RD |
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 | |
8fa876ca | 33 | self.cal.Bind(cal.EVT_CALENDAR_DAY, self.OnCalSelected) |
1e4a197e RD |
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 | ||
d4b73b1b | 46 | # Method overridden from PopupControl |
1e4a197e RD |
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 | |
8fa876ca | 55 | |
1e4a197e RD |
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]) | |
8fa876ca | 61 | |
1e4a197e RD |
62 | if d > 0 and d < 31: |
63 | if m >= 0 and m < 12: | |
64 | if y > 1000: | |
8fa876ca | 65 | self.cal.SetDate(wx.DateTimeFromDMY(d,m,y)) |
1e4a197e | 66 | didSet = True |
8fa876ca | 67 | |
1e4a197e | 68 | if not didSet: |
8fa876ca | 69 | self.cal.SetDate(wx.DateTime_Today()) |
1e4a197e RD |
70 | |
71 | ||
72 | #--------------------------------------------------------------------------- | |
73 | ||
8fa876ca | 74 | class TestPanel(wx.Panel): |
1e4a197e RD |
75 | def __init__(self, parent, log): |
76 | self.log = log | |
8fa876ca | 77 | wx.Panel.__init__(self, parent, -1) |
1e4a197e RD |
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 | ||
1e4a197e | 88 | overview = """<html><body> |
d4b73b1b | 89 | <h2><center>PopupControl</center></h2> |
1e4a197e | 90 | |
d4b73b1b | 91 | PopupControl is a class that can display a value and has a button |
1e4a197e RD |
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 | ||
1e4a197e RD |
103 | if __name__ == '__main__': |
104 | import sys,os | |
105 | import run | |
106 | run.main(['', os.path.basename(sys.argv[0])]) | |
107 |