Page 10 of 42

Posted: Sun 08 May 2016, 10:42
by MochiMoppel
@smokey01, I went through your tutorial:
yad --text-info is used for displaying information.
You will notice there is no =TEXT option.
yad --text-info="Doesn't work"
...
It reads the information from a file and displays it in the --text-info box.
Maybe you should mention that --text-info is not restricted to input from text files:

Code: Select all

yad --text-info <<< "This works"
echo "Piping also works" | yad --text-info
In a way it's very similar to gxmessage. One of the advantages is the optional editability. I also like that ENTER key pushes the OK button. It would be great if it could - as gxmessage - adjust the size to the size of info text - without displaying scrollbars.

Posted: Wed 11 May 2016, 07:20
by MochiMoppel
I stumbled on the mkwallpaper GUI and didn't understand the 10 empty strings at the end of the yad command line. Are these really necessary? Values are already defined for each field, so positional parameters seem to have no effect.

I also noticed the heavy weapons used for parsing the yad output into variables. Opening a subshell, a non-looping loop and then invoking awk 10 times just to get at these 10 values seems more complicated than it needs to be, but maybe I missed something.

A little demo (see below) might show an alternative way to read yad output into variables.

I played with different separators but found the default pipe symbol used by yad the least problematic. Using linefeed is tricky and can cause problems with multiline text fields. Commas etc. can also easily appear in text fields. Nothing is really foolproof, but pipe should be OK in most cases.

IFS separator must be the same as the yad separator. I didn't bother to save and reassign the original IFS ... just in case someone wonders.

Multiline text fields are output as strings containing \n escape sequences to mark linefeeds. These should be "retranslated" before assigning them to variables.

Color fields accept color names besides hex color values. That's a nice touch.

Code: Select all

#!/bin/sh
SAMPLETXT="First line, and now
second line in TXT field"

OUT=$(yad --form \
--field="Multiline text:TXT"                    "$SAMPLETXT" \
--field="Typeless entry with\nmultiline label"  "No field TYPE specified" \
--field="Font selection:FN"                     "Sans 12" \
--field="Colour selection:CLR"                  "gold" )

IFS='|'                                           # field separator used by 'read' and 'yad'
read -r MULTILINE TYPELESS FONT COLOUR <<< "$OUT" # read field values and assign to variables
MULTILINE=$(echo -e $MULTILINE)                   # Convert '\n' in TXT field back into linefeeds 
echo -e "$MULTILINE\n$TYPELESS\n$FONT\n$COLOUR"

Posted: Wed 11 May 2016, 09:47
by smokey01
There's many ways to skin a cat, as they say. Your method looks pretty good. There's a lot about bash I don't know. I believe the simplest method is usually the best. Your code is very cool, I like it. It's going in the tutorial.

Posted: Wed 11 May 2016, 13:14
by step
MochiMoppel wrote:...
Thanks for your script MochiMoppel. Here's a slight variation that works equally well for ash, bash and dash.

Code: Select all

#!/bin/sh
# Works for bash, dash, ash. Change #!/bin/[bd]ash above accordingly.

SAMPLETXT="First line, and now
second line in TXT field"

ifs=$IFS; IFS='|'                               # Field separator used by 'read' and 'yad'
read -r MULTILINE TYPELESS FONT COLOUR scrap << EOF   # read field values and assign to variables
$(yad --form \
--field="Multiline text:TXT"                    "$SAMPLETXT" \
--field="Typeless entry with\nmultiline label"  "No field TYPE specified" \
--field="Font selection:FN"                     "Sans 12" \
--field="Colour selection:CLR"                  "gold" )
EOF
IFS=$ifs

[ -n "$(echo -e)" ] && echo_e= || echo_e=-e     # Use echo -e except for dash
MULTILINE=$(echo $echo_e "$MULTILINE")          # Convert '\n' in TXT field back into linefeeds 
echo $echo_e "$MULTILINE\n$TYPELESS\n$FONT\n$COLOUR"
[/quote]

Posted: Wed 11 May 2016, 23:26
by smokey01
Yadders and Bashers,

Here is a challenge if you choose to accept it.

Convert the script below to Yad with the smallest amount of code possible.

Code: Select all

