The FL option in yad --form don't let me choose files with particular extension

1,186 views
Skip to first unread message

flames D

unread,
Apr 19, 2017, 5:15:16 PM4/19/17
to yad-common
yad --form --field="Select jpg files:":FL 'sf.jpg' --field="Select text files:":FL 'sf.txt'

The above line opens the file selection window with all the files as expected, but I want to open only the files with particular extensions like "*.jpg" or "*.txt"
Is there any way to do that?

Thanks in advance.
Yad is awesome.

Милош Павловић

unread,
Apr 19, 2017, 9:05:16 PM4/19/17
to yad-common
You can use --file-filter or --mime-filter
#!/bin/bash
yad
--form --field="Select jpg files:":FL 'sf.jpg' --field="Select text files:":SFL 'sf.txt' \
--file-filter="Image Files (*.jpg *.jpeg)| *.jpg *.JPG *.jpeg *.JPEG" --file-filter="Text Files (*.txt)| *.txt *.TXT" \
--file-filter="All Files | *.*"

If you want the first field to select only images and the second only text files you can separate them in tabs
#!/bin/bash
yad
--plug=12345 --tabnum=1 --text="first tab" --form --field="Select jpg files:":FL 'sf.jpg' \
--file-filter="Image Files (*.jpg *.jpeg)| *.jpg *.JPG *.jpeg *.JPEG" &> res1 &

yad
--plug=12345 --tabnum=2 --text="second tab" --form --field="Select text files:":SFL 'sf.txt' \
--file-filter="Text Files (*.txt)| *.txt *.TXT!" &> res2 &

yad
--notebook --key=12345 --tab="Tab 1" --tab="Tab 2"

cat res1 res2
| tr "|" " "
rm
-f res1 res2
Have a nice day

flames D

unread,
Apr 20, 2017, 8:27:37 AM4/20/17
to yad-common
Both of your options work. It solved my problem to some extent.
Actually I wanted the user to be able to select ONLY ".jpg" or ONLY ".txt" files right from the GUI for assigned fields, so that I don't need to check if ".jpg" was selected for that field in my program. Your solution does create file filters but it does not restrict user to select only one type of file for a particular field. It creates file-filters and user is allowed to select either ".jpg" or ".txt" for all the fields.

The solution is better, than showing all the files for all fields.
Thank you for the piece of code and I appreciate your prompt reply :)

Julio C. Neves

unread,
Apr 20, 2017, 9:34:03 AM4/20/17
to yad-c...@googlegroups.com
I don know if this dialog is possible at your aplicattion, but...

$ yad --file-selection --mime-filter text/plain \

--mime-filter text/html

$ yad --file-selection --file-filter \*.txt \

--file-filter \*.htm\*

========================================

$ man yad

   File filters options

       --file-filter=NAME | PATTERN1 PATTERN2 ...

              Add a filename filter. NAME is a displayed filter name, PATTERN is a shell-style filename pattern (for example *.txt). This option may be used mul‐

              tiply times.


       --mime-filter=NAME | MIME1 MIME2 ...

              Add  a mime-type filter. NAME is a displayed filter name, PATTERN is a name of mime type (for example text/plain). This option may be used multiply

              times.


       --image-filter=[NAME]

              Add filter for images supported by gdk-pixbuf library. NAME in as optional name for this filter.


       --add-preview

              Add preview widget. Preview images loads  from  large  or  normal  thumbnails  according  to  XDG  Thumbnails  specification  v0.8.0  (http://stan‐

              dards.freedesktop.org/thumbnail-spec/latest/) or creates by yad for image files and saves as large thumbnails.


              This options applies to all of yad's file chooser dialogs.


Mime

Extensões

Mime

Extensões

application/mac-binhex40

hqx

application/octet-stream

bin,exe

application/oda

oda

application/pdf

pdf

application/postscript

ai,eps,ps

application/rtf

rtf

application/x-gtar

gtar

application/x-mif

mif,fm

application/x-shar

shar

application/x-tar

tar

audio/basic

au,snd

audio/x-aiff

aif,aiff,aifc

audio/x-wav

wav

image/gif

gif

image/ief

ief

image/jpeg

jpeg,jpg,jpe

image/tiff

tiff,tif

image/x-rgb

rgb

image/x-xbitmap

xbm

image/x-xpixmap

xpm

image/x-xwindowdump

xwd

magnus-internal/cgi

cgi,exe,bat

magnus-internal/imagemap

map

magnus-internal/jsp

jsp

magnus-internal/parsed-html

shtml

text/html

htm,html

text/plain

txt

text/richtext

rtx

text/tab-separated-values

tsv

text/x-setext

etx

video/mpeg

mpeg,mpg,mpe

video/quicktime

qt,mov

video/x-msvideo

avi






Abcs,
Julio

Damos treinamento em sua empresa por 
um preço, 
no mínimo, 50% mais barato que qualquer curso,
com certificado e nota fiscal.

​​
Nosso time de instrutores in company é formado somente por
autores
​ ​
de Best Sellers
​ ​
​laureados ​sobre os temas. P. exemplo:

