Op 11/03/2016 om 12:19 AM schreef pozzugno: > Il 02/11/2016 18:55, Nicola Fontana ha scritto: >> Il Wed, 2 Nov 2016 14:40:58 +0100 Pozz Pozz <pozzu...@gmail.com> >> scrisse: >> >>> 2016-11-02 11:24 GMT+01:00 Nicola Fontana <n...@entidi.it>: >>>> ... >>>> >>>> you don't necessarily need the handler id. In C (I don't use >>>> python) you could write the following: >>>> >>>> void my_set_value(GtkSpinButton *spin_button, gdouble value) >>>> { >>>> g_signal_handlers_block_matched(spin_button, >>>> G_SIGNAL_MATCH_FUNC, >>>> 0, 0, NULL, >>>> callback_to_skip, >>>> NULL); >>>> >>>> /* This will not trigger callback_to_skip */ >>>> gtk_spin_button_set_value(spin_button, value) >>>> >>>> g_signal_handlers_unblock_matched(spin_button, >>>> G_SIGNAL_MATCH_FUNC, >>>> 0, 0, NULL, >>>> callback_to_skip, >>>> NULL); >>>> } >>>> >>> I got the idea. I don't know if g_signal_handlers_block_matched() or >>> similar functionality is available in Python. However, remaining in >>> C, your >>> code make the assumption there is a single callback function for all >>> the >>> spinbuttons. This is not true: I have a different handler for each >>> spinbutton, because I have to make different things. >> Sorry but I am a developer, not a mind reader. > Yes, of course :-) Thank you for spending some time for me. > > I thought using a different callback for each SpinButton was the more > typical solution. > >> You can match by data or try to lookup the callback by detail with >> g_signal_handler_find or refactor your code to use a single >> callback. > It seems pyGObject implementation gives only two "handler block" > functions: handler_block(), that needs the handler_id that I don't > have; handler_block_by_func() that needs the callback to block (the > same problem of your solution, because I have different callbacks). > > Is it possible to retrieve the list of connected callbacks of an > object and a signal name ("value-changed")? > >> The fact that you are using different callbacks has a >> foul smell indeed. > Yes? I have to generate and send a different request to the device. > Why do you think it's better to have a single callback? > Of course, I could write one single callback as: > > def callback(self, spinbutton): > if spinbutton is spinSetting1: > self.callback_setting1(spinbutton) > elif spinbutton is spinSetting2: > self.callback_setting2(spinbutton) > ... > > def callback_setting1(self,spinbutton): > # This is the callback of the spinbutton associated to setting1 > parameter > set_setting1(spinbutton.get_value()) > > It seems to me a more complicated way to write different callbacks. >
Do you know you can subclass Gtk.SpinButton and override the virtual methods [1] and emit your own custom signal at the time you want it based of some attribute? There are some example on the internets but not much. Ironically the most complete imo is the old pygtk one [2] and gtk3 read the docs is not horrible [3]. And I want to reiterate what Nicola said, create a small example with only 2 or 3 buttons that shows what you are truing to do. It works much easier that way and we do not have to read minds. ~infirit [1] https://lazka.github.io/pgi-docs/#Gtk-3.0/classes/SpinButton.html#virtual-methods [2] http://www.pygtk.org/articles/writing-a-custom-widget-using-pygtk/writing-a-custom-widget-using-pygtk.htm [3] http://python-gtk-3-tutorial.readthedocs.io/en/latest/objects.html _______________________________________________ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list