YAD - Tips

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
achim
Posts: 48
Joined: Thu 13 Apr 2017, 19:36
Location: Germany

Keyboard instead of Mouse

#616 Post by achim »

Hello everybody,

How can I move with the keyboard instead of the mouse in a selection dialog created with "--file-selection"?

Best regards, Achim

User avatar
misko_2083
Posts: 114
Joined: Tue 08 Nov 2016, 13:42

Re: Keyboard instead of Mouse

#617 Post by misko_2083 »

achim wrote:Hello everybody,

How can I move with the keyboard instead of the mouse in a selection dialog created with "--file-selection"?

Best regards, Achim
Tab to change the focus to another widget, then arrow keys up and down.
To get to the right pane when you open a yad file selection press shift+tab.

achim
Posts: 48
Joined: Thu 13 Apr 2017, 19:36
Location: Germany

Re: Keyboard instead of Mouse

#618 Post by achim »

misko_2083 wrote:
achim wrote:Hello everybody,

How can I move with the keyboard instead of the mouse in a selection dialog created with "--file-selection"?

Best regards, Achim
Tab to change the focus to another widget, then arrow keys up and down.
To get to the right pane when you open a yad file selection press shift+tab.
Thanks misko_2083!

artsown
Posts: 403
Joined: Wed 12 Sep 2012, 18:35

cpu temperature monitor

#619 Post by artsown »

Say I have a folder holding icons showing temperatures from 10C to
105C. My bash script finds the temp and selects the appropriate icon.
How using yad can I place the icon in the tray? I would arrange to do
this "find temp and display icon" loop every few seconds.

Edit: The icons are from an old tempicon app having .svg extensions,
if that's a concern or consideration. Maybe they can be converted if
necessary.

Art

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

#620 Post by fredx181 »

misko_2083 wrote:Fredx181, if you want to make one, even simpler version of yradio,
you can use the list for navigation between the radio categories and stations.

Here's an example with the notification icon.
....
....
Hey Misko, thanks anyway, but I have no idea how to implement your code in yradio, if you feel like it sometime, maybe you want to do it ?
(also I'm not sure if I understand what the improvement exactly can be :roll: , but it sounds promising what you're suggesting )

Fred

User avatar
lamplinux
Posts: 31
Joined: Mon 21 Jan 2019, 06:05
Contact:

Want to make a YAD Gui Camera Image viewing program.

#621 Post by lamplinux »

Any pointers will be appreciated.

I have security cameras that use proprietary Web view apps but, if my internet is down I can not see my camera output. I can though, capture snapshots from each camera locally using a URL -- *.cgi script in each camera. Here is the flow I want to acomplish.

1. Use wget to get image form camera http:/admin:pw@192.168.1.100 (Done, this works)

2. wget saves images to snampshot.cgi.1, snapshot.cgi.2, snapshot.cgi.3, etc. (every 3 seconds). (Done)

Need to do this:

A. Rename files:
rename snapshot1.cgi.1 ---> camera0000001.jpg
rename snapshot1.cgi.2 ---> camera0000002.jpg
rename snapshot1.cgi.1 ---> camera0000003.jpg
etc........

Use DevedeNG to make a DVD video out of the files, 1 hour long video file.

This will work on Amcrest Cameras and many others. Once it is done, I'll give credit to all and put it on Github under GPL License 2.1+.

I am just stuck at the Renaming part.

Thanks, Bobby

phat7
Posts: 179
Joined: Fri 05 Jun 2015, 08:54

#622 Post by phat7 »

using yad?

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

Re: Want to make a YAD Gui Camera Image viewing program.

#623 Post by MochiMoppel »

lamplinux wrote:A. Rename files:
rename snapshot1.cgi.1 ---> camera0000001.jpg
rename snapshot1.cgi.2 ---> camera0000002.jpg
Try

Code: Select all

