SpinCtrl and forward tab-cycle

Hello there list,

I noticed that it's not possible to tab-cycle forward when using the code below. It however works fine in the wxPython demos when I add some more widgets to it.

What's wrong with the code below?

Regards,
Matthias

Code:

import wx

class TestFrame(wx.Frame):
    def __init__(self, parent, ID, title, style):
        wx.Frame.__init__(self, parent, ID, title, size=(300, 250), style=style)

        self.box = wx.BoxSizer(wx.VERTICAL)

        self.TelephoneText = wx.TextCtrl(self, -1, "", size=(200, -1))
        self.NumberPackagesText = wx.SpinCtrl(self, -1)
        self.TelephoneText11 = wx.TextCtrl(self, -1, "Blablabla", size=(150, -1))
        self.DeliveryDateText = wx.DatePickerCtrl(self, size=(100,-1),style=wx.DP_DROPDOWN | wx.DP_SHOWCENTURY)

        self.box.Add(self.TelephoneText)
        self.box.Add(self.NumberPackagesText)
        self.box.Add(self.TelephoneText11)
        self.box.Add(self.DeliveryDateText)

        self.SetAutoLayout(True)
        self.SetSizer(self.box)
        self.Layout()

app = wx.PySimpleApp()
frame = TestFrame(None, -1, "Test app", wx.MINIMIZE_BOX | wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX | wx.CLIP_CHILDREN | wx.TAB_TRAVERSAL)
frame.Show()
app.MainLoop()

Matthias,

···

-----Original Message-----
From: mawe [mailto:mawe@typeofundefined.com]
Sent: Tuesday, January 01, 2008 7:11 PM
To: wxPython-users@lists.wxwidgets.org
Subject: SpinCtrl and forward tab-cycle

Hello there list,

I noticed that it's not possible to tab-cycle forward when
using the code below. It however works fine in the wxPython
demos when I add some more widgets to it.

What's wrong with the code below?

Regards,
Matthias

Code:

import wx

class TestFrame(wx.Frame):
    def __init__(self, parent, ID, title, style):
        wx.Frame.__init__(self, parent, ID, title, size=(300,
250), style=style)

        self.box = wx.BoxSizer(wx.VERTICAL)

        self.TelephoneText = wx.TextCtrl(self, -1, "", size=(200, -1))
        self.NumberPackagesText = wx.SpinCtrl(self, -1)
        self.TelephoneText11 = wx.TextCtrl(self, -1,
"Blablabla", size=(150, -1))
        self.DeliveryDateText = wx.DatePickerCtrl(self,
size=(100,-1),style=wx.DP_DROPDOWN | wx.DP_SHOWCENTURY)

        self.box.Add(self.TelephoneText)
        self.box.Add(self.NumberPackagesText)
        self.box.Add(self.TelephoneText11)
        self.box.Add(self.DeliveryDateText)

        self.SetAutoLayout(True)
        self.SetSizer(self.box)
        self.Layout()

app = wx.PySimpleApp()
frame = TestFrame(None, -1, "Test app", wx.MINIMIZE_BOX |
wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX | wx.CLIP_CHILDREN
> wx.TAB_TRAVERSAL)
frame.Show()
app.MainLoop()

The difference between your code and the demo code is that the demo puts
its widgets on a panel and you do not. I added a panel to your code and
then added the widgets to the panel and it worked.

Give it a whirl and see for yourself.

Mike

Mike, thanks for the reply.

You're right, it's just that the demo is using a Panel instead of a BoxSizer.

Strange enough that it works if I cycle backwards through the widgets (SHIFT + TAB).

Regards,
Matthias

Mike Driscoll schrieb:

···

Matthias,

-----Original Message-----
From: mawe [mailto:mawe@typeofundefined.com] Sent: Tuesday, January 01, 2008 7:11 PM
To: wxPython-users@lists.wxwidgets.org
Subject: SpinCtrl and forward tab-cycle

Hello there list,

I noticed that it's not possible to tab-cycle forward when using the code below. It however works fine in the wxPython demos when I add some more widgets to it.

What's wrong with the code below?

Regards,
Matthias

Code:

import wx

class TestFrame(wx.Frame):
    def __init__(self, parent, ID, title, style):
        wx.Frame.__init__(self, parent, ID, title, size=(300, 250), style=style)

        self.box = wx.BoxSizer(wx.VERTICAL)

        self.TelephoneText = wx.TextCtrl(self, -1, "", size=(200, -1))
        self.NumberPackagesText = wx.SpinCtrl(self, -1)
        self.TelephoneText11 = wx.TextCtrl(self, -1, "Blablabla", size=(150, -1))
        self.DeliveryDateText = wx.DatePickerCtrl(self, size=(100,-1),style=wx.DP_DROPDOWN | wx.DP_SHOWCENTURY)

        self.box.Add(self.TelephoneText)
        self.box.Add(self.NumberPackagesText)
        self.box.Add(self.TelephoneText11)
        self.box.Add(self.DeliveryDateText)

        self.SetAutoLayout(True)
        self.SetSizer(self.box)
        self.Layout()

app = wx.PySimpleApp()
frame = TestFrame(None, -1, "Test app", wx.MINIMIZE_BOX | wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX | wx.CLIP_CHILDREN > wx.TAB_TRAVERSAL)
frame.Show()
app.MainLoop()