Shell básico e Programação em Shell Julio Neves
Bacula Heitor Medrado
Zabbix Adail Host
Produção Gráfica e Videografismo Cadunico


--
You received this message because you are subscribed to the Google Groups "yad-common" group.
To unsubscribe from this group and stop receiving emails from it, send an email to yad-common+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Julio C. Neves

unread,
Apr 20, 2017, 9:51:32 AM4/20/17
to yad-c...@googlegroups.com
I forgot to say: if you are using the last version of yad, can also use --file-filter and --mime-filter even at --form dialog:

$ yad --form --field="Select jpg or txt files:":FL --file-filter \*.txt --file-filter \*.sh\* --field Others ''

Abcs,
Julio

Damos treinamento em sua empresa por 
um preço, 
no mínimo, 50% mais barato que qualquer curso,
com certificado e nota fiscal.

​​
Nosso time de instrutores in company é formado somente por
autores
​ ​
de Best Sellers
​ ​
​laureados ​sobre os temas. P. exemplo:

Shell básico e Programação em Shell Julio Neves
Bacula Heitor Medrado
Zabbix Adail Host
Produção Gráfica e Videografismo Cadunico


2017-04-19 18:15 GMT-03:00 flames D <tough...@gmail.com>:

--

Julio C. Neves

unread,
Apr 20, 2017, 12:20:28 PM4/20/17
to yad-c...@googlegroups.com
yad --file --text ="Selecione imagem ou texto:":FL "@kill -USR1 YAD_PID" \
    --file-filter="Image Files (*.jpg *.jpeg)|     \
        *.jpg *.JPG *.jpeg *.JPEG" --file-filter="Text Files (*.txt)| *.txt *.TXT"

When you choose a file, it will act as if the <ENTER> key was pressed

Abcs,
Julio

Damos treinamento em sua empresa por 
um preço, 
no mínimo, 50% mais barato que qualquer curso,
com certificado e nota fiscal.

​​
Nosso time de instrutores in company é formado somente por
autores
​ ​
de Best Sellers
​ ​
​laureados ​sobre os temas. P. exemplo:

Shell básico e Programação em Shell Julio Neves
Bacula Heitor Medrado
Zabbix Adail Host
Produção Gráfica e Videografismo Cadunico


--

flames D

unread,
Apr 20, 2017, 2:43:06 PM4/20/17
to yad-common


I am using yad version 0.38.2 (GTK+ 3.10.8) with Linux 14.04 LTS.

1) The output of yad --file-selection --mime-filter text/plain --mime-filter text/html is: https://lh3.googleusercontent.com/-P0a6nvq0I2Y/WPj3JBWAz3I/AAAAAAAADgU/HmdO352psRM5jx5XnX-IIssGtz_eEHhtwCEw/s1600/cmd1.png

2) The output of yad --file-selection --file-filter \*.txt --file-filter \*.htm\* is: https://lh3.googleusercontent.com/-yZVGKbZJh2s/WPj_OyIAkPI/AAAAAAAADgg/OGp93xQOMOYWkAW8PAKC-g8Nu0D_sIkugCLcB/s1600/cmd2.png
So the commands are working but they are not solving my problem.

3) The link you provided with --add-preview is not working. Also tried --mime-filters, output window is not much different from --file-filter.
4) I am using --file-filter with --form --fields and they are working, but not as I want them to.

I appreciate your willingness to help.
Thank you.


On Thursday, 20 April 2017 02:45:16 UTC+5:30, flames D wrote:

Victor Ananjevsky

unread,
Apr 20, 2017, 3:07:07 PM4/20/17
to yad-c...@googlegroups.com

hi

you cannot set specific file filter to a particular file chooser field in a form

but you can try to use notebook dialog instead of form, and embed some file dialogs with its own filters into a notebook tabs


On Thu, 20 Apr 2017 11:43:06 -0700 (PDT)
flames D <tough...@gmail.com> wrote:

>
>
>
> I am using yad version 0.38.2 (GTK+ 3.10.8) with Linux 14.04 LTS.
>
> 1) The output of *yad --file-selection --mime-filter text/plain**
> --mime-filter text/html *is:
> https://lh3.googleusercontent.com/-P0a6nvq0I2Y/WPj3JBWAz3I/AAAAAAAADgU/HmdO352psRM5jx5XnX-IIssGtz_eEHhtwCEw/s1600/cmd1.png
>
> 2) The output of *yad --file-selection --file-filter \*.txt** --file-filter
> \*.htm\* *is:
> https://lh3.googleusercontent.com/-yZVGKbZJh2s/WPj_OyIAkPI/AAAAAAAADgg/OGp93xQOMOYWkAW8PAKC-g8Nu0D_sIkugCLcB/s1600/cmd2.png
> So the commands are working but they are not solving my problem.
>
> 3) The link you provided with --add-preview is not working. Also tried
> --mime-filters, output window is not much different from --file-filter.
> 4) I am using --file-filter with --form --fields and they are working, but
> not as I want them to.
>
> I appreciate your willingness to help.
> Thank you.
>
> On Thursday, 20 April 2017 02:45:16 UTC+5:30, flames D wrote:
> >
> > yad --form --field="Select jpg files:":FL 'sf.jpg' --field="Select text
> > files:":FL 'sf.txt'
> >
> > The above line opens the file selection window with all the files as
> > expected, but I want to open only the files with particular extensions like
> > "*.jpg" or "*.txt"
> > Is there any way to do that?
> >
> > Thanks in advance.
> > Yad is awesome.
> >
>
> --
> You received this message because you are subscribed to the Google Groups "yad-common" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to yad-common+...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.


