% % Demo with GTK-server and Postscript using FIFO communication % Tested with ESP GhostScript 7.07 and GTK-server 2.0.5 on Slackware 10.1 & 10.2 % % Homepage ESP GhostScript: http://www.cups.org/espgs/ % % First start GTK-server with: % gtk-server -fifo=/tmp/script.gtk & % % Then run this demo as follows, using GhostScript: % gs -q -dNODISPLAY demo.ps % % With ESP Ghostscript 815.00 (2005-08-11) run like this: % gs -q demo.ps % % Oct 10, 2005 - PvE. % Revised for GTK-server 2.0.6 at december 17, 2005 % Tested with GTK-server 2.2.3 at march 25, 2008 - PvE. %-------------------------------------------------------------- % Some global vars /name-of-pipe (/tmp/script.gtk) def /buffer 128 string def % Declare widget variables /window 10 string def /table 10 string def /button1 10 string def /button2 10 string def /entry 10 string def /event 10 string def % Communication routine /gtk { /pipe name-of-pipe (w) file def count { pipe exch writestring pipe ( ) writestring } repeat pipe closefile /pipe name-of-pipe (r) file def pipe buffer readstring pop % <----- Ignore the readstring returnvalue pipe closefile } bind def % Check if pipefile exists name-of-pipe status false eq { (\nStart GTK-server first: gtk-server fifo=/tmp/script.gtk\n\n) print flush quit } { clear } ifelse % Setup the GUI (gtk_init NULL NULL) gtk pop (gtk_window_new 0) gtk window copy pop (\"PostScript demo\") window (gtk_window_set_title) gtk pop (100 100) window (gtk_window_set_default_size) gtk pop (1) window (gtk_window_set_position) gtk pop (gtk_table_new 30 30 1) gtk table copy pop table window (gtk_container_add) gtk pop (gtk_button_new_with_label Exit) gtk button1 copy pop (17 28 20 25) button1 table (gtk_table_attach_defaults) gtk pop (gtk_button_new_with_label \"Print text\") gtk button2 copy pop (2 13 20 25) button2 table (gtk_table_attach_defaults) gtk pop (gtk_entry_new) gtk entry copy pop (2 28 5 15) entry table (gtk_table_attach_defaults) gtk pop window (gtk_widget_show_all) gtk pop % This is the mainloop { (gtk_server_callback WAIT) gtk event copy pop button2 event eq entry event eq or { entry (gtk_entry_get_text) gtk (This is the contents: ) print print flush } if button1 event eq window event eq or { exit } if } loop % Exit GTK-server (gtk_server_exit) gtk % Exit PostScript interpreter quit