]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/PopupControl.py
log wxChoice events in the same format as wxComboBox ones to make it simpler to compa...
[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):
6ab5d488 71 if wx.Platform == "__WXMAC__":
c4ef95da
RD
72 from Main import MessagePanel
73 win = MessagePanel(nb, 'This demo currently fails on the Mac.',
74 'Sorry', wx.ICON_WARNING)
75 return win
6ab5d488
RD
76 else:
77 win = TestPanel(nb, log)
78 return win
1e4a197e
RD
79
80#----------------------------------------------------------------------
81
1e4a197e 82overview = """<html><body>
d4b73b1b 83<h2><center>PopupControl</center></h2>
1e4a197e 84
d4b73b1b 85PopupControl is a class that can display a value and has a button
95bfd958 86that will popup another window similar to how a wx.ComboBox works. The
1e4a197e 87popup window can contain whatever is needed to edit the value. This
95bfd958 88example uses a wx.CalendarCtrl.
1e4a197e 89
95bfd958
RD
90<p>Currently a wx.Dialog is used for the popup. Eventually a
91wx.PopupWindow should be used...
1e4a197e
RD
92
93</body></html>
94"""
95
96
1e4a197e
RD
97if __name__ == '__main__':
98 import sys,os
99 import run
8eca4fef 100 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
1e4a197e 101