Sizer/Layout Troubles

Hello,

I'm a newcomer to wxPython (and GUI programming in general). I'm also
almost completely blind, so creating good-looking interfaces is often
not a walk in the park.

I have attached a simple example program, consisting of a read-only
multi-line text control and two buttons. In the call to
wx.Frame.__init__(), I have specified a size, as using the defaults
seems to create a ridiculously small window. However, sighted users
report that the text in the window is too small, so small as to be
unreadable. If I omit the size parameter and then resize the window
manually, the text is readable, and everything looks as it should (with
the two buttons underneath the text control, aligned to the left and right).

Could anybody tell me where I'm going wrong? I have a feeling I've
messed up somewhere when writing the code for my sizers; it was
suggested that I call sizer.Fit() but when I did that, the buttons
disappeared.

Thanks.

sample_gui.py (1.63 KB)

···

--
James Scholes
http://twitter.com/JamesScholes

Odd -- it works great for me, either with or without specifying an
initial size for the Frame.

Ans i"m confused, initial size and/or doing sizers oddly shouldn't
change the size of the text itself, only the size of widgets and how
they are laid out.

What OS, Python, and wxPython version is this?

(it's working just fine on OS-X, wxPython2.8.12)

I've enclosed a version with some minor code style changes
(see: wxPython Style Guide - wxPyWiki)

HTH,
-Chris

sample_gui.py (1.71 KB)

···

On Thu, Mar 14, 2013 at 2:24 PM, James Scholes <james@jls-radio.com> wrote:

I have attached a simple example program, consisting of a read-only
multi-line text control and two buttons. In the call to
wx.Frame.__init__(), I have specified a size, as using the defaults
seems to create a ridiculously small window. However, sighted users
report that the text in the window is too small, so small as to be
unreadable. If I omit the size parameter and then resize the window
manually, the text is readable, and everything looks as it should (with
the two buttons underneath the text control, aligned to the left and right).

Could anybody tell me where I'm going wrong?

--

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

Chris Barker - NOAA Federal wrote:

What OS, Python, and wxPython version is this?

Windows 7 X64, Python 2.7.2, wxPython 2.9.4.0. Running your code
without a size supplied to the frame constructor results in an
absolutely tiny window.

···

--
James Scholes
http://twitter.com/JamesScholes

Hi James,

Hello,

I'm a newcomer to wxPython (and GUI programming in general). I'm also
almost completely blind, so creating good-looking interfaces is often
not a walk in the park.

I have attached a simple example program, consisting of a read-only
multi-line text control and two buttons. In the call to
wx.Frame.__init__(), I have specified a size, as using the defaults
seems to create a ridiculously small window. However, sighted users
report that the text in the window is too small, so small as to be
unreadable. If I omit the size parameter and then resize the window
manually, the text is readable, and everything looks as it should (with
the two buttons underneath the text control, aligned to the left and right).

Could anybody tell me where I'm going wrong? I have a feeling I've
messed up somewhere when writing the code for my sizers; it was
suggested that I call sizer.Fit() but when I did that, the buttons
disappeared.

I think Chris gave you the answers on your original code.

Attached is an alternative way of doing it using my favorite way of dealing with sizers, i.e. using wx.lib.sized_controls and I also added the WIT - which is very helpful for debugging sizer issues.

http://wiki.wxpython.org/Widget%20Inspection%20Tool

Hope it helps
Werner

sample.py (1.64 KB)

···

On 14/03/2013 22:24, James Scholes wrote:

James Scholes wrote:

Chris Barker - NOAA Federal wrote:

What OS, Python, and wxPython version is this?

Windows 7 X64, Python 2.7.2, wxPython 2.9.4.0. Running your code
without a size supplied to the frame constructor results in an
absolutely tiny window.

The default size of a frame is something like 400x250 pixels, which is not necessarily "absolutely tiny" for a sighted person depending on what the content of the frame is, but which I expect it could certainly be considered to be tiny by a vision impaired person.

The layout in the sample scripts is correct for how the code is written, but I'm guessing that James is expecting something different. It does look a little odd when the window size is increased because the normal sized labels are then sitting inside of a very large empty space, and that is probably what was meant by those who said that the text looked tiny. James, if you are wanting the size of the text to also increase as the space around them increases then you will need to manage that in the code. wxWidgets does not automatically scale the font sizes of labels to fit the widget. That is doable in the application code, but that may look odd for a sighted person too.

On the other hand, if you want the application to look normal for a sighted person but still be large enough to display your results, then one easy change to make would be to use a zero for the proportion parameter when adding the horizontal sizer to the vertical sizer. That will keep the buttons from expanding vertically and to stay at their default height.

···

--
Robin Dunn
Software Craftsman

Robin Dunn wrote:

On the other hand, if you want the application to look normal for a
sighted person but still be large enough to display your results, then
one easy change to make would be to use a zero for the proportion
parameter when adding the horizontal sizer to the vertical sizer. That
will keep the buttons from expanding vertically and to stay at their
default height.

I implemented your suggestion into my main program, generated some
results and took a screenshot of the main window (attached). While this
isn't a code-related question per say, are the results inside the
TextCtrl and the text of the buttons readable? In short, does the
window look normal/usable?

Thanks.

···

--
James Scholes
http://twitter.com/JamesScholes

James Scholes wrote:

Robin Dunn wrote:

On the other hand, if you want the application to look normal for a
sighted person but still be large enough to display your results, then
one easy change to make would be to use a zero for the proportion
parameter when adding the horizontal sizer to the vertical sizer. That
will keep the buttons from expanding vertically and to stay at their
default height.

I implemented your suggestion into my main program, generated some
results and took a screenshot of the main window (attached). While this
isn't a code-related question per say, are the results inside the
TextCtrl and the text of the buttons readable? In short, does the
window look normal/usable?

The "Save to file" button is stuck in the upper-left corner and is underneath the results label, so it probably was accidentally removed from its sizer. Other than that it looks good to me.

···

--
Robin Dunn
Software Craftsman

Robin Dunn wrote:

The "Save to file" button is stuck in the upper-left corner and is
underneath the results label, so it probably was accidentally removed
from its sizer. Other than that it looks good to me.

The "Save to File" button isn't shown until the user selects a valid
folder and the results have been loaded. I added a call to
BoxSizer.Layout after the call to Button .Show, which has hopefully
fixed the problem (hopefully I called Layout on the correct Sizer!).
Screenshot is attached.

Thanks again for all the help on this.

···

--
James Scholes
http://twitter.com/JamesScholes

James Scholes wrote:

Robin Dunn wrote:

The "Save to file" button is stuck in the upper-left corner and is
underneath the results label, so it probably was accidentally removed
from its sizer. Other than that it looks good to me.

The "Save to File" button isn't shown until the user selects a valid
folder and the results have been loaded. I added a call to
BoxSizer.Layout after the call to Button .Show, which has hopefully
fixed the problem (hopefully I called Layout on the correct Sizer!).
Screenshot is attached.

Thanks again for all the help on this.

Ok. Yes, everything looks good in the 2nd screenshot.

Do you call Hide() on that button when it is created? If so then what I saw in the other screenshot may just be a Windows glitch and perhaps adding a wx.CallAfter(self.panel.Refresh) will help, so it gets an extra refresh after the frame is first shown.

···

--
Robin Dunn
Software Craftsman

Hi James,

Robin Dunn wrote:

The "Save to file" button is stuck in the upper-left corner and is
underneath the results label, so it probably was accidentally removed
from its sizer. Other than that it looks good to me.

The "Save to File" button isn't shown until the user selects a valid
folder and the results have been loaded. I added a call to
BoxSizer.Layout after the call to Button .Show, which has hopefully
fixed the problem (hopefully I called Layout on the correct Sizer!).
Screenshot is attached.

Thanks again for all the help on this.

Don't like to disagree with Robin:-) , but the statictext "Results" takes up too much space.

In the orginal code you would change the line:

vSizer.Add(resultsTextLabel, 1, wx.ALL|wx.EXPAND|wx.ALIGN_CENTER, 5)

to:

vSizer.Add(resultsTextLabel, 0, wx.ALL|wx.ALIGN_CENTER, 5)

I.e. set proportion to 0 and do not use wx.EXPAND.

Best regards
Werner

···

On 15/03/2013 21:50, James Scholes wrote: