[wxPython-users] Overlapped controls [was: a scrollbar problem with xrc loaded grid]

Robin Dunn robin at alldunn.com
Mon Dec 3 12:12:06 PST 2007


Stuart McGraw wrote:
> Robin Dunn wrote:
>> Stuart wrote:
> [...]
> 
> Robin, thank you for the excellent explanation of cause
> and fix of the scrollbar anomaly in the grid control when
> loaded via an xrc "unknown" control.
> 
>> A probably better way to take care of this is to not use the unknown
>> control feature at all.  You can use a normal grid class type in the
>> XRC, and set the subclass attribute to the modulename.classname of your
>> grid class.  That causes the subclass factory to create an instance of
>> the class, but in all other ways it will be treated as a wx.grid.Grid.
>> Then there won't be any mysterious container panel created behind the
>> scenes for you to get in the way.  This takes a little tweaking of the
>> class that will be loaded this way, see the demo for an example.
> 
> Yes, I will try doing that next.  But since the current code
> is so close to working, I want to finish it, if only for my
> notes.
> 
>>> The reason there is no sizer in panel2 is that in the
>>> real app, there is also an html control in there,
>>> overlapping the grid, and I will hide one of the other
>>> according to conditions, as per
>>> http://lists.wxwidgets.org/archive/wxPython-users/msg14336.html
> 
>>> Would an "overlap sizer" be a useful addition to wxwidgets?
>>
>> Most people do this simply by putting all of their page windows into a 
>> box sizer, and then hiding all but the one they want shown.  When you 
>> want to show a different page then just show it, hide the old one and 
>> call the sizer's Layout method.
> 
> Ahh, it didn't occur to me that the sizer would take the
> control's visibility into account but it makes sense that
> it would.
> 
> I tried follow your suggestion and it almost works but I still
> have something wrong.  I have an htmlwindow control and an
> xrc.AttachUnknownControl attached Grid subclass in the same sizer,
> and a button to change their Show() states so that when one is
> shown the other is hidden.
> 
> One problem is that (as you pointed out in the previous response)
> the Grid control is placed in an additional Panel created by the
> xrc loader.  So I found I had to show/hide that panel rather
> than the grid itself, which I do by calling grid.GetParent().Show()
> I suppose this is brittle in that XRC might decide to arrange things
> differently someday.  Is there any better way?

No, I don't think there is.


> 
> The second bigger (and remaining) problem is that the shown control
> is not resized correctly after the show status of the grid and
> htmlwindow are swapped (when the Chng View view button in the
> sample code is clicked), but, as soon as the frame size is changed,
> the shown control is properly resized and everything looks right.
> I call the frame's Layout method but it doesn't help.  I also
> tried to generate a synthetic resize event with various permutation
> of ProcessEvent() and CallAfter() but also with no luck, so again
> I could use some help.

Since the sizes of the main frame and panels are not actually changing, 
and since layout is triggered from EVT_SIZE events, you are running into 
a optimization that is preventing the layout you need from happening. 
IOW, since the call to the frame's Layout doesn't actually change the 
size of the panel, then there is no EVT_SIZE of the panel to trigger its 
Layout being called.  So in general when something like this happens the 
answer is to just call the Layout of the window owning the sizer that is 
affected by the change you are making.  In your example that is PANEL2. 
  You can verify this in the widget inspector by selecting PANEL2 in the 
tree, and then typing "obj.Layout()" in the shell.


> 
> Attached are the files overlay.py and overlay.xrc.  The problem
> is evident when the Chng View button is clicked after starting or
> after resizing the frame.
> 
> BTW, thanks for pointer the InspectionTool, it is fantastic.
> 
> Perhaps I am the only person who didn't know about it but in
> case there are others, here are my cheat-sheet cut'n'paste notes
> on using it, in hopes it will save someone a couple minutes.
>     ...
>     import wx.lib.inspection as wxi
>     ...
>     app = wx.Application (...)
>     wxi.InspectionTool().Show()
>     app.MainLoop ()

You can also use the application mixin class and be able to show the 
widget inspector with a hot-key.  See wx.lib.mixins.inspection.


> 
> I also wrote in the original post:
>>> I think a notebook control would also work well if I could
>>> get rid of the tabs and control page switching from buttons
>>> and menus.  Is getting rid of the tabs possible?
> 
> Can I take the lack of an affirmative answer as a negative one?

Oops, sorry I missed that one.  Yes you are right, it is not possible to 
have a wx.Notebook with no tabs.


-- 
Robin Dunn
Software Craftsman
http://wxPython.org  Java give you jitters?  Relax with wxPython!





More information about the wxpython-users mailing list