Communicating between wx.aui.Notebook and wx.stc.StyledTextCtrl

I have a problem that I am hoping has a relative easy solution to. I have created an application which uses the AuiManager to manage various panes and a AuiNotebook. Inside the AuiNotebook I have one StyledTextCtrl editor for the each tab. I have created a separate class for the creation of my StyleTextCtrl editors. My question is, when I modifiy text in my editor I want to reflect the change by modifying the name on the AuiNotebook tab.

I am running into a problem because my AuiNotebook was created in a one class and my editor was created in another class. Does anyone know of a way that I can communicate with my AuiNotebook from an event inside of my editor class?

If this is too vague of a description please let me know.

Thanks in advance
Scott

Scott Hall wrote:

I have a problem that I am hoping has a relative easy solution to. I have created an application which uses the AuiManager to manage various panes and a AuiNotebook. Inside the AuiNotebook I have one StyledTextCtrl editor for the each tab. I have created a separate class for the creation of my StyleTextCtrl editors. My question is, when I modifiy text in my editor I want to reflect the change by modifying the name on the AuiNotebook tab.

I am running into a problem because my AuiNotebook was created in a one class and my editor was created in another class. Does anyone know of a way that I can communicate with my AuiNotebook from an event inside of my editor class?

This a common question that gets asked here weekly, so the archives can give you plenty of details, but basically use Pubsub: http://wiki.wxpython.org/PubSub. There is a good example there. In your STC event, send a message like "editor.modified" and in your AuiNotebook class, subscribe to that message and create a handler which does the appropriate thing. It's just that easy!

- Mike

Mike Rooney wrote:

Scott Hall wrote:

I have a problem that I am hoping has a relative easy solution to. I have created an application which uses the AuiManager to manage various panes and a AuiNotebook. Inside the AuiNotebook I have one StyledTextCtrl editor for the each tab. I have created a separate class for the creation of my StyleTextCtrl editors. My question is, when I modifiy text in my editor I want to reflect the change by modifying the name on the AuiNotebook tab.
I am running into a problem because my AuiNotebook was created in a one class and my editor was created in another class. Does anyone know of a way that I can communicate with my AuiNotebook from an event inside of my editor class?

This a common question that gets asked here weekly, so the archives can give you plenty of details, but basically use Pubsub: http://wiki.wxpython.org/PubSub. There is a good example there. In your STC event, send a message like "editor.modified" and in your AuiNotebook class, subscribe to that message and create a handler which does the appropriate thing. It's just that easy!

I'm always doing it in a different way, now I wonder if this is also "correct"

class A ( object or whatever ) :
    def __init__ ( self, ...)
        ....

    def Do_Something_From_Another_Object ( self, value ) :
        do something with value

class B ( object or whatever ) :
    def __init__ ( self, ...) :
        ....

    def Tell_Me_What_Other_Object_I_Should_Inform ( self, Another ) :
        self.Another = Another

    def On_Some_Event ( self, event ) :
        do something and
         self.Another.Do_Something_From_Another_Object ( event.Get... )

thanks,
Stef Mientki

···

- Mike
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Stef Mientki wrote:

Mike Rooney wrote:

Scott Hall wrote:

I have a problem that I am hoping has a relative easy solution to. I have created an application which uses the AuiManager to manage various panes and a AuiNotebook. Inside the AuiNotebook I have one StyledTextCtrl editor for the each tab. I have created a separate class for the creation of my StyleTextCtrl editors. My question is, when I modifiy text in my editor I want to reflect the change by modifying the name on the AuiNotebook tab.
I am running into a problem because my AuiNotebook was created in a one class and my editor was created in another class. Does anyone know of a way that I can communicate with my AuiNotebook from an event inside of my editor class?

This a common question that gets asked here weekly, so the archives can give you plenty of details, but basically use Pubsub: http://wiki.wxpython.org/PubSub. There is a good example there. In your STC event, send a message like "editor.modified" and in your AuiNotebook class, subscribe to that message and create a handler which does the appropriate thing. It's just that easy!

I'm always doing it in a different way, now I wonder if this is also "correct"

class A ( object or whatever ) :
   def __init__ ( self, ...)
       ....

   def Do_Something_From_Another_Object ( self, value ) :
       do something with value

