]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/PopupControl.py
fixes for unicode build, return values from event handlers (via
[wxWidgets.git] / wxPython / demo / PopupControl.py
CommitLineData
8fa876ca
RD
1
2import wx
3import wx.lib.popupctl as pop
4import wx.calendar as cal
5
d4b73b1b 6class TestDateControl(pop.PopupControl):
1e4a197e 7 def __init__(self,*_args,**_kwargs):
d4b73b1b 8 apply(pop.PopupControl.__init__,(self,) + _args,_kwargs)
1e4a197e 9
8fa876ca
RD
10 self.win = wx.Window(self,-1,pos = (0,0),style = 0)
11 self.cal = cal.CalendarCtrl(self.win,-1,pos = (0,0))
1e4a197e
RD
12
13 bz = self.cal.GetBestSize()
14 self.win.SetSize(bz)
15
16 # This method is needed to set the contents that will be displayed
17 # in the popup
18 self.SetPopupContent(self.win)
19
20 # Event registration for date selection
8fa876ca 21 self.cal.Bind(cal.EVT_CALENDAR_DAY, self.OnCalSelected)
1e4a197e
RD
22
23 # Method called when a day is selected in the calendar
24 def OnCalSelected(self,evt):
25 self.PopDown()
26 date = self.cal.GetDate()
27
28 # Format the date that was selected for the text part of the control
29 self.SetValue('%02d/%02d/%04d' % (date.GetDay(),
30 date.GetMonth()+1,
31 date.GetYear()))
32 evt.Skip()
33
d4b73b1b 34 # Method overridden from PopupControl
1e4a197e
RD
35 # This method is called just before the popup is displayed
36 # Use this method to format any controls in the popup
37 def FormatContent(self):
38 # I parse the value in the text part to resemble the correct date in
39 # the calendar control
40 txtValue = self.GetValue()
41 dmy = txtValue.split('/')
42 didSet = False
8fa876ca 43
1e4a197e
RD
44 if len(dmy) == 3:
45 date = self.cal.GetDate()
46 d = int(dmy[0])
47 m = int(dmy[1]) - 1
48 y = int(dmy[2])
8fa876ca 49
1e4a197e
RD
50 if d > 0 and d < 31:
51 if m >= 0 and m < 12:
52 if y > 1000:
8fa876ca 53 self.cal.SetDate(wx.DateTimeFromDMY(d,m,y))
1e4a197e 54 didSet = True
8fa876ca 55
1e4a197e 56 if not didSet:
8fa876ca 57 self.cal.SetDate(wx.DateTime_Today())
1e4a197e
RD
58
59
60#---------------------------------------------------------------------------
61
8fa876ca 62class TestPanel(wx.Panel):
1e4a197e
RD
63 def __init__(self, parent, log):
64 self.log = log
8fa876ca 65 wx.Panel.__init__(self, parent, -1)
1e4a197e
RD
66 date = TestDateControl(self, -1, pos = (30,30), size = (100,22))
67
68#----------------------------------------------------------------------
69
70def runTest(frame, nb, log):
71 win = TestPanel(nb, log)
72 return win
73
74#----------------------------------------------------------------------
75
1e4a197e 76overview = """<html><body>
d4b73b1b 77<h2><center>PopupControl</center></h2>
1e4a197e 78
d4b73b1b 79PopupControl is a class that can display a value and has a button
95bfd958 80that will popup another window similar to how a wx.ComboBox works. The
1e4a197e 81popup window can contain whatever is needed to edit the value. This
95bfd958 82example uses a wx.CalendarCtrl.
1e4a197e 83
95bfd958
RD
84<p>Currently a wx.Dialog is used for the popup. Eventually a
85wx.PopupWindow should be used...
1e4a197e
RD
86
87</body></html>
88"""
89
90
1e4a197e
RD
91if __name__ == '__main__':
92 import sys,os
93 import run
8eca4fef 94 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
1e4a197e 95