It is currently Sat Jun 29, 2024 11:45 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Get a mouse click or select a pixel in an image in a python plugin?
PostPosted: Thu Dec 29, 2022 7:49 pm  (#1) 
Offline
New Member

Joined: Dec 29, 2022
Posts: 2
GIMP Version: 2.10.32
Operating System: Windows
GIMP Experience: Basic Level



How can a python plug-in get a mouse click position within an image? or... how can a plug-in get have the user select some points within an image? My plug-in needs to prompt the user to designate some points on the image. For example user clicks on a point to select what color is at that pixel, or user clicks on two points to designate the corners of a rectangle, or, even better, user clicks down the mouse an drags it around and the plugin gets sequence of points the mouse was moved in.

The functions I see in libgimp seem to be functions that carry-out the actions like 'set the rectangle selection' to x1,y1 x2,y2' or 'tell me what color is at x,y'. I need to user input side of the operation, not (at this point) the functions to carry-out the operations.


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: Get a mouse click or select a pixel in an image in a python plugin
PostPosted: Fri Dec 30, 2022 6:16 am  (#2) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4752
No way to directly access the mouse position in a plugin. Two solutions, either:

  • have the user make a selection, and infer a position form the selection (corners or center)
  • have the user create a path and use the API to get the anchors
The second solution is more general (any number of points or geometry).

_________________
Image


Top
 Post subject: Re: Get a mouse click or select a pixel in an image in a python plugin
PostPosted: Fri Dec 30, 2022 4:16 pm  (#3) 
Offline
New Member

Joined: Dec 29, 2022
Posts: 2
Thanks ScriptCoder. How does something like the Color Picker Tool do it? Is the Color Picker Tool written as an extension, or could Color Picker Tool be written as an extension -- in C or scriptFu or python? Are there functions in some library that cannot be called from python (perhaps using some C/C++ native interface)?

I get the impression that scriptFu and python plug-ins are envisioned as 'scripts' that just invoke a sequence of high level GIMP 'tools'; rather than a means of making general extensions to GIMP functionality (perhaps not as fast as native C code). Is that true?


Top
 Post subject: Re: Get a mouse click or select a pixel in an image in a python plugin
PostPosted: Sat Dec 31, 2022 5:09 am  (#4) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4752
As you say the Color picker is a "tool"(*). Historically "plugins" do not play with the UI (this is also true for those written in C), only built-in tools can.

You can of course add anything to the Gimp source code and so make your own tools.

(*) which is also used behind the scenes for the "sample points"

_________________
Image


Top
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Eager to learn how to draw pixel functions in GIMP python

2

No new posts Convert GIMP plugin from Python 2 to Python 3

4

No new posts Attachment(s) GEGL Pixel Text - plugin download

8

No new posts Attachment(s) CanNot Move object (Mouse Action Blocked) via mouse cursor Rotate Icon

6

No new posts Script-fu select outline of image inside png

1



* Login  



Powered by phpBB3 © phpBB Group