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
lamplinux
Posts: 31
Joined: Mon 21 Jan 2019, 06:05
Contact:

Menu Context Command --html "open"

#581 Post by lamplinux »

What is the command that is used to get the URL window to open in the Yad --html Dialog ?

For example, Right Click --> in --html Dialog --> Context Menu = "Open"

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

#582 Post by step »

Yad 0.42.0 was released last week https://github.com/v1cont/yad/releases. New features and bug fixes.
It's the last version with gtk2 support.
yad's author wrote: upcoming release (0.42.0) will be the last release with gtk2 support. next releases will depends on gtk 3.22 (with porting to gtk4 in mind) and with versioning in format X.Y where X - a current version, starting from 1, and Y - current patchset.

dialog set will be hardly modified, for example, entry will be dropped, and both progress dialogs will be merged into a single one and some gtk3 specific dialogs like appchooser will be implemented. predefined (aka stock) items will have prefix yad-, and must be translated with yad, so any help with this will be highly appreciated.

support of tray icon will be a compile-time option, and may be dropped too in a future.
[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]

stemsee

#583 Post by stemsee »

How can it be known which tab is selected in a multi-tabbed yad gui. So that the Yad frame which swallows the tabs, and has several buttons can assign the buttons to work in the selected tab, maybe differently than when in another tab? Is it possible without closing and reopening?

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

#584 Post by step »

stemsee wrote:How can it be known which tab is selected in a multi-tabbed yad gui. So that the Yad frame which swallows the tabs, and has several buttons can assign the buttons to work in the selected tab, maybe differently than when in another tab? Is it possible without closing and reopening?
Not exactly what you're looking for but close. I found this short video that demonstrates a navigation system. You'd have to contact the site's author for more info. My guess is that it's implemented as paned top/bottom dialog. The top section looks like an --icons box. The bottom section looks like a multi-button --form. Top and bottom can communicate via a FIFO. Top section listens on the FIFO like this (untested):

yad --icons --listen --plug=1234 &

Any button of the bottom form would then write (to the FIFO): Ctrl-J followed by the list of new icons/commands (see yad help for Iconbox for details). This effectively would switch the contents of the top section.

Caveat: I'm guessing the whole thing.

You could replace --icons in the top section with any other yad widget that accepts --listen and can be reset by sending Ctrl-J to it. For instance, --list satisfies both conditions. You couldn't put a --notebook in the top section.
[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]

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

#585 Post by step »

stemsee wrote:How can it be known which tab is selected in a multi-tabbed yad gui. So that the Yad frame which swallows the tabs, and has several buttons can assign the buttons to work in the selected tab, maybe differently than when in another tab? Is it possible without closing and reopening?
Not exactly what you're looking for but close. I found this short video that demonstrates a navigation system. You'd have to contact the site's author for more info. My guess is that it's implemented as paned top/bottom dialog. The top section looks like an --icons box. The bottom section looks like a multi-button --form. Top and bottom can communicate via a FIFO. Top section listens on the FIFO like this (untested):

yad --icons --listen --plug=1234 &

Any button of the bottom form would then write (to the FIFO): Ctrl-J followed by the list of new icons/commands (see yad help for Iconbox for details). This effectively would switch the contents of the top section.

Caveat: I'm guessing the whole thing.

You could replace --icons in the top section with any other yad widget that accepts --listen and can be reset by sending Ctrl-J to it. For instance, --list satisfies both conditions. You couldn't put a --notebook in the top section.
[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]

stemsee

#586 Post by stemsee »

Hi step

That's a good solution for paned which is limited to two panes and the frame. I am thinking of 4 or more tabs. When a tab is selected yad internally sends signals so it is known which is the last tab selected, I really want to know how to get at that signal/info programmatically, internally without using xdotool. Maybe I will need to post a feature request with Victor.

stemsee

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

#587 Post by step »

stemsee wrote:Hi step

That's a good solution for paned which is limited to two panes and the frame. I am thinking of 4 or more tabs. When a tab is selected yad internally sends signals so it is known which is the last tab selected, I really want to know how to get at that signal/info programmatically, internally without using xdotool. Maybe I will need to post a feature request with Victor.

stemsee
If you do request a feature make sure to tell Victor it's for GTK2 because he's announced future versions won't support GTK2 anymore.

Fatdog64-800 still requires GTK2. Don't know about which Puppies and Dogs do too.
[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]

lika
Posts: 7
Joined: Tue 07 Aug 2018, 01:30

#588 Post by lika »

misko_2083 wrote:Thanks fredx181, don't know why I thought that DIR field in the form dialog doesn't quote the path. :roll:

lika Added pv command to display the progress. One more dependancy to install but I see no other way for now.

