It is currently Mon Jul 08, 2024 3:02 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Gimp plugin with GTK - use signal value_changed
PostPosted: Sun Aug 22, 2021 8:27 am  (#1) 
Offline
New Member

Joined: Aug 22, 2021
Posts: 4
Hi folks,

----- edit: I just realize, this is in the wrong sub board: pleas shift it. Thanks ------

I am new here. I've started recently to write my own gimp plugins. My goal is to create mirror images. With the plugin I want to shift the image and mirrored copy synchronously. The gegl kaleidoscope already does something similar, but with at least 2 mirrors.

By now I have come so far:
My plugin can create additional layers with masks in 2 groups in my image, so that each group contains half the mirror image. :bigthup
I can create a plugin window containing some buttons +100, +20 ...., -20, -100 and by clicking these buttons, my layers are shifted :bigthup
so
shift20_button.connect("clicked", self.shift20_button_clicked, 20)
works fine.

What I would like to achieve is a horizontal scale (that i can already create) that does the job instead of the buttons.
The GTK reference and examples on the internet tell me, there is a "value_changed" signal, a scale emits, which can be used to start the next action.

I've tried the following with x_scale beeing a horizontal scale in my plugin, that I can shift, and changes the value (which I can check with val = x_scale.get_value()" after a button clicked).:

g_signal_connect(x_scale, "value_changed", do_something, NULL)

as well as:
g_signal_connect(G_OBJECT(x_scale), "value_changed", G_CALLBACK(do_something), NULL)

as well as:
x_scale.connect("value_changed", do_something)

and:
gtk_signal_connect(x_scale, "value_changed", do_something)


none of theses brings me to the solution I want.
With the third option, the "do_something" code is executed once on the plugin startup, but the plugin stops at the end of "do_something".
I tried to replace "x_scale" by "x_adj" which is the adjustment of "x_scale". --> same results
I exchanged "value_changed" by "value-changed" and 'value_changed' as I found other examples with these spellings. --> no effect

On https://gimp-werkstatt-forum.de I got the hint to ask here.

Thanks in advance,
TerraX


Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: Gimp plugin with GTK - use signal value_changed
PostPosted: Sun Aug 22, 2021 12:40 pm  (#2) 
Offline
GimpChat Member
User avatar

Joined: Jul 04, 2019
Posts: 136
Location: Lake Havasu City, Arizona, USA
Hi TerraX,

I've used an gtk.Adjustment with an gtk.HScale. You can monitor the Adjustment for change. The adjustment can be shared by multiple widgets. Do you have the PyGTK reference manual?

https://wiki.python.org.br/DocumentacaoPython?action=AttachFile&do=get&target=ref.pdf

_________________
Charles


Top
 Post subject: Re: Gimp plugin with GTK - use signal value_changed
PostPosted: Sun Aug 22, 2021 1:38 pm  (#3) 
Offline
New Member

Joined: Aug 22, 2021
Posts: 4
Hello gasMask,

that pdf in special is new to me. I think I found a good part of the content on some websites. But it looks like I still need some help.
I copied the relevant parts from your pdf:

Quote:
The "value−changed" gtk.Adjustment Signal
def callback(adjustment, user_param1, ...)
adjustment :the object that received the signal
user_param1 :the first user parameter (if any) specified with the connect() method
... :additional user parameters (if any)
The "value−changed" signal is emitted when the adjustment value attribute has changed.

So the signal is emitted automatically, then it is about how to manage the emitted signal
Quote:
gobject.GObject.connect
def connect(detailed_signal, handler, ...)

detailed_signal :a string containing the signal name
handler :a Python function or method object.
... :additional optional parameters
Returns :an integer identifier

The connect() method adds a function or method (handler) to the end of the list of signal handlers for the named detailed_signal but before the default class signal handler. An optional set of parameters may be specified after the handler parameter. These will all be passed to the signal handler when invoked.
For example if a function handler was connected to a signal using:
handler_id = object.connect("signal_name", handler, arg1, arg2, arg3)
The handler should be defined as:
def handler(object, arg1, arg2, arg3):
A method handler connected to a signal using:
handler_id = object.connect("signal_name", self.handler, arg1, arg2)
requires an additional argument when defined: def handler(self, object, arg1, arg2)
A TypeError exception is raised if detailed_signal identifies a signal name that is not associated with the object.

What is the handler? Is it the code I want to execute?
The object I guess is my hscale
The detailed signal is: "value_changed"
The additional arguments will be the hscale.get_value() for example. Right?

Quote:
handler_id = object.connect("signal_name", handler, arg1, arg2, arg3)

handler_id = hscale.connect("value_changed", dosomething, hscale.get_value())

Is that correct?
If so, what do I do with the handler_id? All I want is, that the "dosomething" code is executed after the "value_changed" signal has been emitted.

----------------------

tried it, and it works! :bigthup Thank you! :tyspin


Top
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Can the cursor be changed for the warp transform tool?

1

No new posts GIMP ui font changed by itself, unable to revert the change

5



* Login  



Powered by phpBB3 © phpBB Group