LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Articles > Technical
User Name
Password

Notices


By stomfi at 2006-03-16 08:36
Power to the Users. Shell Scripting & GUI interfacing for Desktop Users. By Stomfi © 2006

Part 7 – Continuing Story Board Scripting

In this part you will create shell scripts that the Transcripts that were written in part 6 call for the activities the story board performs.

In each thumbnail is the line:
Code:
put ($HOME & "/SB/bin/editpic.sh" && CIMAGE && PPROG) into DUEDIT
The file editpic.sh is a shell script which must be written with a text editor. It includes the GPL notice which you must include if you use it under the terms of this license.

This and some of the later scripts check for valid links. These are symbolic links to programs elsewhere on your system. You will have to create these in your SB/bin folder with a command like:

Code:
ln -s /usr/bin/gimp-remote $HOME/SB/bin/picedit
The links used in SB/bin are:

picedit linked to the gimp-remote or gimp
kidspaint linked to tuxpaint
sndedit linked to audacity
sndplayer linked to play

find out where these are on your system with the command

Code:
whereis program_name
where program_name is one of the programs (e.g. audacity)
In any case the scripts should do this themselves as you will see when you type them in.

Code:
#!/bin/bash
#editpic.sh picfile program
#
#Edit pictures converting and reconverting as required
#
# Copyright Stomfi (C) 2005
# 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 2 of the License, or 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, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#
#DEBUG Remove the comment from the set -x line to send each line of the 
#executing script to the RunRev variable watcher in debug mode  or run it in 
#the shell with required $1 and $2 arguments.
#set -x
#END DEBUG
PDIR=`dirname $1` 
#set some useful path variables
SBBIN="$HOME/SB/bin"
SBDIR="$HOME/SB"
SBWORK="$SBDIR/work"
STSAVE="$SBWORK/pics/tux"
SBTSAVE="$STSAVE/saved"
SBGSAVE="$PDIR"
#Make sure tux folders exists
if [ ! -e $STSAVE ]
then
   mkdir $STSAVE
fi
if [ ! -e $SBTSAVE ]
then
   mkdir $SBTSAVE
fi
#Make sure all folders are writeable
chmod +w $STSAVE
chmod +w $SBTSAVE
chmod +w $SBGSAVE

#Test to see if it is an animation and needs the GIMP
PICID=`identify $1 | cut -d" " -f3 | wc -w`
if [ $PICID -gt 1 ]
then
   PPROG="GIMP"
else
   PPROG=$2
fi
#Check for a valid links
if [ $PPROG = "TUX" ]
then
   TUX="$SBBIN/kidspaint"
   if [ ! -e $TUX ]
   then
      TUX=`whereis tuxpaint | cut -d" " -f2`
   fi   
   #Check to see tuxpaint is found
   if [ ! -e $TUX ]
   then
      PPROG="GIMP"
   fi
fi
#Check for a valid GIMP link
if [ $PPROG = "GIMP" ]
then
   GIMP="$SBBIN/picedit"
   if [ ! -e $GIMP ]
   then
      GIMP=`whereis gimp | cut -d" " -f2`
   fi
   #Check to see GIMP is found
   if [ ! -e $TUX ]
   then
      #No valid paint program found so exit
      echo "Cant find Tuxpaint or GIMP"
      exit
   fi