X window button is managed by the window manager so intercepting it is impossible. It's only possible to get the exit status 252 when the window is closed via X.That's why I added undecoratzed to pprevent the paned dialog from closing and --no-escape to prevent closing the same dialog if Escape was pressed. That is the simplest solution. Anything else would be too complex.

To use the checkboxes in the function install_app you would need to check if $2 and $3 are true or false.

The script now displays extra dialogs and prevents them from opening multiple times e.g.if the cancel and abort buttons are clicked several times. This is working for me:

Code: Select all

#!/bin/bash

if ! hash pv; then
   yad --text "install pv first"
   exit 1
fi

export faextraxt='bash -c "install_app %1 %2 %3 %4"'

# We need this to store the main proces ID
export main_proc_id=$(mktemp -u --tmpdir fpid.XXXXXXXX)

export progress_pipe=$(mktemp -u --tmpdir ftd.XXXXXXXX)
mkfifo "$progress_pipe"

export percentage_pipe=$(mktemp -u --tmpdir ftd2.XXXXXXXX)
mkfifo "$percentage_pipe"

export form_pipe=$(mktemp -u --tmpdir ftd3.XXXXXXXX)
mkfifo "$form_pipe"

trap "rm -f $progress_pipe $percentage_pipe $form_pipe $main_proc_id" EXIT

fakey=$(($RANDOM * $$))

function install_app
{
# Form fields are read in a cycle 1-4, each cycle sets new values

# Disables all the form fields when the install starts
echo "@disabled@" > "$form_pipe"
echo "@disabled@" > "$form_pipe"
echo "@disabled@" > "$form_pipe"
echo "@disabled@" > "$form_pipe"

echo "#Selected extraction path: $1" >> "$progress_pipe"
echo "#" >> "$progress_pipe"
echo "#Add a shortcut in the applications menu : $2" >> "$progress_pipe"
echo "#Add a desktop shortcut : $3" >> "$progress_pipe"
echo "#" >> "$progress_pipe"


  echo "#Preparing to extract..." >> "$progress_pipe"

   >"$main_proc_id"
   while read -r line; do
     # If line is a integer number
     if [[ "$line" == +([0-9]) ]];then
        echo "$line" >> "$progress_pipe"
     else
        echo "#$line" >> "$progress_pipe"
     fi

   done < "$percentage_pipe" &
   LOOP_PID="$!"

    # main process example for a demonstration purpose
    # for i in {1..100}; do echo "$i %" 2>&1 >> $percentage_pipe; sleep .1; done & echo $! > "$main_proc_id"

    pv -n archive.tar.xz 2>$percentage_pipe | xzcat | tar xp -C "$1" -v 2>&1 >> $percentage_pipe & echo $! > "$main_proc_id"

    # Wait here
    # Wait returns exit status ${?}
    # It's stderr is redirected to /dev/null to prevent kill command to print messages
    wait $(<$main_proc_id) 2>/dev/null

    if [[ "$?" = 0 ]]
    then
         echo "100%" >> "$progress_pipe"
         echo "#Install completed." >> "$progress_pipe"
         kill "$LOOP_PID"
         >$main_proc_id
         yad --text="Install successfull" --button="gtk-ok:0"  &
    elif [[ ! -s "$main_proc_id" ]]; then
         echo "#Install canceled." >> "$progress_pipe"
         kill "$LOOP_PID"
         >$main_proc_id
    else
         echo "#Install error." >> "$progress_pipe"
         kill "$LOOP_PID"
         >$main_proc_id
    fi

    # Resets the field values when the install ends
    echo "$1" > $form_pipe
    echo "$2" > $form_pipe
    echo "$3" > $form_pipe
    echo "$faextraxt &" > $form_pipe
}
export -f install_app

function get_pid_and_kill () {
Sure_Command='yad --text=Are you sure you want to cancel the installation? --button=gtk-yes:0 --button=gtk-no:1'
Sure_Command_PID="$(ps -eo pid,cmd | grep -F "$Sure_Command" | grep -v "grep" | awk '{ print $1 }')"

if [[ -s "$main_proc_id" ]] && [[ "$Sure_Command_PID" == "" ]] && yad --text="Are you sure you want to cancel the installation?" --button="gtk-yes:0" --button="gtk-no:1"; then
  if [[ -s "$main_proc_id" ]]; then
     BCKUPID="$(<$main_proc_id)"
     >"$main_proc_id"
     kill $BCKUPID 2>/dev/null
     sleep 1
  fi
   # The special yad variable $YAD_PID stores the main window PID
   # killing that PID closes the window
  [[ "$1" == "CLOSE" ]] && kill -s SIGUSR1 $YAD_PID
elif [[ ! -s "$main_proc_id" ]] ; then
  [[ "$1" == "CLOSE" ]] && kill -s SIGUSR1 $YAD_PID
fi

}
export -f get_pid_and_kill

