1
votes

Is it possible to clone a wxPanel across a pair of frames in wxPython?

  • I have tried using the same wxID, which resulted in of significance.
  • I have tried using the same instance of the control which results in only one being drawn.

I am ultimately trying to display the output of LibVLC (which renders to a wxPanel via it's hwnd) on two frames simultaneously. One frame is inside a control window to provide a "preview" of the video while the other is displayed fullscreen on a second monitor.

Here's a reduced version of the code I'm using to display the video output in the preview window:

class MainFrame(wx.Frame):
    def __init__(self, *args, **kwds):
        kwds["style"] = wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)
        self.video_panel = wx.Panel(self, wx.ID_ANY)
        self.video_panel.SetBackgroundColour(wx.Colour(0, 0, 0))
        sizer_video = wx.BoxSizer(wx.VERTICAL)
        sizer_video.Add(self.video_panel, 1, wx.ALL | wx.EXPAND, 2)
        self.SetSizer(sizer_video)
        self.Layout()
        self.Instance = Libraries.vlc.Instance()
        self.player = self.Instance.media_player_new()

    def mediaLoad(self, path):
        self.Media = self.Instance.media_new(unicode(path))
        self.player.set_media(self.Media)
        if sys.platform.startswith('win'):
            self.player.set_hwnd(self.video_panel.GetHandle())
        elif sys.platform.startswith('linux'):
            self.player.set_xwindow(self.video_panel.GetHandle())
        else:
            self.player.set_nsobject(self.video_panel.GetHandle())
1
In short, no, you won't be able to do it the way you envision. Each Panel can have only one parent, and you can't reuse a panel in multiple windows like you're after. You will need to create separate panels for each frame, window, or dialog that needs one. - g.d.d.c

1 Answers

0
votes

You can't do that in wxPython. Each widget has a single parent. I think the best course would be to create a subclass of wx.Panel and have both frames instantiate the class. Then you might use pubsub to communicate between the two frames. I don't think you would be able to get both instances to sync up exactly, but you should be able to get it pretty close.