Sizers and wxMediaCtrl

I’m working with a recent 4.1.0a1.dev daily build trying to get the wxMediaCtrl working on macOS Catalina for a wxPython app that’s worked on earlier versions of macOS for years. I need to support multiple instances of the wxMediaCtrl at the same time. I’m running into difficulty with the MediaCtrl getting a minimum size based on the media file that is loaded. Specifically, I can’t seem to over-ride that size how I want.

Imagine three MediaCtrls arranged horizontally in a frame that is, say, 1800 pixels wide. They’re in a horizontal BoxSizer that gives each MediaCtrl the same proportional size as the others. Before I load any video, the three sizers coexist happily, and when I resize my window, they all adjust to continue to share the available space 1/3, 1/3, and 1/3. This is the behavior I want.

Then I load a media file into each MediaCtrl that has a media width of 720. If I immediately hit “Play”, no problem. I get three videos playing, each with a width of 587 (600 - border pixels, etc.). Looks perfect. Each media player reports the correct size with mediaPlayerX.GetSize(), and the sizer that holds it reports the correct size with mediaPlayerX.GetSizer().GetSize(). mediaPlayerX.GetSizer().GetMinSize() reports (-1, -1). Cool.

But then I change the size of my frame using the mouse. Suddenly, mediaPlayer1 is 728 pixels wide and the GetMinSize() call reports values from the media file’s actual size, (728, 316). Same for mediaPlayer2. mediaPlayer3 gets the remaining 304 pixels, so is MUCH smaller than the other two. This happens whether SetAutoLayout() is True or False.

I’ve tried detecting where exactly the MinSize values are getting set, but I can’t figure it out. They’re not set in the Load() method, and they’re not set when my wx.media.EVT_MEDIA_LOADEDhandler fires. But the data is present when I handle wx.EVT_SIZE, even before I call event.Skip(), and resetting the MinSize to (-1, -1) at the start of my EVT_SIZE handler does nothing.

Any suggestions would be welcome.

David

Hi all,

  In case anyone else ever encounters this, I found a solution to

this problem. I ended up subclassing the wx.BoxSizer class and
over-riding the RepositionChildren() method. It was really easy
in my case because I just wanted everything to be the same size.
It ended up working out really nicely.

David

Hi David,

That sounds like a good fix.

I looked around in the MediaCtrl code and I couldn’t find anything that was changing the min size, just the best size. So it seems that it is either something in the sizer code, or something in the wx.Control or further up the class hierarchy, but in either of those two cases I would expect similar problems with other kinds of controls…

Anyway, I’m glad you found a workaround that works for you.