It is currently Mon Aug 17, 2026 11:31 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: pdb.gimp_forum_subject_add(msg, "Hello World!")
PostPosted: Mon Mar 17, 2014 5:14 pm  (#1) 
Offline
New Member

Joined: Mar 17, 2014
Posts: 2
Hey everyone,

About two weeks ago, I fell in love with Python-Fu, the much more beautiful wrapper around Script-Fu, possibly the best-named piece of code I've ever seen! :ninja

I've never been able to draw, but this is art that I "get" and can do. Best of all, just like everything else in software, oh so much of the heavy lifting is already done. I'm now on a downloading and translating spree, as I seek to build an arsenal of all the effects (ALL THE EFFECTS!!!11!!1) (<- that's how you know I'm serious)

It's gonna be fun, and I can't wait to see where this all takes me. I feel like a higher-level wrapper around the pdb object's standard function calls, is certainly called for and a good place to start. I'll call it Scott-Fu, and it will be glorious! (and has a way better ring to it than Inversus-Fu lol)

Amongst my wild promises are: nice and sensible default named parameters; fill out the missing constants (to a reasonable extent :P ); keeping all the "gimp" and "pdb" stuff available (moar functionality is better functionality!!); and a higher level of abstraction around things on a more conceptual level, thereby adding to the amount of fun you and I both experience. After all, why should I have to:
image = pdb.gimp_image_new(600, 400, RGB)  # create a new image,
layer = pdb.gimp_layer_new(image, 600, 400, RGBA_IMAGE, "Layer", 100, NORMAL_MODE)  # create a new layer,
pdb.gimp_image_insert_layer(image, layer, NO_LAYER_GROUP, TOP_LAYER)  # attach to image,
pdb.gimp_display_new(image)  # create a display for the image,
# and
pdb.gimp_displays_flush()  # flush the displays (not technically necessary, but if I had a nickel for every bug that had to do with some accursed buffer not being flushed...)

?
??
???!!!!!?!?!?????

Ridiculous! Obscene!! Horrifying!!! Who even does something like that!? It's crazy! I want to do that in less characters than it took me to type this sentence, let alone the code above. So, in my "sus" class/object, I have this function:
def img_new(width=600, height=400, layer_name="Layer")
    ... #literally the stuff above with the parameter names subbed in
    return (image, layer)

that, due to the beauty of python's default parameters (so fun), and tuples (possibly even moar fun), it can be called thusly,
(image, layer) = sus.img_new(600, 400, "Layer")

or even thusly:
(image, layer) = sus.img_new()

and will faithfully complete those 5 steps, creating a new image for which you could specify size and layer name, or not.

...and beauty was restored

And then, just for the sake of wretched excess, I present:
def n():
    # lol
    return sus.img_new(1920, 1080, "Your Personal Defaults")

Which can, unsurprisingly, be called thusly:
(image, layer) = n()

OOOOOOooooooooooommmmmmmmmmmmmmmm


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_forum_subject_add(msg, "Hello World!")
PostPosted: Mon Mar 17, 2014 5:18 pm  (#2) 
Offline
New Member

Joined: Mar 17, 2014
Posts: 2
A stroke of genius! Instead of naming the class "sus" after my name, it shall henceforth be known as "fu" for many reasons, including:
Script-Fu
Python-Fu
Scott-Fu
It's shorter
You can't spell fun without "fu"!
There was something else.. I just can't seem to put any of my fingers on in, even the middle one :P


Top
 Post subject: Re: pdb.gimp_forum_subject_add(msg, "Hello World!")
PostPosted: Mon Mar 17, 2014 5:25 pm  (#3) 
Offline
GimpChat Member
User avatar

Joined: Nov 16, 2011
Posts: 5127
Location: Metro Vancouver, BC
Welcome Inversus!
It's nice to see a another happy coder at Gimp Chat. :bigthup

_________________
Image
Gimp 2.8.18, Linux, median user
Gimp Chat Tutorials Index
Spirit Bear (Kermode)


Top
 Post subject: Re: pdb.gimp_forum_subject_add(msg, "Hello World!")
PostPosted: Mon Mar 17, 2014 5:46 pm  (#4) 
Offline
GimpChat Member
User avatar

Joined: Apr 07, 2010
Posts: 14182
Welcome to GimpChat Inversus. Happy Gimping.

_________________
Image


Top
 Post subject: Re: pdb.gimp_forum_subject_add(msg, "Hello World!")
PostPosted: Mon Mar 17, 2014 6:10 pm  (#5) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4812
  1. python-fu isn't a wrapper around script-fu. It does things that script-fu cannot do.
  2. Read the doc about the existing object classes: http://www.gimp.org/docs/python/index.html.
  3. In the Python-fu console, issue a dir() against some objects and notice that some of the stuff isn't documented but works just as well.
  4. Single calls are fine, but don't overdo it.
    • If there is a problem, it's hard to find which parameter is the culprit
    • In many cases either you lose some functionality or you end up with about as much parameters as we several calls (for instance, it is often useful to have an image without a display, or even without a layer).

_________________
Image


Top
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]



* Login  



Powered by phpBB3 © phpBB Group