YAD - Tips

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#461 Post by MochiMoppel »

Argolance wrote:As there is a --wrap option, I thought that without this option, text would be non wrapped
--wrap is an option for the --text-info dialog. If you don't use this option and if the text is wider than the window width, a horizontal scrollbar is added. Window size does not change.

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#462 Post by Argolance »

OK, thanks! Everything is clear now... :)

User avatar
fredx181
Posts: 4448
Joined: Wed 11 Dec 2013, 12:37
Location: holland

#463 Post by fredx181 »

MochiMoppel wrote:Unlike Xdialog yad does not seem to autoexpand the window but breaks lines at word boundaries. A simple way to mimic Xdialog would be to replace ordinary spaces with non-breaking spaces. Would need more sophistication if your text contains tabs.
Code:
....
That's a great workaround, thanks !
I always adjust --width=... to get the text in full width (no-wrap), but it's very much depending on the font size that is configured on the system, so may not work as intended if configured font size is very large.

Fred

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#464 Post by MochiMoppel »

fredx181 wrote:That's a great workaround
Works also with gtkdialog:

Code: Select all

export MSG2
echo '<text><input>echo -e "$MSG2"</input></text>' | gtkdialog -s
Even when font sizes are the same, with gettexted lines you never know how long they will be in translated texts, so hard coding an appropriate window size would be impossible.

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#465 Post by Argolance »

Bonjour,
fredx181 wrote:I always adjust --width=... to get the text in full width (no-wrap).
Strange: I also tried this trick found somewhere on the web, but it doesn't work:

Code: Select all

Impossible to analyze the command line: Impossible to analyze the entire value " " for --width
Running:

Code: Select all

# yad --version
0.33.1 (GTK+ 2.24.10)
Cordialement.

User avatar
fredx181
Posts: 4448
Joined: Wed 11 Dec 2013, 12:37
Location: holland

#466 Post by fredx181 »

Argolance wrote:Bonjour,
fredx181 wrote:I always adjust --width=... to get the text in full width (no-wrap).
Strange: I also tried this trick found somewhere on the web, but it doesn't work:

Code: Select all

Impossible to analyze the command line: Impossible to analyze the entire value " " for --width
Running:

Code: Select all

# yad --version
0.33.1 (GTK+ 2.24.10)
Cordialement.
Ah, sorry, I just meant "--width=<some-value>" for example: --width=800
(and test if e.g. 800 is enough to display the text "full width" without wrapping it, otherwise increase the value)
But Mochi's workaround does it automatically.

Fred

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#467 Post by Argolance »

Bonjour,
fredx181 wrote:Ah, sorry, I just meant "--width=<some-value>" for example: --width=800
Thank you.
In the script I am tweaking, a single Xdialog function is used for different text strings:

Code: Select all

msg () { yad $WIDTH --window-icon=/usr/share/icons/hicolor/48x48/apps/yapi.png --button=gtk-ok --title YaPI --text="$1" 0 0 ; }
So, there are different possible values given to the variable WIDTH I added, according to the chosen text.
Example:

Code: Select all

MSG1="xxxxxxx xxx xxxxxxxxxx xxxxxxxxxxx xx xxxxxxxxx xxx xxxxxxxxxx xxxxx xxx xxxxxxx xxxx xxx xxxxxxx"
MSG2="xxxxxxxxxxxxxxxxx xx xxxxxxxxxxxxxxxxxxxxxxx"
WIDTH="--width=800"
msg "$MSG1 \n\n $MSG2"
... and WIDTH="" or no variable at all, if I want the text to be automatically wrapped by yad.

Cordialement.

User avatar
Mike Walsh
Posts: 6351
Joined: Sat 28 Jun 2014, 12:42
Location: King's Lynn, UK.

#468 Post by Mike Walsh »

Afternoon, all.

Now, then; need a wee bit of advice here, if it so please y'all.

As you all probably know by now, I'm pretty much a neophyte at Bash scripting. I've used YAD successfully in recent months for the occasional info or selector box GUI (courtesy of Grant's comprehensive guide, and the odd snippet I've found on The Linux Rain); easy enough when the required output is simply to run a single command.

What I'm not so clear about is how to capture the output of certain YAD commands.....and then to assign that output to a variable, which can then be used as part of an exec command, later in the same script.

(Remember; beginner here, so excuse me if I seem to be asking absolutely noobish-type questions. We all have to start somewhere..!)

------------------------------------

In particular, something I'm working on at the moment is making use of these two YAD commands:-

Code: Select all

yad --form --field="MDIR:MDIR" /root
.....which brings up the directory selector dialog, and lets you select a specific directory, and this one:-

Code: Select all

