When writing a GIMP Plugin using Python, can the Plugin display a GIMP based Dialog box informing the user if they haven't provided an argument?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

When writing a GIMP Plugin using Python, can the Plugin display a GIMP based Dialog box informing the user if they haven't provided an argument?

Developers mailing list
Hello.

I am writing a GIMP Plugin using Python, and this Plugin expects to receive
a list of files as one of its arguments. My question is, if the user
doesn't provide any files as arguments, can my Plugin display a GIMP based
Dialog box informing them of this?

My Plugin is working as I expect, however I currently have it implemented
so that it throws an Exception if it doesn't receive a list of files as one
of its arguments. GIMP catches this Exception and displays its own Dialog
box informing the user that an Exception has been thrown and caught.
However, I would like to catch this Exception within my Plugin, and present
a Dialog box which is slightly more user-friendly than the one I am
currently seeing from GIMP. After all, not all users know (or even care to
know) what an Exception is.

Any help on this matter would be immensely appreciated.

Thanks in advance.
_______________________________________________
gimp-developer-list mailing list
List address:    [hidden email]
List membership: https://mail.gnome.org/mailman/listinfo/gimp-developer-list
List archives:   https://mail.gnome.org/archives/gimp-developer-list
Reply | Threaded
Open this post in threaded view
|

Re: When writing a GIMP Plugin using Python, can the Plugin display a GIMP based Dialog box informing the user if they haven't provided an argument?

Developers mailing list
On Wednesday, May 8, 2019, Craig Sanders via gimp-developer-list <
[hidden email]> wrote:

> Hello.
>
> I am writing a GIMP Plugin using Python, and this Plugin expects to receive
> a list of files as one of its arguments. My question is, if the user
> doesn't provide any files as arguments, can my Plugin display a GIMP based
> Dialog box informing them of this?
>

gimp.message(You did not provide files)

The message part should be in quotes probably....
_______________________________________________
gimp-developer-list mailing list
List address:    [hidden email]
List membership: https://mail.gnome.org/mailman/listinfo/gimp-developer-list
List archives:   https://mail.gnome.org/archives/gimp-developer-list
Reply | Threaded
Open this post in threaded view
|

Re: When writing a GIMP Plugin using Python, can the Plugin display a GIMP based Dialog box informing the user if they haven't provided an argument?

Developers mailing list
Ahhh. I didn't even think that it might be able to be done that way - but
your solution is exactly what I was looking for. Thankyou very much.

I was thinking that there might be a GIMP Procedure such as;

    pdb.display_dialog(...)

or something similar.

After I submitted my question, I found a snippet of Python code on the
Internet which did what I needed, but nowhere near as nicely as your
answer. When I modified this snippet of Python code, it looked as follows;

import gtk

# A whole lot of code has been left out here!!!

    errDialog = gtk.MessageDialog(

                 None,

                 0,

                 gtk.MESSAGE_ERROR,

                 gtk.BUTTONS_OK,

                 "You must specify at least one file."

                )

    errDialog.show_all()

    errDialog.run()

# And a whole lot of code has been left out here!!!

Thanks once again for your assistance. It is most appreciated.

On Thu, May 9, 2019 at 1:22 AM Carol Spears <[hidden email]> wrote:

>
>
> On Wednesday, May 8, 2019, Craig Sanders via gimp-developer-list <
> [hidden email]> wrote:
>
>> Hello.
>>
>> I am writing a GIMP Plugin using Python, and this Plugin expects to
>> receive
>> a list of files as one of its arguments. My question is, if the user
>> doesn't provide any files as arguments, can my Plugin display a GIMP based
>> Dialog box informing them of this?
>>
>
> gimp.message(You did not provide files)
>
> The message part should be in quotes probably....
>
_______________________________________________
gimp-developer-list mailing list
List address:    [hidden email]
List membership: https://mail.gnome.org/mailman/listinfo/gimp-developer-list
List archives:   https://mail.gnome.org/archives/gimp-developer-list
Reply | Threaded
Open this post in threaded view
|

