#!/usr/bin/env python # generated by wxGlade 0.1.3 on Tue Aug 27 13:09:52 2002 from wxPython.wx import * from wxPython.calendar import * from wxPython.utils import * class wxDateEntry(wxPanel): def __init__(self, parent, id = -1, size = wxDefaultSize, pos = wxDefaultPosition, style = wxTAB_TRAVERSAL, calButton = true): wxPanel.__init__(self, parent, id, pos, size, style) box = wxBoxSizer(wxHORIZONTAL) self.dateCtrl = wxTextCtrl(self, -1) box.Add( self.dateCtrl, 1, wxLEFT|wxCENTER, 5) if calButton: self.buttonCtrl = self.__oneButton() box.Add( self.buttonCtrl, 0, wxCENTER) # add a border around the whole thing and resize the panel to fit outsidebox = wxBoxSizer(wxVERTICAL) outsidebox.Add(box, 1, wxEXPAND|wxALL, 3) outsidebox.Fit(self) self.SetAutoLayout(true) self.SetSizer(outsidebox ) self.Layout() def __oneButton(self): b = wxButton(self, -1, "D", size=(self.dateCtrl.GetSize()[1], -1)) EVT_BUTTON(b, -1, self.onButton) return b def onButton(self, event): print "boton pulsado" pos = self.dateCtrl.ClientToScreen((0,0)) sz = self.dateCtrl.GetSize() a = PopupCalendar(self, -1, "hola", pos=(pos[0], pos[1]+sz.height), date='2002-6-4') a.ShowModal() fecha= a.GetDate() print "a.getdate()", fecha a.Destroy() self.dateCtrl.SetValue(fecha) class PopupCalendar(wxDialog): def __init__(self, *args, **kwds): #kwds["style"] = wxSIMPLE_BORDER kwds["style"] = wxSIMPLE_BORDER if kwds.has_key('date'): self.__isoDate = kwds['date'] del kwds['date'] else: self.__isoDate = wxDateTime_Now().FormatISODate() dia = int(self.__isoDate.split('-')[2]) mes = int(self.__isoDate.split('-')[1])-1 # -1 Important bug ¿? - month begin at 0 anyo = int(self.__isoDate.split('-')[0]) intDate = wxDateTimeFromDMY(dia, mes, anyo) wxDialog.__init__(self, *args, **kwds) panel = wxPanel(self, -1, style = wxRAISED_BORDER|wxTHICK_FRAME) self.Calendar = wxCalendarCtrl(panel, -1, intDate, pos=(0, 0), style= wxCAL_SHOW_HOLIDAYS|wxCAL_SEQUENTIAL_MONTH_SELECTION ) del intDate panel.Fit() bs = self.Calendar.GetBestSize() self.SetSize((bs.width,bs.height)) self.Calendar.SetFocus() self.intDate = wxDateTime_Now() EVT_CALENDAR(self, self.Calendar.GetId(), self.onCalendar) EVT_CHAR(self.Calendar, self.onChar) def onChar(self, event): a = event.KeyCode() if a == 27: wxDialog.EndModal(self, false) event.Skip() def GetDate(self): return self.__isoDate def onCalendar(self, event): self.__isoDate = event.GetDate().FormatISODate() self.EndModal(true) # falta añadir que cuando pierda el foco, SetShow(false) and destroy... class MyFrame(wxFrame): def __init__(self, *args, **kwds): # begin wxGlade: __init__ kwds["style"] = wxDEFAULT_FRAME_STYLE wxFrame.__init__(self, *args, **kwds) self.panel_1 = wxPanel(self, -1) self.label_1_copy = wxStaticText(self.panel_1, -1, "Texto de ejemplo") self.text_ctrl_1_copy = wxDateEntry(self.panel_1, -1) self.button_1_copy = wxButton(self.panel_1, -1, "Calendario") self.button_2_copy = wxButton(self.panel_1, -1, "Salir") self.__set_properties() self.__do_layout() # end wxGlade # mis eventos EVT_BUTTON(self.button_1_copy, -1, self.botonPulsado) def botonPulsado(self, event): print 'botón pulsado... añadiendo calendario...' boton = event.GetEventObject() pos = boton.ClientToScreen((0,0)) sz = boton.GetSize() a = PopupCalendar(self, -1, "hola", pos=(pos[0], pos[1]+sz.height), date='2002-6-4') #a.Position(pos, (0, sz.height)) print "a.getdate()", a.GetDate() a.ShowModal() fecha= a.GetDate() print "a.getdate()", fecha a.Destroy() self.text_ctrl_1_copy.dateCtrl.SetValue(fecha) def __set_properties(self): # begin wxGlade: __set_properties self.SetTitle("Prueba de calendario") #self.text_ctrl_1_copy.SetSize(wxDLG_SZE(self.text_ctrl_1_copy, (34, 12))) self.text_ctrl_1_copy.SetToolTipString("ejemplo") self.button_1_copy.SetToolTipString("Pulsando el botón aparece el calendario...") # end wxGlade def __do_layout(self): # begin wxGlade: __do_layout sizer_1 = wxBoxSizer(wxHORIZONTAL) sizer_4 = wxBoxSizer(wxHORIZONTAL) sizer_2_copy = wxBoxSizer(wxVERTICAL) sizer_3_copy = wxBoxSizer(wxHORIZONTAL) sizer_3_copy.Add(self.label_1_copy, 0, 0, 0) sizer_3_copy.Add(self.text_ctrl_1_copy, 0, 0, 0) sizer_2_copy.Add(sizer_3_copy, 1, wxEXPAND, 0) sizer_2_copy.Add(self.button_1_copy, 0, wxALIGN_CENTER_HORIZONTAL, 0) sizer_2_copy.Add(self.button_2_copy, 0, wxALIGN_CENTER_HORIZONTAL, 0) sizer_4.Add(sizer_2_copy, 1, wxEXPAND, 0) self.panel_1.SetAutoLayout(1) self.panel_1.SetSizer(sizer_4) sizer_4.Fit(self.panel_1) sizer_1.Add(self.panel_1, 1, wxEXPAND, 0) self.SetAutoLayout(1) self.SetSizer(sizer_1) sizer_1.Fit(self) self.Layout() # end wxGlade # end of class MyFrame class MyApp(wxApp): def OnInit(self): wxInitAllImageHandlers() frame_1 = MyFrame(None, -1, "") self.SetTopWindow(frame_1) frame_1.Show(1) return 1 # end of class MyApp if __name__ == "__main__": app = MyApp() app.MainLoop()