yad --form --field=LABEL:NUM "10"
.....or a close variation on it, to allow selection of a numeric value.

In a nutshell, how do you 'capture' the output of these two commands? And, having captured that output, how can I then 'assign' it to a variable?

I'm thinking something like the following for the first example:-

Code: Select all

 --form --field="Choose image directory:-:MDIR" /root =`$DIR` \
.....but I've probably got the principle of the 'backticks' (`) rather muddled up. In fact probably the entire concept of variables totally wrong... A wee bit of clarification would be very much appreciated!

I have several ideas for GUIs I'd like to do for various things, but until I can get this business of capturing outputs and assigning variables straightened out in my head, I admit I'm just whistling in the wind.....


Mike. :wink:

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#469 Post by MochiMoppel »

Code: Select all

#!/bin/bash
read MYNUMBER MYDIR <<< $(yad --form --separator=$'\n' --field=LABEL:NUM "10" --field="MDIR:MDIR" /root)
echo "$MYNUMBER"
echo "$MYDIR"
yad is a bit special as it returns values separated by "|" characters. Changing this character to a linefeed $'\n' returns all values on a separate line and makes it easier to assign the values to variables.

User avatar
fredx181
Posts: 4448
Joined: Wed 11 Dec 2013, 12:37
Location: holland

#470 Post by fredx181 »

Hi Mike,
I see while I was writing this that MochiMoppel replied already.
Anyway here's sort of how I would do it.
This should do to get DIR variable:

Code: Select all

SETUP=$(yad --form --field="Choose image directory:-:MDIR" /root)
# The output of yad has delimiter "|"
echo $SETUP # full output
export DIR="`echo $SETUP | cut -d "|" -f 1`"
echo $DIR
Say you have 2 fields, then , e.g. (note the "f 2" in cut command for OUTDIR)

Code: Select all

SETUP=$(yad --form --field="Choose image directory:-:MDIR" /root \
--field="Choose output directory:-:MDIR" /root)
echo $SETUP # full output, next will separate them
export DIR="`echo $SETUP | cut -d "|" -f 1`"
export OUTDIR="`echo $SETUP | cut -d "|" -f 2`"
echo $DIR
echo $OUTDIR
Fred
Last edited by fredx181 on Tue 04 Sep 2018, 15:21, edited 1 time in total.

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#471 Post by MochiMoppel »

If your yad dialog contains only 1 field then things become simple:

Code: Select all

MYDIR=$(yad --form  --separator=$'\n' --field="MDIR:MDIR" /root)
In this case you could also leave the separator empty:

Code: Select all

MYDIR=$(yad --form  --separator= --field="MDIR:MDIR" /root)

step
Posts: 1349
Joined: Fri 04 May 2012, 11:20

#472 Post by step »

Slightly more elaborate that MochiMoppel's first example but essentially using the same concept (read variable). This one is compatible with all the shells we commonly use in this forum.

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 with dash
MULTILINE=$(echo $echo_e "$MULTILINE")          # Convert '\n' in TXT field back into linefeeds 
echo $echo_e "$MULTILINE\n$TYPELESS\n$FONT\n$COLOUR"
[url=http://murga-linux.com/puppy/viewtopic.php?t=117546]Fatdog64-810[/url]|[url=http://goo.gl/hqZtiB]+Packages[/url]|[url=http://goo.gl/6dbEzT]Kodi[/url]|[url=http://goo.gl/JQC4Vz]gtkmenuplus[/url]

User avatar
Mike Walsh
Posts: 6351
Joined: Sat 28 Jun 2014, 12:42
Location: King's Lynn, UK.

#473 Post by Mike Walsh »

Well, thanks for the replies, everyone. But (and it pains me to say this).....it's like so much Greek to me. Honestly.

For someone who's been using Linux for nearly 5 years (and Puppy for a little over 4 of those), my scripting skill-set is absolutely pathetic. Seriously. As stated in the first post, where scripting is concerned, I'm a raw beginner. To clarify, I can:-

1.) Create & delete files/folders.
2.) Copy & move files/folders around.
3.) Change permissions/ownerships.
4.) Create sym-links, as and where I need them.
5.) Create .desktop entries. And...

...that's about it, really. As I said, pathetic.

I've used YAD on odd occasions to create dialog selector boxes. The one I'm most proud of (:roll:) is attached at the bottom. It's my attempt to create a 'StartCenter', similar to LibreOffice, for the Softmaker FreeOffice packages I managed to accidentally throw together.

I'm under no illusions, here. The attached example could have been crafted (probably with more skill & finesse) by an absolute beginner on their second afternoon with Linux. But I do need to learn some of this other stuff, despite not really having the time (or patience!) to sit down & steadily work my way through an entire Bash scripting course. (I'd like to, but real life, unfortunately, gets in the way far too much.)

