r2526 - people/synrg/xjig

Ben Armstrong synrg at alioth.debian.org
Wed Apr 4 18:38:40 UTC 2007


Author: synrg
Date: 2007-04-04 18:38:39 +0000 (Wed, 04 Apr 2007)
New Revision: 2526

Modified:
   people/synrg/xjig/xjig-menu
Log:
Added Dialog wrapper, started kdialog support

Modified: people/synrg/xjig/xjig-menu
===================================================================
--- people/synrg/xjig/xjig-menu	2007-04-04 17:21:28 UTC (rev 2525)
+++ people/synrg/xjig/xjig-menu	2007-04-04 18:38:39 UTC (rev 2526)
@@ -5,7 +5,7 @@
 
 PROGRAM="`basename ${0}`"
 DESCRIPTION="front-end to launch xjig"
-VERSION="1.2"
+VERSION="1.3"
 COPYRIGHT="${PROGRAM}, version ${VERSION}
 
 Copyright (C) 2007 Ben Armstrong <synrg at sanctuary.nslug.ns.ca>
@@ -35,14 +35,17 @@
 -p|--pieces XxY          number of pieces to make on the X and Y axes
 -s|--scale XxY           scaled image X and Y axis size (default: 640x480)
 -d|--directory DIR       directory to search for image files
+--dialog DIALOG          kind of dialog box to use
 --switches SWITCHES      switches to pass to xjig (default: -no_flip -side 2)
 
 MAKE-OPTIONS
 --make                   make a link to the specified puzzle in the desktop directory and exit
 --desktop-directory DIR  directory where desktop link will be made (default: \$HOME/Desktop)
 
-FILENAME                 png, jpeg or ppm image
+DIALOG                   auto, kdialog, zenity or none (default: auto)
 
+FILENAME                 gif, jpeg or ppm image, or any image type imagemagick can convert
+
 Examples:
    To make a 5x4 (20 piece) puzzle from scene.jpg
 
@@ -116,6 +119,8 @@
    if [ -z "$desktop_directory" ] ; then desktop_directory="${HOME}/Desktop"; fi
    if [ -z "$switches" ] ; then switches="${XJIG_SWITCHES}"; fi
    if [ -z "$switches" ] ; then switches="-no_flip -side 2"; fi
+   if [ -z "$dialog" ] ; then dialog="${XJIG_DIALOG}"; fi
+   if [ -z "$dialog" ] ; then dialog="auto"; fi
 }
 
 Cleanup ()
@@ -123,17 +128,74 @@
    rm -f "$tmpout"
 }
 
+Zenity ()
+{
+   case ${1} in
+      error)
+         dialog_answer="$(zenity --error --text="${2}")"
+         ;;
+      text)
+         dialog_answer="$(zenity --entry --title="${2}" --text="${3}")"
+         ;;
+      file)
+         dialog_answer="$(cd "$directory" && zenity  --title="${2}" --file-selection)"
+         ;;
+   esac
+}
+
+Kdialog ()
+{
+   case ${1} in
+      error)
+         dialog_answer="$(kdialog --error "${2}")"
+         ;;
+      text)
+			# FIXME: in testing, dimensions did not match 40x1
+         dialog_answer="$(kdialog --title "${2}" --textinputbox "${3}" "" 40 1)"
+         ;;
+      file)
+         dialog_answer="$(kdialog --title "${2}" --getopenfilename "$directory")"
+         ;;
+   esac
+}
+
+Nodialog ()
+{
+   case ${1} in
+      error)
+         echo "${1}" >&2
+         ;;
+      text)
+         Error "${PROGRAM}: Internal error 2"
+         ;;
+      file)
+         Error "${PROGRAM}: No filename specified"
+         ;;
+   esac
+}
+
+Dialog ()
+{
+   case $dialog in
+      zenity)
+         Zenity "${1}" "${2}" "${3}"
+         ;;
+      kdialog)
+         Kdialog "${1}" "${2}" "${3}"
+         ;;
+      none)
+         Nodialog "${1}" "${2}" "${3}"
+         ;;
+   esac
+}
+
 Error ()
 {
    if [ -n "${1}" ] ; then
-      if [ -x /usr/bin/zenity ]; then
-         zenity --error --text="${1}"
-      else
-         echo "${1}" >&2
-      fi
+      Dialog error "${1}"
    else
       if [ -x /usr/bin/zenity ]; then
-         zenity --error --text="$(cat $tmperr)"
+         Dialog error "$(cat $tmperr)"
       else
          cat "$tmperr" >&2
       fi
@@ -154,7 +216,7 @@
 
 Arguments ()
 {
-   ARGUMENTS="`getopt --longoptions pieces:,directory:,scale:,switches:,make,desktop_directory:,help,usage,version --name=${PROGRAM} --options p:d:s:mhuv --shell sh -- "${@}"`" 
+   ARGUMENTS="`getopt --longoptions pieces:,directory:,scale:,dialog:,switches:,make,desktop_directory:,help,usage,version --name=${PROGRAM} --options p:d:s:mhuv --shell sh -- "${@}"`" 
    if [ "${?}" != "0" ]
    then
       Error "${PROGRAM}: getopt error" >&2
@@ -174,22 +236,26 @@
             directory="${2}" ; shift 2
             ;;
 
-         -m|--make)
-            make="enabled" ; shift
-            ;;
-
          -s|--scale)
             scale="${2}" ; shift 2
             ;;
 
