]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxPopupControl.py
reSWIGged
[wxWidgets.git] / wxPython / demo / wxPopupControl.py
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
10 import wx
11 import wx.lib.popupctl as pop
12 import wx.calendar as cal
13
14 class TestDateControl(pop.wxPopupControl):
15 def __init__(self,*_args,**_kwargs):
16 apply(pop.wxPopupControl.__init__,(self,) + _args,_kwargs)
17
18 self.win = wx.Window(self,-1,pos = (0,0),style = 0)
19 self.cal = cal.CalendarCtrl(self.win,-1,pos = (0,0))
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
29 self.cal.Bind(cal.EVT_CALENDAR_DAY, self.OnCalSelected)
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
51
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])
57
58 if d > 0 and d < 31:
59 if m >= 0 and m < 12:
60 if y > 1000:
61 self.cal.SetDate(wx.DateTimeFromDMY(d,m,y))
62 didSet = True
63
64 if not didSet:
65 self.cal.SetDate(wx.DateTime_Today())
66
67
68 #---------------------------------------------------------------------------
69
70 class TestPanel(wx.Panel):
71 def __init__(self, parent, log):
72 self.log = log
73 wx.Panel.__init__(self, parent, -1)
74 date = TestDateControl(self, -1, pos = (30,30), size = (100,22))
75
76 #----------------------------------------------------------------------
77
78 def runTest(frame, nb, log):
79 win = TestPanel(nb, log)
80 return win
81
82 #----------------------------------------------------------------------
83
84 overview = """<html><body>
85 <h2><center>wxPopupControl</center></h2>
86
87 wxPopupControl is a class that can display a value and has a button
88 that will popup another window similar to how a wxComboBox works. The
89 popup window can contain whatever is needed to edit the value. This
90 example uses a wxCalendarCtrl.
91
92 <p>Currently a wxDialog is used for the popup. Eventually a
93 wxPopupWindow should be used...
94
95 </body></html>
96 """
97
98
99 if __name__ == '__main__':
100 import sys,os
101 import run
102 run.main(['', os.path.basename(sys.argv[0])])
103