- Posts: 85
- Thank you received: 0
accessing button handlers in multiple python modules
There are get_handlers() functions in both python modules:
in my main python file:
In probe_screen.py:
I've tried referencing the handler functions the following ways, all without success:
I'm stumped at this point. Anyone have any ideas?
Thanks!
Dave L.
Please Log in to join the conversation.
So in your case copy your file probe_screen in that directory.
Then you can test the import once again for functionality.
You type
Good luck !
Please Log in to join the conversation.
You can see a lot of info.
It's a difficult item, i searched 5 mont's ago for the same issue. Then Norbert told me he
was going to program all the button's external. But i don't have a clear example for you right now, sorry.
In all the existing examples, there are no existing button handlers. So i am curious how the coding looks like.
If there is a main pyhon file that looks after the button handler, it works.
In external file, it is a problem. The error is: handler is missing...
So in the main file you have to do all your button handlers, then your problem is solved tonight.
I never seen a exernal button event, also on google there are no plug and play examples.....
Please Log in to join the conversation.
And then in the Gscreen class __init__() function the above gets called as follows:
There should be an easier way to accomplish this for external modules in known locations.
I'll probably just resort to what you suggested and put all the widget handlers in the main python file.
Thanks again!
Please Log in to join the conversation.
Try to figure this out please. You can ask this question on the Python forum to specialists. They will have the ansfer within 2 day's
I would also like to know how the code looks like. Please post your solution over here.
Please Log in to join the conversation.
Handler files isa way to extend GladeVCP without having to add to the source code. Gmoccapy and gscreen use it for the same reason.
If you are creating the source code and don't need to be able to extend it then yes just import the file like normally.
you need to instantiate the class, then reference it through that name.
something like this:
from probe import HandlerClass as Probe # import the class changing the name
self. probe = Probe() # instantiate the class and giving a reference name
self.probe.someFunctionName() # calling the functions using the reference name
By importing while changing the class name you avoid the problem of the two file both being name HandlerClass ( I am assuming that is true)
Hope this helps
Chris M
Please Log in to join the conversation.
But I was trying to have widget signals (those specified in the Glade XML file) "find" their handler functions in the external python module without having to write additional code in the main python file. (So far I'm getting "missing handler" error messages for all the external handlers.)
It seems to hinge on the gladevcp get_handlers() and gtkbuilder.connect_signals() functions. But I haven't worked it out yet.
Please Log in to join the conversation.
This can be tested in Terminal with:
multi-module-test.py:
external_module.py:
I'll work on iterating through the handler classes to more easily create the dictionary for connect_signals(). Will keep you posted...
Please Log in to join the conversation.
Nice that it works now. If i look at the code, it looks like you have more work now then keeping all the button handlers in the same file.
Please Log in to join the conversation.
tripwire wrote: But I was trying to have widget signals (those specified in the Glade XML file) "find" their handler functions in the external python module without having to write additional code in the main python file. (So far I'm getting "missing handler" error messages for all the external handlers.)
It seems to hinge on the gladevcp get_handlers() and gtkbuilder.connect_signals() functions. But I haven't worked it out yet.
Ahh I see. Yes then in that case IIRC that is a limitation of GTK's connect_signals() one can't add module reference to it.
So In that case that is where the get_handlers() was a solution. Again IIRC if adds the handler's function calls to the main python program. Then connects the signals with .connect_signals() so GTK can find the functions.
i'll point out that gscreen and gmocapy's routines are derivatives of gladevcp's own handler function.
gladevcp's functions may be easier to follow the flow as gladevcp is simpler
src/hal/user_comps/gladevcp.py
Chris M
Please Log in to join the conversation.
