Question about tabs

Newbie to wxPython here, so please be gentle:-)

I have been looking at architecture for "data entry" type applications,
which typically have forms with lots of wxTextCtrls, wxComboBoxes and so
forth.

What I have found is this:

If I put wxBoxSizers onto a wxFrame, and then put controls into slots in
the sizers I get no tabbing at all - even if I set the frame style to
include wxTAB_TRAVERSAL.

If I put multiple wxPanels into the wxFrame, then put sizers into the
panels, and controls into slots in the sizers I get tabbing between the
controls but only within each panel.

If I put a single wxPanel into a wxFrame, sizers into the wxPanel, and
controls into slots in the sizers, I get the desired behaviour; i.e. the
user can deal with each control, press tab to navigate to the next one
and so forth until the "form" is done, and they can click 'Save' or
whatever.

Question 1: I assume that is expected behaviour. Is that correct?
Question 2: If so, is the third layout mentioned above the normal way of
going about things?

As ever, thanks,
WH

I ought to have mentioned, in case it is relevant:
wxPython 2.8.12 and python 2.7.2

···

On Mon, 23 Jan 2012 03:09:09 +0000, Walter Hurry wrote:

<snip questions>

On Sun, Jan 22, 2012 at 7:09 PM, Walter Hurry > If I put wxBoxSizers
onto a wxFrame, and then put controls into slots in

the sizers I get no tabbing at all - even if I set the frame style to
include wxTAB_TRAVERSAL.

If I put multiple wxPanels into the wxFrame, then put sizers into the
panels, and controls into slots in the sizers I get tabbing between the
controls but only within each panel.

If I put a single wxPanel into a wxFrame, sizers into the wxPanel, and
controls into slots in the sizers, I get the desired behaviour; i.e. the
user can deal with each control, press tab to navigate to the next one
and so forth until the "form" is done, and they can click 'Save' or
whatever.

Question 1: I assume that is expected behaviour. Is that correct?

yes -- Frames are are the top-level window, and don't proivide much
else -- i.e. no tab traversal.

Panels are a wx.Window designed to hole other widgets, and provide
some reatures to support that -- notably Tab traversal.

But if you put multipel panels on a frame, each will be handling its
own tab traversal.

Question 2: If so, is the third layout mentioned above the normal way of
going about things?

yes -- unless you have a group of controls that work together an you
may re-use on other places -- in that case, having them on a panel by
themselves make sense, and you can manually handle the tab traversal
form one panel to the next if you need that.

Note that I'd make a custom class for your panel, rather than cramming
it all in the frame class.

-Chris

···

--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Thanks, Chris. It sounds as though I am working along the right lines.

But I don't understand your last remark. What is the advantage of using a
custom class as opposed to having my panel be an instance of wxPanel?

···

On Sun, 22 Jan 2012 20:36:31 -0800, Chris Barker wrote:

On Sun, Jan 22, 2012 at 7:09 PM, Walter Hurry > If I put wxBoxSizers
onto a wxFrame, and then put controls into slots in

the sizers I get no tabbing at all - even if I set the frame style to
include wxTAB_TRAVERSAL.

If I put multiple wxPanels into the wxFrame, then put sizers into the
panels, and controls into slots in the sizers I get tabbing between the
controls but only within each panel.

If I put a single wxPanel into a wxFrame, sizers into the wxPanel, and
controls into slots in the sizers, I get the desired behaviour; i.e.
the user can deal with each control, press tab to navigate to the next
one and so forth until the "form" is done, and they can click 'Save' or
whatever.

Question 1: I assume that is expected behaviour. Is that correct?

yes -- Frames are are the top-level window, and don't proivide much else
-- i.e. no tab traversal.

Panels are a wx.Window designed to hole other widgets, and provide some
reatures to support that -- notably Tab traversal.

But if you put multipel panels on a frame, each will be handling its own
tab traversal.

Question 2: If so, is the third layout mentioned above the normal way
of going about things?

yes -- unless you have a group of controls that work together an you may
re-use on other places -- in that case, having them on a panel by
themselves make sense, and you can manually handle the tab traversal
form one panel to the next if you need that.

Note that I'd make a custom class for your panel, rather than cramming
it all in the frame class.

what I was suggesting is that your panel be a subclass of wx.Panel. See:

http://wiki.wxpython.org/wxPython%20Style%20Guide

for this and other ideas.

···

On Sun, Jan 22, 2012 at 9:10 PM, Walter Hurry <walterhurry@lavabit.com> wrote:

But I don't understand your last remark. What is the advantage of using a
custom class as opposed to having my panel be an instance of wxPanel?