cd /path/to/snapshots
for f in snapshot1.cgi* ; do mv $f $(printf 'camera%07d.jpg' ${f##*.}); done

stemsee

Re: cpu temperature monitor

#624 Post by stemsee »

artsown wrote:Say I have a folder holding icons showing temperatures from 10C to
105C. My bash script finds the temp and selects the appropriate icon.
How using yad can I place the icon in the tray? I would arrange to do
this "find temp and display icon" loop every few seconds.

Edit: The icons are from an old tempicon app having .svg extensions,
if that's a concern or consideration. Maybe they can be converted if
necessary.

Art

Code: Select all

mkfifo /tmp/PIPE
exec 4<> /tmp/PIPE

yad --notification --listen <& 4 &
echo "icon:/path/105c.svg" >/tmp/PIPE
svg may need size limit.

EDIT: to clarify, only the 'echo "icon:/*.svg" >/tmp/PIPE' statement needs to be in your loop, which means the icon name needs to be represented with a variable.

Code: Select all

echo "icon:${PATH}${temp}.svg" >/tmp/PIPE
you can do notificaion text in he same way and a menu.

Code: Select all

echo "tooltip:temperature is ${temp}" >/tmp/PIPE
echo "menu:Refresh Temp!bash -c command!/path/to/icon.svg|" >/tmp/PIPE

User avatar
rufwoof
Posts: 3690
Joined: Mon 24 Feb 2014, 17:47

#625 Post by rufwoof »

Rather than storing pre-created svg temperature value files, if you have image magick installed then you could create images dynamically

Code: Select all

# Requires imagemagick

temp=113  # temperature value hard coded here

convert \
    -size 32x32 \
    xc:lightblue \
    -font DejaVu-Sans \
    -pointsize 18 \
    -fill black \
    -gravity center \
    -draw "text 0,0 '${temp}'" \
    image.png
That creates a .png, so you'd have to amend the code that stemsee posted to

Code: Select all

echo "icon:/path/image.png" >/tmp/PIPE
[size=75]( ͡° ͜ʖ ͡°) :wq[/size]
[url=http://murga-linux.com/puppy/viewtopic.php?p=1028256#1028256][size=75]Fatdog multi-session usb[/url][/size]
[size=75][url=https://hashbang.sh]echo url|sed -e 's/^/(c/' -e 's/$/ hashbang.sh)/'|sh[/url][/size]

artsown
Posts: 403
Joined: Wed 12 Sep 2012, 18:35

#626 Post by artsown »

@stemsee & rufwoof
Thanks for your inputs. Meanwhile, SFR provided me with a working
model of the yad method of placing icons on a tray. I've put up my
latest version 1.4 of traytemp in the utilities section.

Art

stemsee

#627 Post by stemsee »

Yad notification screen rotation. Left Click icon for normal. Right click for menu.

Code: Select all

#!/bin/sh
connected=`xrandr | grep connected | cut -f1 -d' ' | head -1`
yad --notification --listen --text="Rotate Screen" --tray-icon="/usr/share/pixmaps/picdrop.png" --command="bash -c 'xrandr --output $connected --rotate normal'" --menu="Rotate Left!xrandr --output $connected --rotate left!|Rotate right!xrandr --output $connected --rotate right!|Rotate Inverted!xrandr --output $connected --rotate inverted!|" 
edit
this version changes the trray icon to indicate rotation, using up down left right arrows (make your own!)

Code: Select all

#!/bin/sh
mkfifo /tmp/RPIPE
exec 3<> /tmp/RPIPE
export connected=`xrandr | grep connected | cut -f1 -d' ' | head -1`
function left (){
	xrandr --output $connected --rotate left
	echo "icon:/usr/share/pixmaps/left.png" >/tmp/RPIPE
}; export -f left
function right (){
	xrandr --output $connected --rotate right
	echo "icon:/usr/share/pixmaps/right.png" >/tmp/RPIPE
}; export -f right
function inverted (){
	xrandr --output $connected --rotate inverted
	echo "icon:/usr/share/pixmaps/inverted.png" >/tmp/RPIPE
}; export -f inverted
function normal (){
	xrandr --output $connected --rotate normal
	echo "icon:/usr/share/pixmaps/normal.png" >/tmp/RPIPE
}; export -f normal

yad --notification --listen --text="Rotate Screen" --tray-icon="/usr/share/pixmaps/normal.png" --command="bash -c normal" --menu="Rotate Left!bash -c left!/usr/share/pixmaps/left.png|Rotate right!bash -c right!/usr/share/pixmaps/right.png|Rotate Inverted!bash -c inverted!/usr/share/pixmaps/inverted.png|" <&3
EDIT: I added /etc/rotate file to remember last orientation so it could be reused easily/auotmatically

Code: Select all

#!/bin/sh
# yad tray screen rotation "ytsr" b stemsee
# copyright (c) 2019 Marcos M Contant
[[ "`whoami`" != "root" ]] && exec sudo -E -S ${0} "$\"" 
running=`ps -e | grep rotate | wc -l` 
[[ "$running" -gt 2 ]] && exit #check if running, one instance only
export OUTPUT_CHARSET=UTF-8
mkfifo /tmp/RPIPE
exec 3<> /tmp/RPIPE
export connected=`xrandr | grep connected | cut -f1 -d' ' | head -1`

function left (){
	xrandr --output $connected --rotate left
	echo "icon:/usr/share/pixmaps/left.png" >/tmp/RPIPE
	echo "left" >/etc/rotate
}; export -f left
function right (){
	xrandr --output $connected --rotate right
	echo "icon:/usr/share/pixmaps/right.png" >/tmp/RPIPE
	echo "right" >/etc/rotate
}; export -f right
function inverted (){
	xrandr --output $connected --rotate inverted
	echo "icon:/usr/share/pixmaps/inverted.png" >/tmp/RPIPE
	echo "inverted" >/etc/rotate

}; export -f inverted
function normal (){
	xrandr --output $connected --rotate normal
	echo "icon:/usr/share/pixmaps/normal.png" >/tmp/RPIPE
	echo "normal" >/etc/rotate
}; export -f normal
function restate (){
	state=`cat /etc/rotate`
	[[ -z "$state" ]] && state=normal
	xrandr --output $connected --rotate $state
	echo "icon:/usr/share/pixmaps/$state.png" >/tmp/RPIPE
	echo "$state" >/etc/rotate
}; export -f restate
bash -c restate &
yad --notification --listen --text="Rotate Screen" --tray-icon="/usr/share/pixmaps/normal.png" --command="bash -c normal" --menu="Rotate Left!bash -c left!/usr/share/pixmaps/left.png|Rotate right!bash -c right!/usr/share/pixmaps/right.png|Rotate Inverted!bash -c inverted!/usr/share/pixmaps/inverted.png|" <&3
Attachments
2019-07-10-150857_257x150_scrot.png
(9.88 KiB) Downloaded 311 times
Last edited by stemsee on Wed 31 Jul 2019, 13:38, edited 1 time in total.

achim
Posts: 48
Joined: Thu 13 Apr 2017, 19:36
Location: Germany

YAD Wrapper for youtube-dl

#628 Post by achim »

Hello everybody,

The code "YAD Wrapper for youtube-dl" by Misko-2083 (http://murga-linux.com/puppy/viewtopic. ... &start=300) needs to be changed slightly. The URL is no longer valid. Unfortunately I do not know the new address, so I need your help for the correction.

Many thanks

Code: Select all

...
function ytdl_version () {
    echo "#Checking youtube-dl version" >> "$ytdpipe"
    wget --spider --user-agent="Mozilla/5.0 Gecko/20100101" --timeout=30 -q "https://rg3.github.io/youtube-dl/" -O /dev/null
    if [[ "$?" -ne "0" ]]; then
       echo "#Can't connect to youtube-dl server site" >> "$ytdpipe"
    fi
    ytdlcv=$(youtube-dl --version)
    ytdllv=$(wget -O- -q "https://rg3.github.io/youtube-dl/update/LATEST_VERSION")
    if [[ "$ytdlcv" == "$ytdllv" ]]; then
   echo "#youtube-dl is up-to-date"  >> "$ytdpipe"
    else
   echo "#youtube-dl update is available" >> "$ytdpipe"
    fi
} 
...

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

#629 Post by fredx181 »

Hi achim, can't see what's wrong with the code (or url), to test I removed the writing to pipe ( >> "$ytdpipe") and it checks ok for me if a youtube-dl update is available or not.

Code: Select all

function ytdl_version () {
    echo "#Checking youtube-dl version"
    wget --spider --user-agent="Mozilla/5.0 Gecko/20100101" --timeout=30 -q "https://rg3.github.io/youtube-dl/" -O /dev/null
    if [[ "$?" -ne "0" ]]; then
       echo "#Can't connect to youtube-dl server site"
    fi
    ytdlcv=$(youtube-dl --version)
    ytdllv=$(wget -O- -q "https://rg3.github.io/youtube-dl/update/LATEST_VERSION")
    if [[ "$ytdlcv" == "$ytdllv" ]]; then
   echo "#youtube-dl is up-to-date"
    else
   echo "#youtube-dl update is available"
    fi
}
ytdl_version
Output:

Code: Select all

# ytdl_version
#Checking youtube-dl version
#youtube-dl is up-to-date
Fred

achim
Posts: 48
Joined: Thu 13 Apr 2017, 19:36
Location: Germany

#630 Post by achim »

Hello Fred

I experimented a bit with the code and made a mistake. I have found this now and everything is working again.

Thanks again!

achim

Wognath
Posts: 423
Joined: Sun 19 Apr 2009, 17:23

accept input at timeout

#631 Post by Wognath »

Hello,
Can yad accept input at timeout, without hitting enter or OK? Like this:

Code: Select all

z=`Xdialog --timeout 5 --interval 5000 --stdout --inputbox "Enter a number and wait" 0 0` ; echo $z
Sorry if the answer is somewhere in this long thread; I looked :shock: Thanks in advance

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

#632 Post by step »

I don't think it can but I'll be happy to stand corrected. There's an --always-print-result option, but the yad manual says
--always-print-result
Print result for any of the return codes. This options doesn't work if timeout was reached or Escape was pressed.
[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]

phat7
Posts: 179
Joined: Fri 05 Jun 2015, 08:54

Re: accept input at timeout

#633 Post by phat7 »

Wognath wrote:Can yad accept input at timeout, without hitting enter or OK? Like this:

Code: Select all

z=`Xdialog --timeout 5 --interval 5000 --stdout --inputbox "Enter a number and wait" 0 0` ; echo $z
Nice

Wognath
Posts: 423
Joined: Sun 19 Apr 2009, 17:23

#634 Post by Wognath »

SIGUSR1: Close dialog with 0 exit code. :D

Code: Select all

 yad --entry > /tmp/z & sleep 5 ; pkill -SIGUSR1 yad ; z=$(</tmp/z)

If more than one yad running:

Code: Select all

yad --title unique    ...    pkill -SIGUSR1 -f "yad.*unique"

phat7
Posts: 179
Joined: Fri 05 Jun 2015, 08:54

#635 Post by phat7 »

Code: Select all

z=$(yad --entry & sleep 5 ; pkill -SIGUSR1 yad)
This may work even better:

Code: Select all

z=$(timeout -s SIGUSR1 5 yad --entry)

Post Reply