It is currently Sun Aug 23, 2026 6:13 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: pdb.gimp_context_set_paint_method for interactive use
PostPosted: Tue Dec 20, 2016 4:14 pm  (#1) 
Offline
GimpChat Member

Joined: Dec 20, 2016
Posts: 6
Hi All

I did tons of searches but fail to find an answer to my question.

The problem statement: when I call pdb.gimp_context_set_paint_method from my python plug-in I don't see that in GIMP's current drawing tool has changed at all.

Example. I'm drawing with pencil and then my plugin calls pdb.gimp_context_set_paint_method("gimp-airbrush"). But gimp user interface itself didn't change anything in a tools dialog. My pen keeps drawing with >>pencil<< tool.

I need some way to select drawing tools in my plug-in (so that my pen/mouse will "see" it). It will help me to create effective tools switcher with keyboard shortcuts.

Best regards
Sunny


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: pdb.gimp_context_set_paint_method for interactive use
PostPosted: Tue Dec 20, 2016 8:58 pm  (#2) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4812
No way... By design the gimp script API cannot interfere with the UI... But why do you need this since you can assign shortcuts to tools (they likely already have one).

_________________
Image


Top
 Post subject: Re: pdb.gimp_context_set_paint_method for interactive use
PostPosted: Tue Dec 20, 2016 10:49 pm  (#3) 
Offline
GimpChat Member

Joined: Dec 20, 2016
Posts: 6
ofnuts wrote:
No way... By design the gimp script API cannot interfere with the UI...

:(

Tool selection is not enough for me. I want to quickly switch between following combinations:

tool+brush settings+dynamics

Preset is a good thing for this, but there are so many of those that mouse picking will consume too much time.

In my plugin I wanted to "scroll" between presets groups by tapping keys. For example: [E][E] will select hard eraser with dynamics off. I change size of it do something. Then I tap [P] and it switch all of tool, dynamics and brush to paintbrush, "charcoal" and soft brush of previous size. Then I draw. Then tap [E] and it selects previous eraser.

I will try to workaround the UI limitation by emulating keypress. Hope I manage to do it.


Top
 Post subject: Re: pdb.gimp_context_set_paint_method for interactive use
PostPosted: Wed Dec 21, 2016 2:53 pm  (#4) 
Offline
GimpChat Member
User avatar

Joined: Jun 06, 2016
Posts: 1033
Maybe I don't understand your wish,
you can write script to change choices by selecting from menu,
you could have multiple items 'preset' in each selection.
you would need to run the script and make a choice ( if that is not too much time ).
But it would run, change the selections, and end.
To change again you would run, make selection again and so forth.

or maybe in your script there is no flush after making the selections?..


Top
 Post subject: Re: pdb.gimp_context_set_paint_method for interactive use
PostPosted: Thu Dec 22, 2016 3:07 pm  (#5) 
Offline
GimpChat Member

Joined: Dec 20, 2016
Posts: 6
animicule wrote:
Maybe I don't understand your wish,
or maybe in your script there is no flush after making the selections?..


What flush do you mean?

Let me give a simplified example. Script defines 2 procedures: select_next_brush and select_next_eraser

When I call select_next_brush first time, it selects first from my predefined tuples (paintbrush tool, dynamics, brush).
When I call select_next_brush afterwards it selects next
When I call select_next_eraser afterwards it selects first from my another predefined tuples (eraser tool, dynamics, brush)
When I call select_next_brush afterwards it switches to last used tuple (paintbrush tool, dynamics, brush)

Moreover, whenever I switch tool, I preserve last brush size and restore it when I switch back.

By binding select_next_brush and select_next_eraser to keyboard I allow myself very fast switching back and forth between these bundles of parameters (tool, dynamics, brush, brush size). It will be quite convenient for my digital painting process.


Top
 Post subject: Re: pdb.gimp_context_set_paint_method for interactive use
PostPosted: Thu Dec 22, 2016 3:40 pm  (#6) 
Offline
GimpChat Member
User avatar

Joined: Jun 06, 2016
Posts: 1033
Ok, I see now. I am learning python scripting and
was playing with contexts a little while ago, and found
that some things can be changed from within a script,
but I could not change the tool, had to use keyboard shortcut.
I don't know about dynamics, but certainly made the brush and
color changes.
I found that I needed to use the pdb.gimp_displays_flush command
in order for the changes to show on the screen.

Good luck with your efforts!


Top
 Post subject: Re: pdb.gimp_context_set_paint_method for interactive use
PostPosted: Mon Dec 26, 2016 7:29 am  (#7) 
Offline
GimpChat Member

Joined: Dec 20, 2016
Posts: 6
So I have implemented my python plugin. I can scroll through painting tools (+dynamics, +brush settings) by tapping 3 keys: P (to switch to or scroll through paintbrushes), E (erasers), N (pencils). However plug-in has some hardcoded stuff inside. Also installation requires from user to bind certain tools to certain keys (paintbrush to <Alt>P, eraser to <Alt>E, pencil to <Alt>N). Need to make this configurable and need to add just some user friendliness for plugin installation.

==Limitations==
a) Works only on Windows (see hacks below)
b) Was tested only on Gimp 2.8.18

==Hacks==
a) Windows keyboard event injection API is used.
b) Current brush size can be read correctly only if paintbrush tool is currently active. So, extra tools switching is applied to preserve current brush size for different tools.

Does anybody think it worth to publish such plugin?


Top
 Post subject: Re: pdb.gimp_context_set_paint_method for interactive use
PostPosted: Mon Dec 26, 2016 8:59 am  (#8) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4812
SunnyI wrote:
b) Current brush size can be read correctly only if paintbrush tool is currently active. So, extra tools switching is applied to preserve current brush size for different tools.

Uh? You cannot get the brush size of the active brush in the context? Also, see the settings preference about sharing brushes among paint tools (Edit>Preferences>Tool options>Paint options shared between tools).

SunnyI wrote:
Does anybody think it worth to publish such plugin?

You'll always find someone who wants it. But this means that you are willing to put reasonable effort to maintain it and make it survive to new Gimp versions, etc...

_________________
Image


Top
 Post subject: Re: pdb.gimp_context_set_paint_method for interactive use
PostPosted: Tue Dec 27, 2016 3:27 am  (#9) 
Offline
GimpChat Member

Joined: Dec 20, 2016
Posts: 6
ofnuts wrote:
Uh? You cannot get the brush size of the active brush in the context?

I can, but it returns the size which mismatches currently selected (in UI) one. If I switch to paintbrush - the context API function starts returning a correct value.
ofnuts wrote:
Also, see the settings preference about sharing brushes among paint tools (Edit>Preferences>Tool options>Paint options shared between tools).

Didn't know that it can be controlled. Thanks! Let me check how it works.
ofnuts wrote:
But this means that you are willing to put reasonable effort to maintain it and make it survive to new Gimp versions, etc...

I wish. But I have to make it more user-friendly. Otherwise the effort to maintain can become unreasonable.


Top
 Post subject: Re: pdb.gimp_context_set_paint_method for interactive use
PostPosted: Tue Dec 27, 2016 8:14 am  (#10) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4812
SunnyI wrote:
I wish. But I have to make it more user-friendly.

Mostly user-resilient... you can't fathom the amount of abuse your scripts will receive:)

Quote:
Otherwise the effort to maintain can become unreasonable.

Not much maintenance required if it is well written and has no specific dependencies.

_________________
Image


Top
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 5 hours [ DST ]



* Login  



Powered by phpBB3 © phpBB Group