It is currently Mon Apr 15, 2024 8:22 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: [SOLVED] Can conditional inputs be programmed for the plugin dialogue?
PostPosted: Mon Mar 25, 2013 11:42 am  (#1) 
Offline
GimpChat Member

Joined: Mar 15, 2013
Posts: 36
I am writing a Python plug-in and for the dialogue for inputs to the plug-in, I need to make certain inputs conditional on other inputs. Can you do this with the register function in a plug-in? Here is a basic test plug-in script for Python.

#!/usr/bin/env python

from gimpfu import *

def test_register(test_1, test_2):
        pass

register(
        "test_register", # proc_name  The name of the command that you can call from the command line or from scripting
        "", # blurb   Information about the plug-in that displays in the procedure browser
        "", # help   Help for the plug-in
        "", # author   The plug-in's author
        "", # copyright   The copyright holder for the plug-in (usually the same as the author)
        "", # date   The copyright date
        "Test Register", # label   "<Image>/Image/Resize to max..."   The label that the plug-in uses in the menu
        "", # imagetypes   "RGB*, GRAY*"   The types of images the plug-in is made to handle
        [
                (PF_INT, "test_1", "THIS IS A TEST 1", 500),
                (PF_INT, "test_2", "THIS IS A TEST 2", 500)
        ], # params   The parameters for the plug-in's method
        [], # results   The results of the plug-in's method
        test_register, # function   The name of the method to call in your Python code
        menu="<Image>/MyScripts" #
        )

main()


Last edited by Grafx on Mon Mar 25, 2013 9:39 pm, edited 1 time in total.

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: Can conditional inputs be programmed for the plug-in dialogue?
PostPosted: Mon Mar 25, 2013 2:50 pm  (#2) 
Offline
Script Coder
User avatar

Joined: Jul 14, 2010
Posts: 697
I don't think you can if using gimp-fu.

If you construct the dialogs yourself (pygtk?), however, you can, I think.

-Rob A>

_________________
Image
Fantasy Cartography and Mapping by RobA


Top
 Post subject: Re: Can conditional inputs be programmed for the plug-in dialogue?
PostPosted: Mon Mar 25, 2013 3:46 pm  (#3) 
Offline
Script Coder
User avatar

Joined: Jun 22, 2010
Posts: 1171
Location: Here and there
It's not at all clear what you are trying to do.

Are you wanting to change the on-screen dialog based on selections you make in the on-screen dialog? If so, then it's not possible using the standard gimp system.

However as RobA says, using pygtk or TkInter, you can build pretty much anything you want, but it's a lot more work.

Kevin


Top
 Post subject: Re: Can conditional inputs be programmed for the plug-in dialogue?
PostPosted: Mon Mar 25, 2013 4:14 pm  (#4) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4734
Grafx wrote:
I am writing a Python plug-in and for the dialogue for inputs to the plug-in, I need to make certain inputs conditional on other inputs. Can you do this with the register function in a plug-in? Here is a basic test plug-in script for Python.

#!/usr/bin/env python

from gimpfu import *

def test_register(test_1, test_2):
        pass

register(
        "test_register", # proc_name  The name of the command that you can call from the command line or from scripting
        "", # blurb   Information about the plug-in that displays in the procedure browser
        "", # help   Help for the plug-in
        "", # author   The plug-in's author
        "", # copyright   The copyright holder for the plug-in (usually the same as the author)
        "", # date   The copyright date
        "Test Register", # label   "<Image>/Image/Resize to max..."   The label that the plug-in uses in the menu
        "", # imagetypes   "RGB*, GRAY*"   The types of images the plug-in is made to handle
        [
                (PF_INT, "test_1", "THIS IS A TEST 1", 500),
                (PF_INT, "test_2", "THIS IS A TEST 2", 500)
        ], # params   The parameters for the plug-in's method
        [], # results   The results of the plug-in's method
        test_register, # function   The name of the method to call in your Python code
        menu="<Image>/MyScripts" #
        )

main()

There is no real way to implement "logic" in the gimpfu dialogs. One way to do it is to have your main choice as two different menu entries leading to two different dialogs (you can register several menu entries). For instance if you have an some hypothetic "fill" plugin that can use either a pattern or a gradient, have the user make that choice by selecting in the menu either "Fill with gradient" or "Fill with pattern". Then each dialog can have specific widgets, while everything ends up processed by the same code.

_________________
Image


Top
 Post subject: Re: Can conditional inputs be programmed for the plug-in dialogue?
PostPosted: Mon Mar 25, 2013 4:33 pm  (#5) 
Offline
GimpChat Member

Joined: Mar 15, 2013
Posts: 36
ofnuts wrote:
There is no real way to implement "logic" in the gimpfu dialogs. One way to do it is to have your main choice as two different menu entries leading to two different dialogs (you can register several menu entries). For instance if you have an some hypothetic "fill" plugin that can use either a pattern or a gradient, have the user make that choice by selecting in the menu either "Fill with gradient" or "Fill with pattern". Then each dialog can have specific widgets, while everything ends up processed by the same code.


OK, so my sample code, for example, might be:

#!/usr/bin/env python

from gimpfu import *

def test_register_A(test_A):
        pass
def test_register_B(test_B):
        pass

register(
        "test_register_A", # proc_name  The name of the command that you can call from the command line or from scripting
        "", # blurb   Information about the plug-in that displays in the procedure browser
        "", # help   Help for the plug-in
        "", # author   The plug-in's author
        "", # copyright   The copyright holder for the plug-in (usually the same as the author)
        "", # date   The copyright date
        "Test Register", # label   "<Image>/Image/Plug_In_A"   The label that the plug-in uses in the menu
        "", # imagetypes   "RGB*, GRAY*"   The types of images the plug-in is made to handle
        [
                (PF_INT, "test_A", "THIS IS A TEST A", 500)
        ], # params   The parameters for the plug-in's method
        [], # results   The results of the plug-in's method
        test_register_A, # function   The name of the method to call in your Python code
        menu="<Image>/MyScripts" #
        )

register(
        "test_register_B", # proc_name  The name of the command that you can call from the command line or from scripting
        "", # blurb   Information about the plug-in that displays in the procedure browser
        "", # help   Help for the plug-in
        "", # author   The plug-in's author
        "", # copyright   The copyright holder for the plug-in (usually the same as the author)
        "", # date   The copyright date
        "Test Register", # label   "<Image>/Image/Plug_In_B"   The label that the plug-in uses in the menu
        "", # imagetypes   "RGB*, GRAY*"   The types of images the plug-in is made to handle
        [
                (PF_INT, "test_B", "THIS IS A TEST B", 500)
        ], # params   The parameters for the plug-in's method
        [], # results   The results of the plug-in's method
        test_register_B, # function   The name of the method to call in your Python code
        menu="<Image>/MyScripts" #
        )

main()


Or you could register two menu entries going to the same function with different arguments possible. And etc.


Top
 Post subject: Re: Can conditional inputs be programmed for the plug-in dialogue?
PostPosted: Mon Mar 25, 2013 6:33 pm  (#6) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4734
Since Python uses a weak typing and allows default parameters in functions you could indeed have the same function called with different parameters, but I wouldn't recommend that. I usually have small facade functions. I also use variables for all the common stuff:

register(
   'space-layers-horizontal',
   spaceHDesc+whoiam,spaceHDesc,
   author,author,
   copyrightYear,
   'Horizontally',
   '*',spaceParms,[],
   spaceHorizontally,
   menu=spaceMenu
)

register(
   'space-layers-vertical',
   spaceVDesc+whoiam,spaceVDesc,
   author,author,
   copyrightYear,
   'Vertically',
   '*',spaceParms,[],
   spaceVertically,
   menu=spaceMenu
)

_________________
Image


Top
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Attachment(s) Un-closable Tool Options Dialogue Panel Covering Top Menu Items

1

No new posts Attachment(s) Baby's first GEGL plugin - a very basic GEGL plugin anyone can make.

9

No new posts Can't get plugin to appear (mostly)

3

No new posts Dying Plugin Pox

2

No new posts Attachment(s) pm_actions_on_multiple_layers plugin

6



* Login  



Powered by phpBB3 © phpBB Group