linus72982
linus72982

Reputation: 1393

wxPython -- GetSize doesn't return actual size

I have a Notebook and add two panels to it. When I try to get the usable area of one of the panels, it returns (20,20) -- I imagine this is its size before stuff is put in. I want to get this size before I put stuff in because some proportions depend on it and I'd prefer not using absolutes.

I haven't set an actual size, I just sized everything with a boxsizer and set proportions. I'd like to get the actual pixel width of the area allotted to the panel (it doesn't take up the entire program window area).

I've tried calling Layout before GetSize, I've tried GetVirtualSize and Get ClientSize and any other available size returns, still (20, 20) or sometimes (10,40). I've tried getting the parent size, no go. I get the grandparent size and it shows correctly, but this is the size of the entire program window. Is there a way to get the potentially usable area of a panel? If need be, I can post the layout, but it's long.

Upvotes: 0

Views: 249

Answers (1)

RobinDunn
RobinDunn

Reputation: 6306

It sounds like you are trying to do this at the time of the creation of the window, before the initial layout and sizing is done, so everything still has its initial size. There are some alternative ways to deal with this situation. You could delay creating the content of the panel until the first size event. Or you could design your sizer layout to be adaptable to any (resonable) size. Or you could adjust/redo the sizer layout later if needed.

Or perhaps the easiest would be to send a fake size event to the parent or top-level parent so they will do what their normal layout resizing the child windows, which will cascade to your panel. This may not work in all situations, but it is common enough that there is a window method for it, SendSizeEvent.

Upvotes: 1

Related Questions