So I bumble along, picking up a little bit here, a wee bit there. To give you guys a better idea of what I'm attempting to do here, I'm also attaching the YAD script I'm working on. It's a GUI for running a slide-show with qiv.


Image


This is as far as I've got with the script:-

Code: Select all

#!/bin/sh
#
# GUI for the QIV slideshow
#

yad --no-buttons --center --window-icon=/usr/local/lib/X11/pixmaps/qiv.png --title="Q.I.V Slideshow" --form --width=450 --text="     Please make your selections:-" \
--form --field="Choose image directory:-:MDIR" /root  \
--field="Select timeout interval:-:NUM"  \
--field="Run  Q.I.V  slideshow":fbtn \
The code to run the sideshow is:-

Code: Select all

qiv -s -f -i -d x /path/to/directory
...where:-
-s starts the slide immediately
-f starts it in full-screen
-i disables the on-screen status bar
-d is the delay interval for how long you want each image to show for (in 'x' seconds)

I'd like to assign the output of the first field (the file-chooser window) to a variable, then substitute it for 'path/to/directory'.

I'd then like to assign the output of the second field (the number-chooser) to a variable, and substitute it for 'x'.

I then want to run the command itself, from the 'Run Slideshow' field button.

All this is so that a user can choose the directory of images they want to use, and select the number of seconds they want each image to show for, before moving to the next image. Having selected these two parameters, they can choose to run the slideshow.

I haven't a clue how you would accomplish these tasks.....which just proves how 'pathetic' my skill-set is.

(*shrug*)

So shoot me!!! :lol:


Mike. :wink:
Attachments
FreeOffice.sh.gz
FreeOffice 'StartCenter' (remove the fake .gz extension to view in Geany)
(672 Bytes) Downloaded 63 times

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#474 Post by MochiMoppel »

Mike Walsh wrote:I'd like to assign the output of the first field (the file-chooser window) to a variable, then substitute it for 'path/to/directory'.

I'd then like to assign the output of the second field (the number-chooser) to a variable, and substitute it for 'x'.

I then want to run the command itself, from the 'Run Slideshow' field button.
Well, then replace the echo lines of my first example with

Code: Select all

qiv -s -f -i -d $MYNUMBER "$MYDIR"
That's all.

User avatar
mikeslr
Posts: 3890
Joined: Mon 16 Jun 2008, 21:20
Location: 500 seconds from Sol

#475 Post by mikeslr »

Hi Mike,

Thanks for picking up where I left off. I have it on my ToDo list. Fortunately, life is much easier to cope with now that I rarely remember to look at my ToDo list, :roll: especially when, as in this instance, subsumed in the simple command "ToDo" is the subsidiary command "Learn a Dialog Application" which when conscious recognition of the same is achieved results in :shock:

and Thanks to the other posters for moving this forward.

'tother Mike

p.s. Before I forget, I don't think the attachment was the one you intended.

User avatar
johnywhy
Posts: 879
Joined: Sat 20 Aug 2011, 14:52

#476 Post by johnywhy »

Hi!

this script works great

Code: Select all

#!/bin/sh
BRIGHTNESS=`yad --scale --max-value 12700000`
echo $BRIGHTNESS  > /sys/class/backlight/intel_backlight/brightness
Problem is, the value selected doesn't get applied until the dialog is closed.
How can i grab the scale value continually, without closing the dialog?

i tried --form, but that has same issue.

Code: Select all

yad --form --field="Max size:SCL" '5!1..20!1'
Seems this should be doable without a loop :)

THX
[b]Now[/b]: X-Tahr 2.0! StretchDog! DevuanDog!
[b]Tops[/b]: TarhNOP Vlina-R2 Racy
[b]Used[/b]: Puppeee Precise Lucid Wary Tahrpup Quirky Slacko MacPup Saluki Puppy Studio LxPupTarh Lina-Lite Lina
[i]i ♥ Puppy[/i]

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#477 Post by MochiMoppel »

johnywhy wrote:i tried --form, but that has same issue.

Code: Select all

yad --form --field="Max size:SCL" '5!1..20!1'
What issue? It's only incomplete :lol:

Try this:

Code: Select all

yad --form --field="Max size:SCL" '5!1..20!1' --field="Set brightness:FBTN" 'sh -c "echo %1 > /tmp/brightness"' 
This echoes the value of the scale field to the test file /tmp/brightness. If it works, replace the path with /sys/class/backlight/intel_backlight/brightness. I don't want to try it and mess with my system.

