SetStatusWidths bug?

Hi (Robin),

    I got a bug report from a Phoenix user regarding the use of
SetStatusWidths for a wx.StatusBar. there is no error message, but the
user claims it doesn't work. The (not-runnable) sample included was:

# A Statusbar in the bottom of the window
        self.CreateStatusBar(number=2)
        ar= self.GetStatusBar()
        ly= array('i')
        ly=[100, 200]
        ar.SetStatusWidths(ly)

# Won't work on Python 3.2 and wxPhoenix r73041
# In Python 2.7 and wxPython 2.9 it does.

I didn' test it (yet), but I can see that the documentation of
wx.StatusBar.SetStatusWidths and the one of wx.Frame.SetStatusWidths
are inconsistent:

1. In wx.Frame.SetStatusWidths:

http://wxpython.org/Phoenix/docs/html/Frame.html#Frame.SetStatusWidths

SetStatusWidths(self, widths_field)
Sets the widths of the fields in the status bar.

Parameters:
n (int) – The number of fields in the status bar. It must be the same
used in CreateStatusBar.
widths_field (int) – Must contain an array of n integers, each of
which is a status field width in pixels. A value of -1 indicates that
the field is variable width; at least one field must be -1. You should
delete this array after calling SetStatusWidths .

There is no "n" parameter in the method signature.

2. In wx.StatusBar.SetStatusWidths:

http://wxpython.org/Phoenix/docs/html/StatusBar.html#StatusBar.SetStatusWidths

SetStatusWidths(self, n, widths_field)
Sets the widths of the fields in the status line.

... skipped docs ...

Parameters:
n (int) – The number of fields in the status bar. Must be equal to the
number passed to SetFieldsCount the last time it was called.
widths_field (int) – Contains an array of n integers, each of which is
either an absolute status field width in pixels if positive or
indicates a variable width field if negative. The special value None
means that all fields should get the same width.

The method seems to use the "n" parameter, but I would say it is
inconsistent with the wx.Frame one if the wx.Frame one does not use
the "n" parameter (and in Classic, it doesn't).

···

--
Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://www.infinity77.net

# ------------------------------------------------------------- #
def ask_mailing_list_support(email):

    if mention_platform_and_version() and include_sample_app():
        send_message(email)
    else:
        install_malware()
        erase_hard_drives()
# ------------------------------------------------------------- #

Hi (Robin),

     I got a bug report from a Phoenix user regarding the use of
SetStatusWidths for a wx.StatusBar. there is no error message, but the
user claims it doesn't work. The (not-runnable) sample included was:

# A Statusbar in the bottom of the window
         self.CreateStatusBar(number=2)
         ar= self.GetStatusBar()
         ly= array('i')
         ly=[100, 200]
         ar.SetStatusWidths(ly)

# Won't work on Python 3.2 and wxPhoenix r73041
# In Python 2.7 and wxPython 2.9 it does.

I didn' test it (yet), but I can see that the documentation of
wx.StatusBar.SetStatusWidths and the one of wx.Frame.SetStatusWidths
are inconsistent:

[...]

The method seems to use the "n" parameter, but I would say it is
inconsistent with the wx.Frame one if the wx.Frame one does not use
the "n" parameter (and in Classic, it doesn't).

The C++ declarations are like this:

     virtual void SetStatusWidths(int n, const int* widths_field);

and for wx.Frame.SetStatusWidths I had done these tweaks:

     c.find('SetStatusWidths.n').arraySize = True
     c.find('SetStatusWidths.widths_field').array = True

But I hadn't done it for wx.StatusBar, it's done now.

The tweaks basically tell SIP that the n parameter is the size of the array pointed to by width_field, and the generated code will then accept a single parameter that is a Python list of integers and will then build the n and widths_field parameters before calling the C++ method. So if you're not already doing it then it would be a good idea to check if the arraySize attribute is set and then not generate any docs for that parameter if it is.

···

On 11/28/12 12:08 PM, Andrea Gavana wrote:

--
Robin Dunn
Software Craftsman

Oops. After writing a quick unittest for this case I discovered that those annotations don't work for integer arrays for some reason. (Only wrapped types or char arrays.) I'll have to do something more creative instead.

···

On 11/28/12 1:55 PM, Robin Dunn wrote:

The C++ declarations are like this:

     virtual void SetStatusWidths(int n, const int* widths_field);

and for wx.Frame.SetStatusWidths I had done these tweaks:

     c.find('SetStatusWidths.n').arraySize = True
     c.find('SetStatusWidths.widths_field').array = True

But I hadn't done it for wx.StatusBar, it's done now.

The tweaks basically tell SIP that the n parameter is the size of the
array pointed to by width_field, and the generated code will then accept
a single parameter that is a Python list of integers and will then build
the n and widths_field parameters before calling the C++ method. So if
you're not already doing it then it would be a good idea to check if the
arraySize attribute is set and then not generate any docs for that
parameter if it is.

--
Robin Dunn
Software Craftsman