fi
#Test the Program name and follow case procedure.
case $PPROG in 
   #Add new prog names and case procedures here.

    "TUX") #Use TUXPAINT which uses png files and an auto save folder
           #convert picfile to png if not png
           #Set local variables for picture name and extension
           #xwininfo -root gives a list of details about the screen including
           #its size on a line -geometry widthxheight+0+0
           #Use grep and cut to get the WxH size
           XWINSIZE=`xwininfo -root | grep geometry | cut -d" " -f4 | cut -d"+" -f1`
           #Make tuxpaint window one resolution less
           case $XWINSIZE in
	        "1280x1024")  TWINSIZE=1024x768 ;;
	         "1024x768")  TWINSIZE=800x600 ;;
	                  *)  TWINSIZE=640x480 ;;
	     esac	      
           #
           #Clean out Tux work folder
           rm -f $SBTSAVE/*.png
           #
           #Get the extension and pic name
           FEXTN=`basename $1 | cut -d"." -f2`
           FNAME=`basename $1 | cut -d"." -f1`
	     #If FEXTN is equal to png 
           if [ $FEXTN != "png" ]
           then
             #Use modified tuxpaint-import script
             $SBBIN/stomfitux-import  $1 
           else
	     #Copy to working folder
             cp $1 $SBTSAVE
           fi
           #Change the Tuxpaint root savedir current_id.txt file to point
           #to the new file
           echo "$FNAME" > $STSAVE/current_id.txt 

           #Set auto save over, window size, and nosound.
           #sound hangs on some platforms
           $TUX --saveover --nosound --$TWINSIZE --savedir $SBWORK/pics/tux

           #Replace file
           if [ $FEXTN != "png" ]
           then
             #Convert type
             convert $SBTSAVE/$FNAME.png $1
	     else   
	       mv -f $SBTSAVE/$FNAME.$FEXTN $1
           fi  
	     #Clean out working folder for next time
           #DEBUG COMMENT OUT NEXT LINE
	     rm -f $SBTSAVE/*.png
	     ;;
           #
        *) #Run GIMP with $1 file
           cd $SBGSAVE
           $GIMP $1
	     ;;
           #GIMP creates new pics when adding effects. How do we get
	     #the user to remember to not save the original when quitting?
           #Maybe hope they read the howto
esac	   
echo 1
Save this file in the $HOME/SB/bin folder and use the command

Code:
chmod +x $HOME/SB/bin/editpic.sh
to make it executable. You will have to do this for each shell script you write.

This next line is in the CLICK ME menu

Code:
put ($HOME & "/SB/bin/donewsnd.sh" && NEWSND) into DUNEW
Here is its donewsnd.sh shell script.

Code:
#!/bin/bash
#donewsnd.sh sndfile sndprog
#
#Create a new sound from template and return a done flag
#
# Copyright Stomfi (C) 2005
# 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 2 of the License, or 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, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#Check for a valid links
#Only got audacity at present
#DEBUG
#set -x
#DEBUG END
SPROG="$HOME/SB/bin/sndedit" 
if [ ! -e $SPROG ]
then
      SPROG=`whereis audacity | cut -d" " -f2`
fi
#Check to see  is found
if [ ! -e $SPROG ]
then
      #No valid program found so exit
      echo "Cant find Audacity"
      exit
fi
#Make sure sound folder is writeable
SNDDIR=`dirname $1`
chmod a+w $SNDDIR
$SPROG $1
echo 1
Save and change this file to executable mode.

There is also a line for the animation image that says:
set the filename of image "ANIM" to $HOME & "/SB/sclblue.gif"

This is the image I use. It is from my SCOOL program and is distributed under a Creative Commons license which allows you to copy it as long as you state that Stomfi is the author, and you don't use it commercially.

Picture of sclblue.gif:
[img=640x480]http://images.linuxquestions.org/articles/sclblue.gif[/code]


The only other external call is this one:
#Use the new recorder stack.
go card "SOUND" of stack "SB"

This is going to have to wait till later as I want you to finish the SB window before creating another one.

Right click on any blank part of the window and edit the stack script.
Write these lines and apply. Save the stack.

Code:
on openStack
  put  the shell of ($HOME & "/SB/bin/sbflder.sh") into DUNFLDR
end openStack
Now do the same thing for the card script.

Code:
on openCard
  global NUMPICS
  global PDIR
  put 0 into NUMPICS
  put empty into PDIR
  put empty into field "PMESG"
  put empty into field "MESG"
  set the visible of button "NEWPIC" to false
  #Empty the image filenames
  put 0 into PICNUM
  repeat for 49 times
    add 1 to PICNUM
    put "Im" & PICNUM into ThisImage
    set the filename of image ThisImage to empty
  end repeat
  put ($HOME & "/SB/work/pics/") into MYPICDIR
  set the defaultFolder to MYPICDIR
  set the filename of image "ANIM" to $HOME & "/SB/sclblue.gif"
  set the visible of button "NEWPIC" to false
  set the visible of button "ANIMCTRL" to false
  set the visible of button "ANIMTEST" to false
  #Make sure SB/tmp exists
  put the shell of ("mkdir" && $HOME & "/SB/tmp") into DUNTMP
end openCard
This script makes sure everything is clean and set before opening the window.

This is the sbfldr.sh shell script. Write it save it and set its executable mode.

Code:
 #!/bin/bash
#sbfldr.sh 
#
#Creates the directories in $HOME/SB/
#
# Copyright Stomfi (C) 2005
# 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 2 of the License, or 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, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
if [ ! -e $HOME/SB ]
then
    mkdir $HOME/SB
    HOMEDIR="$HOME/SB"
    mkdir $HOMEDIR/info
    mkdir $HOMEDIR/processing
    mkdir $HOMEDIR/tmp
    mkdir $HOMEDIR/work
    mkdir $HOMEDIR/work/sounds
    mkdir $HOMEDIR/work/pics
    mkdir $HOMEDIR/work/pics/tux
    mkdir $HOMEDIR/work/pics/gimp
    mkdir $HOMEDIR/work/pics/animations
    mkdir $HOMEDIR/work/pics/animations/gifs
    mkdir $HOMEDIR/work/pics/animations/layouts
    mkdir $HOMEDIR/work/clips
    mkdir $HOMEDIR/work/clips/pics
    mkdir $HOMEDIR/work/clips/sounds
fi
#Check existing tree
HOMEDIR="$HOME/SB"

if [ ! -e $HOMEDIR/info ]
then
    mkdir $HOMEDIR/info
fi
if [ ! -e $HOMEDIR/processing ]
then
    mkdir $HOMEDIR/processing
fi
if [ ! -e $HOMEDIR/tmp ]
then
    mkdir $HOMEDIR/tmp
fi
if [ ! -e $HOMEDIR/work ]
then
    mkdir $HOMEDIR/work
fi
if [ ! -e $HOMEDIR/work/sounds ]
then
    mkdir $HOMEDIR/work/sounds
fi
if [ ! -e $HOMEDIR/work/pics ]
then
    mkdir $HOMEDIR/work/pics
fi
if [ ! -e $HOMEDIR/work/clips/sounds ]
then
    mkdir $HOMEDIR/work/clips/sounds
fi
if [ ! -e $HOMEDIR/work/clips/pics ]
then
    mkdir $HOMEDIR/work/clips/pics
fi
if [ ! -e $HOMEDIR/work/pics/tux ]
then
    mkdir $HOMEDIR/work/pics/tux
fi
if [ ! -e $HOMEDIR/work/pics/gimp ]
then
    mkdir $HOMEDIR/work/pics/gimp
fi
if [ ! -e $HOMEDIR/work/pics/animations ]
then
    mkdir $HOMEDIR/work/pics/animations
fi
if [ ! -e $HOMEDIR/work/pics/animations/gifs ]
then
    mkdir $HOMEDIR/work/pics/animations/gifs
fi
if [ ! -e $HOMEDIR/work/pics/animations/layouts ]
then
    mkdir $HOMEDIR/work/pics/animations/layouts
fi
#Recursively change the ownership to user and group for
#all folders and files in the HOMEDIR tree.
#This command pipe the out put of a long listing of the users HOME folder
#into an awk command which prints the fourth field of the third line.
#Notice the syntax where the action is enclosed in single quotes and
#curly braces. Awk uses C language syntax in its tests. Thus the == for equals.
#The third line makes sure the . and .. filenames which belong to root are
#bypassed and it is a users file which is processed.  
GROUP=`ls  -l $HOME|awk '{if(NR == 3) print $4}'`
chown -R $USER:$GROUP $HOMEDIR
#Make sure users can write
chmod -R +rw $HOMEDIR
#Make sure programs can write to processing, work and tmp
chmod -R a+rw $HOMEDIR/processing
chmod -R a+rw $HOMEDIR/work
chmod -R a+rw $HOMEDIR/tmp
This is the QUIT button script

Code:
on mouseUp
  visual barn door open slowly
  hide stack "SB"
  quit
end mouseUp
The visual line adds a visual effect to the next window change action.
The quit statement does just that and the program will end.

This is the script for the NEWPIC button

Code:
on mouseUp
  global NUMPICS
  global PDIR
  answer "Use TUXPAINT or GIMP" with "Cancel" or "GIMP" or "TUX"
  put it into PANSWER
  if PANSWER <> "Cancel"
  then
    #This is an ask command which pops up a text entry box with an OK button
    ask "Enter a one word name for your new picture"
    put it into NPIC
    if NPIC <> empty
    then
      put ($HOME & "/SB/work/pics") into SBWORK
      if PANSWER = "TUX"
      then
        put (SBWORK & "/tux/saved") into SAVEDIR
        put the shell of ("rm -f" && SAVEDIR &"/*") into RMSAVE
        put NPIC &".png" into NFILE
        put (SAVEDIR & "/" & NFILE) into PICFILE
        replace return with empty in PICFILE
        put ("cp /opt/SB/info/template.png" && PICFILE) into DUCOP
        replace return with empty in DUCOP
        put the shell of DUCOP into DUNCOP
        put  ("echo" && quote & NPIC & quote && ">"  && SBWORK & "/tux/current_id.txt") into DUTUXID
        replace return with empty in DUTUXID
        put the shell of DUTUXID into DUNTUXID
      else
        put (SBWORK & "/gimp/saved") into SAVEDIR
        put NPIC & ".gif" into NFILE
        put (SAVEDIR & "/" & NFILE) into PICFILE
        replace return with empty in PICFILE
        put the shell of ("cp /opt/SB/info/template.gif" && PICFILE) into DUNCOP
        put the shell of ("chmod +w" && PICFILE) into DUNCHMOD
      end if
      put ($HOME & "/SB/bin/makepic.sh" && quote & PICFILE & quote && quote & PDIR & quote && PANSWER) into DUPIC
      replace return with empty in DUPIC
      put the shell of DUPIC into DUNPIC
      #save new pic from saved folder into PDIR
      #put the shell of ("mv" && PICFILE && PDIR) into DUNMOVE
      #Add it to the story board into the first empty slot
      put 1 into PIN
      if NUMPICS < 50
      then
        put "Im" & PIN into NCPIC
        put (PDIR & "/" & NFILE) into PICPATH
        put "NO" into SAVDPIC
        repeat while SAVDPIC = "NO"
            put the filename of image NCPIC into DPIC
            if DPIC = empty
            then
              set the filename of image NCPIC to PICPATH
              put "YES" into SAVDPIC
              exit repeat
            else
              add 1 to PIN
               put "Im" & PIN into NCPIC
             end if
          end repeat
        end if
        add 1 to NUMPICS
    end if
  end if
  if NUMPICS > 2
  then
    set the visible of button "ANIMTEST" to true
  else
    #do nothing
  end if
end mouseUp
This script refers to two template files which are reproduced here:
put ("cp /opt/SB/info/template.png" && PICFILE) into DUCOP
put the shell of ("cp /opt/SB/info/template.gif" && PICFILE) into DUNCOP

Picture of template.png:
[img=640x480]http://images.linuxquestions.org/articles/template.png[/img]

Picture of template.gif:
[img=640x480]http://images.linuxquestions.org/articles/template.gif[/code]

These templates make sure the called programs have something to open and save.

There is also reference to a shell script makepic.sh for you to write, save and make executable.
put ($HOME & "/SB/bin/makepic.sh" && quote & PICFILE & quote && quote & PDIR & quote && PANSWER) into DUPIC

Here is the shell script.

Code:
#!/bin/bash
#makepic.sh picfile pdir program
#
#Create of new picture from template and return a done flag
#
# Copyright Stomfi (C) 2005
# 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 2 of the License, or 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, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#DEBUG
#set -x
#END DEBUG
PDIR=$2 
PICFILE=`basename $1`
#set some useful path variables
SBBIN="$HOME/SB/bin"
SBDIR="$HOME/SB"
SBWORK="$SBDIR/work"
PICSAVE="$SBWORK/pics"
STSAVE="$PICSAVE/tux"
SBTSAVE="$STSAVE/saved"
SGSAVE="$PICSAVE/gimp"
SBGSAVE="$SGSAVE/saved"
#Make sure folders exists and all are writeable
if [ ! -e $STSAVE ]
then
   mkdir $STSAVE
fi
if [ ! -e $SBTSAVE ]
then
   mkdir $SBTSAVE
fi
chmod +w $STSAVE
chmod +w $SBTSAVE
if [ ! -e $SGSAVE ]
then
   mkdir $SGSAVE
fi
if [ ! -e $SBGSAVE ]
then
   mkdir $SBGSAVE
fi
chmod +w $SGSAVE
chmod +w $SBGSAVE

#Check for a valid links
PPROG=$3
if [ $PPROG = "TUX" ]
then
   TUX="$SBBIN/tuxpaint"
   if [ ! -e $TUX ]
   then
      TUX=`whereis tuxpaint | cut -d" " -f2`
   fi   
   #Check to see tuxpaint is found
   if [ ! -e $TUX ]
   then
      PPROG="GIMP"
   fi
fi
#Check for a valid GIMP link
if [ $PPROG = "GIMP" ]
then
   GIMP="$SBBIN/picedit"
   if [ ! -e $GIMP ]
   then
      GIMP=`whereis gimp | cut -d" " -f2`
   fi
   #Check to see GIMP is found
   if [ ! -e $GIMP ]
   then
      #No valid paint program found so exit
      echo "Cant find Tuxpaint or GIMP"
      exit
   fi
fi
#Test to see if it is an animation and needs the GIMP
PICID=`identify $1 | cut -d" " -f3 | wc -w`
if [ $PICID -gt 1 ]
then
   PPROG="GIMP"
else
   PPROG=$3
fi
#Get the picture name
NPIC=`basename $1 | cut -d"." -f1`
#Test the Program name and follow case procedure.
case $PPROG in 
   #Add new prog names and case procedures here.

   "TUX") #Use TUXPAINT which uses png files and an auto save folder
	    #Set local variables for picture name and extension
          #xwininfo -root gives a list of details about the screen including
          #its size on a line -geometry widthxheight+0+0
          #Use grep and cut to get the WxH size
          XWINSIZE=`xwininfo -root | grep geometry | cut -d" " -f4 | cut -d"+" -f1`
          #Make tuxpaint window one resolution less
	    case $XWINSIZE in
	      "1280x1024")  TWINSIZE=1024x768 ;;
	       "1024x768")  TWINSIZE=800x600 ;;
	                *)  TWINSIZE=640x480 ;;
	    esac	      
          #
          #Set auto save over, window size, and nosound.
          #sound hangs on some platforms
          $TUX --saveover --nosound --$TWINSIZE --savedir $STSAVE
          #List the created file 
          TBNAME=`ls $SBTSAVE/*.png`
	    #DEBUG
          #Move to project folder 
          mv -f $TBNAME $PDIR
	    #Clean out working folder for next time
	    rm -f $SBTSAVE/*.png
	    ;;
          #
       *) #Run GIMP with $1 file 
          cd $SBGSAVE
          $GIMP $1
          mv -f $1 $PDIR
          ;;
          #GIMP creates new pics when adding effects. How do we get
	    #the user to remember to not save the original when quitting.
esac	   
echo 1
This is mostly the same script as editpic.sh so you can copy this file with the command

Code:
cp $HOME/SB/bin/editpic.sh $HOME/SB/bin/makepic.sh
then edit the makepic.sh file to make the required changes. Makes the work much simpler doesn't it?

This next script is the all important animation ANIMTEST button. This script can resize pictures as well as play an animation sound if one has been added to a layout folder. This functionality will be added to the load folder item as well later on as the program gets refined.

There are some new constructs and commands in this script. A new construct puts the message for the answer command into a variable name. A new script command uses the “contains” operator in a string test. A new shell command “identify” prints information about images. Another new shell command creates a unique filename from the shell date command. A new RunRev set of commands, opens and creates a new file, writes to it and closes it after writing.

Code:
on mouseUp
  global NUMPICS
  #Run animate program
  put "YES" into DOANIM
  put "NONE" into RSIZE
  #Animate all images showing on screen in the on screen order
  #Collect non empty image filenames
  put empty into ANPICS
  put 1 into PICCOUNT
  repeat for NUMPICS times
    put "Im" & PICCOUNT  into APIC
    put the filename of image APIC into TPIC
    if TPIC <> empty
    then
      put TPIC & space after ANPICS
    end if
    add 1 to PICCOUNT
  end repeat
  if ANPICS <> empty
  then
    #Check the sizes and ask user for size if different
    #We do this now in case the user wants to quit and edit the files
    put ("identify" && ANPICS && "| cut -d" & quote & space & quote && "-f3") into DUID
    replace return with empty in DUID
    put the shell of DUID into DUNID
    #Check to see if any lines are different
    put "NOT" into FDIFF
    put empty into FSIZE
    repeat for each line SLINE in DUNID
      if FSIZE <> empty
      then
        #Check next
        if SLINE <> FSIZE
        then
          put "DIFF" into FDIFF
          exit repeat
        end if
      else
        put SLINE into FSIZE
      end if
    end repeat 
    if FDIFF <> "NOT"
    then
      put return & DUNID after field "MESG"
      put "Varying picture sizes in your animation" & return & "You can see these at the end of Messages" & return into AMSG
      put "Choose RESIZE, OK, or Cancel" after AMSG
      answer AMSG with "Cancel" or "OK" or"RESIZE"
      put it into RANS
      switch RANS
        case "RESIZE"
          ask "Enter Resize from Messages e.g. 450x380"
          put it into RSIZE
          break
        case "OK"
          put "NONE" into RSIZE
          break
        case "Cancel"
          put "NO" into DOANIM
          break
      end switch
    end if
    if DOANIM <> "NO"
    then
      set the filename of image "ANIM" to $HOME & "/SB/info/doanim.png"
      #Use grep to see if it a layout
      put empty into ISLAY
      if line 1 of field "PMESG" contains "layouts"
      then
        put "YES"  into ISLAY
      end if
      #The order of names in ANPICS is the layout, so gets saved in the
      # animation layouts folder
      put the shell of ("date" && quote & "+%y%m%d%H%M%S" & quote) into ATIME
      put ATIME & ".txt" into ALAY
      put ($HOME & "/SB/work/pics/animations/layouts/" & ALAY) into ALAYFILE
      replace return with empty in ALAYFILE
      open file ALAYFILE for write
      write ANPICS to file ALAYFILE
      close file ALAYFILE
      put ($HOME & "/SB/bin/panimate.sh" && quote & ANPICS & quote && ATIME && RSIZE) into DUANIM
      replace return with empty in DUANIM
      put the shell of DUANIM into DUNANIM
      replace return with empty in DUNANIM
      #If this is a layout folder and there is a sound file, play sound
      if ISLAY <> empty
      then
        #get sound file name which will be the path in PMESG plus last word
        #in SPATH.wav i.e. /home/username/SB/work/layouts/layname/layname.wav
        put line 1 of field "PMESG" into SPATH
        put the shell of ("echo" && SPATH && "|cut -d/ -f7") into SNAME
        global LAYSND 
        put (SPATH & "/" & SNAME & ".wav")  into LAYSND
        replace return with empty in LAYSND
        set the visible of button "PSOUND" to true
      end if
      #Start the animation
      set the visible  of button "ANIMCTRL" to true
      set the filename of image "ANIM" to DUNANIM
    end if
  end if
end mouseUp
The two external calls in this script are:
set the filename of image "ANIM" to $HOME & "/SB/info/doanim.png"
put ($HOME & "/SB/bin/panimate.sh" && quote & ANPICS & quote && ATIME && RSIZE) into DUANIM

Here is the doanim picture created with tuxpaint

Picture of doanim.png:
[img=640x480]http://images.linuxquestions.org/articles/doanim.png[/img]

Yeah.

I'll finish this part off with the stomfitux-import script. This uses the netpbm package files which in my case I copied to the SB/bin folder, because they are not found on all distributions, but if they are there on your distro you can leave out the path names and the LD_LIBRARY_PATH and just call the command.

Code:
#!/bin/sh
# tuxpaint-import
# "Tux Paint Import"
# Import an arbitrary GIF, JPEG or PNG into Tux Paint
# by Bill Kendrick
# bill@newbreedsoftware.com
# http://www.newbreedsoftware.com/tuxpaint/
# September 21, 2002 - October 23, 2005
# Modified for SB single picture import by Stomfi
#DEBUG
#set -x
#END DEBUG
#Set the paths to include SB
PATH="$PATH:$HOME/SB/bin"
export LD_LIBRARY_PATH=/lib:/usr/lib:/usr/X11R6/lib:$HOME/SB/lib
SAVEDIR=$HOME/SB/work/pics/tux/saved
TMPDIR=$HOME/SB/tmp
if [ $# -eq 0 ]; then
  # No arguments provided (sorry, you can't pipe into this script's stdin!)
  echo "Usage: stomfitux-import filename"
  echo "       stomfitux-import --help"
  exit
fi
if [ $1 = "--help" ]; then
  # --help, show usage:
  echo
  echo "stomfitux-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: stomfitux-import filename"
  echo "       stomfitux-import --help"
  echo
  exit
fi
# Make sure savedir exists!
if [ ! -d $SAVEDIR ]; then
  mkdir -p $SAVEDIR
  chmod a+w $SAVEDIR
fi
# Make sure savedir thumbs directory exists!
if [ ! -d $SAVEDIR/.thumbs ]; then
  mkdir -p $SAVEDIR/.thumbs
  chmod a+w $SAVEDIR/.thumbs
fi
if [ -e $1 ]; then
    # Determine a filename for it: 
    NEWFILENAME=`basename $1 | cut -d"." -f1`
    echo "$1 -> $SAVEDIR/$NEWFILENAME.png"
    # Convert and scale down, save as a temp file:
    anytopnm $1 | pnmscale -xysize 448 376 > $TMPDIR/$NEWFILENAME.ppm
    # Place inside the correctly-sized canvas:
    # FIXME: Center, instead of placing at upper right
    ppmmake "#FFFFFF" 448 376 \
    | pnmpaste -replace $TMPDIR/$NEWFILENAME.ppm 0 0 \
    | pnmtopng > $SAVEDIR/$NEWFILENAME.png
    # Remove temp file:
    rm $TMPDIR/$NEWFILENAME.ppm
    # Create thumbnail for 'Open' dialog:
    pngtopnm $SAVEDIR/$NEWFILENAME.png | pnmscale -xysize 50 50 \
    | pnmtopng > $SAVEDIR/.thumbs/$NEWFILENAME -t.png
else
    # File wasn't there!
    echo "$1 - File not found"
fi
Notice that the backslashes “\” at the end of some line are there to escape the meaning of the carriage return so that the shell sees these lines as one continuous command without any new lines. Makes it easier to read and that's all folks for this time.

Don't forget to save the stack, enter Browse mode and try out all the new functionality. If things don't work as expected, read the article about debugging and see if you can spot the mistake. No worries, it will be there somewhere, as my scripts all work as planned.

In Part 8 we will finish all the other scripts and get on to making the Sound sub stack. Hope you are having fun.


  



All times are GMT -5. The time now is 12:16 AM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration