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 Wed 27 Aug 2014, 17:01
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
About yad [SOLVED]
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 2 [20 Posts]   Goto page: 1, 2 Next
Author Message
Argolance


Joined: 06 Jan 2008
Posts: 1825
Location: PORT-BRILLET (Mayenne - France)

PostPosted: Sat 14 Sep 2013, 10:29    Post subject:  About yad [SOLVED]
Subject description: Rigth click menu icons? How to kill a specific yad process?
 

Bonjour,
2 questions about yad:
    - Is it possible to get icons inside a yad right click menu? If yes, how?
    - How to get the ID of a specific yad process? For example: I would like the "good" one to be "killed" if several are running simultaneously?

Thank you for your attention.

Cordialement.

_________________


Last edited by Argolance on Wed 09 Oct 2013, 16:33; edited 2 times in total
Back to top
View user's profile Send private message Visit poster's website 
matiasbatero


Joined: 11 Oct 2012
Posts: 57
Location: Mar del Plata, Argentina

PostPosted: Sat 14 Sep 2013, 13:57    Post subject: Yad notification
Subject description: Response
 

Yes, it's possible.

Check my example:

Code:
#!/bin/bash

mkfifo /tmp/01
exec 3<> /tmp/01

yad --notification --kill-parent --listen <&3 &

title="<b><big>✔</big> Testing notification                              </b>"
text="<i>Using HTML markup</i>"
add_2="⏏ Eject (right-click to open menu)"
#print
echo "icon:gtk-cdrom" >&3
echo "tooltip:$title $progress \n\n$text\n\n$add_2" >&3
echo "menu:Eject /dev/sr0!bash -c eject /dev/sr0!gtk-cdrom|Exit!quit!gtk-quit" >&3


Yad stdin format for menu is:

menu: LABEL ! COMMAND ! ICON

By default: ! symbol is used to separate values. (you can change it)
By deault: | symbol is used to separate menu items. (you can change it)

To change separator characters:

--separator=STRING

--item-separator=STRING

For example (menu with 2 items)
menu: LABEL1 ! COMMAND1 ! ICON1 | LABEL2 ! COMMAND2 ! ICON2 etc..


To get the pid, you can do this:

Code:
yad --options &
PID=$!
Back to top
View user's profile Send private message 
Argolance


Joined: 06 Jan 2008
Posts: 1825
Location: PORT-BRILLET (Mayenne - France)

PostPosted: Sat 14 Sep 2013, 17:25    Post subject:  

Bonsoir matiasbatero,
Thank you for replying!
Concerning text markup, I had no difficulties to get expected results (please see picture below!)
Very Happy Great!
On the other hand, I couldn't get icons inside the right click menu which looks like this (please see picture below!):
Code:
echo "menu:$REFRESH_TEXT!bash -c REFRESH_TRAY||$EXIT_TEXT!bash -c CLOSE_QUIT" >&3

More (fortunately that I had saved my work before testing Cool ), when I left clicked on the system tray icon of the running script you wrote above, PC rebooted instantaneously Shocked
So, those who want to test this script should be very careful: pleeeeaaaase, do not left click on the notification icon if you have something which is cooking lovingly in the oven.
Just right click!


Don't know exactly why...
Quote:
To get the pid, you can do this:

Code:
yad --options &
PID=$!

Sorry but I don't know how to use this inside the script I am working on Embarassed I must admit Yad is quite new for me.

[EDIT]: After some tests, this is ok for the PID Very Happy

Cordialement.
130914_231432_3200x1200_easyshot.png
 Description   
 Filesize   15.66 KB
 Viewed   431 Time(s)

130914_231432_3200x1200_easyshot.png

130914_224546_3200x1200_easyshot.png
 Description   
 Filesize   20.98 KB
 Viewed   431 Time(s)

130914_224546_3200x1200_easyshot.png


_________________


Last edited by Argolance on Sun 15 Sep 2013, 04:08; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website 
Karl Godt


Joined: 20 Jun 2010
Posts: 3964
Location: Kiel,Germany

PostPosted: Sat 14 Sep 2013, 17:37    Post subject:  

Have not tested anything and not using yad , but


ME_PID=$$

command &
zPID0=$!

KILL_PID=`ps | grep "${0##*/}" | grep -w "$zPID0"`
kill -9 $KILL_PID

probably could do it -- actually Barry uses $! quite a while in his scripts as in
/usr/sbin/bootmanager