Re: When writing a GIMP Plugin using Python, can the Plugin display a GIMP based Dialog box informing the user if they haven't provided an argument?

Ofnuts-2
If the plugin is for public use, gimp.message() is a better solution
because it will display in a dialog box or in the Gimp message console 
depending on user preferences. You don't really need to drag in all the
GTK support just to display an error message.

On the other hand, I don't see how you pass a list of files to a
plugin.. If this is a batch script, things are a bit different, but then
there may be no UI at all, and the message would be better printed to
the console.

On 5/9/19 1:32 AM, Craig Sanders via gimp-developer-list wrote:

> Ahhh. I didn't even think that it might be able to be done that way - but
> your solution is exactly what I was looking for. Thankyou very much.
>
> I was thinking that there might be a GIMP Procedure such as;
>
>      pdb.display_dialog(...)
>
> or something similar.
>
> After I submitted my question, I found a snippet of Python code on the
> Internet which did what I needed, but nowhere near as nicely as your
> answer. When I modified this snippet of Python code, it looked as follows;
>
> import gtk
>
> # A whole lot of code has been left out here!!!
>
>      errDialog = gtk.MessageDialog(
>
>                   None,
>
>                   0,
>
>                   gtk.MESSAGE_ERROR,
>
>                   gtk.BUTTONS_OK,
>
>                   "You must specify at least one file."
>
>                  )
>
>      errDialog.show_all()
>
>      errDialog.run()
>
> # And a whole lot of code has been left out here!!!
>
> Thanks once again for your assistance. It is most appreciated.
>
> On Thu, May 9, 2019 at 1:22 AM Carol Spears <[hidden email]> wrote:
>
>>
>> On Wednesday, May 8, 2019, Craig Sanders via gimp-developer-list <
>> [hidden email]> wrote:
>>
>>> Hello.
>>>
>>> I am writing a GIMP Plugin using Python, and this Plugin expects to
>>> receive
>>> a list of files as one of its arguments. My question is, if the user
>>> doesn't provide any files as arguments, can my Plugin display a GIMP based
>>> Dialog box informing them of this?
>>>
>> gimp.message(You did not provide files)
>>
>> The message part should be in quotes probably....
>>
> _______________________________________________
> gimp-developer-list mailing list
> List address:    [hidden email]
> List membership: https://mail.gnome.org/mailman/listinfo/gimp-developer-list
> List archives:   https://mail.gnome.org/archives/gimp-developer-list


_______________________________________________
gimp-developer-list mailing list
List address:    [hidden email]
List membership: https://mail.gnome.org/mailman/listinfo/gimp-developer-list
List archives:   https://mail.gnome.org/archives/gimp-developer-list
Reply | Threaded
Open this post in threaded view
|

Re: When writing a GIMP Plugin using Python, can the Plugin display a GIMP based Dialog box informing the user if they haven't provided an argument?

Developers mailing list
You should IMHO prevent performing an operation when the input is invalid.
Yes, it's definitely easier to throw an exception, but those are IMHO
rather to deal with some unexpected errors.

On Sat, May 11, 2019, 23:44 Ofnuts <[hidden email]> wrote:

