RSS/Atom feed Twitter
Site is read-only, email is disabled

Calling a function from a custom module

This discussion is connected to the gimp-developer-list.gnome.org mailing list which is provided by the GIMP developers and not related to gimpusers.com.

This is a read-only list on gimpusers.com so this discussion thread is read-only, too.

8 of 8 messages available
Toggle history

Please log in to manage your subscriptions.

Calling a function from a custom module kowboy_koder 18 Apr 11:12
  Calling a function from a custom module Roman Joost 18 Apr 13:20
   Calling a function from a custom module kowboy_koder 18 Apr 14:22
    Calling a function from a custom module Joao S. O. Bueno 19 Apr 04:03
    Calling a function from a custom module Roman Joost 19 Apr 04:52
  Calling a function from a custom module saulgoode@flashingtwelve.brickfilms.com 19 Apr 06:52
   Calling a function from a custom module Roman Joost 19 Apr 09:58
    Calling a function from a custom module kowboy_koder 20 Apr 06:54
2010-04-18 11:12:05 UTC (about 15 years ago)
postings
3

Calling a function from a custom module

Hey all. I'm more or less a beginner when it comes to GIMP scripting (though I do have a few years of exp in general development) and I've run into a bump with PyGimp that I was hoping someone might be able to give me a hand with.

As general practice, I've written a function that I put inside a file called "ofstream.py" (placed in the same folder as gimpfu.py), which consists of:

def fout: f = open("C:\testFile.dat")
f.write("Hello World!")
f.close()

I then have another script (placed in my plugins folder, to be picked up by Gimp) which contains:

import math from gimpfu import *
from ofstream import *

def testFile: fout()

#register code follows...

But I keep getting an 'execution error' linked to the fout statement. If I comment out that line and replace it with something else, it works fine. The 'import ofstream' line gives me no trouble; its the function call thats the problem.

Why am I having this issue? I can use functions located in gimpfu.py just fine (register, main, etc). Why can't I use my own function?

Thanks in advance everyone.

Cheers.

Roman Joost
2010-04-18 13:20:34 UTC (about 15 years ago)

Calling a function from a custom module

On Sun, Apr 18, 2010 at 11:12:05AM +0200, Jason S. wrote:

As general practice, I've written a function that I put inside a file called "ofstream.py" (placed in the same folder as gimpfu.py), which consists of: [...] example code
But I keep getting an 'execution error' linked to the fout statement.

Could you paste the error as well?

If I comment out that line and replace it with something else, it works fine. The 'import ofstream' line gives me no trouble; its the function call thats the problem.

IMHO it's better do use absolute imports like:

import ofstream ....
ofstream.fout()

But that will not fix your problem.

Why am I having this issue? I can use functions located in gimpfu.py just fine (register, main, etc). Why can't I use my own function?

It would be much more helpful if you could paste the whole traceback...

If you can import your module, it should also be possible to access your function. What will happen if you you explicitly import your function:

from ofstrem import fout

Cheers

2010-04-18 14:22:44 UTC (about 15 years ago)
postings
3

Calling a function from a custom module

Thanks for the reply.

I tried importing the 'fout' function explicitly; it worked.

from ofstream import fout

worked just fine. No problems. I still have an issue using the 'fout' function though. I know its not a problem with the code within the function; I've tried copying the fout function code and placing it within my module directly- that works fine.

The only error info I get is:

"Traceback (most recent call last): File "", line 1, in
RuntimeError: execution error"

which really isnt much to work with- this is what makes PyGimp debugging so frustrating. When you're working with .NET, Flash or even C/C++, your compiler / interpreter at least gives you some insight into your problem with its error messages. PyGimp won't even give me a line number >.<

Anyways, any help is much appreciated. Thanks heaps every1.

Cheers, Jay.

Joao S. O. Bueno
2010-04-19 04:03:57 UTC (about 15 years ago)

Calling a function from a custom module

On Sun, Apr 18, 2010 at 9:22 AM, Jason S. wrote:

Thanks for the reply.

I tried importing the 'fout' function explicitly; it worked.

from ofstream import fout

worked just fine. No problems. I still have an issue using the 'fout' function though. I know its not a problem with the code within the function; I've tried copying the fout function code and placing it within my module directly- that works fine.

I fyou r8un gimp fromteh consoe, instead of clickingon it, you will get line numbers.
AAlso, pygimp allows you to test any code you want formt he interatcvie consoel, with a Live gimp and images, just open the console in the pygimp sub menu,
ad get a reference to an open image with something like

img = gimp.list_images()[0]

The only error info I get is:

"Traceback (most recent call last): File "", line 1, in
RuntimeError: execution error"

which really isnt much to work with- this is what makes PyGimp debugging so frustrating. When you're working with .NET, Flash or even C/C++, your compiler / interpreter at least gives you some insight into your problem with its error messages. PyGimp won't even give me a line number >.<

Anyways, any help is much appreciated. Thanks heaps every1.

Cheers,      Jay.

--
Jason S. (via www.gimpusers.com)

Roman Joost
2010-04-19 04:52:58 UTC (about 15 years ago)

Calling a function from a custom module

On Sun, Apr 18, 2010 at 02:22:44PM +0200, Jason S. wrote:

I tried importing the 'fout' function explicitly; it worked.

from ofstream import fout

worked just fine. No problems.

Maybe you're overwriting a function or method which is declared elsewere with the same name and that's why you get your mysterious results?

The only error info I get is:

"Traceback (most recent call last): File "", line 1, in
RuntimeError: execution error"

Hm.. You're right - not really helpful. Where is '' coming from? Hm... maybe it is passed as a text or string and executed ...

which really isnt much to work with- this is what makes PyGimp debugging so frustrating. When you're working with .NET, Flash or even C/C++, your compiler / interpreter at least gives you some insight into your problem with its error messages. PyGimp won't even give me a line number >.<

Does this code work if you put it into a Python module and don't execute it from within GIMP afterall? There is also a Python console available in GIMP from where you can start trying to debug your program.

Cheers,

saulgoode@flashingtwelve.brickfilms.com
2010-04-19 06:52:41 UTC (about 15 years ago)

Calling a function from a custom module

Quoting "Jason S." :

Hey all. I'm more or less a beginner when it comes to GIMP scripting (though I
do have a few years of exp in general development) and I've run into a bump with PyGimp that I was hoping someone might be able to give me a hand with.

As general practice, I've written a function that I put inside a file called "ofstream.py" (placed in the same folder as gimpfu.py), which consists of:

def fout: f = open("C:\testFile.dat")
f.write("Hello World!")
f.close()

Doesn't the backslash need to be escaped in Python string constants?

Roman Joost
2010-04-19 09:58:29 UTC (about 15 years ago)

Calling a function from a custom module

On Mon, Apr 19, 2010 at 12:52:41AM -0400, saulgoode@flashingtwelve.brickfilms.com wrote:

Quoting "Jason S." :

def fout:
f = open("C:\testFile.dat")
f.write("Hello World!")
f.close()

Doesn't the backslash need to be escaped in Python string constants?

I guess that could be it. I just wonder why it throws an execution error and not an IOError...

Cheers,

2010-04-20 06:54:09 UTC (about 15 years ago)
postings
3

Calling a function from a custom module

Yeah, it was the backslashes.

I needed to use "\\" :$

Python reminds me of BASIC I guess lol. Gotta get out of that mindset :P

Thanks every1 who replied.