From db25b0c9caebf7dfc80d2e6cb35bb1c41f973082 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Wed, 4 Jan 2012 16:06:36 +0100 Subject: [PATCH] Added a new infrastructure to autogenerate screenshots of dialog boxes --- src/ui/gui/automake.mk | 60 ++++++++++++++++--- src/ui/gui/dark.rc | 16 +++++ src/ui/gui/default.rc | 8 +++ src/ui/gui/dialog-capture.c | 130 +++++++++++++++++++++++++++++++++++++++++ src/ui/gui/gen-screenshots.sh | 88 +++++++++++++++++++++++++++ src/ui/gui/high-contrast.rc | 19 ++++++ 6 files changed, 312 insertions(+), 9 deletions(-) create mode 100644 src/ui/gui/dark.rc create mode 100644 src/ui/gui/default.rc create mode 100644 src/ui/gui/dialog-capture.c create mode 100644 src/ui/gui/gen-screenshots.sh create mode 100644 src/ui/gui/high-contrast.rc diff --git a/src/ui/gui/automake.mk b/src/ui/gui/automake.mk index c007a83..9dce7ed 100644 --- a/src/ui/gui/automake.mk +++ b/src/ui/gui/automake.mk @@ -48,22 +48,39 @@ EXTRA_DIST += \ src/ui/gui/pspp.desktop if HAVE_GUI -bin_PROGRAMS += src/ui/gui/psppire +bin_PROGRAMS += src/ui/gui/psppire \ + src/ui/gui/dialog-capture -src_ui_gui_psppire_CFLAGS = $(GTK_CFLAGS) $(GTKSOURCEVIEW_CFLAGS) -Wall -DGDK_MULTIHEAD_SAFE=1 +src_ui_gui_dialog_capture_SOURCES = $(gui_sources) \ + src/ui/gui/dialog-capture.c -src_ui_gui_psppire_LDFLAGS = \ +nodist_src_ui_gui_dialog_capture_SOURCES = $(nodist_gui_sources) + +src_ui_gui_dialog_capture_CFLAGS = $(GTK_CFLAGS) $(GTKSOURCEVIEW_CFLAGS) -Wall -DGDK_MULTIHEAD_SAFE=1 + +src_ui_gui_dialog_capture_LDADD = \ + src/ui/gui/sheet/libsheet.la \ + lib/gtk-contrib/libgtksheet.a \ + src/ui/libuicommon.la \ + src/libpspp.la \ + src/libpspp-core.la \ + $(GTK_LIBS) \ + $(GTKSOURCEVIEW_LIBS) \ + $(CAIRO_LIBS) \ + $(LIBINTL) + +src_ui_gui_dialog_capture_LDFLAGS = \ $(PSPPIRE_LDFLAGS) \ $(PG_LDFLAGS) - if RELOCATABLE_VIA_LD -src_ui_gui_psppire_LDFLAGS += `$(RELOCATABLE_LDFLAGS) $(bindir)` +src_ui_gui_dialog_capture_LDFLAGS += `$(RELOCATABLE_LDFLAGS) $(bindir)` else -src_ui_gui_psppire_LDFLAGS += -rpath $(pkglibdir) +src_ui_gui_dialog_capture_LDFLAGS += -rpath $(pkglibdir) endif +src_ui_gui_psppire_CFLAGS = $(GTK_CFLAGS) $(GTKSOURCEVIEW_CFLAGS) -Wall -DGDK_MULTIHEAD_SAFE=1 src_ui_gui_psppire_LDADD = \ src/ui/gui/sheet/libsheet.la \ @@ -76,6 +93,20 @@ src_ui_gui_psppire_LDADD = \ $(CAIRO_LIBS) \ $(LIBINTL) + +src_ui_gui_psppire_LDFLAGS = \ + $(PSPPIRE_LDFLAGS) \ + $(PG_LDFLAGS) + + +if RELOCATABLE_VIA_LD +src_ui_gui_psppire_LDFLAGS += `$(RELOCATABLE_LDFLAGS) $(bindir)` +else +src_ui_gui_psppire_LDFLAGS += -rpath $(pkglibdir) +endif + + + src_ui_gui_psppiredir = $(pkgdatadir) @@ -127,7 +158,7 @@ dist_src_ui_gui_psppire_DATA = \ $(top_srcdir)/src/ui/gui/icons/splash.png -src_ui_gui_psppire_SOURCES = \ +gui_sources = \ src/ui/gui/psppire-dialog.c \ src/ui/gui/psppire-keypad.c \ src/ui/gui/psppire-selector.c \ @@ -191,7 +222,6 @@ src_ui_gui_psppire_SOURCES = \ src/ui/gui/k-means-dialog.h \ src/ui/gui/ks-one-sample-dialog.c \ src/ui/gui/ks-one-sample-dialog.h \ - src/ui/gui/main.c \ src/ui/gui/missing-val-dialog.c \ src/ui/gui/missing-val-dialog.h \ src/ui/gui/oneway-anova-dialog.c \ @@ -292,10 +322,18 @@ src_ui_gui_psppire_SOURCES = \ src/ui/gui/widgets.c \ src/ui/gui/widgets.h -nodist_src_ui_gui_psppire_SOURCES = \ +nodist_gui_sources = \ src/ui/gui/psppire-marshal.c \ src/ui/gui/psppire-marshal.h + +nodist_src_ui_gui_psppire_SOURCES = $(nodist_gui_sources) + +src_ui_gui_psppire_SOURCES = $(gui_sources) \ + src/ui/gui/main.c + + + yelp-check: @if ! yelp --version > /dev/null 2>&1 ; then \ echo ; \ @@ -345,3 +383,7 @@ src/ui/gui/include/gtk/gtk.h: src/ui/gui/include/gtk/gtk.in.h mv address@hidden $@ CLEANFILES += src/ui/gui/include/gtk/gtk.h EXTRA_DIST += src/ui/gui/include/gtk/gtk.in.h + +.PHONY: screenshots +screenshots: + $(SHELL) $(top_srcdir)/src/ui/gui/gen-screenshots.sh $(top_srcdir) \ No newline at end of file diff --git a/src/ui/gui/dark.rc b/src/ui/gui/dark.rc new file mode 100644 index 0000000..16b9188 --- /dev/null +++ b/src/ui/gui/dark.rc @@ -0,0 +1,16 @@ +style "Dark" +{ + font_name = "Sans Italic 10" + base[NORMAL] = "#343434" + base[INSENSITIVE] = mix (0.7, "#343434", "#d3d3d3") + text[NORMAL] = "#d3d3d3" + bg[NORMAL] = "#555555" + bg[INSENSITIVE] = mix (0.7, "#555555", "#e3e3e3") + fg[NORMAL] = "#e3e3e3" + + engine "clearlooks" {} +} + + +class "*" style "Dark" + diff --git a/src/ui/gui/default.rc b/src/ui/gui/default.rc new file mode 100644 index 0000000..791c5f0 --- /dev/null +++ b/src/ui/gui/default.rc @@ -0,0 +1,8 @@ + +style "default" +{ +} + + +class "*" style "default" + diff --git a/src/ui/gui/dialog-capture.c b/src/ui/gui/dialog-capture.c new file mode 100644 index 0000000..580f2e3 --- /dev/null +++ b/src/ui/gui/dialog-capture.c @@ -0,0 +1,130 @@ +/* PSPPIRE - a graphical user interface for PSPP. + Copyright (C) 2012 Free Software Foundation + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + + +/* + This program loads a GtkBuilder .UI file and displays a widget from it. + + Once the widget has been shown, the Window ID will be printed to stdout, + the program will then fork and exit. + + It's intended to be used as a testing tool, not for end users. +*/ + +#include + +#include +#include +#include + +#include + +#include +#include "widgets.h" +#include + +static void +fork_me (void) +{ + pid_t pid; + + pid = fork(); + + if(pid == -1) + { + perror("fork"); + exit(-1); + } + else if(pid == 0) + { + /* Child. Continue running */ + } + else + { + /* parent */ + exit (0); + } +} + + +static gboolean +on_expose (GtkWidget *dialog, GdkEvent *event, gpointer data) +{ + gulong *handler = data; + + GdkWindow *window = gtk_widget_get_window (dialog); + + XID xid = gdk_x11_drawable_get_xid (GDK_DRAWABLE (window)); + + g_print ("0x%x\n", (unsigned int) xid); + + fork_me (); + + g_signal_handler_disconnect (dialog, *handler); + + return FALSE; +} + + + +int +main (int argc, char *argv[]) +{ + GtkBuilder *xml; + GtkWidget *dialog; + gulong handler = 0; + int arg; + + for (arg = 1; arg < argc; ++arg) + { + if (0 == strcmp (argv[arg], "--version")) + { + g_print ("dialog-capture %s\n", PACKAGE_VERSION); + exit (0); + } + else if (0 == strcmp (argv[arg], "--help")) + { + g_print ("Usage: dialog-capture \n"); + exit (0); + } + } + + /* This is called in all GTK applications. Arguments are parsed + * from the command line and are returned to the application. */ + gtk_init (&argc, &argv); + + if ( argc < 3) + { + g_error ("Usage: dialog-capture "); + return 1; + } + + preregister_widgets (); + + xml = builder_new_x (argv[1]); + + dialog = get_widget_assert (xml, argv[2]); + + handler = g_signal_connect_after (dialog, "expose-event", G_CALLBACK (on_expose), &handler); + + gtk_widget_show (dialog); + + gtk_window_parse_geometry (GTK_WINDOW (dialog), "+0+0"); + + gtk_main (); + + return 0; +} diff --git a/src/ui/gui/gen-screenshots.sh b/src/ui/gui/gen-screenshots.sh new file mode 100644 index 0000000..efe31af --- /dev/null +++ b/src/ui/gui/gen-screenshots.sh @@ -0,0 +1,88 @@ +#!/bin/sh + +if test $# -lt 1; then + echo 'Usage: gen-screenshots.sh ' + exit 1 +fi + +top_srcdir=$1 + +errorfile=/dev/null + +idfile=`mktemp -p /tmp` + +XSERVER=Xvfb +XOPTS="-screen 0 1024x768x24" + +#XSERVER=Xephyr +#XOPTS= + + +rcdir=$top_srcdir/src/ui/gui/ + +capture() +{ + dname=$1:$2 + + # Kill any clients and prepare the Xserver for use + kill -HUP $servpid + + # Display the widget + GTK2_RC_FILES=$rcdir/$3 ./src/ui/gui/dialog-capture --display=$display $1 $2 > $idfile 2> $errorfile + + # Capture it + xwd -display $display -id `cat $idfile` -out $dname.xwd + + # Give some kind of confidence indicator + if test $? -ne 0; then + echo Could not capture $dname; + cat $idfile + else + printf "." + fi +} + + +#look for an unused Display +n=1 +while test -e /tmp/.X11-unix/X$n ; do + n=`expr $n + 1` +done +display=":$n" + + +# START the X Server + +$XSERVER $display $XOPTS 2> $errorfile & +servpid=$! + +# Wait for server to initialise +sleep 1 + +if ! test -e /tmp/.X11-unix/X$n ; then + echo "$XSERVER could not be started. Is it installed ?"; + exit 1 +fi + + +UIDIR=$top_srcdir/src/ui/gui +for rc in default dark high-contrast ; do + printf "Generating screenshots for \"$rc\" style " + + # Find all the PsppireDialogs which might be declared in a .ui file and run "capture" on them + + for a in $UIDIR/*.ui; do + if grep -q 'class="PsppireDialog"' $a ; then + awk '/class="PsppireDialog"/' $a | sed -e 's//\1/' | while read d ; do + capture `basename $a` "$d" "$rc".rc + done + fi + done + echo + mkdir -p Screenshots/$rc + mv *.xwd Screenshots/$rc +done + + +kill -TERM $servpid +rm -f $idfile \ No newline at end of file diff --git a/src/ui/gui/high-contrast.rc b/src/ui/gui/high-contrast.rc new file mode 100644 index 0000000..66cafd0 --- /dev/null +++ b/src/ui/gui/high-contrast.rc @@ -0,0 +1,19 @@ + +style "Light" +{ + xthickness = 5 + ythickness = 5 + fg[NORMAL] = "black" + text[NORMAL] = "black" + + base[NORMAL] = "white" + bg[NORMAL] = "white" + + font_name = "Sans Bold 10" + + engine "hcengine" {} +} + + +class "*" style "Light" + -- 1.7.2.5