> If the plugin is for public use, gimp.message() is a better solution
> because it will display in a dialog box or in the Gimp message console
> depending on user preferences. You don't really need to drag in all the
> GTK support just to display an error message.
>
> On the other hand, I don't see how you pass a list of files to a
> plugin.. If this is a batch script, things are a bit different, but then
> there may be no UI at all, and the message would be better printed to
> the console.
>
> On 5/9/19 1:32 AM, Craig Sanders via gimp-developer-list wrote:
> > Ahhh. I didn't even think that it might be able to be done that way - but
> > your solution is exactly what I was looking for. Thankyou very much.
> >
> > I was thinking that there might be a GIMP Procedure such as;
> >
> >      pdb.display_dialog(...)
> >
> > or something similar.
> >
> > After I submitted my question, I found a snippet of Python code on the
> > Internet which did what I needed, but nowhere near as nicely as your
> > answer. When I modified this snippet of Python code, it looked as
> follows;
> >
> > import gtk
> >
> > # A whole lot of code has been left out here!!!
> >
> >      errDialog = gtk.MessageDialog(
> >
> >                   None,
> >
> >                   0,
> >
> >                   gtk.MESSAGE_ERROR,
> >
> >                   gtk.BUTTONS_OK,
> >
> >                   "You must specify at least one file."
> >
> >                  )
> >
> >      errDialog.show_all()
> >
> >      errDialog.run()
> >
> > # And a whole lot of code has been left out here!!!
> >
> > Thanks once again for your assistance. It is most appreciated.
> >
> > On Thu, May 9, 2019 at 1:22 AM Carol Spears <[hidden email]>
> wrote:
> >
> >>
> >> On Wednesday, May 8, 2019, Craig Sanders via gimp-developer-list <
> >> [hidden email]> wrote:
> >>
> >>> Hello.
> >>>
> >>> I am writing a GIMP Plugin using Python, and this Plugin expects to
> >>> receive
> >>> a list of files as one of its arguments. My question is, if the user
> >>> doesn't provide any files as arguments, can my Plugin display a GIMP
> based
> >>> Dialog box informing them of this?
> >>>
> >> gimp.message(You did not provide files)
> >>
> >> The message part should be in quotes probably....
> >>
> > _______________________________________________
> > gimp-developer-list mailing list
> > List address:    [hidden email]
> > List membership:
> https://mail.gnome.org/mailman/listinfo/gimp-developer-list
> > List archives:   https://mail.gnome.org/archives/gimp-developer-list
>
>
> _______________________________________________
> gimp-developer-list mailing list
> List address:    [hidden email]
> List membership:
> https://mail.gnome.org/mailman/listinfo/gimp-developer-list
> List archives:   https://mail.gnome.org/archives/gimp-developer-list
>
_______________________________________________
gimp-developer-list mailing list
List address:    [hidden email]
List membership: https://mail.gnome.org/mailman/listinfo/gimp-developer-list
List archives:   https://mail.gnome.org/archives/gimp-developer-list
Reply | Threaded
Open this post in threaded view
|

Re: When writing a GIMP Plugin using Python, can the Plugin display a GIMP based Dialog box informing the user if they haven't provided an argument?

Ofnuts-2
When you write a Gimp plugin in Python, either you do your whole
interactive UI with PyGTK, or you let Gimp auto-generate a dialog to
collect parameters from the user before calling you. Of course the
second solution is a bit less user-friendly(*) but in many scripts,
doing the whole UI would represent the larger and most complex part of
the code.

(*) though not as bad as it looks, you can normally expect passed
image/layers/files/colors to exist since they have been specified using
specific dialogs.

On 5/12/19 5:50 PM, Michal Vašut wrote:

> You should IMHO prevent performing an operation when the input is
> invalid.
> Yes, it's definitely easier to throw an exception, but those are IMHO
> rather to deal with some unexpected errors.
>
> On Sat, May 11, 2019, 23:44 Ofnuts <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     If the plugin is for public use, gimp.message() is a better solution
>     because it will display in a dialog box or in the Gimp message
>     console
>     depending on user preferences. You don't really need to drag in
>     all the
>     GTK support just to display an error message.
>
>     On the other hand, I don't see how you pass a list of files to a
>     plugin.. If this is a batch script, things are a bit different,
>     but then
>     there may be no UI at all, and the message would be better printed to
>     the console.
>

_______________________________________________
gimp-developer-list mailing list
List address:    [hidden email]
List membership: https://mail.gnome.org/mailman/listinfo/gimp-developer-list
List archives:   https://mail.gnome.org/archives/gimp-developer-list