a simple question... how to detect click action in another module?

R

Ringwraith

Hello!

How to detect in Python that some click action was performed in some module
imported by my main module?
Let's assume I have a tree.py module that implements all functionality of a
tree view widget and my sample application (let's say myapp.py) that imports
those tree module to create tree view control inside the main frame. I want
in my application to have some method that responds immediately (!!!!) to
click action performed within the tree module.... So if the click action is
performed in the tree module, some method from my myapp.py module
immediately executes... it could be for example a method that just displays
currently selected item of a tree (on a status bar) or whatever.....

Any hints would be appreciated.

Thank You in advance!

Please forgive me any english mistakes ;-)

Best Regards,

Sylwia
 
B

Brian Kelley

Ringwraith said:
Hello!

How to detect in Python that some click action was performed in some module
imported by my main module?

What you are talking about is an observer pattern. Most GUI widgets
supply an EVENT mechanism that when triggered call a python function.
This event mechanism will be dependent upon your GUI toolkit. I'm
assuming that you are using a GUI, otherwise you can roll your own event
mechanism or just use an existing one:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/131499

The basic Tkinter example is here, notice the frame.bind call:
http://effbot.org/zone/tkinter-events-and-bindings.htm

wxpython has a full tree example in their demo, just install wxpython
from http://wxpython.org/ and run the demo application. Examining the
source code will tell you how to capture wxpython tree-click events.

If you could be more specific about what GUI you are using, we could
give you a more specific answer.

Brian Kelley
 
R

Ringwraith

Uzytkownik "Brian Kelley said:
If you could be more specific about what GUI you are using, we could
give you a more specific answer.

Oh, I forgot to add that I use Tkinter!
Anyway you helped me very much!!!! The link to the 'recipe' describing how
to implement the observer pattern in Python was great!!!
Thanks to You I solved my problem!
Thanks!!!

Best Regards,

Sylwia
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,183
Messages
2,570,965
Members
47,513
Latest member
JeremyLabo

Latest Threads

Top