-         --desktop_directory)
-            desktop_directory="${2}" ; shift 2
+         --dialog)
+            dialog="${2}" ; shift 2
             ;;
 
          --switches)
             switches="${2}" ; shift 2
             ;;
 
+         -m|--make)
+            make="enabled" ; shift
+            ;;
+
+         --desktop_directory)
+            desktop_directory="${2}" ; shift 2
+            ;;
+
          -h|--help)
             Help; shift
             ;;
@@ -212,7 +278,7 @@
             ;;
 
          *)
-            echo "Internal error."
+            echo "${PROGRAM}: Internal error 1" >2&
             exit 1
             ;;
       esac
@@ -221,15 +287,55 @@
 
 Validate ()
 {
-   # FIXME: wrap zenity in Dialog function supporting file|text|error
-   if [ -z "$filename" ] && [ -x /usr/bin/zenity ] ; then
-      filename="$(cd "$directory" && zenity  --title='Select a file to turn into a puzzle' --file-selection)"
+   case "$dialog" in
+# FIXME: In tests on a non-KDE desktop kdialog was so slow it was
+#			unusable.  Disabled until I can figure out why and fix it.
+#      kdialog)
+#         if [ ! -x /usr/bin/kdialog ]; then
+#            dialog="none"
+#            Dialog error "${PROGRAM}: Missing /usr/bin/kdialog"
+#         fi
+#         ;;
+      zenity)
+         if [ ! -x /usr/bin/zenity ]; then
+            dialog="none"
+            Dialog error "${PROGRAM}: Missing /usr/bin/zenity"
+         fi
+         ;;
+      auto)
+# FIXME: We currently prefer to use kdialog over zenity because it provides
+#			image previews.  But ideally the dialog chosen by 'auto' should
+#			match the user's session type (kdialog for KDE, zenity for
+#			GNOME & XFCE).  If zenity ever supports previews, do this kind
+#			of autodetection of the user's desktop.
+#         if [ -x /usr/bin/kdialog ]; then
+#            dialog="kdialog"
+#         elif [ -x /usr/bin/zenity ]; then
+			if [ -x /usr/bin/zenity ]; then
+            dialog="zenity"
+         else
+            dialog="none"
+         fi
+         ;;
+      none)
+         ;;
+      *)
+         specified_dialog="$dialog"
+         dialog="none"
+         Dialog error "${PROGRAM}: Invalid dialog: $specified_dialog"
+         ;;
+   esac
+   if [ -z "$filename" ] ; then
+      Dialog file "Select a file to turn into a puzzle"
+      filename="$dialog_answer"
    fi
    if [ -z "$filename" ] || [ ! -f "$filename" ] ; then
       Error "${PROGRAM}: File not found: $filename"
    fi
    if [ -z "$pieces" ] && [ -x /usr/bin/zenity ] ; then
-      pieces="$(zenity --entry --title='Select number of pieces of puzzle' --text='Specify height and width in pieces as XxY, e.g. 5x4 for 20 pieces')"
+      Dialog text "Select number of pieces of puzzle" \
+         "Specify height and width in pieces as XxY, e.g. 5x4 for 20 pieces"
+      pieces="$dialog_answer"
    fi
    width="$(echo $pieces | cut -dx -f1)"
    height="$(echo $pieces | cut -dx -f2)"
@@ -263,7 +369,6 @@
 Xjig ()
 {
    tmperr=`tempfile --prefix=xjigxjig --suffix=.log`
-   # FIXME: make everything configurable/overridable (e.g. -no_flip, -side 2)
    xjig -w $width -h $height -file "${1}" $switches 2>"$tmperr"
    err=$?
    if [ $err -eq 1 ] ; then
@@ -276,6 +381,7 @@
 Main ()
 {
    typeset -i width=0 height=0 scale_width=0 scale_height=0
+   typeset dialog_answer=""
 
    Defaults
    Arguments "${@}"




More information about the Pkg-games-commits mailing list