yeslist_func() {
#choose extra modules to load at bootup.
yaf-splash -font "8x16" -outline 0 -margin 4 -bg orange -text "Please wait, processing..." &
X1PID=$!

*
Don't confuse "$!" with "!$" !
Back to top
View user's profile Send private message Visit poster's website 
Argolance


Joined: 06 Jan 2008
Posts: 1825
Location: PORT-BRILLET (Mayenne - France)

PostPosted: Sun 15 Sep 2013, 06:39    Post subject:  

Thank you Karl! Very Happy
_________________

Back to top
View user's profile Send private message Visit poster's website 
Argolance


Joined: 06 Jan 2008
Posts: 1825
Location: PORT-BRILLET (Mayenne - France)

PostPosted: Sun 15 Sep 2013, 13:37    Post subject:  

Bonjour,
I played and had fun with yad...
1)
Quote:
On the other hand, I couldn't get icons inside the right click menu which looks like this (please see picture below!):
Code:
echo "menu:$REFRESH_TEXT!bash -c REFRESH_TRAY||$EXIT_TEXT!bash -c CLOSE_QUIT" >&3

I was running an old version of yad (0.12.1). After compiling/installing the latest version (0.23.0), I get the icons in the right click menu! Very Happy
Question @matiasbatero
But: This works using customized icons (ex: usr/share/pixmaps/mycon.png), and only with some gtk icons. gtk-preference, for example, is correctly displayed, but not the icons gtk-quit, gtk-close... Sad
How could this be solved?

2)
Quote:
More (fortunately that I had saved my work before testing Cool ), when I left clicked on the system tray icon of the running script you wrote above, PC rebooted instantaneously Shocked
So, those who want to test this script should be very careful: pleeeeaaaase, do not left click on the notification icon if you have something which is cooking lovingly in the oven.
Just right click!

I was running this script directly in terminal, so the option "--kill-parent" was the reason of the problem. Either you test it in terminal without this option, or you use it inside a bash script. The option will kill the bash script while exiting the yad system tray and nothing happens while left clicking on the yad system tray icon (LEFT_CLICK. has to be defined) Very Happy

Hope this can be helpful!

Cordialement.

_________________

Back to top
View user's profile Send private message Visit poster's website 
matiasbatero


Joined: 11 Oct 2012
Posts: 57
Location: Mar del Plata, Argentina

PostPosted: Sun 15 Sep 2013, 23:58    Post subject:  

Hi!

You can use only this stock gtk-icons, this is the list: http://developer.gnome.org/gtk2/2.24/gtk2-Stock-Items.html

Also you can use icons using app names. Like: leafpad thunar rox

Here, gtk-close, gtk-quit works! and it's Yad 0.23

This line, works here:

Code:
echo "menu:Eject /dev/sr0!bash -c eject /dev/sr0!gtk-cdrom|Exit!quit!gtk-close" >&3


It's strange that some icons work and others not.

1) Check if you have that icons, or symbolic links.
2) I can't remember if works, but i read in some time, that one can add Eviroment Variables with icon paths. Maybe this can help you if some configuration file is missing..
Back to top
View user's profile Send private message 
matiasbatero


Joined: 11 Oct 2012
Posts: 57
Location: Mar del Plata, Argentina

PostPosted: Mon 16 Sep 2013, 00:06    Post subject:  

TIP:

If you want dynamic icon menu refreshing. Like.. Loading states, Copy status, anyway.. a notification with a progress indicator for example.

You can check my program, i wrote a bash function with a nice trick, that works very well. You can use to add more functionality or "stetic purposes"

http://murga-linux.com/puppy/viewtopic.php?t=87856

Screnshot (icon progress)


Regards!
Matías Gastón.[/code]
Back to top
View user's profile Send private message 
Karl Godt


Joined: 20 Jun 2010
Posts: 3964
Location: Kiel,Germany

PostPosted: Mon 16 Sep 2013, 07:06    Post subject:  

--kill-parent
killed PID Nr 1 - literally init , that led to immediate reboot .
Back to top
View user's profile Send private message Visit poster's website 
Argolance


Joined: 06 Jan 2008
Posts: 1825
Location: PORT-BRILLET (Mayenne - France)

PostPosted: Wed 09 Oct 2013, 16:21    Post subject:  

Bonsoir,
Code:
   ## Function kill yad process
   function KillYad(){
      echo "`ps | grep yad`" > $TEMP_DIR/yad_pid_tmp1
      grep POSou $TEMP_DIR/yad_pid_tmp1 > $TEMP_DIR/yad_pid_tmp2
      sed -i 's/^\s*//' $TEMP_DIR/yad_pid_tmp2
      cut -d" " -f 1 $TEMP_DIR/yad_pid_tmp2 > $TEMP_DIR/yad_pid
      YAD_PID="`cat $TEMP_DIR/yad_pid`"
      kill -15 $YAD_PID
   } # End of function


