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
fredx181
Posts: 4448
Joined: Wed 11 Dec 2013, 12:37
Location: holland

#511 Post by fredx181 »

Hi Mike,
Question, if I may? Is 'awk' actually a separate language used within Bash?
It's separate program with its own binary, not a bash builtin.
I see you're using the '*' symbol in the print statement. Am I right in thinking that here it's simply being used as the 'multiplication' symbol, rather than a 'wild card'?
Yes, multiplication.
Anyway; just tried it out, and.....it works beautifully, Fred. The whole reason I wanted to do this was because I liked the idea of a straight-forward true 'brightness' control; RedShift has one built-in, as you know, but it's actually manipulating the gamma ramp, and (on my monitor at least) I get slightly odd side-effects from it.
Ok, good to hear it works. The "redshiftgui" btw, has also a 'normal' brightness control (not manipulating the gamma)

https://sourceforge.net/projects/redshiftgui/files/
I see why you set 5 as a minimum!
Yes, better for who's afraid of the dark :) Yes, 10 may be better (in fact it is the same as 0.1 setting for xrandr)

EDIT:
I'll probably supply a recent version of YAD for it, too, but I'll do so as a separate package this time, rather than building it in
I agree, always better to keep it separate, in case someone downloads your "brightness slider" .pet who's running a 64-bit OS.
If a 32-bit yad binary would be inside the pet, then yad probably doesn't work anymore on 64-bit (if it's being overwritten).

Fred

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

#512 Post by step »