The difference between your code and the demo code is that the demo puts
its widgets on a panel and you do not. I added a panel to your code and
then added the widgets to the panel and it worked.

Give it a whirl and see for yourself.

Mike

Matthias

From: mawe [mailto:mawe@typeofundefined.com]
Sent: Wednesday, January 02, 2008 3:32 PM
To: wxPython-users@lists.wxwidgets.org
Subject: Re: [wxPython-users] RE: SpinCtrl and forward tab-cycle

Mike, thanks for the reply.

You're right, it's just that the demo is using a Panel
instead of a BoxSizer.

Strange enough that it works if I cycle backwards through the
widgets (SHIFT + TAB).

Regards,
Matthias

<snip>

That is weird. Just an FYI though: I left the BoxSizer in your code alone.
I decided that maybe I should just include the code too, so it's attached.
I have noticed that other people on this list have had odd things happen
to them when they use only a frame as the parent of the widgets. Robin
will hopefully weigh in and explain all.

Mike

test.py (1.06 KB)

···

-----Original Message-----

Mike Driscoll wrote:

Matthias

From: mawe [mailto:mawe@typeofundefined.com] Sent: Wednesday, January 02, 2008 3:32 PM
To: wxPython-users@lists.wxwidgets.org
Subject: Re: [wxPython-users] RE: SpinCtrl and forward tab-cycle

Mike, thanks for the reply.

You're right, it's just that the demo is using a Panel instead of a BoxSizer.

Strange enough that it works if I cycle backwards through the widgets (SHIFT + TAB).

Regards,
Matthias

<snip>

That is weird. Just an FYI though: I left the BoxSizer in your code alone.
I decided that maybe I should just include the code too, so it's attached.
I have noticed that other people on this list have had odd things happen
to them when they use only a frame as the parent of the widgets. Robin
will hopefully weigh in and explain all.

Some of the native widgets on Windows do some tab traversal behavior internally. It's probably just left over code from before the tab traversal was handled by a platform API and the controls had to implement it themselves.

···

-----Original Message-----

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

Thanks to you two. Mike, your "workaround" works somehow. But it destroys my layout, since it seems to depend on SetAutoLayout(True). Furthermore, the tab-cycle in my actual app seems to be broken somehow, again.

I've attached my complete code, with my orignal attempts commented out and Mikes suggestions just below.
Please bear with me and the code, they're my first steps in wxPython.

Regards,
Matthias

Robin Dunn schrieb:

GLSExporter.py (13.3 KB)

···

Mike Driscoll wrote:

Matthias

-----Original Message-----
From: mawe [mailto:mawe@typeofundefined.com] Sent: Wednesday, January 02, 2008 3:32 PM
To: wxPython-users@lists.wxwidgets.org
Subject: Re: [wxPython-users] RE: SpinCtrl and forward tab-cycle

Mike, thanks for the reply.

You're right, it's just that the demo is using a Panel instead of a BoxSizer.

Strange enough that it works if I cycle backwards through the widgets (SHIFT + TAB).

Regards,
Matthias

<snip>

That is weird. Just an FYI though: I left the BoxSizer in your code alone.
I decided that maybe I should just include the code too, so it's attached.
I have noticed that other people on this list have had odd things happen
to them when they use only a frame as the parent of the widgets. Robin
will hopefully weigh in and explain all.

Some of the native widgets on Windows do some tab traversal behavior internally. It's probably just left over code from before the tab traversal was handled by a platform API and the controls had to implement it themselves.

mawe wrote:

Thanks to you two. Mike, your "workaround" works somehow. But it destroys my layout, since it seems to depend on SetAutoLayout(True). Furthermore, the tab-cycle in my actual app seems to be broken somehow, again.

I've attached my complete code, with my orignal attempts commented out and Mikes suggestions just below.
Please bear with me and the code, they're my first steps in wxPython.

[...]

        self.topText = wx.StaticText(self, -1, "Top", (20, 10))
        self.middleText = wx.StaticText(self, -1, "Middle", (20, 10))
        self.bottomText = wx.StaticText(self, -1, "Bottom", (20, 10))

[...]

        # All the commented below is my old code
        #self.SetSizer(self.mainSizer) #self.SetAutoLayout(True)
        #self.mainSizer.Fit(self)
        #self.Show(1)
                # And these are the suggestions by Mike Driscoll
        panel = wx.Panel(self,-1)
        panel.SetSizer(self.mainSizer)
        panel.Layout()
        self.Show()

You missed the point. You should not only put the panel in the frame, but you should make all your widgets be children of the panel instead of the frame. The panel is what manages the tab-traversal of it's children, but in your sample it has no children at all so it can't do anything. Move the creation of the panel to the top of the __init__ method, and change all the other widgets to use the panel as the parent instead of self.

···

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

Thanks Robin, that last hint got me sorting it out. Again, thanks a lot!

Regards,
Matthias

Robin Dunn schrieb:

···

You missed the point. You should not only put the panel in the frame, but you should make all your widgets be children of the panel instead of the frame. The panel is what manages the tab-traversal of it's children, but in your sample it has no children at all so it can't do anything. Move the creation of the panel to the top of the __init__ method, and change all the other widgets to use the panel as the parent instead of self.