Re: [Gimp-developer] Gimp choking on python invocation



On 11/19/2012 10:54 PM, Vio wrote:
Hello,
Newcomer on this list but old time python coder with a Gimp itch
someone might have an idea how to scratch.
Task seem simple enough: make Gimp do some back-flips from afar
through snaky incantations ... This imply combining 2 libs:  gimpfu and xmlrpc.
Well, after a sleepless night trying to solve this query, I am almost
ready to give up.
so I feel ready to get enlightened. I'm most probably doing something
stupid someplace,
but I need another pair of eyeballs to put me on the right track to
see my error.

My simple test-case below, followed by some simple test output I get.
I'm on ubuntu, my gimp is 2.6.8, python version is ... whatever is
embedded there

-------------------------------------------------------
#! /usr/bin/env python
from gimpfu import *

# xmlrpc
from SimpleXMLRPCServer import SimpleXMLRPCServer
from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler
# Restrict to a particular path.
class RequestHandler(SimpleXMLRPCRequestHandler):
     print 'TRACE> RequestHandler()'
     rpc_paths = ('/RPC2',)
# Create server
server = SimpleXMLRPCServer(("localhost", 8000), allow_none=True)

def echo(*args):
     print "echo:", args
server.register_function(echo, 'myecho')

def farmsg(msg):
     return 'farmsg is: %s' % msg
server.register_function(farmsg)

def pixh(*args):
     print "args:", args
     src_path = args[0]
     print 'pixh src>%s<' % (src_path)
     img = pdb.file_jpeg_load(src_path, 1)
     pdb.gimp_image_undo_disable(img)
     h = img.height
     print 'pixh result>%d<' % (h)
     return 'pixh result>%d<' % (h)
server.register_function(pixh)

register(
   "clientecho", "", "", "", "", "",
   "<Toolbox>/Xtns/Languages/Python-Fu/Test/_Console Echo", "",
   [
   (PF_STRING, "arg0", "argument 0", "/tmp/t/default.jpg"),
   (PF_INT,    "arg1", "argument 1", 100          ),
   (PF_FLOAT,  "arg2", "argument 2", 1.2          ),
   (PF_COLOR,  "arg3", "argument 3", (0, 0, 0)    ),
   ],
   [],
#  echo
   pixh
   )

print 'TRACE> entering main()'
main()

print 'TRACE> entering serve_forever()'
server.serve_forever()

------------------------------------------------------------------
Some output I'm getting (or lack of)

STARTING SERVER WITH:
gimp --no-interface --batch '(python-fu-clientecho RUN-NONINTERACTIVE
"/tmp/t/rihanna.jpg")' &

TALKING TO SERVER WITH (xmlrpc server seem to work Ok, it's the Gimp
which fails below):
import xmlrpclib
s = xmlrpclib.ServerProxy('http://localhost:8000')
TRACE> RequestHandler()
TRACE> entering main()
TRACE> entering serve_forever()
s.myecho('sssssssss')
$ echo: ('sssssssss',)
s.farmsg('homeeeer')
'farmsg is: homeeeer'
s.pixh('/tmp/t/rihanna.jpg')
pixh src>/tmp/t/rihanna.jpg<
... then nothing

My understanding is that Gimp chokes on this code for some unknown reason.
Perhaps I am not invoking it correctly?
Killing a Gimp child gaves some error message:
GIMP-Error: Opening '/dd/d/devel.../MY/(gimp-quit 1)' failed: No such
file or directory
So I removed the '(gimp-quit 1)' startup invocation...
That error dissapeared, but so did Gimp's conversational skills...

I know what you're saying: by now I should just start learning Scheme
and use extrans/gimpclient.py
to send Scheme instructions to the embedded Gimp-server. But my question is:
why can't I invoke gimp-python remotely as the scheme crowd can?
Where am I putting my foot in my mouth in this code?
I know others have solved this puzzle, as I see a few web-apps using
gimp as their graphics workhorse.
But can it be solved in python alone (no scheme)?

PS. if this has been answered before elsewhere, a link to that post
would be most appreciated.
But I've googled this topic non-stop for over 24 hours straight now,
with no luck. Not expecting miracles.
Anyway, any suggestion very welcome ;)

Cheers!
zaz
_______________________________________________
gimp-developer-list mailing list
gimp-developer-list gnome org
https://mail.gnome.org/mailman/listinfo/gimp-developer-list

To expand on Jon's answer, I believe that what you want to do is doable, but a bit differently. You have to start Gimp as if running in batch mode, specifying a Python script to initiate. This script (that doesn't need to register, and shouldn't do so) should then be able to run your processing loop.




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]