]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/PopupControl.py
xcode 1.2 native targets
[wxWidgets.git] / wxPython / demo / PopupControl.py
1
2 import wx
3 import wx.lib.popupctl as pop
4 import wx.calendar as cal
5
6 class TestDateControl(pop.PopupControl):
7 def __init__(self,*_args,**_kwargs):
8 apply(pop.PopupControl.__init__,(self,) + _args,_kwargs)
9
10 self.win = wx.Window(self,-1,pos = (0,0),style = 0)
11 self.cal = cal.CalendarCtrl(self.win,-1,pos = (0,0))
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
21 self.cal.Bind(cal.EVT_CALENDAR_DAY, self.OnCalSelected)
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
34 # Method overridden from PopupControl
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
43
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])
49
50 if d > 0 and d < 31:
51 if m >= 0 and m < 12:
52 if y > 1000:
53 self.cal.SetDate(wx.DateTimeFromDMY(d,m,y))
54 didSet = True
55
56 if not didSet:
57 self.cal.SetDate(wx.DateTime_Today())
58
59
60 #---------------------------------------------------------------------------
61
62 class TestPanel(wx.Panel):
63 def __init__(self, parent, log):
64 self.log = log
65 wx.Panel.__init__(self, parent, -1)
66 date = TestDateControl(self, -1, pos = (30,30), size = (100,22))
67
68 #----------------------------------------------------------------------
69
70 def runTest(frame, nb, log):
71 win = TestPanel(nb, log)
72 return win
73
74 #----------------------------------------------------------------------
75
76 overview = """<html><body>
77 <h2><center>PopupControl</center></h2>
78
79 PopupControl is a class that can display a value and has a button
80 that will popup another window similar to how a wx.ComboBox works. The
81 popup window can contain whatever is needed to edit the value. This
82 example uses a wx.CalendarCtrl.
83
84 <p>Currently a wx.Dialog is used for the popup. Eventually a
85 wx.PopupWindow should be used...
86
87 </body></html>
88 """
89
90
91 if __name__ == '__main__':
92 import sys,os
93 import run
94 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
95