tuxpaint-import shell script now examines Tux Paint's configuration

file (first in /usr/local/etc/tuxpaint, then /etc/tuxpaint, then $HOME)
for the window size settings and saved-file directory options
(rather than assuming a 640x480 screen and images saved in
$HOME/.tuxpaint/saved/).

Discovered (or assumed) window size and directory settings are shown
when tuxpaint-import is first run (even with no arguments).
This commit is contained in:
William Kendrick 2006-02-18 07:35:40 +00:00
parent 27c35cdf23
commit aee93b1713
2 changed files with 112 additions and 30 deletions

View file

@ -19,6 +19,15 @@ $Id$
back into 16-bit unicode characters to satisfy SDL_ttf. Tested on back into 16-bit unicode characters to satisfy SDL_ttf. Tested on
Windows and Linux.) Windows and Linux.)
John Popplewell <john@johnnypops.demon.co.uk> John Popplewell <john@johnnypops.demon.co.uk>
* tuxpaint-import shell script now examines Tux Paint's configuration
file (first in /usr/local/etc/tuxpaint, then /etc/tuxpaint, then $HOME)
for the window size settings and saved-file directory options
(rather than assuming a 640x480 screen and images saved in
$HOME/.tuxpaint/saved/).
Discovered (or assumed) window size and directory settings are shown
when tuxpaint-import is first run (even with no arguments).
* Magic tool improvements: * Magic tool improvements:
------------------------ ------------------------

View file