--
Victor Ananjevsky <anan...@gmail.com>

Милош Павловић

unread,
Apr 20, 2017, 4:01:37 PM4/20/17
to yad-common
Sure it's possible, but not with FL.
#!/bin/bash

function IMAGE
{
while : ; do
  FILE
="$(yad --file-selection --width=500 --height=400 \
              --title="
Select an Image" --file-filter='Image Files (*.jpg *.jpeg)| *.jpg *.JPG *.jpeg *.JPEG' \
              || echo 'sf.jpg'
          )"

 
if [[ "$FILE" == "sf.jpg" ]] || [[ -f "$FILE" ]]; then
     
break
 
fi
done
  printf
"%s" "1:$FILE"
}
export -f IMAGE

function TEXT
{
while : ; do
   FILE
="$(yad yad --file-selection --width=500 --height=400 \
                   --title="
Select a Text File" --file-filter='Text Files *.txt | *.txt *.TXT' \
                   || echo 'sf.txt'
          )"

 
if [[ "$FILE" == "sf.txt" ]] || [[ -f "$FILE" ]]; then
     
break
 
fi
done
  printf
"%s\n" "2:$FILE"
}
export -f TEXT

# Main dialog
yad
--form --width=550 --height=400 \
   
--field="Image:":RO "sf.jpg" \
   
--field="Text:":RO "sf.txt" \
   
--field="Select Image":fbtn '@bash -c "IMAGE %1"' \
   
--field="Select Text":fbtn '@bash -c "TEXT %1"'

flames D

unread,
Apr 20, 2017, 7:11:59 PM4/20/17
to yad-common
@Victor Ananjevsky: M already using six notebook tabs for selecting some options so, if I use tabs again for selecting files it will make the UI look a little weird. It's okay as yad is already allowing users to select files. I am trying to put if-conditions to restrict users from choosing wrong files. Thank you for making yad :D

@Милош Павловић: I loved your idea of using buttons, only problem is that the button will not show the file-path as the :FL option shows.
May be m wanting much :P I am using your last solution of having --file-filters with --forms, it was nice. M handling the rest with if-conditions. Thank you :)

I love such clean groups and forums where people from similar fields can post their questions and get them answered from some
really nice people.
Thanks to Internet. Thanks to all the nice people involved.

On Thursday, 20 April 2017 02:45:16 UTC+5:30, flames D wrote:

Милош Павловић

unread,
Apr 21, 2017, 11:02:47 AM4/21/17
to yad-common
This is what I came up with:
#!/bin/bash

function IMAGE
{
while : ; do

  FILE
="$(yad --file-selection --width=800 --height=600 --add-preview \
              --title="
Select an Image" --file-filter='Image Files (*.jpg *.jpeg *.png)| *.jpg *.JPG *.jpeg *.JPEG *.png *.PNG' \
              || echo 'sf.jpg'
          )"

 
if [[ "$FILE" == "sf.jpg" ]] || [[ -f "$FILE" ]]; then
     
break
 
fi
done

  printf
"%s\n" "1:$FILE"
  printf
"%s" "1:@disabled@"

}
export -f IMAGE

function TEXT
{
while : ; do

   FILE
="$(yad yad --file-selection --width=600 --height=400 \
                   --title="
Select a Text File" --file-filter='Text Files *.txt | *.txt *.TXT' \
                   || echo 'sf.txt'
          )"

 
if [[ "$FILE" == "sf.txt" ]] || [[ -f "$FILE" ]]; then
     
break
 
fi
done
  printf
"%s\n" "2:$FILE"

  printf
"%s" "2:@disabled@"

}
export -f TEXT


# Main dialog
yad
--form --width=550 --height=400 \

   
--field="Image:":FL "@disabled@" \
   
--field="Text:":FL "@disabled@" \

   
--field="Select Image":fbtn '@bash -c "IMAGE %1"' \
   
--field="Select Text":fbtn '@bash -c "TEXT %1"'
Although the FL form fields are disabled the data stored in them can be used.
The only problem is: it's hard to see the file name with some gtk themes. :)
Best regards

flames D

unread,
Apr 25, 2017, 9:37:31 AM4/25/17
to yad-common
Wao! It worked. I tried much but was unsuccessful. You structured the functions in a beautiful way. For the UI am making now, it's necessary to show the file paths, so I will use it in a different UI :) I appreciate your efforts. Thank you :D
I will share the UI with yad-common once am done.

 
On Thursday, 20 April 2017 02:45:16 UTC+5:30, flames D wrote:
Reply all
Reply to author
Forward
0 new messages