#! /bin/bash
export MAIN_DIALOG='
<vbox>
<frame Stock>
<tree rules_hint="true" exported_column="1">
<height>400</height><width>250</width>
<label>Stock ID</label>
<item stock="gtk-dialog-authentication">gtk-dialog-authentication</item>
<item stock="gtk-dialog-info">gtk-dialog-info</item>
<item stock="gtk-dialog-warning">gtk-dialog-warning</item>
<item stock="gtk-dialog-error">gtk-dialog-error</item>
<item stock="gtk-dialog-question">gtk-dialog-question</item>
<item stock="gtk-dnd">gtk-dnd</item>
<item stock="gtk-dnd-multiple">gtk-dnd-multiple</item>
<item stock="gtk-about">gtk-about</item>
<item stock="gtk-add">gtk-add</item>
<item stock="gtk-apply">gtk-apply</item>
<item stock="gtk-bold">gtk-bold</item>
<item stock="gtk-cancel">gtk-cancel</item>
<item stock="gtk-cdrom">gtk-cdrom</item>
<item stock="gtk-clear">gtk-clear</item>
<item stock="gtk-close">gtk-close</item>
<item stock="gtk-color-picker">gtk-color-picker</item>
<item stock="gtk-convert">gtk-convert</item>
<item stock="gtk-connect">gtk-connect</item>
<item stock="gtk-copy">gtk-copy</item>
<item stock="gtk-cut">gtk-cut</item>
<item stock="gtk-delete">gtk-delete</item>
<item stock="gtk-directory">gtk-directory</item>
<item stock="gtk-disconnect">gtk-disconnect</item>
<item stock="gtk-edit">gtk-edit</item>
<item stock="gtk-execute">gtk-execute</item>
<item stock="gtk-file">gtk-file</item>
<item stock="gtk-find">gtk-find</item>
<item stock="gtk-find-and-replace">gtk-find-and-replace</item>
<item stock="gtk-floppy">gtk-floppy</item>
<item stock="gtk-fullscreen">gtk-fullscreen</item>
<item stock="gtk-goto-bottom">gtk-goto-bottom</item>
<item stock="gtk-goto-first">gtk-goto-first</item>
<item stock="gtk-goto-last">gtk-goto-last</item>
<item stock="gtk-goto-top">gtk-goto-top</item>
<item stock="gtk-go-back">gtk-go-back</item>
<item stock="gtk-go-down">gtk-go-down</item>
<item stock="gtk-go-forward">gtk-go-forward</item>
<item stock="gtk-go-up">gtk-go-up</item>
<item stock="gtk-harddisk">gtk-harddisk</item>
<item stock="gtk-help">gtk-help</item>
<item stock="gtk-home">gtk-home</item>
<item stock="gtk-index">gtk-index</item>
<item stock="gtk-indent">gtk-indent</item>
<item stock="gtk-info">gtk-info</item>
<item stock="gtk-unindent">gtk-unindent</item>
<item stock="gtk-italic">gtk-italic</item>
<item stock="gtk-jump-to">gtk-jump-to</item>
<item stock="gtk-justify-center">gtk-justify-center</item>
<item stock="gtk-justify-fill">gtk-justify-fill</item>
<item stock="gtk-justify-left">gtk-justify-left</item>
<item stock="gtk-justify-right">gtk-justify-right</item>
<item stock="gtk-leave-fullscreen">gtk-leave-fullscreen</item>
<item stock="gtk-missing-image">gtk-missing-image</item>
<item stock="gtk-media-forward">gtk-media-forward</item>
<item stock="gtk-media-next">gtk-media-next</item>
<item stock="gtk-media-pause">gtk-media-pause</item>
<item stock="gtk-media-play">gtk-media-play</item>
<item stock="gtk-media-previous">gtk-media-previous</item>
<item stock="gtk-media-record">gtk-media-record</item>
<item stock="gtk-media-rewind">gtk-media-rewind</item>
<item stock="gtk-media-stop">gtk-media-stop</item>
<item stock="gtk-network">gtk-network</item>
<item stock="gtk-new">gtk-new</item>
<item stock="gtk-no">gtk-no</item>
<item stock="gtk-ok">gtk-ok</item>
<item stock="gtk-open">gtk-open</item>
<item stock="gtk-paste">gtk-paste</item>
<item stock="gtk-preferences">gtk-preferences</item>
<item stock="gtk-print">gtk-print</item>
<item stock="gtk-print-preview">gtk-print-preview</item>
<item stock="gtk-properties">gtk-properties</item>
<item stock="gtk-quit">gtk-quit</item>
<item stock="gtk-redo">gtk-redo</item>
<item stock="gtk-refresh">gtk-refresh</item>
<item stock="gtk-remove">gtk-remove</item>
<item stock="gtk-revert-to-saved">gtk-revert-to-saved</item>
<item stock="gtk-save">gtk-save</item>
<item stock="gtk-save-as">gtk-save-as</item>
<item stock="gtk-select-color">gtk-select-color</item>
<item stock="gtk-select-font">gtk-select-font</item>
<item stock="gtk-sort-ascending">gtk-sort-ascending</item>
<item stock="gtk-sort-descending">gtk-sort-descending</item>
<item stock="gtk-spell-check">gtk-spell-check</item>
<item stock="gtk-stop">gtk-stop</item>
<item stock="gtk-strikethrough">gtk-strikethrough</item>
<item stock="gtk-undelete">gtk-undelete</item>
<item stock="gtk-underline">gtk-underline</item>
<item stock="gtk-undo">gtk-undo</item>
<item stock="gtk-yes">gtk-yes</item>
<item stock="gtk-zoom-100">gtk-zoom-100</item>
<item stock="gtk-zoom-fit">gtk-zoom-fit</item>
<item stock="gtk-zoom-in">gtk-zoom-in</item>
<item stock="gtk-zoom-out">gtk-zoom-out</item>
</tree>
</frame>
<hbox>
<button cancel></button>
<button ok></button>
</hbox>
</vbox>
'
gtkdialog --program=MAIN_DIALOG

