Ceci est une ancienne révision du document !


GUI pour mp3report

Ce script ne fonctionne pas encore, merci de ne pas l'utiliser.

Ce script a pour but de donner une interface graphique à mp3report. Il est composé de plusieurs fichiers :

  • GUImp3report.bash : script principal
  • controldependencies.bash : contrôle de la présence de zenity et mp3report
  • init.bash : initialisation des variables
  • chooseoptions.bash : boite de choix des options (cases à cocher)
  • chooseparameters.bash : choix des paramètres pour les options cochées qui en demandent
  • choosedirectories.bash : choix des répertoires à scanner
  • buildcommandline.bash : construction de la commande à exécuter
  • executecommand.bash : confirmation de l'exactitude de la commande par l'utilisateur et exécution

GUImp3report.bash

#!/bin/bash
 
################################################################
# Asks for the options and parameters for the "mp3report       #
# command and executes it, all this in a gui (zenity)          #
#                                                              #
# Auteur : kamui57 < kamui_57 AT yahoo DOT fr >                #
#                                                              #
# Licence : Ce script est un logiciel libre ; vous pouvez le   #
# redistribuer et/ou le modifier selon les termes de la        #
# Licence Publique Générale GNU ( GNU GPL ) publiée par la Free#
# Software Foundation.                                         #
################################################################
 
source $HOME/controldependencies.bash
 
source $HOME/init.bash
 
source $HOME/chooseoptions.bash
 
if [ "$chosen" != "" ]
then
    source $HOME/chooseparameters.bash
fi
 
source $HOME/choosedirectories.bash
 
source $HOME/buildcommandline.bash
 
source $HOME/executecommand.bash
# help for zenity found here
# http://linux.byexamples.com/archives/259/a-complete-zenity-dialog-examples-1/

controldependencies.bash

#!/bin/bash
 
################################################################
# Control that the required dependencies zenity and mp3report  #
#  are present.                                                #
#                                                              #
# Auteur : kamui57 < kamui_57 AT yahoo DOT fr >                #
#                                                              #
# Licence : Ce script est un logiciel libre ; vous pouvez le   #
# redistribuer et/ou le modifier selon les termes de la        #
# Licence Publique Générale GNU ( GNU GPL ) publiée par la Free#
# Software Foundation.                                         #
#                                                              #
################################################################
 
error=""
missing=0
#zenitymissing=0
#mp3reportmissing=0
# control if the required dependencies are present
if [[ !  `which zenity` ]]
then 
    missing=1
    error="${error}The required dependency \"zenity\" is missing.\n"
fi
 
if [[ !  `which mp3report` ]]
then 
    missing=1
    error="${error}The required dependency \"mp3report\" is missing.\n"
fi
 
# if not display an error message and exit
if [ $missing -eq 1 ]
then
  zenity --error --text "${error}\nPlease install the required dependencies and run the script again. "
  exit
fi

init.bash

#!/bin/bash
 
################################################################
# Initialises some variables for the script :                  #
# - the list of available options                              #
# - the titles of the columns for the "choose options" box     #
# - the text for the "choose options" box                      #
# - the separator for the list of the chosen options           #
# - the chosen state of each option                            #
#                                                              #
# Auteur : kamui57 < kamui_57 AT yahoo DOT fr >                #
#                                                              #
# Licence : Ce script est un logiciel libre ; vous pouvez le   #
# redistribuer et/ou le modifier selon les termes de la        #
# Licence Publique Générale GNU ( GNU GPL ) publiée par la Free#
# Software Foundation.                                         #
#                                                              #
################################################################
 
# Variables for the options checkboxes
# titles
titre[0]="Pick"
titre[1]="Options"
titre[2]="Explanation"
# names of the options and brief explanation
options[0]="help"
explanation[0]="shows the help screen"
options[1]="printmode"
explanation[1]="uses a smaller font for printing"
options[2]="title"
explanation[2]="sets the title used in the report"
options[3]="outfile"
explanation[3]="file to write report to, '-' for STDOUT"
options[4]="template"
explanation[4]="file to use as report template"
options[5]="stdgenres"
explanation[5]="use standard genres instead of winamp genres"
options[6]="id3v2"
explanation[6]="enable id3v2 support (experimental)"
 
