I am writing a program to play a video on the right panel when a button pressed on a left panel after selecting what to play. This acts as a test function to show the user. I am a beginner in using Python and WXPython. Learning on the go. I have added a snippet of the code that I am stuck on below:
import wx, wx.media
filePathList = ["None", "None", "None", "None", "None"]
class FrameClass (wx.Frame):
def __init__(self, parent):
super(FrameClass, self).__init__(None, title = "Super Bot", size = (750, 400))
vsplitter = wx.SplitterWindow(self)
left = LeftPanel(vsplitter, self)
self.right = RightPanel(vsplitter, self)
vsplitter.SplitVertically(left, self.right)
vsplitter.SetMinimumPaneSize(200)
self.Show(True)
class LeftPanel (wx.Panel):
def __init__(self, parent, *args, **kwargs):
wx.Panel.__init__(self, parent = parent)
testBtn1 = wx.Button(self, -1, "Test", pos = (5, 20))
self.Bind(wx.EVT_BUTTON, self.buttonPressed1, testBtn1)
def buttonPressed1(self, event):
file0 = filePathList[0]
self.right.onTestClick(file0)
class RightPanel (wx.Panel):
def __init__(self, parent, media):
wx.Panel.__init__(self, parent = parent)
self.mediaFilePath = media
def onTestClick(self):
self.testMedia = wx.media.MediaCtrl(self, size = (500, 300), style=wx.SIMPLE_BORDER, szBackend = wx.media.MEDIABACKEND_WMP10)
self.testMedia.Bind(wx.media.EVT_MEDIA_LOADED, self.play)
self.testMedia.Load(self.mediaFilePath)
def play(self, event):
self.testMedia.Play()
Currently all works well. What apart from passing the video to the rightPanel video onTestClick. Where is shows the current error
Traceback (most recent call last):
File "frame1.py", line 151, in buttonPressed1
self.right.onTestClick(file0)
AttributeError: 'LeftPanel' object has no attribute 'right'
I can imagine that because right is defined in the FrameClass that it is not known about inside of the LeftPanel when trying to use it. Any help would be appreciated.
Finally got it working. Thank you for your inputs as well. Most helpful. I just needed to make the left panel aware of the right panel. In this case...
vsplitter = wx.SplitterWindow(self)
right = RightPanel(vsplitter, self)
left = LeftPanel(vsplitter, right)
vsplitter.SplitVertically(left, right)
vsplitter.SetMinimumPaneSize(200)
self.Show(True)
class LeftPanel (wx.Panel):
def __init__(self, parent, top):
wx.Panel.__init__(self, parent = parent)
self.refTop = top
and when I wanted to send it something, I reference "self.refTop". Such as...
def buttonPressed1(self, event):
file1 = filePathList[0]
self.refTop.onTestClick(file1)
making sure that RightPanel has an argument ready for it.
class RightPanel (wx.Panel):
def __init__(self, parent, media):
self.mediaFilePath = media