Size of controls and XRC

The attached script and XRC file demonstrates something that I can't figure
out how to do. I'm attaching my own control to an "Unknown" control using
AttachUnknownControl(). I want the control have it's own natural default
size... in other words, I don't want to set the size (or more specifically,
the height). I can hard code the size of the control in the XRC file, but
then the size won't be the default size on some operating systems. I can
change the size of the control after calling AttachUnknownControl(), but
AutoLayout doesn't seem to take the new size into consideration.

The demo shows 3 cases:

  Control 1) A standard button, for comparison
  Control 2) don't set the size in the XRC file
  Control 3) set the width in the XRC file

I'd like for the custom controls to be the same height as the default button
height.

The results are:

  Control 2) Height is too small
  Control 3) Height is WAY to big

Any help would be greatly appreciated,

  Matthew

<<,test.py>> <<,test.xrc>>

,test.py (1.87 KB)

,test.xrc (2.89 KB)

Matthew Thornley wrote:

The attached script and XRC file demonstrates something that I can't figure out how to do. I'm attaching my own control to an "Unknown" control using AttachUnknownControl(). I want the control have it's own natural default size... in other words, I don't want to set the size (or more specifically, the height). I can hard code the size of the control in the XRC file, but then the size won't be the default size on some operating systems. I can change the size of the control after calling AttachUnknownControl(), but AutoLayout doesn't seem to take the new size into consideration.

The thing to know about the "unknown" type is that there is actually a panel created as a placeholder when the resource is loaded, and then when you call AttachUnknownControl the new control is made a child of that panel. So you have to take that extra window into account when trying to set sizes and such. You might try something like this:

     xctrl = XRCCTRL(self, idText)
     xctrl.SetSize(ctrl.GetBestSize())
     self.GetSizer().SetItemMinSize(xctrl,

                                    xctrl.GetSize().width,

                                    xctrl.GetSize().height)

The sizer will probably need a bit more tweaking though to get it to work right...

  Control 2) Height is too small
  Control 3) Height is WAY to big

I'm not sure why #3 is so huge, on wxGTK all the buttons are real close to the right size. Does it still do this if you use a panel and frame instead of a dialog?

···

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