# separator of the checked options' list
separator=":"
# text displayed in the box to choose options
texte="Neon Goat MP3 Report Generator v1.0.2
Copyright (C) 2000, David Parker, Neon Goat Productions.
www.neongoat.com - david@neongoat.com
 
This script lets you choose the options, the parameters and the directories
Please choose the options you want to use."
 
# initialisation of the chosen state of each option
# default : no option is chosen
for index in "${!options[@]}"
 do
    picked[$index]=FALSE;
done  

chooseoptions.bash

#!/bin/bash
 
################################################################
# Displays a zenity box to choose the options to use for       #
# mp3report and stores the obtained list in the string named   #
# "chosen"                                                     #
#                                                              #
# Auteur : kamui57 < kamui_57 AT yahoo DOT fr >                #
#                                                              #
# Licence : Ce script est un logiciel libre ; vous pouvez le   #
# redistribuer et/ou le modifier selon les termes de la        #
# Licence Publique Générale GNU ( GNU GPL ) publiée par la Free#
# Software Foundation.                                         #
################################################################
 
# dialog box
ans=$(zenity  --list  --text "$texte" --checklist\
 --height=400 \
 --column "${titre[0]}" \
 --column "${titre[1]}" \
 --column "${titre[2]}" \
FALSE "help" "shows the help screen" \
FALSE "printmode" "uses a smaller font for printing" \
FALSE "title" "=TITLE sets the title used in the report" \
FALSE "outfile" "=OUTFILE file to write report to, '-' for STDOUT" \
FALSE "template" "=FILE file to use as report template" \
FALSE "stdgenres" "use standard genres instead of winamp genres" \
FALSE "id3v2" "enable id3v2 support (experimental)" \
--separator=$separator); 
 
if [ "$ans" = "" ]
then
    chosen=""
else
# splitting options' list
    OLD_IFS="$IFS"
    IFS="$separator"
    chosen=( $ans )
    IFS=$OLD_IFS
fi

chooseparameters.bash

#!/bin/bash
 
################################################################
# For each chosen option, if this option requires a parameter, #
# prompts the user to choose the corresponding parameter.      #
#                                                              #
# - For the option "title", asks for the title in an input     #
#   text box.                                                  #
# - For the option "outputfile", asks first if the output must #
#   be on the standard output, if not open a filedialog window #
#   to pick the output file.                                   #
# - For the option "template", open a file dialog window to    #
#   pick the template file.                                    #
#                                                              #
# Auteur : kamui57 < kamui_57 AT yahoo DOT fr >                #
#                                                              #
# Licence : Ce script est un logiciel libre ; vous pouvez le   #
# redistribuer et/ou le modifier selon les termes de la        #
# Licence Publique Générale GNU ( GNU GPL ) publiée par la Free#
# Software Foundation.                                         #
#                                                              #
################################################################
 
indexOptions=0
for indexChosen in ${!chosen[@]}; do
    chosenFound=0
    while [ $chosenFound = 0 ]
    do
    if [ ${options[$indexOptions]} = ${chosen[$indexChosen]} ]
    then
        break
    else
        indexOptions=$(($indexOptions+1))
    fi
    done
    picked[$indexOptions]=TRUE;
done  
 
########### option "title" picked ##############
if [ ${picked[2]} = "TRUE" ]
then
    titleInput=$(zenity --entry --text "You have picked the option \"title\". This options requires an argument : the title used in the report. Please enter it here." --entry-text ""); 
    if [ "$titleInput" = "" ]
    then
    zenity --warning \
        --text="You have not chosen any title. This option will be ignored."
    fi
 
fi
 
