Separate instances from multiple button click

Hi all,
in my “main gui” I have a button that creates an object containing a separate application in a separate frame.
The application, natively, uses messages to comunicate among its classes.
If I click just once, there is no problem.

If I click twice (or more) I get another windows that basically are “mirrors” of the first one (as far as I understand they share messages, variables and so on).
Of course I don’t want something like that, I want to have separate instances of that class.

Any idea?
Should I use thread?

Thank you very much.
Robert

in my "main gui" I have a button that creates an object containing a
separate application in a separate frame.

In this kind of circumstance you need to be rather precise with your
language. If this is all part of one process, then there is only one
application. There is one wx.App object, and one main loop. You can
certainly have multiple top-level windows hanging off of a single
application, and I'm guessing that what you really have.

The application, natively, uses messages to comunicate among its classes.
If I click just once, there is no problem.

If I click twice (or more) I get another windows that basically are
"mirrors" of the first one (as far as I understand they share
messages, variables and so on).
Of course I don't want something like that, I want to have separate
instances of that class.

It depends. When you click again, do you create a new instance of the
other window? If so, then that window has its own class object and its
own variables, and it only processes messages that are aimed for that
window.

When you say "messages", what do you mean? Have you implemented your
own messaging architecture? If you are doing a simple
publish/subscribe, where all subscribers see all messages that are
published, then you might have the problem you describe. But if you are
using wxPython messaging, then each message has a "target", and they
won't get confused.

If you have done your own messaging system, and you don't have the
concept of a "target" for the message, then you may need to add that.

···

robert.pelson1@gmail.com wrote:

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

in my “main gui” I have a button that creates an object containing a

separate application in a separate frame.

In this kind of circumstance you need to be rather precise with your

language. If this is all part of one process, then there is only one

application. There is one wx.App object, and one main loop. You can

certainly have multiple top-level windows hanging off of a single

application, and I’m guessing that what you really have.

Yes, sorry for the confusion.
I have a single wx.App and multiple frames.

The application, natively, uses messages to comunicate among its classes.

If I click just once, there is no problem.

If I click twice (or more) I get another windows that basically are

“mirrors” of the first one (as far as I understand they share

messages, variables and so on).

Of course I don’t want something like that, I want to have separate

instances of that class.

It depends. When you click again, do you create a new instance of the

other window? If so, then that window has its own class object and its

own variables, and it only processes messages that are aimed for that

window.

I create a new instance.

When you say “messages”, what do you mean? Have you implemented your

own messaging architecture? If you are doing a simple

publish/subscribe, where all subscribers see all messages that are

published, then you might have the problem you describe. But if you are

using wxPython messaging, then each message has a “target”, and they

won’t get confused.

I’m using wx.lib.pubsub.pub version 1 and, honestly, I don’t have the concept of target.

If you have done your own messaging system, and you don’t have the

concept of a “target” for the message, then you may need to add that.

Thank you very much!

···

Il giorno giovedì 17 novembre 2016 19:02:23 UTC+1, Tim Roberts ha scritto:

robert....@gmail.com wrote:


Tim Roberts, ti...@probo.com

Providenza & Boekelheide, Inc.

Do you get what I mean there? If you have a message like
"display.update", then you might add an "instance ID" in the message, so
you send "0.display.update" or "1.display.update". That way, the
application that is instance #0 can ignore messages for other instances.

Note that I just made this up -- it's possible that pubsub might have
this kind of thing built-in. I don't know the package very well.

···

robert.pelson1@gmail.com wrote:

I'm using wx.lib.pubsub.pub version 1 and, honestly, I don't have the
concept of target.

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

Like Tim say, you can create top level topics based on each top-level window. Although I thought topic names needed to start with an alpha character and not zero through nine. This is likely the simplest solution.

Or, you can also create multiple publishers. I use version 3 of pubsub and not so much wx.lib.pubsub.pub.

Typical usage is:

from pubsub import pub

``

However you can looking into using:

instance0_pub = pubsub.Publisher(…)
instance1_pub = pubsub.Publisher(…)

``

You’ll have to figure out the arguments for the Publisher class.

Provided here for quick reference:

http://pypubsub.readthedocs.io/en/stable/index.html

Sorry -- I didn't know the details of pubsub.

···

On Nov 17, 2016, at 5:01 PM, DevPlayer <devplayer@gmail.com> wrote:

Like Tim say, you can create top level topics based on each top-level window. Although I thought topic names needed to start with an alpha character and not zero through nine. This is likely the simplest solution.


Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

Wow! Many thanks to all…it looks like I have a lot of things to study!
In the meantime that I find the way to “delivery” the messages in the right way, how can I disable the button for all the time that the frame is opened?
I mean: I click on the button, the frame is opened and the button is disable until I don’t close the frame (this to avoid multiple instances that share the messages in the wrong manner).

Really many thanks!
Best

Robert

···

Il giorno venerdì 18 novembre 2016 07:16:36 UTC+1, Tim Roberts ha scritto:

On Nov 17, 2016, at 5:01 PM, DevPlayer devp...@gmail.com wrote:

Like Tim say, you can create top level topics based on each top-level window. Although I thought topic names needed to start with an alpha character and not zero through nine. This is likely the simplest solution.

Sorry – I didn’t know the details of pubsub.


Tim Roberts, ti...@probo.com

Providenza & Boekelheide, Inc.

class SecondFrame(wx.Frame):
def onClose(self, event):
pub.sendMessage(‘button.enable’, options=None)
event.Skip()

class FirstFrame(wx.Frame):
def init(self, …):
self.Bind(wx.BUTTON, onClick, self.Button)
pub.subscribe(self.enableButton, ‘button.enable’)

def onClick(self):
    if function_launch_second_frame():
        self.Button.Disable()
   
def enableButton(self):
    self.Button.Enable()

``

class SecondFrame(wx.Frame):
    def onClose(self, event):
        pub.sendMessage('button.enable', options=None)
        event.Skip()

class FirstFrame(wx.Frame):
    def __init__(self, ...):
        self.Bind(wx.BUTTON, onClick, self.Button)
        pub.subscribe(self.enableButton, 'button.enable')

    def onClick(self):
        if function_launch_second_frame():
            self.Button.Disable()

    def enableButton(self):
        self.Button.Enable()