Why there is no focus on tab ? (sample from wxDemo)

Hello,
I've interested in using TestDateControl class.
The only problem - it does not getting any focus when i've pressed TAB
key.
Below is the sample code which i've copied from wxDemo, i've just added
one more control to see how things going on.
Problem is: when i've press the TAB - no focus gained on any of the
controls.It's sure can be simple to modify this code a little, but
i've just don't have any clue, so hint is needed.

****CODE****
from wxPython.wx import *
#from wxPython.lib.popupctl import wxPopupControl
from popupctl import wxPopupControl
from wxPython.calendar import *

class TestDateControl(wxPopupControl):
    def __init__(self,*_args,**_kwargs):
        apply(wxPopupControl.__init__,(self,) + _args,_kwargs)

        self.win = wxWindow(self,-1,pos = (0,0),style = 0)
        self.cal = wxCalendarCtrl(self.win,-1,pos = (0,0))

        bz = self.cal.GetBestSize()
        self.win.SetSize(bz)

        # This method is needed to set the contents that will be displayed
        # in the popup
        self.SetPopupContent(self.win)

        # Event registration for date selection
        EVT_CALENDAR_DAY(self.cal,self.cal.GetId(),self.OnCalSelected)

    # Method called when a day is selected in the calendar
    def OnCalSelected(self,evt):
        self.PopDown()
        date = self.cal.GetDate()

        # Format the date that was selected for the text part of the control
        self.SetValue('%02d/%02d/%04d' % (date.GetDay(),
                                          date.GetMonth()+1,
                                          date.GetYear()))
        evt.Skip()

    # Method overridden from wxPopupControl
    # This method is called just before the popup is displayed
    # Use this method to format any controls in the popup
    def FormatContent(self):
        # I parse the value in the text part to resemble the correct date in
        # the calendar control
        txtValue = self.GetValue()
        dmy = txtValue.split('/')
        didSet = False
        if len(dmy) == 3:
            date = self.cal.GetDate()
            d = int(dmy[0])
            m = int(dmy[1]) - 1
            y = int(dmy[2])
            if d > 0 and d < 31:
                if m >= 0 and m < 12:
                    if y > 1000:
                        self.cal.SetDate(wxDateTimeFromDMY(d,m,y))
                        didSet = True
        if not didSet:
            self.cal.SetDate(wxDateTime_Today())

···

#---------------------------------------------------------------------------

class TestPanel(wxPanel):
    def __init__(self, parent, log):
        self.log = log
        wxPanel.__init__(self, parent, -1)
        
        date0 = TestDateControl(self, -1, pos = (30,30), size = (100,22))
        date1 = TestDateControl(self, -1, pos = (30 ,50), size = (100,22))

#----------------------------------------------------------------------

def runTest(frame, nb, log):
    win = TestPanel(nb, log)
    return win

#----------------------------------------------------------------------

overview = """<html><body>
<h2><center>wxPopupControl</center></h2>

wxPopupControl is a class that can display a value and has a button
that will popup another window similar to how a wxComboBox works. The
popup window can contain whatever is needed to edit the value. This
example uses a wxCalendarCtrl.

<p>Currently a wxDialog is used for the popup. Eventually a
wxPopupWindow should be used...

</body></html>
"""

if __name__ == '__main__':
    import sys,os
    import run
    run.main(['', os.path.basename(sys.argv[0])])
*** END OF CODE ***

Thanks in advance.
--

                     mailto:igor@tyumbit.ru

Igor Prischepoff wrote:

Hello,
I've interested in using TestDateControl class.
The only problem - it does not getting any focus when i've pressed TAB
key.
Below is the sample code which i've copied from wxDemo, i've just added
one more control to see how things going on.
Problem is: when i've press the TAB - no focus gained on any of the
controls.It's sure can be simple to modify this code a little, but
i've just don't have any clue, so hint is needed.

wxPopupControl should probably catch the EVT_SET_FOCUS event and then when it gets the focus set the focus to the embedded wxTextCtrl. If you want to test this and send me a patch I'd appreciate it.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Thanks,Robin.

wxPopupControl should probably catch the EVT_SET_FOCUS event and then
when it gets the focus set the focus to the embedded wxTextCtrl.

I've managed to get it working.
Now another problem, wxTextCtrl really is not good at entering date.
We have more advanced control - wxMaskedTextCtrl (beta), so ideally -
it should be used instead of wxTextCtrl. I've attached 2 files which
try to utilize wxMaskedTextCtrl.

Problem is : it's getting focus BUT not giving it away when i'm trying
to tab out of field.If this problem will be fixed, i think we get more
advanced Date Entry Control with mask and visual popup
calendar, ( absolute dream :slight_smile: )

If you
want to test this and send me a patch I'd appreciate it.

I can send it,but may be more advanced sample with an absolute ergonomic
Date Entry Control based on previos control will be more preferrable?
Is Gerrit van Dyk - original author of control still around? What does
he thinks of it?

P.S. When i've trying to close window with mouse NASTY thing happens. :frowning:
Python 2.2.2
wxWindow 2.4.0
Win2000 professional

wxApp.py (3.07 KB)

popupctl.py (7.65 KB)

···

--
                         mailto:igor@tyumbit.ru

Igor Prischepoff wrote:

Thanks,Robin.
> wxPopupControl should probably catch the EVT_SET_FOCUS event and then
> when it gets the focus set the focus to the embedded wxTextCtrl.
I've managed to get it working.

Thanks

Now another problem, wxTextCtrl really is not good at entering date.
We have more advanced control - wxMaskedTextCtrl (beta), so ideally -
it should be used instead of wxTextCtrl. I've attached 2 files which
try to utilize wxMaskedTextCtrl.

But wxPopupCtrl should be able to be used for more than just dates. Perhaps a better approach would be to (optionally) pass in a class to be used to make the embedded text ctrl...

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!