########### option "outputfile" picked ##############
if [ ${picked[3]} = "TRUE" ] 
then
    zenity --title "Choice of the output file" --question --text  "You have picked the option \"outputfile\". Do you want to write on the standard output (yes) or on a file (no)?";
    if [ "$?" -eq "0" ] # standard input chosen
    then
    outfileInput='-';
    else #  not to standard input, therefore to a file, which must be chosen
    zenity --info \
        --text="You have chosen to write report to a file. Please choose the file you want to write the report to."
    outfileInput=$(zenity --file-selection --save --confirm-overwrite);
    fi
    if [ "$outputfileInput" = "" ]
    then
    zenity --warning \
        --text="You have not chosen any output file. This option will be ignored."
    fi
 
fi
 
########### option "template" picked ##############
if [ ${picked[4]} = "TRUE" ]
then
    zenity --info \
    --text="You have chosen to specify the template to use. Please choose this file."
    templateInput=$(zenity --file-selection);
 
    if [ "$templateInput" = "" ]
    then
    zenity --warning \
        --text="You have not chosen any template. This option will be ignored."
    fi
fi

choosedirectories.bash

#!/bin/bash
 
################################################################
# Displays a directories selection box to choose the scanned   #
# directories.                                                 #
# - Multiple selection is allowed                              #
# - The subdirectories are included too                        #
#                                                              #
# Auteur : kamui57 < kamui_57 AT yahoo DOT fr >                #
#                                                              #
# Licence : Ce script est un logiciel libre ; vous pouvez le   #
# redistribuer et/ou le modifier selon les termes de la        #
# Licence Publique Générale GNU ( GNU GPL ) publiée par la Free#
# Software Foundation.                                         #
#                                                              #
################################################################
 
 zenity --info \
    --text="Please choose now the directories to scan. The subdirectories will be included."
 
directoriesInput=$(zenity --file-selection --directory --multiple --separator=$separator);
 
if [ "$directoriesInput" = "" ]
then
    zenity --error --text "No directory given! The script will abort."
    exit
fi

buildcommandline.bash

#!/bin/bash
 
################################################################
# Builds the command line to execute from the chosen options   #
# and parameters.                                              #
#                                                              #
# Auteur : kamui57 < kamui_57 AT yahoo DOT fr >                #
#                                                              #
# Licence : Ce script est un logiciel libre ; vous pouvez le   #
# redistribuer et/ou le modifier selon les termes de la        #
# Licence Publique Générale GNU ( GNU GPL ) publiée par la Free#
# Software Foundation.                                         #
#                                                              #
################################################################
 
commande="mp3report "
for indexOptions in ${!options[@]}; do
    if [ ${picked[$indexOptions]} = TRUE ]
    then
    ligne="--${options[$indexOptions]}"
    case $indexOptions in
        2)  # title
        if [ "$titleInput" != "" ]
        then
            ligne="${ligne}=\"$titleInput\""
        else
            ligne=""
        fi
        ;;
        3)  # outfile
        if [ "$outfileInput" != "" ]
        then
            ligne="${ligne}=\"$outfileInput\""
        else
            ligne=""
        fi
        ;;
        4)  # template
        if [ "$templateInput" != "" ]
        then
            ligne="${ligne}=\"$templateInput\""
        else
            ligne=""
        fi
        ;;
        *);;
    esac
    commande="${commande} ${ligne}"
    fi
done
 
commande="${commande} \"${directoriesInput}\""

executecommand.bash

#!/bin/bash
 
################################################################
# Prompts if the command is the good command and launches it   #
#                                                              #
# Auteur : kamui57 < kamui_57 AT yahoo DOT fr >                #
#                                                              #
# Licence : Ce script est un logiciel libre ; vous pouvez le   #
# redistribuer et/ou le modifier selon les termes de la        #
# Licence Publique Générale GNU ( GNU GPL ) publiée par la Free#
# Software Foundation.                                         #
################################################################
 
zenity --title "Execution" --question --text  "The command you have built is : $commande, do you agree?";
    if [ "$?" -eq "0" ] # standard input chosen
    then
    echo ok
    else #  not to standard input, therefore to a file, which must be chosen
    echo "pas ok"
    fi
 
#gksudo lsof | zenity --text-info --width 530
echo $commande
echo "sortie"
$commande

  • utilisateurs/kamui57/guimp3report.1282735700.txt.gz
  • Dernière modification: Le 18/04/2011, 14:43
  • (modification externe)