This >gist deals with an issue you may encounter while developing tabbed/paned yad dialogs. Killing the dialog (with kill [options]) may lead to unreleased shared memory. The linked script can assist in reclaiming the shared memory.
[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
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

Buttons labels not translated anymore...

#513 Post by Argolance »

Bonjour,
I recently upgraded yad 0.33 to the latest 0.40 release and, with some small modifications of my scripts using it (especially yad --notification > icon size) all is right. One thing though, the button labels are now in English (close, execute, ok, cancel and so on).
What's wrong?

Thanks.
Cordialement.

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

#514 Post by fredx181 »

Discussing Here about display of gif images for gtkdialog-splash.
Always thought display of animated .gif isn't possible with yad, but it is: with the --picture option, e.g:

Code: Select all

yad --picture --size=orig --filename=/usr/share/pixmaps/launch.gif --width=280 --height=190 --center --inc=2 --text="<b>Working...</b>" --no-buttons --undecorated --text-align=center --timeout=13
Fred
Attachments
try.gif
Display animated .gif with yad
(253.98 KiB) Downloaded 1014 times

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

Re: Buttons labels not translated anymore...

#515 Post by step »

Argolance wrote:Bonjour,
I recently upgraded yad 0.33 to the latest 0.40 release and, with some small modifications of my scripts using it (especially yad --notification > icon size) all is right. One thing though, the button labels are now in English (close, execute, ok, cancel and so on).
What's wrong?

Thanks.
Cordialement.
How did you upgrade, did you compile the project from github source? https://github.com/v1cont/yad
There you will find a folder named po, inside it a file named fr.po, which needs to be compiled into fr.mo with msgfmt -o fr.mo fr.po, and copied to /usr/share/locale/fr/LC_MESSAGES/yad.mo. This is the standard way to add translations for GNU gettext.
[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
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

Re: Buttons labels not translated anymore...

#516 Post by Argolance »

Bonjour,
step wrote:How did you upgrade, did you compile the project from github source? https://github.com/v1cont/yad
There you will find a folder named po, inside it a file named fr.po, which needs to be compiled into fr.mo with msgfmt -o fr.mo fr.po, and copied to /usr/share/locale/fr/LC_MESSAGES/yad.mo. This is the standard way to add translations for GNU gettext.
Thank you for replying.
I compiled it from github source and the mo files were automatically generated. But it seems that the problem doesn't depend on any translation file but more on an integration of yad to the system. For example, gtkdialog has no translation file but all the main button labels of the gtkdialog GUIs are displayed in the current language.
It seems to me that there is something else to configure, but what and where?

Cordialement.

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

#517 Post by Argolance »

Bonjour,

Code: Select all

yad --borders=10 --width=400 --undecorated --mouse --skip-taskbar --on-top --fixed --sticky\
		 --entry-label="$(gettext 'Command:')" --entry --editable --entry-text list --column="command"\
		 --button="$(gettext 'Clear list')!gtk-clear":2 --button="$(gettext 'Run')!gtk-execute":0 --button="$(gettext 'Cancel')!gtk-cancel":1
How could I add such a check box in the window?

Code: Select all

yad --form --field check:chk
Additional question: why do I get this warning message in console:

Code: Select all

(yad:17944): Gtk-WARNING **: Error loading icon from file 'yad':
	Couldn't recognize the image file format for file 'yad'
Thanks.
Cordialement.

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

#518 Post by fredx181 »

Hi Argolance, something like this maybe ?

Code: Select all

yad --borders=10 --width=400 --undecorated --mouse --skip-taskbar --on-top --fixed --sticky --form  \
--field "$(gettext 'Command:'): " "list" \
--field check:chk \
--button="$(gettext 'Clear list')!gtk-clear":2 --button="$(gettext 'Run')!gtk-execute":0 --button="$(gettext 'Cancel')!gtk-cancel":1
The first field can also be this (using "txt")

Code: Select all

--field "$(gettext 'Command:'):txt" "list" \
But then the text window will be larger.

In your code you have also --column="command", I don't think it's doing anything, as far as I know it only applies for when using --list.
Additional question: why do I get this warning message in console:
Code:
(yad:17944): Gtk-WARNING **: Error loading icon from file 'yad':
Couldn't recognize the image file format for file 'yad'
Could be because you don't have the yad icon in one of the icon paths.

Fred

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

#519 Post by Argolance »

Bonjour,
Thanks for replying.
(Sorry, I don't know why, but I do not receive any notification when replies are posted to the messages :? !)
Your lines work - I already tried this - but the 3 buttons "Clear", "Run" and "Cancel" are not displayed anymore.
fredx181 wrote:Could be because you don't have the yad icon in one of the icon paths.
The yad icon is in /usr/share/pixmaps. Probably due to the way I compiled yad (--prefix /usr)? Copying the icon to /usr/local/share/pixmaps solves the problem and this may give an answer to my question above about the button labels...

Cordialement.

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

#520 Post by Mike Walsh »

@ Argolance:-

You don't necessarily need to worry about placing the icon in one of the *recognized* paths. You could put the icon anywhere you wanted to, as long as you then give the FULL path to its location.

I know folks think I'm odd.....because even though I place icons in the accepted 'paths', I still give the full path-name to make absolutely certain I get it!


Mike. :wink:

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

#521 Post by Argolance »

Bonjour,
Mike Walsh wrote:I know folks think I'm odd.....because even though I place icons in the accepted 'paths', I still give the full path-name to make absolutely certain I get it!
I'm not of those who think so: I usually do the same! :wink:
My script doesn't have any icon except the yad one (that I copied to /usr/local/share/pixmaps but should be ignored because the window is "undecorated") and the gtk stock icons for which the problem of the path does not arise either...
I recompiled yad but the standard button labels (ok, cancel..) are still in English while there were in French running the 0.30 yad version.

Cordialement.

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

#522 Post by misko_2083 »

Xlunch is one of Fredx181's favourite applications :lol: ,
however yad can also serve a fullscreen launcher.

Here's what happened:

A dev from a distro I never heard of before, with minimalistic goals, asked me:
miyo wrote: What I'm trying to do is...create a full-screen application launcher that will close AFTER a user clicks on an application. Here is the basic command that I'm working with...

yad --icons --read-dir=/usr/share/applications --fullscreen --sort-by-name --undecorated --single-click --skip-taskbar

If I can figure this out, I will also add...

--no-buttons

...to the command.

I know that you can close yad after clicking on a button, but I can't find a way to close it after clicking on one of the icons in the window.

I've tried xlunch, and it works well. smile

I'm just trying to keep extra packages out if I can...so that there are no packages (or as few packages as possible) not included in the system's repositories. wink

If I can't figure this out, I may use xlunch.
A light bulb flashed over my head , :idea:
and told him to get the process id of the yad window and use the strace to watch for SIGCHLD signal.
When the SIGCHLD signal is emited, send SIGURS1 signal to yad.

Code: Select all

#!/bin/bash
yad --icons --read-dir=/usr/share/applications \
--fullscreen --sort-by-name --undecorated \
--single-click --skip-taskbar --no-buttons & ICONS_PID=$!

strace -p $ICONS_PID -e trace=signal -s 32 2>&1 \
| while read -r line; do
        if [[ $line =~ "--- SIGCHLD" ]];then
           kill -s SIGUSR1 $ICONS_PID
           break
         fi
done
Signal SIGUSR1 closes the yad dialog with 0 exit status.

Problem bypassed.

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

#523 Post by MochiMoppel »

misko_2083 wrote:A light bulb flashed over my head , :idea:
and told him to get the process id of the yad window and use the strace to watch for SIGCHLD signal.
...if he has the strace command installed. My Puppy hasn't.

This is another idea. Works similar to a menu. yad is killed when it loses focus:

Code: Select all

#!/bin/bash
yad --icons --read-dir=/usr/share/applications \
 --fullscreen --sort-by-name --undecorated \
 --single-click --skip-taskbar --no-buttons & ICONS_PID=$!

sleep 1	#allow some time to create yad window
ACTIVEWINDOW=$(xprop -root _NET_ACTIVE_WINDOW)
while : ;do
	sleep 1
	[[ $(xprop -root _NET_ACTIVE_WINDOW) != $ACTIVEWINDOW ]] && kill $ICONS_PID && break
done

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

#524 Post by misko_2083 »

Spying on the root window's property _NET_ACTIVE_WINDOW is very useful when a new window is added to the window stack.

There is --close-on-unfocus, which closes the yad window when it loses focus. Not sure from which version of yad.

I was thinking about this. Launching applications doesn't nesesary make yad to lose the focus.
Some apps don't have a window or show a window only when the user press a key combo or at certain time (alarm), some may go to tray or to a different workspace, or simply start behind fullscreen yad.

In those cases you wouldn't know if you launched the application and may start it several times. Closing the icons dialog is like a confirmation in this case and more important, it stays out of your way after it's clicked.

If yad icons could write at stout or stderr we would know when the app is launched from it and close it. But it does not.

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

#525 Post by misko_2083 »

Just playing with html dialog.
Loading/previewing images.

Code: Select all

yad --html --uri=/home/misko/Desktop/test.html

Image

Here's test.html

Code: Select all

 <!DOCTYPE html>
<html>
<body>

    <link rel="stylesheet" media="all" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />

<style>
  .thumb {
    height: 300px;
    border: 1px solid #000;
    margin: 10px 5px 0 0;
  }
</style>

example 1

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form id="form1" runat="server">
  <input type='file' id="imgInp" />
  <img id="blah" class="thumb" src="#" alt="your image" />
</form>
<script>
function readURL(input) {

  if (input.files && input.files[0]) {
    var reader = new FileReader();

    reader.onload = function(e) {
      $('#blah').attr('src', e.target.result);
    }

    reader.readAsDataURL(input.files[0]);
  }
}

$("#imgInp").change(function() {
  readURL(this);
});

</script>

<p>example 2</p>



<input type="file" id="files" style="display:none" accept="image/x-png,image/gif,image/jpeg" name="files[]" multiple />
<a href="javascript:;" onclick="getImage()"/>
    <img src="/usr/share/icons/Faenza/actions/32/gtk-open.png"/>
</a>
<output id="list"></output>

<script>
     function getImage(){
       $('#files').click();
     }
</script>

<script>
  function handleFileSelect(evt) {
    var files = evt.target.files; // FileList object

    // Loop through the FileList and render image files as thumbnails.
    for (var i = 0, f; f = files[i]; i++) {

      // Only process image files.
      if (!f.type.match('image.*')) {
        continue;
      }

      var reader = new FileReader();

      // Closure to capture the file information.
      reader.onload = (function(theFile) {
        return function(e) {
          // Render thumbnail.
          var span = document.createElement('span');
          span.innerHTML = ['<img class="thumb" src="', e.target.result,
                            '" title="', escape(theFile.name), '"/>'].join('');
          document.getElementById('list').insertBefore(span, null);
        };
      })(f);

      // Read in the image file as a data URL.
      reader.readAsDataURL(f);
    }
  }

  document.getElementById('files').addEventListener('change', handleFileSelect, false);

</script>
</body>
</html> 
OK but how to set the desktop background now? :lol:

Most likely not possible, but something like Yradio-html radio player is probably doable?!

stemsee

#526 Post by stemsee »

I am interested to know what other ways I can utilise exclusively (time slots) a yad dnd panel which is part of --notebook --paned gui.

So far I am using tee together with a variable which that yad dnd element is piped to. This gives two pipes out of the dnd. When I want only the tee output I redifine the variable to tap=/dev/null . It works. But I found that I can also define the output of the dnd by association, dndout=$(yad --dnd | tee /tmp/outdnd &>$tap &) &, and seems to work without affecting its function in the --notebook gui.

I want to know how many pipes I can feed to without using tee... is this possible in theory

Code: Select all

dndout=$(yad --plug=$$ --tabnum=2  --dnd &>$tap &>$apt &>$pat &) &
currently

Code: Select all

yad --listen --plug=$$ --tabnum=1 --item-separator=" " --form --cycle-read --columns=2 --field=A --field=0 --field=1 --field=2 --field=3 --field=4 --field=5 --field=6 --field=7 --field=8 --field=9 --field=10 <& 2 &
yad --plug=$$ --tabnum=2 --text="\t\t\t\t\t\t\tDnD panel\n\tClick a button\n\tThen Drag the mac address here!" --dnd | tee $pat 1>$tap &
yad --geometry=$(cat $camino/geometry/$WINDOWTITLE) --title="$WINDOWTITLE" --title=Bluetooth --window-icon=$pics/bluetooth-active.png --key=$$ --columns=2 --paned --height=220 --width=300 --tab=Found --tab=DnD --button="Command":"echo command" --button="Scan":"echo btscanfn" --button="Remove":"echo rmdev" --button="Connect":"echo btcon" --button="Disconnect":"echo btdisconfn" 1>/tmp/Wifi-TrayNet/btfn &

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

#527 Post by misko_2083 »

stemsee wrote:I am interested to know what other ways I can utilise exclusively (time slots) a yad dnd panel which is part of --notebook --paned gui.

So far I am using tee together with a variable which that yad dnd element is piped to. This gives two pipes out of the dnd. When I want only the tee output I redifine the variable to tap=/dev/null . It works. But I found that I can also define the output of the dnd by association, dndout=$(yad --dnd | tee /tmp/outdnd &>$tap &) &, and seems to work without affecting its function in the --notebook gui.

I want to know how many pipes I can feed to without using tee... is this possible in theory

Code: Select all

dndout=$(yad --plug=$$ --tabnum=2  --dnd &>$tap &>$apt &>$pat &) &
currently

Code: Select all

yad --listen --plug=$$ --tabnum=1 --item-separator=" " --form --cycle-read --columns=2 --field=A --field=0 --field=1 --field=2 --field=3 --field=4 --field=5 --field=6 --field=7 --field=8 --field=9 --field=10 <& 2 &
yad --plug=$$ --tabnum=2 --text="\t\t\t\t\t\t\tDnD panel\n\tClick a button\n\tThen Drag the mac address here!" --dnd | tee $pat 1>$tap &
yad --geometry=$(cat $camino/geometry/$WINDOWTITLE) --title="$WINDOWTITLE" --title=Bluetooth --window-icon=$pics/bluetooth-active.png --key=$$ --columns=2 --paned --height=220 --width=300 --tab=Found --tab=DnD --button="Command":"echo command" --button="Scan":"echo btscanfn" --button="Remove":"echo rmdev" --button="Connect":"echo btcon" --button="Disconnect":"echo btdisconfn" 1>/tmp/Wifi-TrayNet/btfn &
Hi there Stemsee, long time no chat :)

Thinking that this kind of redirection &>$tap &>$apt &>$pat is possible only in zsh.

About the paned dialog, what is the purpose of the ten fields in the first tab?

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

#528 Post by step »

Hi stemsee, so you want to fan output to N taps using shell only? What about piping to a "while read; do" loop and echoing to as many files as you need inside the body of the loop? Something like:

Code: Select all

dndout=$(yad --plug --tabnum=2 --dnd |
while read s; do
  echo "$s" >> $tap; echo "$s" >> $apt; echo "$s" >> $path; echo "$s"
done)
[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
lamplinux
Posts: 31
Joined: Mon 21 Jan 2019, 06:05
Contact:

Yad Launcher

#529 Post by lamplinux »

Is it possible for yad to display all file names in a folder, i.e. /usr/share/applications... like firefox.desktop google-chrome.destop, etc. and have a chck box next to each listed file displayed in list.

Then user checks the box of each file they want to use in a home folder (directory).

Then upon button click - checked files are then copied from /usr/share/applications to /home/user/yadlauncher/applications ?

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

Re: Yad Launcher

#530 Post by step »

lamplinux wrote:Is it possible for yad to display all file names in a folder, i.e. /usr/share/applications... like firefox.desktop google-chrome.destop, etc. and have a chck box next to each listed file displayed in list.

Then user checks the box of each file they want to use in a home folder (directory).

Then upon button click - checked files are then copied from /usr/share/applications to /home/user/yadlauncher/applications ?
Yes. Here's a template you can elaborate on:

Code: Select all

cd /usr/share/local/share/applications/ && ls *.desktop | yad --center --list --column= --checklist --column=file | cut -d'|' -f2 | xargs echo cp -t /dest/dir 
This will print the copy command that would be executed. If that's OK delete "echo" from the command to get a working version. Of course change /dest/dir, absolute path to the destination directory, as you see fit.

If you then want to display an icon grid for the files in /dest/dir use:

Code: Select all

yad --icons --read-dir=/dest/dir
[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]

Post Reply