Result in panel 2 for the action in panel 1 on single frame.

Hi All,

I am Siva, I am very new to this group and to wxpython also.

Please forgive me if any error or wrong communication structure.

I am trying to create an application using wxpython.

The app description is,

I am creating a frame, adding two panels to the same frame.

Trying to get the result in panel 2 for the action in panel 1. But I am not getting the result.

Code:

import wx

#Panel 1 class
class PanelOne(wx.Panel):

    def __init__(self, parent):
        """Constructor"""
        wx.Panel.__init__(self, parent=parent)
        self.SetBackgroundColour("Blue")

        #Calling function two create a button in panel 1
        self.CreateExpiryCheckTogleBtn()

    def CreateExpiryCheckTogleBtn(self):

        #Button creation
        expirychkTogleBtn = wx.ToggleButton(self)
        expirychkTogleBtn.SetLabel("Expiry Check")

        #Binding the event
        self.Bind(wx.EVT_TOGGLEBUTTON, self.OnExpiryTogle, expirychkTogleBtn)

        #event function
    def OnExpiryTogle(self,event):
        #function calling to create UI/widgets/put data in panel 2
        self._DoLayout()
    def _DoLayout(self):
        #main object create
        _frame = MyFrame()

        #panel 2 object create , pass parent as main frame object
        _panel2 = PanelTwo(_frame)
        text = wx.StaticText(_panel2, -1,"This is the Toggle button event in Panel 2")
        text.Show()

#panel 2
class PanelTwo(wx.Panel):
    def __init__(self, parent):
        """Constructor"""
        wx.Panel.__init__(self, parent=parent)
        self.SetBackgroundColour("black")

#main frame
class MyFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, -1, "Main Frame", size = (1366, 768))

        #Spliiting the panels
        splitter = wx.SplitterWindow(self)

        self.panelone = PanelOne(splitter)
        self.paneltwo = PanelTwo(splitter)

        splitter.SplitVertically(self.panelone, self.paneltwo,-9 )
        splitter.SetMinimumPaneSize(200)

        self.sizer = wx.BoxSizer(wx.HORIZONTAL)
        self.sizer.Add(splitter, 1, wx.EXPAND)

        self.SetSizer(self.sizer)

#app class
class MyApp(wx.App):
    def OnInit(self):
        frame = MyFrame()
        frame.Show()
        return True
if __name__ == "__main__":
    app = MyApp(False)
    print(wx.GetDisplaySize())
    app.MainLoop()

Note: Please rectify me if any wrong coding standards or naming standards.

Thanks All in Advance

···

Thanks and Regards,

Jampala Sivanarayana

GO-GREEN3

Save Water. Go Paperless. Always Recycle.

No, because this code in Panel1 is creating yet another copy of
Panel2, unrelated to the copy you placed into the splitter:
If you want that specific Panel1 to communicate with that specific
Panel2, you have a couple of choices. The KEY is that you need to
save the pieces you need to do the communication. One option is to
let the frame do the work. So, have your event handler in Panel1
call a function in MyFrame, and let MyFrame either do the action, or
call into its copy of Panel2. To do that, the Panel1 init
function will need to save the parent in a member variable so it can
refer to it later.
The other alternative is to have Panel1 call directly into Panel2.
To do that, the frame (which is the only component that knows about
both panels) would have to pass the Panel2 instance into Panel1.
Either way works. It depends on what feels better to you.
Or option two:
You just need to set up the plumbing yourself.

···

sivanarayana jampala wrote:

      I am creating a frame, adding two

panels to the same frame.

Trying to get the ** result in panel
2** for the action in panel 1. But I am not
getting the result.

def _DoLayout(self        ):
#main object create

        _frame = MyFrame()
#panel 2 object create , pass parent as main frame object
                _panel2 = PanelTwo(_frame)
text = wx.StaticText(_panel2, -1,"This is the Toggle button event in Panel 2"        )
text.Show()

` class PanelOne(wx.Panel):``

``        def __init__(self, parent, frame):``

``            ...``

``            self.frame = frame``

``

``        def someEvent(self, event):``

``            self.frame.GoTellPanel2( action )``

``

``    ...``

``    class MyFrame(wx.Frame):``

``        def __init__( ... ):``

``            self.panelone = PanelOne(splitter, self)``

``            ...``

``        def GoTellPanel2( self, action ):``

``            self.paneltwo.TakeAction( action )`

`

``    class PanelOne(wx.Panel):``

``        ...``

``        def setOtherPanel( self, panel ):``

``            self.sibling = panel``

``        def someEvent(self, event):``

``            self.sibling.TakeAction( action )``

``    ....``

``    class MyFrame(wx.Frame):``

``
          def __init__( ... ):``

``                 

…``

``            self.panelone = PanelOne(splitter)``

``            self.paneltwo = PanelTwo(splitter)``

``                 

self.panelone.setOtherPanel( self.paneltwo )``

`
-- Tim Roberts, Providenza & Boekelheide, Inc.

timr@probo.com