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