[pygtk] gnomeprint.Config.to_string and gnomeprint.config_from_string

abel deuring adeuring at gmx.net
Thu Jun 29 07:42:52 WST 2006


Hi all,

next problem with gnomeprint: Since I am using an obviously too old
version of Gnome to mix threading and printer dialogs, I thought
that I could give it a try to show the printer dialog in a separate
process.

gnomeprint.Config.to_string and gnomeprint.config_from_string can be
used to pass data between parent and child process -- but this
results in a new problem:

----------------------------------------------
import gnomeprint, gnomeprint.ui, subprocess, md5

printerdlg = """
import sys, gnomeprint, gnomeprint.ui, md5

cfg = gnomeprint.config_from_string(sys.stdin.read(), 0)
job = gnomeprint.Job(cfg)
dlg = gnomeprint.ui.Dialog(job, "Printer Setup", 0)
res = dlg.run()
s = cfg.to_string(0)

if res == gnomeprint.ui.DIALOG_RESPONSE_PRINT:
    sys.stdout.write(s)
    m = md5.new()
    m.update(s)
    sys.stderr.write("md5/child %s\\n" % m.hexdigest())
"""

printconfig = gnomeprint.config_default()

cmd = ["python", "-c", "exec(%s)" % repr(printerdlg)]

p = subprocess.Popen(cmd,
                     stdin=subprocess.PIPE,
                     stdout=subprocess.PIPE)
res, err = p.communicate(input=printconfig.to_string(0))
if res:
    printconfig = gnomeprint.config_from_string(res)
    printjob = gnomeprint.Job(printconfig)
    m = md5.new()
    m.update(res)
    print "md5/parent %s" % m.hexdigest()
-------------------------------------------------------

If I select anything except "Create a PDF" or "Generic Postscript"
in the dialog window, I get the following output:

md5/child 3fe7b94d9fb3b7560d2f7b5ae3e729d8
Model not found, discarding config
md5/parent 3fe7b94d9fb3b7560d2f7b5ae3e729d8

The line "Model not found..." comes from "printconfig =
gnomeprint.config_from_string(res)" near the end of the script.

In other words: The XML description produced in the child is
unusable in the parent, though it is not modified.

Any ideas?

Abel

PS: the problems with gnomeprint aside, I am really excited about
the quality and reliability of PyGTK. In contrast to working with
many other larger Python wrapper modules, I never had a single
segfault or other nasty problem using PyGTK (except self-made ones,
of course ;)



More information about the pygtk mailing list