Posted: Thu 12 May 2016, 03:13
by MochiMoppel
Very basically and without any frills maybe something like this:

Code: Select all

#!/bin/sh
for i in about add apply bold cancel caps-lock-warning cdrom clear close color-picker connect convert copy cut delete dialog-authentication dialog-error dialog-info dialog-question dialog-warning directory disconnect dnd dnd-multiple edit execute file find find-and-replace floppy fullscreen go-back go-down go-forward go-up goto-bottom goto-first goto-last goto-top harddisk help home indent index info italic jump-to justify-center justify-fill justify-left justify-right leave-fullscreen media-forward media-next media-pause media-play media-previous media-record media-rewind media-stop missing-image network new no ok open orientation-landscape orientation-portrait orientation-reverse-landscape orientation-reverse-portrait page-setup paste preferences print print-error print-paused print-preview print-report print-warning properties quit redo refresh remove revert-to-saved save save-as select-all select-color select-font sort-ascending sort-descending spell-check stop strikethrough undelete underline undo unindent yes zoom-100 zoom-fit zoom-in zoom-out
do
ICONS="$ICONS gtk-$i gtk-$i"
done
yad --list --width=280 --height=500 --no-headers --column='':IMG --column='' $ICONS
BUT: Strangely some icons are not displayed. I checked with the dialog in PupControl (/usr/local/PupControl/gtk.icons) which displays all icons properly (see screenshot), then I copied PupControl's icon name list to make sure that the names are OK, but no change. No idea what is wrong here. Yad bug? As long as this mystery isn't solved there is no point to invest more efforts in making it look exactly like your dialog.

Edit: As expected I also can't use these not displaying icons in other yad elements, i.e. buttons.

Posted: Thu 12 May 2016, 05:52
by rg66

Code: Select all

for i in `find -L /usr/share/icons/hicolor/16x16 -type f | grep gtk`; do
ICONS="$ICONS $i `basename ${i%.*}`"
done
yad --list --width=280 --height=500 --no-headers --column=":IMG" --column="" $ICONS 
This might be specific to X-series as I'm not sure if other puppies have the gtk-icons in /usr/share/icons/hicolor. And, it doesn't look like all gtk icons are there.

Posted: Thu 12 May 2016, 07:04
by stemsee
Here; seems to display all icons.

Code: Select all

yad --title="GTK Stock Icons" --window-icon=/usr/share/icons/gtk-apply.png --list --width=280 --height=500 --no-headers --column=":IMG" --column="" `ls /usr/share/icons/ | grep 'gtk' | cut -f1 -d '.'`

Posted: Thu 12 May 2016, 08:17
by MochiMoppel
stemsee wrote:Here; seems to display all icons
:lol: Really? Look closer. Do the descriptions match the icons? Note that the yad list has 2 columns, so you will need 2 parameters for each line, not just 1. Each description in your screenshot shows no icon and each icon has no description.