*POSou: pattern.
.... don't know if it is "beautiful" code lines, but it works!

Thanks!

Cordialement.
Back to top
View user's profile Send private message Visit poster's website 
Karl Godt


Joined: 20 Jun 2010
Posts: 3964
Location: Kiel,Germany

PostPosted: Wed 09 Oct 2013, 22:58    Post subject:  

use
grep -w PATTERN
if
pattern contains no spaces or puncts .
Without -w option it would grab everything that contains the pattern .
For example if the pattern would be "1000" it would grab 1000, 11000, 21000, 31000 .

Code:
kill_yad(){
PidWanted=`ps-FULL h -o pid,args | grep yad | awk '{print $1}' | grep -w "$1"`
[ "$PidWanted" ] || return 0
ps-FULL -p $PidWanted && { kill -15 $PidWanted && echo "Killed $1 ." || echo "Killing failed."; } || echo "Pid '$1' seems already gone."
}
Back to top
View user's profile Send private message Visit poster's website 
Argolance


Joined: 06 Jan 2008
Posts: 1825
Location: PORT-BRILLET (Mayenne - France)

PostPosted: Thu 10 Oct 2013, 10:58    Post subject:  

Thank you!
This seems complex to me! Embarassed
Sorry if my question is silly, but where is the pattern in these code lines (in my case "POSou, which is a part of the name of the png icon notification tray)? I mean, if there are several yad apps running at the same time, what could distinguish the one I have to kill from the others?
Code:
15521 root       0:00 yad --notification --auto-kill --listen --no-middle --image=/usr/local/lib/X11/mini-icons/POSou_no-updates.png --text= <b>ToOpPy EST À JOUR! </b> -------------------------------------  Clic gauche: <i>POSou GUI</i>  Clic droit: <i>Menu</i> --command=bash -c LEFT_CLICK

Cordialement.

_________________

Back to top
View user's profile Send private message Visit poster's website 
seaside

Joined: 11 Apr 2007
Posts: 886

PostPosted: Thu 10 Oct 2013, 13:52    Post subject:  

Quote:
I mean, if there are several yad apps running at the same time, what could distinguish the one I have to kill from the others?


One approach is to track the pid when the process is created with a unique identifier.
Code:
yad &
yad_program-pid=$! # OR
 
# If you need to keep the pid in a tmp file
 echo $! >/tmp/yad_program-pid


Then you can kill that specific pid --"kill $yad_program-pid"

Cheers,
s
Back to top
View user's profile Send private message 
Argolance


Joined: 06 Jan 2008
Posts: 1825
Location: PORT-BRILLET (Mayenne - France)

PostPosted: Fri 11 Oct 2013, 06:36    Post subject:  

Bonjour,
Quote:
One approach is to track the pid when the process is created with a unique identifier.

Thank you seaside.
This is obviously the more known/simple way to get the pid of a process (and I already explored it!) but, in my case, this doesn't give me the pid of the yad process itself, but the pid of the the script from which yad is run.
So, lines I found above are not very pretty but work quite perfectly... and I understand how they work! Wink
I actually don't see how to adapt/make Karl Godt code lines work in my script. As far as I know, they actually don't.

Cordialement.

_________________

Back to top
View user's profile Send private message Visit poster's website 
Karl Godt


Joined: 20 Jun 2010
Posts: 3964
Location: Kiel,Germany

PostPosted: Fri 11 Oct 2013, 07:05    Post subject:  

Hi Argolance !

I myself misunderstood your code, especially misinterpreted *POSou: pattern.
I thought that would be "$POSou" - a variable , since functions make much sense
when they could be used several times by

KillYad ARGUMENT1 [ ARGUMENT2 ]

.

What you want to do is to kill a specific yad-GUI for "ToOpPy EST À JOUR! "

As stated you can get the process-id by assigning VARIABLE1=$!

Then call

KillYad VARIABLE1

.

My code with grep -w "$1" would treat $1 as $VARIABLE1 in the grep pipe , while the awk $1 should be awk specific .

*

For the sub-script problem it seems that it needs to be fixed inside the sub-script , by for example assigning

SUB_SCRIPT_PID=$$
echo $YAD_PID >/tmp/${SUB_SCRIPT_PID}.pid

inside the sub-script
and with the sub-script-pid by $! at the main script it should be accessible by

read YAD_PID </tmp/${!}.pid
kill -15 $YAD_PID
Back to top
View user's profile Send private message Visit poster's website 
Display posts from previous:   Sort by:   
Page 1 of 2 [20 Posts]   Goto page: 1, 2 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.0991s ][ Queries: 12 (0.0066s) ][ GZIP on ]