I don't know what the '5!1..20!1' does except setting initial value to 5. Seems to be the same as a simple '5'
SCL is hardcoded to a range of 0..100. You need some multiplication in our command to translate these values to brightness values.

User avatar
johnywhy
Posts: 879
Joined: Sat 20 Aug 2011, 14:52

#478 Post by johnywhy »

Thx, MochiMoppel! Good solution!
MochiMoppel wrote:I don't know what the '5!1..20!1' does except setting initial value to 5. Seems to be the same as a simple '5'
i think you're correct. Seems same function as --value, which sets your starting value. Can you share your source for that command? One limitation of SCL forms is they are fixed at a range of 0 to 100.

Anyway, somebody shared a better method :oops: Try this at a command-line:

Code: Select all

yad --scale --print-partial
https://groups.google.com/forum/#!topic ... rCcH1h7ODo

Here's my final script. Works like a dream. Now i can remove heavy 'power manager' apps!

Code: Select all

#!/bin/sh 
BrPath='/sys/class/backlight/intel_backlight/' 
BrCur=`cat ${BrPath}brightness` 
BrMax=`cat ${BrPath}max_brightness` 
BrMin=$(( (BrMax + (100 - 1)) / 100))   # 100th max-brightness, rounded up to nearest integer 
yad --scale --min-value $BrMin --max-value $BrMax --value $BrCur --print-partial --title 'Set brightness' --width 300 --fixed --sticky --mouse --on-top --escape-ok --button OK --hide-value | while read BrNew 
   do echo "$BrNew" > ${BrPath}brightness 
   done 
https://groups.google.com/forum/#!topic ... rCcH1h7ODo
Attachments
2018-09-05-000720_302x94_scrot.png
(7.09 KiB) Downloaded 419 times
[b]Now[/b]: X-Tahr 2.0! StretchDog! DevuanDog!
[b]Tops[/b]: TarhNOP Vlina-R2 Racy
[b]Used[/b]: Puppeee Precise Lucid Wary Tahrpup Quirky Slacko MacPup Saluki Puppy Studio LxPupTarh Lina-Lite Lina
[i]i ♥ Puppy[/i]

User avatar
fredx181
Posts: 4448
Joined: Wed 11 Dec 2013, 12:37
Location: holland

#479 Post by fredx181 »

Mike Walsh wrote:This is as far as I've got with the script:-

Code:
....
yad --no-buttons --center --window-icon=/usr/local/lib/X11/pixmaps/qiv.png --title="Q.I.V Slideshow" --form --width=450 --text=" Please make your selections:-" \
--form --field="Choose image directory:-:MDIR" /root \
--field="Select timeout interval:-:NUM" \
--field="Run Q.I.V slideshow":fbtn \

The code to run the sideshow is:-

Code:
qiv -s -f -i -d x /path/to/directory
Hi Mike, this should work:

Code: Select all

yad --no-buttons --center --window-icon=/usr/local/lib/X11/pixmaps/qiv.png --title="Q.I.V Slideshow" --form --width=450 --text="     Please make your selections:-" \
--field="Choose image directory:-:MDIR" '/root' \
--field="Select timeout interval:-:NUM" '1' \
--field="Run  Q.I.V  slideshow:FBTN" 'qiv -s -f -i -d %2 %1'
But the dialog stays open, don't know if you want that, this will close the dialog after clicking the button:

Code: Select all

 SLIDESHOW=$(yad --center --window-icon=/usr/local/lib/X11/pixmaps/qiv.png --title="Q.I.V Slideshow" --width=450 --text="     Please make your selections:-" \
--form --field="Choose image directory:-:MDIR" '/root' \
--field="Select timeout interval:-:NUM" "1" \
--buttons-layout=center --button="Run  Q.I.V  slideshow:0")
echo $SLIDESHOW      # total output, next will split
DIR="`echo $SLIDESHOW | cut -d "|" -f 1`"
TIMEOUT="`echo $SLIDESHOW | cut -d "|" -f 2`"
qiv -s -f -i -d $TIMEOUT $DIR
Works for me, but probably can be more compact.

Fred

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#480 Post by MochiMoppel »

step wrote:

Code: Select all

.
.
[ -n "$(echo -e)" ] && echo_e= || echo_e=-e     # Use echo -e except with dash
MULTILINE=$(echo $echo_e "$MULTILINE")          # Convert '\n' in TXT field back into linefeeds 
echo $echo_e "$MULTILINE\n$TYPELESS\n$FONT\n$COLOUR"
Looks a bit ugly. Mike would call it "Greek".
Can't we forget echo -e and just use printf? Would this be an alternative and acceptable for dash?

Code: Select all

printf %b "$MULTILINE\n$TYPELESS\n$FONT\n$COLOUR"

Post Reply