@ rg66, stemsee : We are talking about GTK stock IDs and their associated icons. These icons are built into GTK and not saved anywhere in the file system as individual image files. You may use a customized GTK theme with replacements for the built-in icons in /usr/share/icons, but that's not what smokey01's and my script is about, e.g I'm using Slacko 5.6 and I have only one image file in my file system that matches the pattern gtk-* (/usr/share/icons/gtk-harddisk.xpm). What you see in my screenshot are built-in icons.

Posted: Thu 12 May 2016, 09:22
by SFR
MochiMoppel wrote:Strangely some icons are not displayed.
Most likely a GTK thing.

See here for more info and a patch:
http://www.murga-linux.com/puppy/viewto ... 362#847362

Those particular icons (on your screenshot) display fine for me in Fatdog, thanks to the above patch, but some (gtk-go-back, gtk-go-forward, etc.) still don't.
I guess I need to modify the patch to include them, too.

EDIT: Ok, I fixed the patch, here it is:
http://www.murga-linux.com/puppy/viewto ... 490#903490

All icons are displayed fine now.

Greetings!

Posted: Thu 12 May 2016, 11:46
by MochiMoppel
Hmm...what I don't understand: All icons work fine here in gtkdialog, ROX, Geany etc. Only exception is yad. How can this be a GTK and not a yad issue?

Posted: Thu 12 May 2016, 12:08
by SFR
Not only YAD - also SpaceFM as well as Gtkdialog (for icons in titlebar).
http://www.murga-linux.com/puppy/viewto ... 355#820355

Check this - theoretically it should display the icon not only within button, but also in titlebar, right?

Code: Select all

echo '<window icon-name="gtk-dialog-error"><button><input file stock="gtk-dialog-error"></input></button></window>' | gtkdialog -s
So, does it work for you? It does for me with the patched libgtk.

Greetings!

Posted: Thu 12 May 2016, 12:34
by MochiMoppel
SFR wrote:So, does it work for you?
No :oops:

Posted: Thu 12 May 2016, 12:43
by smokey01
I've noticed many older gtkdialog scripts don't always display all icons. Changing the icon-name to stock seems to fix the problem.
I don't know how to wangle stock into MochiMoppel script.

Posted: Sat 14 May 2016, 02:57
by MochiMoppel
Bottomline: For listing gtk stock icons yad is not a good choice - unless the user has applied SFR's patch.

Let's try our luck with other images. For searching icons in my system I normally use SFR's excellent Icon Finder. The only drawback: this thing can be terribly slow.

I tried yad as a faster alternative and was impressed by the speed. To be fair it does much less than Icon Finder, e.g. it does not sniff image dimensions and doesn't do any scaling. All images are rendered in their original size. On the other side it can do things Icon Finder can not, e.g. sorting by file size or name.

Basically it can be done with a one-liner, but I made it four :lol: :

Code: Select all

#!/bin/bash
function showinrox { rox -s "$4"  ;} ; export -f showinrox
IFS=";"
FOUND=$(find /usr/local/lib/X11/pixmaps -regextype gnu-awk -iregex  ".*\.(png|jpg|gif|xpm)$" -printf "%p${IFS}%f${IFS}%s${IFS}%p${IFS}")
yad --list --dclick-action='sh -c "showinrox %s"' --editable --geometry=700x500  --column=icon:IMG --column=name --column=size:NUM --column=path $FOUND
IFS can be set to any character not used in the resulting file names, even a unicode character will do. This character is used in find's -printf argument to separate 4 output fields. Yad then uses this character to split FOUND, a huge one line string, into column fields. In principal it's possible not to (re)define IFS and pray that none of the file names includes a space, but let's keep it safe.

In the demo I use /usr/local/lib/X11/pixmaps as the search directory. If this works try /usr/local/lib/X11. This should find much more icons. Initially yad sorts them as find found them, i.e. sorted by directories. Sorting by name will make it possible to easily compare similar or same name icons. Sorting by file size is also interesting.

It is possible to search more that one directory tree. Just add more search path e.g. find /root /usr /mnt/home ....

The find command searches for files with typical extensions. Add more if you like, e.g. try svg. This may find some monster svg icons (why do they have to be so huge when they are scalable anyway?).

In yad I added the --editable option. This makes it possible to click on an icon path and copy it (or drag&drop it into an editor).

Double clicking on an image will jump to the image file in ROX. Yad passes all field values to the showinrox function, but only the 4th is of interest as it represents the full path.

Posted: Sat 14 May 2016, 04:25
by 01micko
SFR wrote:Not only YAD - also SpaceFM as well as Gtkdialog (for icons in titlebar).
http://www.murga-linux.com/puppy/viewto ... 355#820355
My guess is that gtk+ developers all have an icon theme installed. Lazy in other words.

