List Info

Thread: StaticBoxSizer bug?




StaticBoxSizer bug?
user name
2006-04-23 02:29:18
I've run into a disparity in the behavior of StaticBoxSizer
between
wxruby2 and straight C++ wxWindows or wxPython.  I've
attached three
equivalent test programs that place some text in a panel
using a
StaticBoxSizer to create a decorative rectangle around the
text region.
The C++ and wxPython programs create the desired result,
with the
StaticBox expanding to the available space in the window and
adjusting
as the window is resized.  In wxruby2, the StaticBox is
displayed
at its minimum size in the upper left hand corner of the
window
and does not resize.  I've tested all the programs on both
Linux/GTK
and Windows with the same results.  I've tried both an
April 10th
checkout of wxruby2 with SWIG 1.3.24 and the latest April
22nd
checkout with SWIG 1.3.29 with the same result.

After spending a lot of time assuming I was doing something
wrong with
either wxruby2 or the wxWindows API, I finally wrote the
three
test programs for comparison.  I've tried to find the
source of the
problem in wxruby2, but I've verified that the
SWIG-generated code is
calling StaticBoxSizer::Add with the proper parameter
values.  I was
hoping someone on the list might already be aware of the
problem
and point me to a workaround.  At the very least I figured
I'd report
the problem if it had not been identified previously.  I'll
spend
a bit more time trying to track down the source of the
problem, but
I bet it's something really obvious to someone with more
experience
than I at hacking the wxruby2 source.

daniel

#include <wx/wx.h>

class SizerTestApp : public wxApp {
public:
  virtual bool OnInit();
};

class SizerTestFrame : public wxFrame {
public:
  SizerTestFrame(const wxString & title);
};

IMPLEMENT_APP(SizerTestApp);

bool SizerTestApp::OnInit() {
  SizerTestFrame *frame = new
SizerTestFrame("Test");

  frame->Show(true);

  return true;
}

SizerTestFrame::SizerTestFrame(const wxString & title) :
  wxFrame(NULL, wxID_ANY, title)
{
  wxPanel *panel       = new wxPanel(this, wxID_ANY);
  wxBoxSizer *boxSizer = new wxBoxSizer(wxHORIZONTAL);
  wxStaticBox *box     = new wxStaticBox(panel, wxID_ANY,
wxT("BoxTitle"));
  wxStaticText *text   = new wxStaticText(panel, wxID_ANY,
wxT("Some text!"));
  wxStaticBoxSizer *staticBoxSizer = new
wxStaticBoxSizer(box, wxVERTICAL);

  staticBoxSizer->Add(text, 1, wxEXPAND | wxALL, 16);
  boxSizer->Add(staticBoxSizer, 1, wxEXPAND | wxALL, 16);
  panel->SetSizerAndFit(boxSizer);
}
#!/usr/bin/env python

from wxPython.wx import *