exec 3<> $progress_pipe
exec 4<> $percentage_pipe
exec 5<> $form_pipe

yad --plug="$fakey" --tabnum=1 --form \
    --field="Choose a folder:DIR" \
    --field="Add a shortcut in the applications menu:CHK" \
    --field="Add a desktop shortcut:CHK" \
    --field="Install!system-software-install:fbtn" --cycle-read <&5 &

    # This is the initial cycle that sets the form field values
    echo "${HOME}" > $form_pipe         # set default folder in this line
    echo "TRUE" > $form_pipe               # default first checkbox value
    echo "FALSE" > $form_pipe              # default second checkbox value
    echo "$faextraxt &" > $form_pipe

yad --plug="$fakey" --tabnum=2 --window-icon="$ICON" --progress \
--enable-log="Show log" --log-height=100 --tail --borders=5 <&3 &


yad --paned --key="$fakey" --buttons-layout=edge \
    --button="gtk-close":'bash -c "get_pid_and_kill CLOSE" 2>/dev/null' \
    --button="Abort!gtk-stop":'bash -c "get_pid_and_kill" 2>/dev/null' \
    --text="" --title="TEST" --window-icon="$ICON" --center \
    --no-escape --undecorated & MAIN_PID=$!

# Redirecting kill output from get_pid_and_kill function to /dev/null
wait $MAIN_PID 2>/dev/null

exec 3>&-
exec 4>&-
exec 5>&-
The script now displays extra dialogs and prevents them from opening multiple times e.g.if the cancel and abort buttons are clicked several times.
I tried this script, but the dialog opens every time if I click Cancel or Abort buttons.
Now I try to make a display progress and log output with 7z only (without tar), but it turns out only a log. Can you help how to do this?
This line:

Code: Select all

pv -n | "$percentage_pipe" | 7za x archive.7z -bb3 -o"$1" 2>&1 >> "$percentage_pipe" & echo "$!" > "$main_proc_id"
-bb3 is output log level

Is there a way to make an Abort button inactive while unpacking? Even better to make one "Abort and Quit" button (fbtn) below the Install button and progress bar + log at the bottom of the window?

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

#589 Post by Argolance »

Bonsoir,
May be is there an answer among the 40 pages of this thread. If yes, just a link would be appreciated, if no:
For example, this works fine:

Code: Select all

yad --text-info --back=red --fore=white < /root/\.history --fontname=Monospace
How could it work clicking a notification icon to display the text?
I tried this and many other combinations but without success:

Code: Select all

yad --notification --text "TEXT TEST" --command="yad --text-info --back=red --fore=white < /root/\.history --fontname=Monospace" &
Thank you for your attention.

[EDIT] : when I couldn't believe it, I finally found a solution (for those who would be interested):

Code: Select all

text () {
yad --text-info --back=red --fore=white < /root/\.history --fontname=Monospace
}
export -f text
yad --notification --icon-size=24 --auto-kill --text "TEXT TEST" --command="bash -c text" &
Cordialement.

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

#590 Post by fredx181 »

Hi Argolance, I see you found solution, but just for info, it can work without function by using --filename= , e.g.:

Code: Select all

yad --notification --text "TEXT TEST" --command="yad --text-info --back=red --fore=white --fontname=Monospace --filename=/root/\.history" &
Fred

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

#591 Post by Argolance »

Bonjour,
Thanks fredx181!
It is why I said "a" solution but not "the" solution...
The more I use yad, the more I appreciate and discover the extent of what can be done with it. Not to mention the work of smokey01 and a few others: huge and so useful!

Cheers.
Last edited by Argolance on Sun 07 Apr 2019, 21:32, edited 1 time in total.

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

#592 Post by fredx181 »

@Argolance Ah, catched your avatar, now I know, you are fooling us all :lol:
Attachments
Argolance-is-fooling-us.png
(2.56 KiB) Downloaded 432 times

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

#593 Post by fredx181 »

Replying to question from here:
http://murga-linux.com/puppy/viewtopic. ... 66#1024466

