Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Mon 16 Sep 2019, 08:36
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
YAD - Tips
Post new topic   Reply to topic View previous topic :: View next topic
Page 13 of 48 [711 Posts]   Goto page: Previous 1, 2, 3, ..., 11, 12, 13, 14, 15, ..., 46, 47, 48 Next
Author Message
MochiMoppel


Joined: 26 Jan 2011
Posts: 1897
Location: Japan

PostPosted: Sun 08 May 2016, 06:42    Post subject:  

@smokey01, I went through your tutorial:
Quote:
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:
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.
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1897
Location: Japan

PostPosted: Wed 11 May 2016, 03:20    Post subject:  

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:
#!/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"
yadtest.png
 Description   
 Filesize   20.91 KB
 Viewed   1727 Time(s)

yadtest.png

Back to top
View user's profile Send private message 
smokey01


Joined: 30 Dec 2006
Posts: 2811
Location: South Australia :-(

PostPosted: Wed 11 May 2016, 05:47    Post subject:  

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.
_________________
Software <-> Distros <-> Tips <-> Newsletters
Back to top
View user's profile Send private message Visit poster's website 
step

Joined: 04 May 2012
Posts: 1197

PostPosted: Wed 11 May 2016, 09:14    Post subject:  

MochiMoppel wrote:
...

Thanks for your script MochiMoppel. Here's a slight variation that works equally well for ash, bash and dash.

Code:
#!/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]
_________________
Fatdog64-802|+Packages|Kodi|Findnrun|+forum|gtkmenuplus
Back to top
View user's profile Send private message 
smokey01


Joined: 30 Dec 2006
Posts: 2811
Location: South Australia :-(

PostPosted: Wed 11 May 2016, 19:26    Post subject:  

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:
#! /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

_________________
Software <-> Distros <-> Tips <-> Newsletters
Back to top
View user's profile Send private message Visit poster's website 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1897
Location: Japan

PostPosted: Wed 11 May 2016, 23:13    Post subject:  

Very basically and without any frills maybe something like this:
Code:
#!/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.
stockicons.png
 Description   
 Filesize   62.42 KB
 Viewed   1684 Time(s)

stockicons.png


Last edited by MochiMoppel on Thu 12 May 2016, 02:59; edited 1 time in total
Back to top
View user's profile Send private message 
rg66


Joined: 23 Jul 2012
Posts: 1160
Location: Vancouver, BC Canada / Entebbe, Uganda Africa!?!

PostPosted: Thu 12 May 2016, 01:52    Post subject:  

Code:
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.

_________________
X-slacko-5b1 - X-tahr-2.0 - X-precise-2.4
X-series repo

Last edited by rg66 on Thu 12 May 2016, 03:43; edited 2 times in total
Back to top
View user's profile Send private message 
stemsee

Joined: 27 Jun 2013
Posts: 2451
Location: In The Way

PostPosted: Thu 12 May 2016, 03:04    Post subject:  

Here; seems to display all icons.
Code:
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 '.'`
capture9044.png
 Description   
 Filesize   42.61 KB
 Viewed   1556 Time(s)

capture9044.png

Back to top
View user's profile Send private message MSN Messenger 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1897
Location: Japan

PostPosted: Thu 12 May 2016, 04:17    Post subject:  

stemsee wrote:
Here; seems to display all icons
Laughing 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.
Back to top
View user's profile Send private message 
SFR


Joined: 26 Oct 2011
Posts: 1731

PostPosted: Thu 12 May 2016, 05:22    Post subject:  

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/viewtopic.php?p=847362#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/viewtopic.php?p=903490#903490

All icons are displayed fine now.

Greetings!
yad-stock.gif
 Description   
 Filesize   238.12 KB
 Viewed   1645 Time(s)

yad-stock.gif


_________________
[O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1897
Location: Japan

PostPosted: Thu 12 May 2016, 07:46    Post subject:  

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?
Back to top
View user's profile Send private message 
SFR


Joined: 26 Oct 2011
Posts: 1731

PostPosted: Thu 12 May 2016, 08:08    Post subject:  

Not only YAD - also SpaceFM as well as Gtkdialog (for icons in titlebar).
http://www.murga-linux.com/puppy/viewtopic.php?p=820355#820355

Check this - theoretically it should display the icon not only within button, but also in titlebar, right?
Code:
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!
gtkdialog_icon_titlebar.png
 Description   
 Filesize   9 KB
 Viewed   1450 Time(s)

gtkdialog_icon_titlebar.png


_________________
[O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1897
Location: Japan

PostPosted: Thu 12 May 2016, 08:34    Post subject:  

SFR wrote:
So, does it work for you?

No Embarassed
Back to top
View user's profile Send private message 
smokey01


Joined: 30 Dec 2006
Posts: 2811
Location: South Australia :-(

PostPosted: Thu 12 May 2016, 08:43    Post subject:  

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.

_________________
Software <-> Distros <-> Tips <-> Newsletters
Back to top
View user's profile Send private message Visit poster's website 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1897
Location: Japan

PostPosted: Fri 13 May 2016, 22:57    Post subject:  

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 Laughing :
Code:
#!/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.
yad-list.png
 Description   
 Filesize   45.83 KB
 Viewed   1591 Time(s)

yad-list.png

Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 13 of 48 [711 Posts]   Goto page: Previous 1, 2, 3, ..., 11, 12, 13, 14, 15, ..., 46, 47, 48 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0852s ][ Queries: 13 (0.0104s) ][ GZIP on ]