Try this one

Posted: Sat 14 May 2016, 12:43
by SFR
MochiMoppel wrote:For searching icons in my system I normally use SFR's excellent Icon Finder. The only drawback: this thing can be terribly slow.
Yeah, it's slow indeed... It was even slower before v1.4:
changelog wrote:- ~250% faster image filtering;
The worst part is that if there's a lot (thousands) of icons, it takes ages for Gtkdialog to digest all that stuff before it displays the window.
MochiMoppel wrote:I tried yad as a faster alternative and was impressed by the speed.
Nice, light alternative. Only had to add '-L' to find, because in Fatdog /usr/local/lib/X11/pixmaps is a symlink.
___________
01micko wrote:My guess is that gtk+ developers all have an icon theme installed. Lazy in other words.
Most likely... Also, all "big" distros have some full icon theme preinstalled, so nobody is noticing that something's not right.
01micko wrote:Try this one
Yeah, I downloaded it some time ago - an excellent collection of tiny (size) icons to have!

Greetings!

Posted: Sun 15 May 2016, 05:00
by MochiMoppel
Compared with gtkdialog's tree widget the yad -list option has a big advantage. While gtkdialog requires to define the "exported-column" beforehand and then can do stuff only with this specified column value, yad allows access to the values of all columns.

However it seems that in yad you can't do much with these values. There is the --dclick-action, which I used in my previous demo. There is also the --select-action, which I didn't use because I simply can't think of anything useful to do with it. It would also interfere with the --editable option.

It would be nice to select a row and then do all sorts of stuff with any column value. Impossible? Not really. Below is an example that adds buttons to the list which perform different actions. The trick is to let the --select-action write all row values to a tmp file and let the buttons and their associated functions read these values.

The "Info" button uses exiv2 to show (mostly non-existent) exif data, the "Show Location" button does the same thing that double clicking did in the previous demo and the "Copy Path" button uses xclip to copy the path to the clipboard. None of the functions use any other value than the 4th column, but this is only due to my lack of fantasy and the limited usefulness of an icon list.

Code: Select all

#!/bin/bash
export TMPFILE=/tmp/yadvalues
function savevalues { echo -e "IMGNAME=\"$2\"\nIMGSIZE=$3\nIMGPATH=\"$4\"" > $TMPFILE ;} ; export -f savevalues
function showinfo   { source $TMPFILE ; exiv2   "$IMGPATH" 2>/dev/null | gxmessage -c -fn mono -file -  ;} ; export -f showinfo
function showinrox  { source $TMPFILE ; rox -s  "$IMGPATH"  ;} ; export -f showinrox
function copypath   { source $TMPFILE ; echo -n "$IMGPATH" | xclip -i -selection clipboard  ;} ; export -f copypath
SEP=";"
FOUND=$(find -L /usr/local/lib/X11/pixmaps -regextype gnu-awk -iregex  ".*\.(png|jpg|gif|xpm)$" -printf "%p${SEP}%f${SEP}%s${SEP}%p${SEP}")
IFS=$SEP
yad --list  --geometry=700x500 \
--select-action='sh -c "savevalues %s"' \
--column=icon:IMG \
--column=name \
--column=size:NUM \
--column=path \
--button="Info":'sh -c "showinfo"' \
--button="Show Location":'sh -c "showinrox"' \
--button="Copy Path":'sh -c "copypath"' \
--button="gtk-ok":0 \
--button="gtk-cancel":1 \
$FOUND
Edit: To prevent the replacement of the separator with a space character should the FOUND variable ever be echoed to a file or stdout I changed
      IFS=";"
      FOUND=$(find .... -printf "%p${IFS}%f${IFS}%s${IFS}%p${IFS}")
      yad ....
to
      SEP=";"
      FOUND=$(find .... -printf "%p${SEP}%f${SEP}%s${SEP}%p${SEP}")
      IFS=$SEP
      yad ....

Posted: Sun 15 May 2016, 21:05
by step
Very nice, thanks MochiMoppel.

Do I need a specific yad version? I have 0.28.1 and when I select a row with one left click then press one of the buttons stderr prints "sh: /tmp/yadvalues: No such file or directory".

@others: the forum seems to have added a space character at the end of each line in MochiMoppel's script. Make sure to delete such characters or yad will print an error message "No column titles specified for List dialog."

Posted: Sun 15 May 2016, 23:14
by smokey01