Child frame autospawn and not reactive if reopening it after having been closed

hi all,

i use MVC pattern in which run.py have bind method.

it is great , it helps to organize my project, but when doing this, child frame spawns when i launch my prog. And when i close the child window, if i want it again from main frame, it’s not reactive anymore if i click “ok”.

here is my files:

run.py (controller and starter)

import wx

from top import Top
from v_WC import v_WC

class Controller:
def init(self, app):

    self.ct_top = Top(None)
   
    self.ct_top.button_viewWC.Bind(wx.EVT_BUTTON, self.ct_top.Onbutton_viewWCButton, id=-1)        

    self.ct_v_WC = v_WC(parent = self.ct_top)
   
    self.ct_v_WC.btn_ok.Bind(wx.EVT_BUTTON, self.ct_v_WC.OnClose)

app = wx.App(False)

controller = Controller(app)
controller.ct_top.Show()
app.MainLoop()

``

here my main frame (top.py)

import wx
import wx.lib.dialogs

import v_WC

class Top(wx.Frame):
def init(self, parent):
wx.Frame.init(self, id=-1, parent=parent, size=wx.Size(800, 600), title=‘Top’)
self.panel1 = wx.Panel(self, id=-1)

    self.button_viewWC = wx.Button(self.panel1, id=-1, label='viewWC', pos=wx.Point(96, 200), size=wx.Size(187, 28), style=0)

def Onbutton_viewWCButton(self, event):
    self.v_WC = v_WC.create(self)
    self.v_WC.Show()
    event.Skip()

``

here is my child frame (v_WC.py)

import wx

def create(parent):
return v_WC(parent)

class v_WC(wx.Frame):
def init(self, parent):

    wx.Frame.__init__(self, id=-1, parent=parent, title='v_WC', size=(700, 550))
    self.panel1 = wx.Panel(self, id=-1, size=wx.Size(700, 550))

    self.btn_ok = wx.Button(self.panel1, label="Ok ", pos=(20, 400), size=(60, -1))
    self.Centre()
    self.Show(True)

def OnClose(self, e):
    self.Close(True)

``

···

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/0e1fec97-a09f-421d-8ccd-8a2762050884%40googlegroups.com.

If I understand correctly, the problem is that in the Controller you are binding the EVT_BUTTON event for the first child window, but all future instances of the child windows are not getting any event bindings for their Ok button. You will probably have more luck if you do your event bindings in the classes that create the items sending the events. It’s much easier to not get lost handling the events locally. If they need to inform other objects that the event happened, then that can be done by just catching the event and sending a message, or perhaps calling a method of the Controller, and let the Controller handle any extra stuff that needs to be done.

···

On Wednesday, July 24, 2019 at 8:06:23 AM UTC-7, chris tophe wrote:

hi all,

i use MVC pattern in which run.py have bind method.

it is great , it helps to organize my project, but when doing this, child frame spawns when i launch my prog. And when i close the child window, if i want it again from main frame, it’s not reactive anymore if i click “ok”.

Robin

Discuss wxPython

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/ecf94f46-485a-417f-ad31-f1f481c94500%40googlegroups.com.

thank you Robin

···

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/24568d80-a497-41ba-a29b-ecbfd02d2a50%40googlegroups.com.