--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Ah, right. I see what you mean now about subclassing wx.Panel. Yes,
that's how I'm doing it; I just didn't understand the terminology.

Also, thanks for the pointer to your syle guide - very helpful. I'm happy
to report that I'm doing almost everything the way you suggest. One
notable exception is that I don't yet even know what docstrings are! But
I shall very soon.

···

On Sun, 22 Jan 2012 21:25:25 -0800, Chris Barker wrote:

On Sun, Jan 22, 2012 at 9:10 PM, Walter Hurry <walterhurry@lavabit.com> > wrote:

But I don't understand your last remark. What is the advantage of using
a custom class as opposed to having my panel be an instance of wxPanel?

what I was suggesting is that your panel be a subclass of wx.Panel. See:

wxPython Style Guide - wxPyWiki

for this and other ideas.

Docstrings are the first comment in each file/function they should be
treble quoted and explain what the file/class/function is to do, (so far
just like a normal comment), but they are preserved and are available to
the user/program/programmer. Try the following:

create a python file called myfile.py with at the beginning a treble
quoted comment about the file, also def a function called fred with at
the beginning a treble quoted comment about the function and save it.
Open the python console in the same directory and type import myfile
then type help(myfile) then type help(myfile.fred), you can also access
the docstring as __doc__ in the file/class/function scope.

This can be VERY useful.

Gadget/Steve

···

On 23/01/2012 4:00 PM, Walter Hurry wrote:

On Sun, 22 Jan 2012 21:25:25 -0800, Chris Barker wrote:

On Sun, Jan 22, 2012 at 9:10 PM, Walter Hurry <walterhurry@lavabit.com> >> wrote:

But I don't understand your last remark. What is the advantage of using
a custom class as opposed to having my panel be an instance of wxPanel?

what I was suggesting is that your panel be a subclass of wx.Panel. See:

wxPython Style Guide - wxPyWiki

for this and other ideas.

Ah, right. I see what you mean now about subclassing wx.Panel. Yes,
that's how I'm doing it; I just didn't understand the terminology.

Also, thanks for the pointer to your syle guide - very helpful. I'm happy
to report that I'm doing almost everything the way you suggest. One
notable exception is that I don't yet even know what docstrings are! But
I shall very soon.

Tabbing between items in sibling panels or between items in parent/child panels should work out of the box. There may have to be one single panel (or other window type that supports tab-traversal) at the top of the containment hierarchy though.

···

On 1/22/12 8:36 PM, Chris Barker wrote:

yes -- unless you have a group of controls that work together an you
may re-use on other places -- in that case, having them on a panel by
themselves make sense, and you can manually handle the tab traversal
form one panel to the next if you need that.

--
Robin Dunn
Software Craftsman

Thanks, I'm sure it can. But I'm not looking for help on docstrings here
until I've done my own learning and testing. Then if there's something
I'm confused or unsure about, I'll come back and ask.

The signal to noise ratio in this group is excellent, and the quality and
helpfulness of the responses could hardly be improved. As a novice I
shall doubtless ask many silly questions, but I won't trouble you folk
without doing my homework first.

Thans for the pointer, though.

WH

···

On Mon, 23 Jan 2012 17:33:02 +0000, Gadget/Steve wrote:

On 23/01/2012 4:00 PM, Walter Hurry wrote:

On Sun, 22 Jan 2012 21:25:25 -0800, Chris Barker wrote:

On Sun, Jan 22, 2012 at 9:10 PM, Walter Hurry >>> <walterhurry@lavabit.com> wrote:

But I don't understand your last remark. What is the advantage of
using a custom class as opposed to having my panel be an instance of
wxPanel?

what I was suggesting is that your panel be a subclass of wx.Panel.
See:

wxPython Style Guide - wxPyWiki

for this and other ideas.

Ah, right. I see what you mean now about subclassing wx.Panel. Yes,
that's how I'm doing it; I just didn't understand the terminology.

Also, thanks for the pointer to your syle guide - very helpful. I'm
happy to report that I'm doing almost everything the way you suggest.
One notable exception is that I don't yet even know what docstrings
are! But I shall very soon.

Docstrings are the first comment in each file/function they should be
treble quoted and explain what the file/class/function is to do, (so far
just like a normal comment), but they are preserved and are available to
the user/program/programmer. Try the following:

create a python file called myfile.py with at the beginning a treble
quoted comment about the file, also def a function called fred with at
the beginning a treble quoted comment about the function and save it.
Open the python console in the same directory and type import myfile
then type help(myfile) then type help(myfile.fred), you can also access
the docstring as __doc__ in the file/class/function scope.

This can be VERY useful.