• yad > les formulaires et les saisies

      GENERALITES

      yad --entry

       

       

      yad --entry --entry-label="blabla"

       


      yad --entry --entry-label="blabla" --entry-text="toto"


       

      yad --text-align=center --text="foobar" --entry --entry-label="blabla" --entry-text="toto"
      



      Récupération de la saisie

      #!/bin/sh
      INPUTTEXT=`yad --entry --entry-label="saisie"`
      yad --text="Vous avez saisi : $INPUTTEXT"
      

      FORMULAIRE

      #!/bin/sh
      ~$ yad --height=150 --width=300 --text="<span foreground='yellow'><b><big>mon <big>texte</big></big></b></span>" \
      --form --field="<b><big>Prem</big></b>" --field="<b><big>Deuz</big></b>"

       

      TYPES DE DONNÉES

      password

      yad --entry --entry-label=password --hide-text


      nombres

      yad --entry --numeric


       

      Uses a spin button for text entry and won’t allow character entry. Entering data can be manually typed in.

      There are 6 decimal points. EG: 100.000000

      AUTO-COMPLETION

      --completion

      searches the data in the script and matches it against your input.

       

      #!/bin/sh
      yad --completion --entry="Name:" "" \
      "Pink Floyd" "King Crimson" "Portishead" "Primus" "Beatles" | while read line; do
         ENTRY=`echo $line | awk -F',' '{print $1}'`
         echo $ENTRY
      done


      Now after typing b

       

      ICONES

      yad --entry --licon=/usr/local/lib/X11/pixmaps/home48.png


       

      Notice the icon justified to the left of the entry box.

       

      yad --entry --licon=/usr/local/lib/X11/pixmaps/home48.png --licon-action=rox



      Click on the rox icon in the entry field to launch rox.

       

      yad --entry --ricon=/usr/local/lib/X11/pixmaps/home48.png


       

      Notice the icon justified to the right of the entry box.

       

      yad --entry --ricon=/usr/local/lib/X11/pixmaps/home48.png --ricon-action=rox


       

      Click on the rox icon in the entry field to launch rox.

      EXPANDER

      yad --entry --expander="click here to show entry"

       

      ——>   

       

      Whatever you type is parsed like the script below.

       

      #!/bin/sh
      ANSWER=`yad --entry --expander="click here to show entry"`
      yad --text="You typed $ANSWER in the entry box"

       

      --entry-label=STRING Set the entry label text.

       

      --entry-text=STRING Set the initial entry text or default item in combo-box.

       

      --hide-text Hide the entry text.

       

      --completion Use completion instead of combo-box.

       

      --complete=TYPE Use specific type for extended completion. TYPE can be any for match any of typed words, all for match all of typed words or regex when typed text treats as regular expression.

       

      --editable Allow make changes to text in combo-box.

       

      --numeric Use spin button instead of text entry. Additional parameters in command line treats as minimum and maximum values, step value and precisions (in that order). All this values are optional. Default range is from 0 to 65535 with step 1.

       

      --float-precision=NUMBER Set precision of floating point numbers. By default precision is three digits after point.

       

      --licon=IMAGE Set an icon on a left side of entry.

       

      --licon-action=CMD Specify a command which will be run when the left icon clicked. Output of command will be set as entry text.

       

      --ricon=IMAGE Set an icon on a right side of entry.

       

      --ricon-action=CMD Specify a command which will be run when the right icon clicked. Output of command will be set as entry text.

       

      --num-output Output index of active element instead of text for combo-box entry. Any extra data specified in command line adds as an items of combo-box entry, except of numeric mode.

       

      If icon specified and icon action is not given, click on icon just clear the entry. Numeric fields will ignore the icons.

       

       

       

      --fontname=FONTNAME This command sets the font type : yad --width=250 --text-info < hello.txt --fontname="Serif bold italic 20″

       

      Form options

      http://www.thelinuxrain.com/articles/multiple-item-data-entry-with-yad

      http://rpm.pbone.net/index.php3/stat/45/idpl/17003956/numer/1/nazwa/yad

       

      holidays=$(echo "Gold Coast,Bali,Phuket,Sydney,other")
      yad --title="" --text="coucou" --image="/image/phone.png" --form --date-format="%-d %B %Y" --separator="," --item-separator="," \
      --field="Nom" --field="Prénom" --field="Status":RO --field="Date":DT --field="Last holiday":CBE --field="Liste:":TXT \
      "" "" "All round good guy" "Click calendar icon" "$holidays"

       

       

      --field=LABEL[:TYPE] (TYPE - H, RO, NUM, CHK, CB, CBE, FL, SFL, MFL, DIR, CDIR, MDIR, FN, DT, CLR, BTN, LBL ou TXT)

       

      Par défaut, le type du champ est une saisie simple.

       

      yad --form --field=LABEL


      H - Hidden : mot de passe

      yad --form --field=LABEL:H


       

      sortie > monmotdepass|

      RO - Read Only

      yad --form --field=LABEL:RO "Default Text"


      NUM - Numéeique

      yad --form --field=LABEL:NUM


       

      yad --form --field=LABEL:NUM "10"


       

      To control a Minimum and Maximum number, say 0.0 - 20.0:

       

      yad --form --field="Number:NUM" 0\!0..20\!1\!1


      NOTE : ‘\‘ escape characters. These are not required in a script but are from the CLI.


       

      Lets set the Minimum to 0.0 and the Maximum to 100.0 with 0.5 increments.

       

      yad --form --field="Number:NUM" 0\!0..100\!0.05\!2


      CHK - Check Box

      yad --form --field="Number:CHK"

       

       

      Checked returns True, Unchecked returns False.

      CB - Combo Box

      note the escape ‘\’ characters.


      yad --form --field="ComboBox:CB" One\!Two\!Three


      CBE - Combo Box Editable

      Combo Box is Editable. In other words you can add data on the fly by typing.

       

      yad --form --field="ComboBox:CBE" One\!Two\!Three


       

      When you press OK in the above example More Stuff| is returned.

      CE - Entry with Completion

      completes a string from matching data. In the example below There are a number of vehicle makes. If you type h in the entry box you will be given a choice of vehicles listed that begin with h EG: Holden and Honda.

       

      yad --title="Vehicle Makes" --form --field ':CE' 'Toyota!Honda!Fiat!Mitsubishi!Nissan!Bentley!Citroen'


      —>

      FL - Folder List

      yad --form --field="Folder List:FL"


       

      Notice (None) is displayed, this is because a path was not specified. Lets add a path to /root:

       

      yad --form --field="Folder List:FL" /root


      SFL - Select FileList

      select a file from a list.

       

      yad --form --field="Folder List:SFL" /root


       

      Now you can drill down through the folders, starting at /root, and select a file. Sortie > /path/filename|

      MFL - Multiple File List

      to select multiple files. You need to hold the CTRL key while left mouse clicking to do so.

       

      yad --form --field="Folder List:MFL" /root


       

      The dialog looks the same as SFL however, when you select multiple files the /path/filenames are separated by a ‘!’

      /root/cruise0002.jpg!/root/cruise0003.jpg!/root/cruise0004.jpg|

      As you can see I selected three files.

      DIR - Directory

      display a basic directory structure.

       

      yad --form --field="Folder List:DIR" /root


      CDIR - Select/Create Folders

      yad --form --field="CDIR:CDIR" /root

      MDIR - Select Folders Only

      yad --form --field="MDIR:MDIR" /root

      FN - Font Dialog

      yad --form --field="Font::FN"


       

      When you click on the Font Button:

       

       

      Tip: Did you notice "Font::FN" in the command? The first colon is added to the Label and the second defines the field type.

      DT - Date Picker

      yad --form --field="Date::DT"


       

      Notice the little Calendar in the right of the field. When you click on it, you get a Calendar. Select the date and click on OK. The following is returned: 20/04/16|

      CLR - Color Picker

      yad --form --field="Color::CLR" "#F507D0"

      #F507D0 couleur par défaut

       

      NOTE : In the Color name field you can type recognised names like teal to select a colour.

      BTN - Bouton

      yad --form --field="Button::BTN"


       

      Now we add a command so it will open your default image viewer.

      yad --form --field="Image Viewer::BTN" defaultimageviewer

      LBL : label - TXT : texte

      NOTE : Whatever you put inside the quotes before the colon becomes the Label.

       

      yad --form --field="This is a Label Maaate:LBL"


       

      Something similar with the TXT type.

       

      yad --form --field="Text::TXT" "This is a Text box where you can display various information."


       

      Form Example This code was written as a GUI for 01micko’s wonderful little CLI wallpaper maker.

       

      #!/bin/sh
      yad --title="Make Wallpaper" --form --separator="," \
      --field="Name:" "Slacko630" \
      --field="Label:" "Slacko-6.3.0" \
      --field="Font::FN" "Sans 50" \
      --field="Format::CB" "png!svg" \
      --field="Width:" "1024" \
      --field="Height:" "768" \
      --field="Embossed::CB" "Yes!No" \
      --field="Gradient Offset::NUM" 0!0..1!0.05!2 \
      --field="Gradient Angle::NUM" 0!0..20!0.05!2 \
      --field="Colour::CLR" "#008080" \
      "" "" "" "" "" "" "" "" "" "" | while read line; do
      IMAGENAME=`echo $line | awk -F',' '{print $1}'`
      LABELNAME=`echo $line | awk -F',' '{print $2}'`
      FONT=`echo $line | awk -F',' '{print $3}'`
      FORMAT=`echo $line | awk -F',' '{print $4}'`
      WIDTH=`echo $line | awk -F',' '{print $5}'`
      HEIGHT=`echo $line | awk -F',' '{print $6}'`
      EMBOSSED=`echo $line | awk -F',' '{print $7}'`
      OFFSET=`echo $line | awk -F',' '{print $8}'`
      ANGLE=`echo $line | awk -F',' '{print $9}'`
      COLOUR=`echo $line | awk -F',' '{print $10}'`
      echo $NAME $LABEL $FONT $FORMAT $WIDTH $HEIGHT $EMBOSSED $OFFSET $ANGLE $COLOUR
      # Convert the colour string xxxxxx to xx xx xx RGB
      multi="0.003906"
      red=`echo $COLOUR | cut -c2-3`
      green=`echo $COLOUR | cut -c4-5`
      blue=`echo $COLOUR | cut -c6-7`
      # Convert colour string to decimal
      fred="$((16#$red))"
      fgreen="$((16#$green))"
      fblue="$((16#$blue))"
      # Scale the decimal numbers to 01micko's range
      r=$(echo "$fred * $multi" | bc)
      g=$(echo "$fgreen * $multi" | bc)
      b=$(echo "$fblue * $multi" | bc)
      # Separate font type from size
      FONTY=`echo $FONT | awk '{ $NF = ""; print $0}'`
      SIZEY=`echo $FONT | rev | cut -d' ' -f1 | rev`
      # Run mkwallpaper, 01micko's cli application
      mkwallpaper -n "$IMAGENAME" -l "$LABELNAME" -f "$FONTY" -p $FORMAT -x  $WIDTH -y $HEIGHT -s $SIZEY -k $EMBOSSED \
      -o "$OFFSET" -z "$r $g $b" -a  $ANGLE
      # Fixed a minor bug in the SVG format. Change pt to px to make sizing work properly .
      sed -i 's/pt/px/g' /usr/share/backgrounds/"$IMAGENAME.svg"
      # Display wallpaper
      defaultimageviewer /usr/share/backgrounds/$IMAGENAME.$FORMAT
      done

       

       

      --align=TYPE alignement des champs (left, center ou right)

       

      yad --form --align=right --field="Label Aligned Right":LB

       

       

      --columns=NUMBER nombre de colonnes.

       

      yad --form --columns=2 --field="Prénom:" "Billy" --field="Age:" "21" --field="Nom:" "Bloggs" --field="Sex::"CB "Male!Female"


       

      NOTE : l’ordonnance des champs va de haut en bas.

       

      --separator=SEPARATOR

       

      Par défaut le séparateur est |

       

      yad --form --field="Firstname:" "Billy" --field="Lastname:" "Bloggs"

       

       

      Sortie > Billy|Bloggs|

       

      yad --form --separator="@" --field="Firstname:" "Billy" --field="Lastname:" "Bloggs"

       

       

      Sortie > Billy@Bloggs@

       

      --item-separator=SEPARATOR Set the separator character for combobox or scale data.

       

      You may have noticed on the --columns command I used a CB (Combo Box). We want to add a few items to the CB so we need to use a separator character to separate them. The default character is the exclamation mark !

       

      yad --form --field="Sex::"CB "Male!Female!Other"

       

       

      Output: Make|

       

      Now lets be bold and change both default separators, the --separator and --item-separator.

       

      yad --form --separator=" " --item-separator="," --field="Sex::"CB "Male,Female,Other" --item-separator=","

       

      The GUI looks the same but the CB choices are now separated by a comma instead of an exlamation mark and the pipe has disappeared from the end of the output. I selected Other and clicked on OK. Output: Other

       

      --date-format=PATTERN Set the format for the returned date.

       

      yad --form --separator=" " --date-format="%-d %B %Y" --field="Date:":DT

       

       

      Click on the little calendar, choose a date, click OK. then click OK again. Output: 26 April 2016

       

      Icons box options

       

      --read-dir=DIRECTORY

      --compact

      --generic

      --stdin

      --item-width

      --term=PATTERN Use specified pattern for launch command in terminal (default: xterm -e %s)

      --sort-by-name --descend

       

       

      --field=LABEL[:TYPE] Add field to form.

      Type may be H, RO, NUM, CHK, CB, CBE, CE, FL, SFL, DIR, CDIR, FN, MFL, MDIR, DT, SCL, CLR, BTN, FBTN, LBL or TXT.
      H - hidden field type. All characters are displayed as the invisible char.
      RO - field is in read-only mode.
      NUM - field is a numeric. Initial value format for this field is VALUE[!RANGE[!STEP![PREC]]], where RANGE must be in form MIN..MAX. `!’ is a default item separator. PREC is a precision for decimals.
      CHK - checkbox field. Initial value is a case insensitive boolean constant (TRUE or FALSE).
      CB - combo-box field. Initial value is a list VAL1!VAL2!…. The separator is the same as in NUM field. Value started with `^’ threats as default for combo-box.
      CBE - editable combo-box field. Initial value same as for combo-box.
      CE - entry with completion. Initial value same as for combo-box.
      FL - file selection button.
      SFL - field for create file.
      DIR - directory selection button.
      CDIR - field for create folder.
      FN - font selection button. Initial value same as in font dialog.
      MFL - select multiple files. Value of this field is a list of files separated by item-separator.
      MDIR - select multiple folders. Value of this field is a list of folders separated by item-separator.
      DT - date field.
      SCL - scale field. Value of this field in a range 0..100.
      CLR - color selection button. Output values for this field generates in the same manner as for color dialog.
      BTN - button field. Label may be in form text in a form LABEL[!ICON[!TOOLTIP]] where ‘!‘ is an item separator. LABEL is a text of button label or gtk stock id. ICON is a buttons icon (stock id or file name).

      TOOLTIP is an optional text for popup help string. Initial value is a command which is running when button is clicked. A special sympols %N in command are replaced by value of field N. If command starts with @, the output of command will be parsed and lines started with number and colon will be treats as a new field values. A quoting style for value when sh -c is used - a single quotes around command and double quotes around -c argument
      FBTN - same as button field, but with full relief of a button.
      LBL - text label. If field name is empty, horizontal separator line will be shown.
      TXT - multiline text entry. This field is always occupy all of form width.Without type field will be a simple text entry.

      --align=TYPE Set alignment of field labels. Possible types are left, center or right. Default is left. --columns=NUMBER Set number of columns in form. Fields will be placed from top to bottom. --separator=STRING Set output separator character. Default is `|’.

      --focus-field=NUMBER Set focused field.

      --cycle-read Cycled reading of stdin data. Sending FormFeed character clears the form. This symbol may be sent as echo -e ‘\f’.

      --item-separator=STRING Set separator character for combo-box or scale values. Default is `!’.

      --date-format=PATTERN Set the format for the date fields (same as in calendar dialog).

      --float-precision=NUMBER Set precision of floating point numbers. By default precision is three digits after point. --complete=TYPE Use specific type for extended completion. TYPE can be any for match any of typed words, all for match all of typed words or regex when typed text treats as regular expression.

      --scroll Make form scrollable.

      --quoted-output Output values will be in shell-style quotes.

      --output-by-row Output field values row by row if several columns is specified.

      --num-output Output index of active element instead of text for combo-box fields. Additional data in command line interprets as a default values for form fields. A special value @disabled@ makes corresponding field inactive. If no extra arguments specified in a command line, data will be readed from stdin, one value per line. Cycled reading means that for N fields N+1 value will replace the first field. Empty values are skipped when reading from stdin.

 

Aucun commentaire

 

Laissez un commentaire