class B ( object or whatever ) :
   def __init__ ( self, ...) :
       ....

   def Tell_Me_What_Other_Object_I_Should_Inform ( self, Another ) :
       self.Another = Another

   def On_Some_Event ( self, event ) :
       do something and
        self.Another.Do_Something_From_Another_Object ( event.Get... )

Well, IMO this approach is "less correct", and is problematic to maintain. By doing this you are adding a fair amount of coupling, see Coupling (computer programming) - Wikipedia . Using this approach as you can see, your B object has to maintain a reference to A, which can cause synchronization issues, and it also has to know about the implementation details of A, such as what method to call and what to pass it. Now whenever you change A, you have to change B and any other object like it.

Using pubsub compared to this is a MUCH cleaner approach because it eliminates the references to the other objects, and the need to know anything about them. In fact with pubsub, you don't even need to know if anything is listening! You just send a message, and anything concerned with that message (could be zero, 1, or any number of things...you don't worry about it) can respond to it as IT deems appropriate.

Now when you want to refactor A, you don't have to root around for everything that called "Do_Something_From..." and change that, you just subscribe to the same message. And if you want something else to respond to the same message, you just subscribe to it there, no adding another self.Another2.Do_Something... et cetera.

There definitely are cases where storing references is the right thing to do, but I don't think this is one of them. What do you think?

- Mike

Mike Rooney wrote:

Stef Mientki wrote:

Mike Rooney wrote:

Scott Hall wrote:

I have a problem that I am hoping has a relative easy solution to. I have created an application which uses the AuiManager to manage various panes and a AuiNotebook. Inside the AuiNotebook I have one StyledTextCtrl editor for the each tab. I have created a separate class for the creation of my StyleTextCtrl editors. My question is, when I modifiy text in my editor I want to reflect the change by modifying the name on the AuiNotebook tab.
I am running into a problem because my AuiNotebook was created in a one class and my editor was created in another class. Does anyone know of a way that I can communicate with my AuiNotebook from an event inside of my editor class?

This a common question that gets asked here weekly, so the archives can give you plenty of details, but basically use Pubsub: http://wiki.wxpython.org/PubSub. There is a good example there. In your STC event, send a message like "editor.modified" and in your AuiNotebook class, subscribe to that message and create a handler which does the appropriate thing. It's just that easy!

I'm always doing it in a different way, now I wonder if this is also "correct"

class A ( object or whatever ) :
   def __init__ ( self, ...)
       ....

   def Do_Something_From_Another_Object ( self, value ) :
       do something with value

class B ( object or whatever ) :
   def __init__ ( self, ...) :
       ....

   def Tell_Me_What_Other_Object_I_Should_Inform ( self, Another ) :
       self.Another = Another

   def On_Some_Event ( self, event ) :
       do something and
        self.Another.Do_Something_From_Another_Object ( event.Get... )

Well, IMO this approach is "less correct", and is problematic to maintain. By doing this you are adding a fair amount of coupling, see Coupling (computer programming) - Wikipedia . Using this approach as you can see, your B object has to maintain a reference to A, which can cause synchronization issues, and it also has to know about the implementation details of A, such as what method to call and what to pass it. Now whenever you change A, you have to change B and any other object like it.

Using pubsub compared to this is a MUCH cleaner approach because it eliminates the references to the other objects, and the need to know anything about them. In fact with pubsub, you don't even need to know if anything is listening! You just send a message, and anything concerned with that message (could be zero, 1, or any number of things...you don't worry about it) can respond to it as IT deems appropriate.

Now when you want to refactor A, you don't have to root around for everything that called "Do_Something_From..." and change that, you just subscribe to the same message. And if you want something else to respond to the same message, you just subscribe to it there, no adding another self.Another2.Do_Something... et cetera.

There definitely are cases where storing references is the right thing to do, but I don't think this is one of them. What do you think?

thanks Mike,
for the explanation and the links ( as you might have guessed I'm not a programmer :wink:

Although I think I understand what you mean,
I'm right now struggling with winPDB / rpdb2,
17000 lines of loose coupled routines (in just 2 files),
and I can assure that readability is very low :wink:

cheers,
Stef

···

- Mike
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users