Friday, May 3, 2024
 Popular · Latest · Hot · Upcoming
4
rated 0 times [  4] [ 0]  / answers: 1 / hits: 1503  / 1 Year ago, thu, march 23, 2023, 11:48:21

I'm writing this application using quickly.



I'm looking for a way to toggle button without running function which is connected to this button.



def on_button_text_italic_toggled(self, widget):
print "Italic"

def on_buttone_test_clicked(self, widget):
self.button_text_italic.set_active(True)


So I need this to make button_text_italic to be toggled but without printing out "Italic" text.



Thanks for any help!


More From » python

 Answers
2

If you want the function to be run most of the time the toggle signal is emitted, and not when you manually toggle it (e.g. when loading saved settings and displaying the appropriate state), then you need to block and unblock the signal. To do so you'll need the handle_id that was returned when the signal was connected to the function. Just assign a variable when you connect the signal. Here's an example:



#!/usr/bin/python
from gi.repository import Gtk

def on_toggle(widget,data=None):
print "toggled, emitted signal"

def on_button1_clicked(widget, data=None):
print "manually toggle, no signal"
toggle.handler_block(handle_id)
state=toggle.get_active()
toggle.set_active(not state)
toggle.handler_unblock(handle_id)


win=Gtk.Window()
win.connect('destroy', Gtk.main_quit)
box=Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
button1=Gtk.Button('Toggle with no signal')
button1.connect('clicked', on_button1_clicked)
button1.show()
box.pack_start(button1,True,True,10)
toggle=Gtk.ToggleButton('Toggle')
handle_id=toggle.connect('toggled', on_toggle)
toggle.show()
box.pack_start(toggle,True,True,0)
box.show_all()
win.add(box)
win.show()
Gtk.main()

[#31791] Thursday, March 23, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
irripri

Total Points: 164
Total Questions: 111
Total Answers: 107

Location: South Georgia
Member since Sun, Aug 8, 2021
3 Years ago
irripri questions
Mon, Aug 29, 22, 03:19, 2 Years ago
Thu, Mar 30, 23, 01:56, 1 Year ago
Thu, Dec 30, 21, 08:53, 2 Years ago
;