class SizerTestFrame(wxFrame):
  def __init__(self, parent, ID, title):
    wxFrame.__init__(self, parent, ID, title)
    panel    = wxPanel(self, wxID_ANY)
    boxSizer = wxBoxSizer(wxHORIZONTAL)
    box      = wxStaticBox(panel, wxID_ANY,
"BoxTitle")
    text     = wxStaticText(panel, wxID_ANY, "Some
text!")
    staticBoxSizer = wxStaticBoxSizer(box, wxVERTICAL)

    staticBoxSizer.Add(text, 1, wxEXPAND | wxALL, 16)
    boxSizer.Add(staticBoxSizer, 1, wxEXPAND | wxALL, 16)
    panel.SetSizerAndFit(boxSizer)

class SizerTestApp(wxApp):
  def __init__( self  ):
    wxApp.__init__( self )

  def OnInit(self):
    self.frame = SizerTestFrame(NULL, wxID_ANY,
"Test")
    self.frame.Show(true)
    return true

SizerTestApp().MainLoop()
#!/usr/bin/env ruby

require 'wx'

class SizerTestFrame < Wx::Frame
  def initialize(*args)
    super(*args)

    panel     = Wx::Panel.new(self, Wx::ID_ANY)
    box_sizer = Wx::BoxSizer.new(Wx::HORIZONTAL)
    box       = Wx::StaticBox.new(panel, Wx::ID_ANY, 'Box
Title')
    text      = Wx::StaticText.new(panel, Wx::ID_ANY, 'Some
text!')
    static_box_sizer = Wx::StaticBoxSizer.new(box,
Wx::VERTICAL)

    static_box_sizer.add(text, 1, Wx::EXPAND | Wx::ALL, 16)
    box_sizer.add(static_box_sizer, 1, Wx::EXPAND | Wx::ALL,
16)
    panel.set_sizer_and_fit(box_sizer)
  end
end

class SizerTestApp < Wx::App
  def on_init
    frame = SizerTestFrame.new(nil, Wx::ID_ANY, 'Test')
    frame.show
  end
end

SizerTestApp.new.main_loop
_______________________________________________
wxruby-users mailing list
wxruby-usersrubyforge.org
ht
tp://rubyforge.org/mailman/listinfo/wxruby-users
StaticBoxSizer bug?
user name
2006-04-23 02:49:15
I wrote:
>and Windows with the same results.  I've tried both an
April 10th
>checkout of wxruby2 with SWIG 1.3.24 and the latest
April 22nd
>checkout with SWIG 1.3.29 with the same result.

I forgot to add that I'm using wxWindows 2.6.3.

daniel

_______________________________________________
wxruby-users mailing list
wxruby-usersrubyforge.org
ht
tp://rubyforge.org/mailman/listinfo/wxruby-users
StaticBoxSizer bug?
user name
2006-04-23 03:36:51
Daniel,

Thanks for the sample code.  Sizers do appear to have a
problem and it's 
on the list to take a look at.  I'm currently reworking
several classes 
and trying to fix some of the big compatibility bugs.  I
will test your 
code with my latest builds but I don't think I've gotten
to the sizers yet.

Roy

Daniel F. Savarese wrote:
> I've run into a disparity in the behavior of
StaticBoxSizer between
> wxruby2 and straight C++ wxWindows or wxPython.  I've
attached three
> equivalent test programs that place some text in a
panel using a
> StaticBoxSizer to create a decorative rectangle around
the text region.
> The C++ and wxPython programs create the desired
result, with the
> StaticBox expanding to the available space in the
window and adjusting
> as the window is resized.  In wxruby2, the StaticBox is
displayed
> at its minimum size in the upper left hand corner of
the window
> and does not resize.  I've tested all the programs on
both Linux/GTK
> and Windows with the same results.  I've tried both an
April 10th
> checkout of wxruby2 with SWIG 1.3.24 and the latest
April 22nd
> checkout with SWIG 1.3.29 with the same result.
>
> After spending a lot of time assuming I was doing
something wrong with
> either wxruby2 or the wxWindows API, I finally wrote
the three
> test programs for comparison.  I've tried to find the
source of the
> problem in wxruby2, but I've verified that the
SWIG-generated code is
> calling StaticBoxSizer::Add with the proper parameter
values.  I was
> hoping someone on the list might already be aware of
the problem
> and point me to a workaround.  At the very least I
figured I'd report
> the problem if it had not been identified previously. 
I'll spend
> a bit more time trying to track down the source of the
problem, but
> I bet it's something really obvious to someone with
more experience
> than I at hacking the wxruby2 source.
>
> daniel
>
>   
>
------------------------------------------------------------
------------
>
> #include <wx/wx.h>
>
> class SizerTestApp : public wxApp {
> public:
>   virtual bool OnInit();
> };
>
> class SizerTestFrame : public wxFrame {
> public:
>   SizerTestFrame(const wxString & title);
> };
>
> IMPLEMENT_APP(SizerTestApp);
>
> bool SizerTestApp::OnInit() {
>   SizerTestFrame *frame = new
SizerTestFrame("Test");
>
>   frame->Show(true);
>
>   return true;
> }
>
> SizerTestFrame::SizerTestFrame(const wxString &
title) :
>   wxFrame(NULL, wxID_ANY, title)
> {
>   wxPanel *panel       = new wxPanel(this, wxID_ANY);
>   wxBoxSizer *boxSizer = new wxBoxSizer(wxHORIZONTAL);
>   wxStaticBox *box     = new wxStaticBox(panel,
wxID_ANY, wxT("BoxTitle"));
>   wxStaticText *text   = new wxStaticText(panel,
wxID_ANY, wxT("Some text!"));
>   wxStaticBoxSizer *staticBoxSizer = new
wxStaticBoxSizer(box, wxVERTICAL);
>
>   staticBoxSizer->Add(text, 1, wxEXPAND | wxALL,
16);
>   boxSizer->Add(staticBoxSizer, 1, wxEXPAND | wxALL,
16);
>   panel->SetSizerAndFit(boxSizer);
> }
>   
>
------------------------------------------------------------
------------
>
> #!/usr/bin/env python
>
> from wxPython.wx import *
>
> class SizerTestFrame(wxFrame):
>   def __init__(self, parent, ID, title):
>     wxFrame.__init__(self, parent, ID, title)
>     panel    = wxPanel(self, wxID_ANY)
>     boxSizer = wxBoxSizer(wxHORIZONTAL)
>     box      = wxStaticBox(panel, wxID_ANY,
"BoxTitle")
>     text     = wxStaticText(panel, wxID_ANY,
"Some text!")
>     staticBoxSizer = wxStaticBoxSizer(box, wxVERTICAL)
>
>     staticBoxSizer.Add(text, 1, wxEXPAND | wxALL, 16)
>     boxSizer.Add(staticBoxSizer, 1, wxEXPAND | wxALL,
16)
>     panel.SetSizerAndFit(boxSizer)
>
> class SizerTestApp(wxApp):
>   def __init__( self  ):
>     wxApp.__init__( self )
>
>   def OnInit(self):
>     self.frame = SizerTestFrame(NULL, wxID_ANY,
"Test")
>     self.frame.Show(true)
>     return true
>
> SizerTestApp().MainLoop()
>   
>
------------------------------------------------------------
------------
>
> #!/usr/bin/env ruby
>
> require 'wx'
>
> class SizerTestFrame < Wx::Frame
>   def initialize(*args)
>     super(*args)
>
>     panel     = Wx::Panel.new(self, Wx::ID_ANY)
>     box_sizer = Wx::BoxSizer.new(Wx::HORIZONTAL)
>     box       = Wx::StaticBox.new(panel, Wx::ID_ANY,
'Box Title')
>     text      = Wx::StaticText.new(panel, Wx::ID_ANY,
'Some text!')
>     static_box_sizer = Wx::StaticBoxSizer.new(box,
Wx::VERTICAL)
>
>     static_box_sizer.add(text, 1, Wx::EXPAND | Wx::ALL,
16)
>     box_sizer.add(static_box_sizer, 1, Wx::EXPAND |
Wx::ALL, 16)
>     panel.set_sizer_and_fit(box_sizer)
>   end
> end
>
> class SizerTestApp < Wx::App
>   def on_init
>     frame = SizerTestFrame.new(nil, Wx::ID_ANY,
'Test')
>     frame.show
>   end
> end
>
> SizerTestApp.new.main_loop
>   
>
------------------------------------------------------------
------------
>
> _______________________________________________
> wxruby-users mailing list
> wxruby-usersrubyforge.org
> ht
tp://rubyforge.org/mailman/listinfo/wxruby-users
_______________________________________________
wxruby-users mailing list
wxruby-usersrubyforge.org
ht
tp://rubyforge.org/mailman/listinfo/wxruby-users
StaticBoxSizer bug?
user name
2006-04-24 01:11:42
In message <444AF653.3060203mindspring.com>, Roy
Sutton writes:
>Thanks for the sample code.  Sizers do appear to have a
problem and it's 
>on the list to take a look at.  I'm currently reworking
several classes 
>and trying to fix some of the big compatibility bugs.  I
will test your 
>code with my latest builds but I don't think I've
gotten to the sizers yet.

I'm not very intimate with SWIG, so it's taken me a lot
longer to figure
out what's going on than it would have otherwise.  However,
I verified
that the code generated in StaticBoxSizer.cpp makes calls to
wxBoxSizer
methods and not wxStaticBoxSizer methods.  I hand-changed
the call to
wxBoxSizer::RecalcSizes() in 
void SwigDirector_wxStaticBoxSizer::RecalcSizes()
to wxStaticBoxSizer::RecalcSizes() and my sample program
worked properly.

After that, I realized the overridden virtual method was
missing in
wxStaticBoxSizer.h.  I've attached a patch.

Now that I've spent enough time getting familiar with the
way the
code is generated, I'm left wondering if there's an
alternative to
maintaining custom wxFoo.h headers.  Is there a way to
generate them
from existing wxWidgets headers?  It seems error prone and a
lot of
work to maintain a separate set of headers.  I'm probably
just
revealing my general ignorance of SWIG.  Is there a
convention
being used to decide which methods/constructors are included
and
which omitted?  For example, the second wxStaticBoxSizer
constructor
is omitted.  My guess was it might have something to do with
memory
allocation, so I didn't add it even though on the surface
it worked.
If there's some documentation about this sort of stuff,
I'd appreciate
any pointers so I can contribute conformant patches as I run
into issues.
I'll be brushing up on the SWIG manual too.

daniel
_______________________________________________
wxruby-users mailing list
wxruby-usersrubyforge.org
ht
tp://rubyforge.org/mailman/listinfo/wxruby-users
StaticBoxSizer bug?
user name
2006-04-24 04:00:27
Daniel F. Savarese wrote:
> I'm not very intimate with SWIG, so it's taken me a
lot longer to figure
> out what's going on than it would have otherwise.
Now you know how we all feel. 
> After that, I realized the overridden virtual method
was missing in
> wxStaticBoxSizer.h.  I've attached a patch.
>   
The patch didn't apply for me.  I have created a new patch
for the two 
affected files.
> Now that I've spent enough time getting familiar with
the way the
> code is generated, I'm left wondering if there's an
alternative to
> maintaining custom wxFoo.h headers.  Is there a way to
generate them
> from existing wxWidgets headers?  It seems error prone
and a lot of
> work to maintain a separate set of headers.  I'm
probably just
> revealing my general ignorance of SWIG.
As to the reason for the header files....  Well....  Perhaps
Kevin can 
get into that some more.   SWIG is very good at certain
things and it 
may even be able to do much of what's needed with the raw
headers now.
> Is there a convention
> being used to decide which methods/constructors are
included and
> which omitted?  For example, the second
wxStaticBoxSizer constructor
> is omitted.  My guess was it might have something to do
with memory
> allocation, so I didn't add it even though on the
surface it worked.
> If there's some documentation about this sort of
stuff, I'd appreciate
> any pointers so I can contribute conformant patches as
I run into issues.
> I'll be brushing up on the SWIG manual too.
>   
I added in the 2nd constructor.  There's not much reason
for it to be 
missing.  The SWIG manual only reveals its wisdom slowly.
Good luck! 

Roy

C:\RubyDev>diff -b -u
wxruby2_old/swig/classes/include/wxBoxSizer.h
wxruby2/swig/classes/include/wxBoxSizer.h  
--- wxruby2_old/swig/classes/include/wxBoxSizer.h	2005-08-21
23:48:04.000000000 -0400
+++ wxruby2/swig/classes/include/wxBoxSizer.h	2006-04-23
23:41:28.544736000 -0400
 -10,10
+10,11 
   virtual ~wxBoxSizer();
 
   int GetOrientation() ;
+  void SetOrientation(int orient);
 
   // define pure virtual methods from base classes
-  virtual void RecalcSizes();
-  virtual wxSize CalcMin();
+  void RecalcSizes();
+  wxSize CalcMin();
 };
 
 

C:\RubyDev>diff -b -u
wxruby2_old/swig/classes/include/wxStaticBoxSizer.h
wxruby2/swig/classes/include/wxStaticBoxSizer.h  
---
wxruby2_old/swig/classes/include/wxStaticBoxSizer.h	2006-04-
23 22:59:10.284897600 -0400
+++
wxruby2/swig/classes/include/wxStaticBoxSizer.h	2006-04-23
23:30:33.582947200 -0400
 -7,8
+7,9 
 {
 public:
   wxStaticBoxSizer(wxStaticBox* box, int orient);
-  virtual void RecalcSizes();
-  virtual wxSize CalcMin();
+  wxStaticBoxSizer(int orient, wxWindow *win, const
wxString& label = wxEmptyString);
+  void RecalcSizes();
+  wxSize CalcMin();
   wxStaticBox* GetStaticBox() const;
   virtual void ShowItems(bool show);
 };
_______________________________________________
wxruby-users mailing list
wxruby-usersrubyforge.org
ht
tp://rubyforge.org/mailman/listinfo/wxruby-users
-fvirtual and compactdefaultargs (was StaticBoxSizer bug?)
user name
2006-04-24 21:12:10
In message <444C4D5B.6060801mindspring.com>, Roy
Sutton writes:
>The patch didn't apply for me.  I have created a new
patch for the two 
>affected files.

You probably needed a -p0 (assuming application from inside
wxruby2/)
or we had slightly different versions of the source files or
maybe
the .orig file suffix threw off your version of patch and it
prefers
the top-level directories to differ.  If the convention for
wxruby2
patch submissions is to generate them from a level above the
source
tree, I can do that in the future.  Is the mailing list the
preferred
patch submission medium?  I noticed that there's a
little-used Patch
category in the issue tracker.

How do people feel about adding -fvirtual to swig_options in
rake/rakewx.rb to eliminate redundant wrapper generation?  I
raise this question because prior to declaring RecalcSize()
in the
wxStaticBoxSizer.h, the wrapper generated for it in
StaticBoxSizer.cpp
was a redundant version of what was generated for BoxSizer. 
Also, how
about using %feature("compactdefaultargs")
across the board (putting it
in common.i) to reduce the library size?  It shaved off
700KB
of object code for me.  For example, Sizer::Add went from
having
18 wrapper functions to just 6.

daniel
_______________________________________________
wxruby-users mailing list
wxruby-usersrubyforge.org
ht
tp://rubyforge.org/mailman/listinfo/wxruby-users
-fvirtual and compactdefaultargs (was StaticBoxSizer bug?)
user name
2006-04-25 03:07:36
Daniel F. Savarese wrote:
> In message <444C4D5B.6060801mindspring.com>, Roy
Sutton writes:
>   
>> The patch didn't apply for me.  I have created a
new patch for the two 
>> affected files.
>>     
>
> You probably needed a -p0 (assuming application from
inside wxruby2/)
> or we had slightly different versions of the source
files or maybe
> the .orig file suffix threw off your version of patch
and it prefers
> the top-level directories to differ.  If the convention
for wxruby2
> patch submissions is to generate them from a level
above the source
> tree, I can do that in the future.  Is the mailing list
the preferred
> patch submission medium?  I noticed that there's a
little-used Patch
> category in the issue tracker.
>   
We've been using the mailing list.  We were working on
getting a darcs 
repository going but I really don't recall now whether
that's up and 
running (anyone?).

> How do people feel about adding -fvirtual to
swig_options in
> rake/rakewx.rb to eliminate redundant wrapper
generation?  I
> raise this question because prior to declaring
RecalcSize() in the
> wxStaticBoxSizer.h, the wrapper generated for it in
StaticBoxSizer.cpp
> was a redundant version of what was generated for
BoxSizer.  Also, how
> about using %feature("compactdefaultargs")
across the board (putting it
> in common.i) to reduce the library size?  It shaved off
700KB
> of object code for me.  For example, Sizer::Add went
from having
> 18 wrapper functions to just 6.
>   
Hmm.  I will test all my samples.  I actually think
"compactdefaultargs" 
will fix at least one bug (the listbox bug) in the SWIG
wrappers.  I 
will do a complete rebuild and try each of these options.

Roy
_______________________________________________
wxruby-users mailing list
wxruby-usersrubyforge.org
ht
tp://rubyforge.org/mailman/listinfo/wxruby-users
StaticBoxSizer bug?
user name
2006-04-30 01:01:13
On Mon, 2006-04-24 at 00:00 -0400, Roy Sutton wrote:
> Daniel F. Savarese wrote:
> > After that, I realized the overridden virtual
method was missing in
> > wxStaticBoxSizer.h.  I've attached a patch.
> >   
> The patch didn't apply for me.  I have created a new
patch for the two 
> affected files.

The follow-up patches didn't look right to me, as they were
missing the
"virtual" keyword in some cases. So I took a mix
of Daniel's original
patch and your two patches, and hopefully ended up with
something great.
A special thanks to Daniel, not only for the patch, but for
submitting a
great problem report with sample code. Definitely makes my
job easier!

> > Now that I've spent enough time getting familiar
with the way the
> > code is generated, I'm left wondering if there's
an alternative to
> > maintaining custom wxFoo.h headers.  Is there a
way to generate them
> > from existing wxWidgets headers?  It seems error
prone and a lot of
> > work to maintain a separate set of headers.  I'm
probably just
> > revealing my general ignorance of SWIG.

Not at all. The biggest problem in trying to SWIG the wx
headers
directly is that wx is a complex cross-platform app. They
actually have
a set of shared headers, and then a whole large set of
headers for each
platform. The only way I could see that it might work would
be to swig
each platform's set of headers separately, but I'm afraid
that would
minimize our ability to fix bugs in one place to benefit all
platforms.

The best short-term answer would probably be to build a
comprehensive
test suite.

In my perfect world, the creators of all the wx wrappers for
all the
languages (python, ruby, lua, etc) would work together to
create one
perfect set of wx .h files. I haven't actively contacted
those other
maintainers to see if there is any interest. But if I create
bindings
for Io someday, at least I'll have good swiggable wx .h
files to start
from.

Kevin


_______________________________________________
wxruby-users mailing list
wxruby-usersrubyforge.org
ht
tp://rubyforge.org/mailman/listinfo/wxruby-users
-fvirtual and compactdefaultargs (was StaticBoxSizer bug?)
user name
2006-04-30 02:42:47
On Mon, 2006-04-24 at 17:12 -0400, Daniel F. Savarese wrote:
> If the convention for wxruby2 patch submissions is to
generate them 
> from a level above the source tree, I can do that in
the future.  

It is. I am accustomed to using -p1 because some tool I used
a while
back only accepted patches in that form.

> Is the mailing list the preferred patch submission
medium?  

Yes, for now. As Roy mentioned, there is a darcs mirror, and
I have
accepted some darcs patches in the past. I'm not that fond
of darcs, but
it is the most stable distributed RCS tool out there. I
still hope to
switch wxruby to bzr at some point, but that is probably at
least six
months away.

> How do people feel about adding -fvirtual to
swig_options in
> rake/rakewx.rb to eliminate redundant wrapper
generation?  
(snip)
> Also, how about using
%feature("compactdefaultargs") across the board 

Sounds good to me. I rebuilt everything, and quick testing
seemed to
show that nothing had become worse (or better). It cut the
src directory
by about 2 megs, the obj directory by about 4 megs, and the
resulting
wxruby2.so library by about 2 megs.

Thanks!

Kevin


_______________________________________________
wxruby-users mailing list
wxruby-usersrubyforge.org
ht
tp://rubyforge.org/mailman/listinfo/wxruby-users
StaticBoxSizer bug?
user name
2006-04-30 03:59:39
Kevin Smith wrote:
> The follow-up patches didn't look right to me, as they
were missing the
> "virtual" keyword in some cases. So I took
a mix of Daniel's original
> patch and your two patches, and hopefully ended up with
something great.
I left off virtual on purpose because the actual wx header
files don't 
have them.

Roy
_______________________________________________
wxruby-users mailing list
wxruby-usersrubyforge.org
ht
tp://rubyforge.org/mailman/listinfo/wxruby-users
[1-10] [11-12]

about | contact  Other archives ( Real Estate discussion Medical topics )