@ -28,32 +28,51 @@
# September 21, 2002 - February 17, 2006 # September 21, 2002 - February 17, 2006
SAVEDIR=$HOME/.tuxpaint/saved SAVEDIR=$HOME/.tuxpaint
TMPDIR=$SAVEDIR TMPDIR=$SAVEDIR
if [ $# -eq 0 ]; then if [ $# -ne 0 ]; then
# No arguments provided (sorry, you can't pipe into this script's stdin!) if [ $1 = "--help" ]; then
echo "Usage: tuxpaint-import filename(s)" # --help, show usage:
echo " tuxpaint-import --help" echo
exit echo "tuxpaint-import"
echo
echo "Imports an arbitrary image (GIF, JPEG, PNG, etc. format)"
echo "into Tux Paint (see: tuxpaint(1)) so that it appears in the"
echo "'Open' dialog."
echo
echo "Usage: tuxpaint-import filename(s)"
echo " tuxpaint-import --help"
echo
exit
fi
fi fi
if [ $1 = "--help" ]; then
# --help, show usage: # Determine preferred savedir
echo
echo "tuxpaint-import" # First, check /usr/local/etc/
echo x=`grep -m 1 "^savedir=" /usr/local/etc/tuxpaint/tuxpaint.conf`
echo "Imports an arbitrary image (GIF, JPEG, PNG, etc. format)" if test $? = 0 ; then
echo "into Tux Paint (see: tuxpaint(1)) so that it appears in the" SAVEDIR=`echo $x | cut -d = -f 2-99`
echo "'Open' dialog."
echo
echo "Usage: tuxpaint-import filename(s)"
echo " tuxpaint-import --help"
echo
exit
fi fi
# First, check /etc/
x=`grep -m 1 "^savedir=" /etc/tuxpaint/tuxpaint.conf`
if test $? = 0 ; then
SAVEDIR=`echo $x | cut -d = -f 2-99`
fi
# First, check $HOME
x=`grep -m 1 "^savedir=" $HOME/.tuxpaintrc`
if test $? = 0 ; then
SAVEDIR=`echo $x | cut -d = -f 2-99`
fi
echo "Using save directory: $SAVEDIR/saved"
# Make sure savedir exists! # Make sure savedir exists!
if [ ! -d $SAVEDIR ]; then if [ ! -d $SAVEDIR ]; then
@ -61,10 +80,63 @@ if [ ! -d $SAVEDIR ]; then
mkdir -p $SAVEDIR mkdir -p $SAVEDIR
fi fi
# Make sure savedir/saved exists!
if [ ! -d $SAVEDIR/saved ]; then
echo "Creating $SAVEDIR/saved"
mkdir -p $SAVEDIR/saved
fi
# Make sure savedir thumbs directory exists! # Make sure savedir thumbs directory exists!
if [ ! -d $SAVEDIR/.thumbs ]; then if [ ! -d $SAVEDIR/saved/.thumbs ]; then
echo "Creating $SAVEDIR/.thumbs" echo "Creating $SAVEDIR/saved/.thumbs"
mkdir -p $SAVEDIR/.thumbs mkdir -p $SAVEDIR/saved/.thumbs
fi
# Determine appropriate size for images, based on Tux Paint's current
# configuration
# First, assume 800x600 Tux Paint
window_width=800
window_height=600
# First, check /usr/local/etc/
x=`grep -m 1 "^windowsize=" /usr/local/etc/tuxpaint/tuxpaint.conf`
if test $? = 0 ; then
window_width=`echo $x | cut -d = -f 2 | cut -d x -f 1`
window_height=`echo $x | cut -d = -f 2 | cut -d x -f 2`
fi
# First, check /etc/
x=`grep -m 1 "^windowsize=" /etc/tuxpaint/tuxpaint.conf`
if test $? = 0 ; then
window_width=`echo $x | cut -d = -f 2 | cut -d x -f 1`
window_height=`echo $x | cut -d = -f 2 | cut -d x -f 2`
fi
# First, check $HOME
x=`grep -m 1 "^windowsize=" $HOME/.tuxpaintrc`
if test $? = 0 ; then
window_width=`echo $x | cut -d = -f 2 | cut -d x -f 1`
window_height=`echo $x | cut -d = -f 2 | cut -d x -f 2`
fi
# (Image width is window width minus 192,
# image height is window height minus 104)
width=`expr $window_width - 192`
height=`expr $window_height - 104`
echo "Using $width x $height images (for $window_width x $window_height Tux Paint"
if [ $# -eq 0 ]; then
# No arguments provided (sorry, you can't pipe into this script's stdin!)
echo
echo "Usage: tuxpaint-import filename(s)"
echo " tuxpaint-import --help"
exit
fi fi
@ -74,26 +146,27 @@ do
if [ -e $i ]; then if [ -e $i ]; then
# Determine a filename for it: # Determine a filename for it:
NEWFILENAME=`date "+%Y%m%d%H%M%S"` NEWFILENAME=`date "+%Y%m%d%H%M%S"`
echo "$i -> $SAVEDIR/$NEWFILENAME.png" echo "$i -> $SAVEDIR/saved/$NEWFILENAME.png"
# Convert and scale down, save as a temp file: # Convert and scale down, save as a temp file:
anytopnm $i | pnmscale -xysize 448 376 > $TMPDIR/$NEWFILENAME.ppm anytopnm $i | pnmscale -xysize $width $height > $TMPDIR/saved/$NEWFILENAME.ppm
# Place inside the correctly-sized canvas: # Place inside the correctly-sized canvas:
# FIXME: Center, instead of placing at upper right # FIXME: Center, instead of placing at upper right
ppmmake "#FFFFFF" 448 376 \ ppmmake "#FFFFFF" $width $height \
| pnmpaste -replace $TMPDIR/$NEWFILENAME.ppm 0 0 \ | pnmpaste -replace $TMPDIR/saved/$NEWFILENAME.ppm 0 0 \
| pnmtopng > $SAVEDIR/$NEWFILENAME.png | pnmtopng > $SAVEDIR/saved/$NEWFILENAME.png
# Remove temp file: # Remove temp file:
rm $TMPDIR/$NEWFILENAME.ppm rm $TMPDIR/saved/$NEWFILENAME.ppm
# Create thumbnail for 'Open' dialog: # Create thumbnail for 'Open' dialog:
pngtopnm $SAVEDIR/$NEWFILENAME.png | pnmscale -xysize 92 56 \ pngtopnm $SAVEDIR/saved/$NEWFILENAME.png | pnmscale -xysize 92 56 \
| pnmtopng > $SAVEDIR/.thumbs/$NEWFILENAME-t.png | pnmtopng > $SAVEDIR/saved/.thumbs/$NEWFILENAME-t.png
else else
# File wasn't there! # File wasn't there!
echo "$i - File not found" echo "$i - File not found"
fi fi
done done