This proposes enhancing PDB gimp_display_new() to successfully return a
null display when non-interactive, and enhancing PDB gimp_display_delete
to return success even for a null display.

Most scripts (Python and Scheme) that call gimp_display_new() abort the
script when run in batch mode.  The proposed changes implement null
displays.  Only the behavior changes, not the signature.

Probably no scripts will need to be changed, neither scripts distributed
with Gimp nor third party scripts.  (Few use other than

The benefit of this change is that it simplifies plugin programming.
Plugin authors can worry less about the mode. Batch programmers can use
more plugins without regard for whether they call gimp_display_new().

(About ten Scheme plugins distributed with Gimp will cease to abort when
called in batch mode. Since the plugins don't return an image except to
display it, the plugins are not useful in batch mode, but the lack of a
return value from Scheme plugins is another issue.)

One disadvantage is that the error when a display cannot be created
(because of exhaustion of system resources) cannot be detected in a
script after this change.  The error when a display cannot be created
because an invalid image is passed will still abort a script.

An alternative in Python is to bracket a call to gimp_display_new() with
try:except:, but there is no such alternative in Scheme.

The null display is similar to the null Linux device.  The new, flush,
and delete display PDB operations will act on a null display, without
aborting, just as on a real display.  

The other PDB operations on a null display: 
gimp_display_is_valid() will return False on a null display, 
gimp_display_reconnect will abort a script, 
gimp_display_get_window_handle() will abort a script (on invalid
argument for the display.)

A patch is attached.  It includes changes in display.pdb to
gimp_display_new() and gimp_display_delete().
>From 218285d3cb532e01177616b3434654bd20e2ae14 Mon Sep 17 00:00:00 2001
From: Lloyd Konneker <>
Date: Mon, 20 Sep 2010 19:59:46 -0400
Subject: [PATCH] Enhance PDB display new and delete so plugins don't abort in batch mode

 tools/pdbgen/pdb/display.pdb |   22 +++++++++++-----------
 1 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/tools/pdbgen/pdb/display.pdb b/tools/pdbgen/pdb/display.pdb
index 168cdfd..83e58c8 100644
--- a/tools/pdbgen/pdb/display.pdb
+++ b/tools/pdbgen/pdb/display.pdb
@@ -21,7 +21,7 @@ sub display_is_valid {
     $help = <<'HELP';
 This procedure checks if the given display ID is valid and refers to an
-existing display.
+existing display.  It returns False for the null display.
     &neo_pdb_misc('2007', '2.4');
@@ -52,8 +52,8 @@ sub display_new {
 Creates a new display for the specified image. If the image already has a
 display, another is added. Multiple displays are handled transparently by
 GIMP. The newly created display is returned and can be subsequently destroyed
-with a call to gimp_display_delete(). This procedure only makes sense for use
-with the GIMP UI.
+with a call to gimp_display_delete(). This returns the null display 
+if there is no UI.
@@ -81,10 +81,7 @@ HELP
       if (gimp_image_get_display_count (image) == 1)
         g_object_unref (image);
-  else
-    {
-      success = FALSE;
-    }
+  /* else return SUCCESS and the null display. */
@@ -97,20 +94,22 @@ sub display_delete {
 This procedure removes the specified display. If this is the last remaining 
 display for the underlying image, then the image is deleted also. Note that
 the display is closed no matter if the image is dirty or not. Better save
-the image before calling this procedure.
+the image before calling this procedure.  Deleting the null display returns
     @inargs = (
-	{ name => 'display', type => 'display',
+	{ name => 'display', type => 'display', no_validate => 1,
 	  desc => 'The display to delete' }
     %invoke = (
 	code => <<'CODE'
-  gimp_delete_display (gimp, display);
+  if (display) /* If not the null display */
+    gimp_delete_display (gimp, display);
@@ -123,7 +122,8 @@ sub display_get_window_handle {
 This procedure returns a handle to the native window for a given image
 display. For example in the X backend of GDK, a native window handle is
 an Xlib XID. A value of 0 is returned for an invalid display or if this
-function is unimplemented for the windowing system that is being used.
+function is unimplemented for the windowing system that is being used
+or for the null display.
     &neo_pdb_misc('2005', '2.4');

Gimp-developer mailing list

Reply via email to