wx.lib.pubsub (Pubsub)

Don’t just hide the popup. Close or Destroy it after you send the message. Then it should work. I created a tutorial that shows almost this very activity: wxPython and PubSub: A Simple Tutorial - Mouse Vs Python

  • Mike
···

On Monday, July 2, 2012 4:34:34 PM UTC-5, jskoeh9 wrote:

Hi all,

I am trying to use pubsub to send data back to my main frame from a popup frame upon a button press. The button press hides the popup panel and then sends a message to the main frame via pubsub.

The data is successfully transferred. However, when I exit the GUI, python continues to run as if not all of the windows have closed. When I comment out the pubsub command, press the button, and try to close, the program successfully exits. It is only with the pubsub command that the GUI does not exit completely.

Here is the sending portion of the code:

def OnGenerate(self, event):

Get type of graph user selected

self.type = self.lb_choose_type.GetStringSelection()

if self.type == “Balanced Tree”:

factor = int(self.txt_branch_factor.GetValue())

height = int(self.txt_height.GetValue())

self.G = nx.balanced_tree(factor, height)

self.parent.Show(False)

self.parent.Centre()

Publisher.sendMessage((“Data Generated”))

and the receiving panel:

Publisher.subscribe(self.GetData, (“Data Generated”))

The popup consists of a panel in a “fake popup frame.” This frame’s parent is the main frame.

Any insight as to why the GUI would not close successfully with Pubsub would be much appreciated.

I am running OSX 10.6.8, python 2.7, and wxPython 2.8.12.1.

Thank you

Josh

Hi Mike,

Thanks for such a fast response. So would the best thing to do then be to destroy the popup and create a new one each time it is needed? My thoughts were to just reuse the panel when needed. But this is not correct?

Very nice tutorial. It was actually because of it that I stumbled across pubsub which has been very handy.

~ Josh

···

On Monday, July 2, 2012 5:51:30 PM UTC-4, Mike Driscoll wrote:

On Monday, July 2, 2012 4:34:34 PM UTC-5, jskoeh9 wrote:

Hi all,

I am trying to use pubsub to send data back to my main frame from a popup frame upon a button press. The button press hides the popup panel and then sends a message to the main frame via pubsub.

The data is successfully transferred. However, when I exit the GUI, python continues to run as if not all of the windows have closed. When I comment out the pubsub command, press the button, and try to close, the program successfully exits. It is only with the pubsub command that the GUI does not exit completely.

Here is the sending portion of the code:

def OnGenerate(self, event):

Get type of graph user selected

self.type = self.lb_choose_type.GetStringSelection()

if self.type == “Balanced Tree”:

factor = int(self.txt_branch_factor.GetValue())

height = int(self.txt_height.GetValue())

self.G = nx.balanced_tree(factor, height)

self.parent.Show(False)

self.parent.Centre()

Publisher.sendMessage((“Data Generated”))

and the receiving panel:

Publisher.subscribe(self.GetData, (“Data Generated”))

The popup consists of a panel in a “fake popup frame.” This frame’s parent is the main frame.

Any insight as to why the GUI would not close successfully with Pubsub would be much appreciated.

I am running OSX 10.6.8, python 2.7, and wxPython 2.8.12.1.

Thank you

Josh

Don’t just hide the popup. Close or Destroy it after you send the message. Then it should work. I created a tutorial that shows almost this very activity: http://www.blog.pythonlibrary.org/2010/06/27/wxpython-and-pubsub-a-simple-tutorial/

  • Mike

Hmmm…well, there’s certainly nothing wrong with reusing it, but if closing it completely works, then do that. Of course, reading further I see that that didn’t work. You can try the method in this thread: Redirecting to Google Groups which loops over all the children widgets and tries to close frames. You could keep a list of opened frames / dialogs and in your close handler, close them all.

If you have a wx.Timer running, it needs to be stopped. I’ve also had task bar icons hang my program, so if you have one of those you’ll want to destroy it. Finally, if you have and thread handles open, you’ll need to stop those too. Otherwise, we’ll need a small runnable sample app!

  • Mike
···

On Monday, July 2, 2012 9:04:40 PM UTC-5, jskoeh9 wrote:

Hi Mike,

Thanks for such a fast response. So would the best thing to do then be to destroy the popup and create a new one each time it is needed? My thoughts were to just reuse the panel when needed. But this is not correct?

Very nice tutorial. It was actually because of it that I stumbled across pubsub which has been very handy.

~ Josh