简体   繁体   中英

pyGTK - call event handler function from within another function

People have asked questions similar to this but because of how generic it is, I am getting undesired results, such as jquery related things. I apologize in advanced if this question has been asked before.

I have a GUI application that I have built using the Glade Interface Designer in Linux (Ubuntu 14.04).

I have, for example, this function :

def on_togglebutton2_toggled(self, widget, data=None):

        map = widget.get_colormap()
        color_off = map.alloc_color("red")
        color_on  = map.alloc_color("green")
        label = widget.get_label()
        ......more code.

I have a button that is used to select a file to read. Based on what is read, the toggle buttons will be set to a certain state.

Instead of having to manually set these buttons ( such as widget.set_active(1) ), is there a way to simulate a 'click' without having to physically 'click' the toggle button for the code to execute? A huge part of this is for code re-use.

How am I able to call on_toggle_button2_toggled() from another function within the same file?

EDIT:

For example :

I want to be able to do this :

def function_name_here(self):
    code here...
    self.on_toggle2_toggle() #call the action listener function.

EDIT2: Calling the set_active(0 or 1) also invokes the listener function.

Thanks in advance all.

This was a un-needed question.

If anyone is wanting to call their action listener from a function without invoking an action :

toggle1 = self.builder.get_object("togglebutton1")
self.on_togglebutton1_toggled(toggle1)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM