Sizer.AddSpacer: int or size? deprecated?

Hello!

I just have a couple of questions about the AddSpacer method of sizers:

* According to the latest wxWidgets manual, AddSpacer looks like this:

   wxSizerItem* AddSpacer(int size)

That is, I should be able to pass an int to the AddSpacer method to
get a nice spacing in a BoxSizer. However, after testing a bit with
wxPython, it turns out AddSpacer wants a size-tuple instead. How come?

* When a pass a size-tuple to the AddSpacer method, everything works
fine, but I get this message in the prompt from which I run my
program:

    basic_gui.py:71: DeprecationWarning: AddSpacer is deprecated, use
`Add` instead.
        szr1.AddSpacer((0, 23))

Now the wxWidgets manual doesn't say anything about the method being
deprecated and the description of the method is the following:

  "Adds non-stretchable space to the sizer. More readable way of
calling Add(size, size, 0)."

To me, this sounds like a nice method to have. Why has it been
deprecated in wxPython?

//Jonatan

Jonatan Johansson wrote:

Hello!

I just have a couple of questions about the AddSpacer method of
sizers:

* According to the latest wxWidgets manual, AddSpacer looks like
this:

wxSizerItem* AddSpacer(int size)

That is, I should be able to pass an int to the AddSpacer method to get a nice spacing in a BoxSizer. However, after testing a bit with wxPython, it turns out AddSpacer wants a size-tuple instead. How
come?

See at bottom

* When a pass a size-tuple to the AddSpacer method, everything works fine, but I get this message in the prompt from which I run my program:

basic_gui.py:71: DeprecationWarning: AddSpacer is deprecated, use `Add` instead. szr1.AddSpacer((0, 23))

Now the wxWidgets manual doesn't say anything about the method being deprecated and the description of the method is the following:

"Adds non-stretchable space to the sizer. More readable way of calling Add(size, size, 0)."

Because the wxWidgets manual is not the "real" wxPython Manual. You can
find it at wxPython API Documentation — wxPython Phoenix 4.2.2 documentation
Here (http://wxpython.org/docs/api/wx.Sizer-class.html#AddSpacer) you
can find:

"""
AddSpacer(self, *args, **kw)
Compatibility alias for Add.
"""

To me, this sounds like a nice method to have. Why has it been deprecated in wxPython?

Because wxWidgets != wxPython :slight_smile: wxPython is not a binding of all the
wxWidgets methods, but an adapt to its widgets to python, so can be some
differences.

//Jonatan

Michele

Because the wxWidgets manual is not the "real" wxPython Manual. You can
find it at wxPython API Documentation — wxPython Phoenix 4.2.2 documentation

Yeah, I know, and I looked at those before posting but they are very
much imcomplete..

Here (http://wxpython.org/docs/api/wx.Sizer-class.html#AddSpacer) you
can find:

"""
AddSpacer(self, *args, **kw)
Compatibility alias for Add.
"""

It doesn't say anything about sending a size instead of an integer there.

> To me, this sounds like a nice method to have. Why has it been
> deprecated in wxPython?

Because wxWidgets != wxPython :slight_smile: wxPython is not a binding of all the
wxWidgets methods, but an adapt to its widgets to python, so can be some
differences.

I know. But usually, differences between the two have good reasons.
The wxPython docs does not say anything about the type of the
parameter OR why the method has been deprecated. In other words, both
my questions remain unanswered so far.

//Jonatan

Hi Jonatan,

Jonatan Johansson wrote:

Because the wxWidgets manual is not the "real" wxPython Manual. You can
find it at wxPython API Documentation — wxPython Phoenix 4.2.2 documentation
   
Yeah, I know, and I looked at those before posting but they are very
much imcomplete..

The nice thing about the API doc is that it shows all things supported by wxPython, so things in wxWidgets which are not wrapped in wxPython are NOT shown.

The signature (correct term?) of each method is documented, however what is missing is explanation on how things are used.

Actually one of the ones quit well documented is sizer.Add,

http://wxpython.org/docs/api/wx.Sizer-class.html#Add

if you look at it you can see that it is the reason that AddSpacer, AddSizer and AddWindow to no longer be recommended. Check also the changes.txt with wx 2.6.1:
Quote:
wx.Sizer.AddWindow, AddSizer, AddSpacer and etc. have now been
undeprecated at the request of Riaan Booysen, the Boa Constructor team
lead. Boa needs them to help keep track of what kind of item is being
managed by the sizer. They are now just simple compatibility aliases
for Add, and etc.
EndQuote

Hope this helps
Werner

···

Here (http://wxpython.org/docs/api/wx.Sizer-class.html#AddSpacer) you
can find:

"""
AddSpacer(self, *args, **kw)
Compatibility alias for Add.
"""
   
It doesn't say anything about sending a size instead of an integer there.

To me, this sounds like a nice method to have. Why has it been
deprecated in wxPython?
     

Because wxWidgets != wxPython :slight_smile: wxPython is not a binding of all the
wxWidgets methods, but an adapt to its widgets to python, so can be some
differences.
   
I know. But usually, differences between the two have good reasons.
The wxPython docs does not say anything about the type of the
parameter OR why the method has been deprecated. In other words, both
my questions remain unanswered so far.

//Jonatan

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

Hi Jonatan,

To add spacer use:

sizer.Add( (nn,mm) ),

where is nn is amount of horizontal space, mm is amount of vertical space. Note that you can specify "weight" and flags too which gives you many interesting possibilities.

Say code:
sizer.Add( (1,2), 1, wx.EXPAND )
will add spacer that can grow in both dimensions but will not shrink below 1x2 pixels.

    Vladimir Ignatov

The nice thing about the API doc is that it shows all things supported
by wxPython, so things in wxWidgets which are not wrapped in wxPython
are NOT shown.

The signature (correct term?) of each method is documented, however what
is missing is explanation on how things are used.

Exactly. Signatures are autogenerated from the code, so they are all there.
And explanation is missing, yes. Sometimes one can guess the datatypes
and figure out what should be passed and what is returned by looking
at the names, but when you see stuff like

    AddSpacer(self, *args, **kw)

without explanation there's obviously some lack of documentation
(which I imagine is the biggest hurdle for people that are thinking
about using wxPython -- lack of clear documentation).

Check also the
changes.txt with wx 2.6.1:
Quote:
wx.Sizer.AddWindow, AddSizer, AddSpacer and etc. have now been
undeprecated at the request of Riaan Booysen, the Boa Constructor team
lead. Boa needs them to help keep track of what kind of item is being
managed by the sizer. They are now just simple compatibility aliases
for Add, and etc.
EndQuote

That I had not seen (seems like it appeared in 2.5.4.1 btw). That
answers the question "why do the deprecated methods still work?". I
guess the reason for deprecating them in the first place were that you
can pass the exact same argument (size-tuple) to Add and get the same
result in wxPython (you can't send a wxSize or an int to Add in the
wxWidgets -- only two ints). However, I just looked a bit closer at
wxWidgets' AddSpacer and it appears it's just for quadratic spacers:

    More readable way of calling Add(size, size, 0)

And so that's why it only takes one int instead of a wxSize (or two
ints). Silly of me not noticing that. (I will not question why
wxPython doesn't have a simple method for doing quadratic spacers,
since I think those are silly :)) Anyway, I'll just use the Add and
pass it a size-tuple. I still feel the documentation could be clearer
though (how about just copying that part from the changelog to the
AddSpacer, AddWindow and AddSizer methods in the wxPython manual?)

//Jonatan