]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/PopupControl.py
   3 import  wx
.lib
.popupctl 
as  pop
 
   4 import  wx
.calendar     
as  cal
 
   6 class TestDateControl(pop
.PopupControl
): 
   7     def __init__(self
,*_args
,**_kwargs
): 
   8         apply(pop
.PopupControl
.__init
__,(self
,) + _args
,_kwargs
) 
  10         self
.win 
= wx
.Window(self
,-1,pos 
= (0,0),style 
= 0) 
  11         self
.cal 
= cal
.CalendarCtrl(self
.win
,-1,pos 
= (0,0)) 
  13         bz 
= self
.cal
.GetBestSize() 
  16         # This method is needed to set the contents that will be displayed 
  18         self
.SetPopupContent(self
.win
) 
  20         # Event registration for date selection 
  21         self
.cal
.Bind(cal
.EVT_CALENDAR_DAY
, self
.OnCalSelected
) 
  23     # Method called when a day is selected in the calendar 
  24     def OnCalSelected(self
,evt
): 
  26         date 
= self
.cal
.GetDate() 
  28         # Format the date that was selected for the text part of the control 
  29         self
.SetValue('%02d/%02d/%04d' % (date
.GetDay(), 
  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('/') 
  45             date 
= self
.cal
.GetDate() 
  53                         self
.cal
.SetDate(wx
.DateTimeFromDMY(d
,m
,y
)) 
  57             self
.cal
.SetDate(wx
.DateTime_Today()) 
  60 #--------------------------------------------------------------------------- 
  62 class TestPanel(wx
.Panel
): 
  63     def __init__(self
, parent
, log
): 
  65         wx
.Panel
.__init
__(self
, parent
, -1) 
  66         date 
= TestDateControl(self
, -1, pos 
= (30,30), size 
= (100,22)) 
  68 #---------------------------------------------------------------------- 
  70 def runTest(frame
, nb
, log
): 
  71     if wx
.Platform 
== "__WXMAC__": 
  72         from Main 
import MessagePanel
 
  73         win 
= MessagePanel(nb
, 'This demo currently fails on the Mac.', 
  74                            'Sorry', wx
.ICON_WARNING
) 
  77         win 
= TestPanel(nb
, log
) 
  80 #---------------------------------------------------------------------- 
  82 overview 
= """<html><body> 
  83 <h2><center>PopupControl</center></h2> 
  85 PopupControl is a class that can display a value and has a button 
  86 that will popup another window similar to how a wx.ComboBox works.  The 
  87 popup window can contain whatever is needed to edit the value.  This 
  88 example uses a wx.CalendarCtrl. 
  90 <p>Currently a wx.Dialog is used for the popup.  Eventually a 
  91 wx.PopupWindow should be used... 
  97 if __name__ 
== '__main__': 
 100     run
.main(['', os
.path
.basename(sys
.argv
[0])] + sys
.argv
[1:])