Hi achim, it looks like that the problem is that the commands are all on one line, separating them makes it work for me ( I've put an empty line between the command lines to make the separation more clear) :

Code: Select all

#!/bin/bash

INPUT=$(yad --width=600 --height=400 --file-selection --file-filter='*.mp3 *.mp4 *.avi')
 
eval $(yad --width=400 --form --field=start --field=end --field=output:SFL "00:00:00" "00:00:00" "${INPUT/%.*}-out.${INPUT##*.}" | awk -F'|' '{printf "START=%s\nEND=%s\nOUTPUT=\"%s\"\n", $1, $2, $3}')
 
[[ -z $START || -z $END || -z $OUTPUT ]] && exit 1

DIFF=$(($(date +%s --date="$END")-$(date +%s --date="$START")))
 
OFFSET=""$(($DIFF / 3600)):$(($DIFF / 60 % 60)):$(($DIFF % 60))
 
ffmpeg -ss "$START" -t "$OFFSET" -i "$INPUT" "$OUTPUT"
The resulting quality is not the best IMO (from what I tested), but that's another story.

Fred

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

#594 Post by achim »

Hello Fred,

Thanks for your help, that's how it works for me.
I put the quality over the command "ffmpeg -ss", where you probably mean the audio result. Do you have a better suggestion for that?

achim

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

#595 Post by fredx181 »

achim wrote:Hello Fred,

Thanks for your help, that's how it works for me.
I put the quality over the command "ffmpeg -ss", where you probably mean the audio result. Do you have a better suggestion for that?

achim
Specially I found the video quality not good, is ok for me when using copy, then final ffmpeg line:

Code: Select all

ffmpeg -i "$INPUT" -acodec copy -vcodec copy -ss "$START" -t "$OFFSET" "$OUTPUT"

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

#596 Post by Argolance »

fredx181 wrote:@Argolance Ah, catched your avatar, now I know, you are fooling us all :lol:
Ah ah!
+1
:D

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

#597 Post by achim »

Hello Fred,

that worked great. Thanks again for the support. Now I would like to adjust the selection of exact filter and possibly subsequently to the filter result via fi or esac different parameters for ffmpeg. So far, I've created the code like this:
OUTFILETYPE=$(yad --list --title="Select File Type" --text="file type selection" \
--column="Select" --column="File Type" --radiolist false avi true mp4 false mp3)
I do not know how to connect it to the code above. Do you have a suggestion?

achim

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

#598 Post by fredx181 »

Hi achim, I'm not sure at which point in the script you'd like to add this selection dialog, anyway, maybe something like this ? (added --print-column=2) :

Code: Select all

OUTFILETYPE=$(yad --list --title="Select File Type" --text="file type selection" \
--column="Select" --column="File Type" --radiolist --print-column=2 false avi true mp4 false mp3)
[ $? -ne 0 ] && exit

if [ "$OUTFILETYPE" = "avi|" ]; then
ffmpeg ... ...
fi
if [ "$OUTFILETYPE" = "mp4|" ]; then
ffmpeg ... ...
fi
if [ "$OUTFILETYPE" = "mp3|" ]; then
ffmpeg ... ...
fi
EDIT:
Or maybe just this (no selection dialog, if condition based on the extension of $OUTPUT, e.g. avi ):

Code: Select all

if [ "${OUTPUT##*.}" = "avi" ]; then
ffmpeg ... ...
fi
if [ "${OUTPUT##*.}" = "mp4" ]; then
ffmpeg ... ...
fi
if [ "${OUTPUT##*.}" = "mp3" ]; then
ffmpeg ... ...
fi
Fred

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

#599 Post by achim »

Hello Fred,

I have now decided once for this variant:
#!/bin/bash

INPUT=$(yad --width=1000 --height=600 --file-selection --file-filter='*.avi' --file-filter='*.mp3' --file-filter='*.mp4')

eval $(yad --width=400 --form --field=start --field=end --field=output:SFL "00:00:00" "00:00:00" "${INPUT/%.*}-out.${INPUT##*.}" | awk -F'|' '{printf "START=%s\nEND=%s\nOUTPUT=\"%s\"\n", $1, $2, $3}')

[[ -z $START || -z $END || -z $OUTPUT ]] && exit 1

DIFF=$(($(date +%s --date="$END")-$(date +%s --date="$START")))

OFFSET=""$(($DIFF / 3600)):$(($DIFF / 60 % 60)):$(($DIFF % 60))

if [ "${OUTPUT##*.}" = "avi" ]; then
ffmpeg ... ...
fi
if [ "${OUTPUT##*.}" = "mp4" ]; then
ffmpeg -ss "$START" -t "$OFFSET" -i "$INPUT" "$OUTPUT"
fi
if [ "${OUTPUT##*.}" = "mp3" ]; then
ffmpeg ... ...
fi
exit 1
Gladly I would have your suggestion with the parameter choice for FFMPEG taken over, however, then each time with the new video file the first 4-5 seconds without picture, but with sound. Of course, the code is not finished yet, I can think of a lot more. If you have any other suggestions, feel free to sign up again. I was very happy about your help and hope that I can return the favor.

achim

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

#600 Post by achim »

Hi Fred,

if you're interested, I changed the parameter order for the FFMPEG command as follows:

Code: Select all

ffmpeg -ss "$START" -t "$OFFSET" -i "$INPUT" -acodec copy -vcodec copy "$OUTPUT"
So everything works to my satisfaction.

Best regards

achim

Post Reply