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 Sat 23 Jun 2018, 00:15
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
How to place an executable icon in the systray area?[SOLVED]
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 4 [50 Posts]   Goto page: 1, 2, 3, 4 Next
Author Message
Mike Walsh


Joined: 28 Jun 2014
Posts: 3800
Location: King's Lynn, UK.

PostPosted: Sat 10 Mar 2018, 11:56    Post subject:  How to place an executable icon in the systray area?[SOLVED]
Subject description: I'm guessing this involves using GTK....yes/no?
 

Afternoon, boys & girls.

This may be the right place for this, it may not.....but here goes anyway.

What would be the easiest way to get an icon to show up in the system-tray area (for a small utility I'm developing)? All I need is for this icon to execute a simple script when 'clicked' upon each time.

I suspect this may turn out to be somewhat more involved than I think it will..! Smile

Am I right in thinking GTK is involved here? Scripting is not my strong point, but I'm steadily picking up more & more as time goes by; this is the first time I've wanted to include something like this into a package, and I'm a wee bit lost as to where to go next.

Any ideas/suggestions/tips would, as usual, be very much appreciated.

TIA.


Mike. Wink

_________________
MY PUPPY PACKAGES | 'Thanks' are always appreciated!
--------------------------------------


Last edited by Mike Walsh on Mon 12 Mar 2018, 20:15; edited 2 times in total
Back to top
View user's profile Send private message Visit poster's website 
drunkjedi


Joined: 24 May 2015
Posts: 897

PostPosted: Sat 10 Mar 2018, 12:55    Post subject:  

Hey Mike,
If I remember correctly (I am at work and can't check ATM),
Look inside file ~/.jwmrc-tray
You will get pretty good idea what needs to be done.
Just append some line in given format.
Give a name, then icon location, then what script or command to execute.

If you want to do it with a pet, you may need to make a post install script which will append those lines to the file.

In an sfs it is also possible, just place a script which will append those lines in /root/startup folder. (I have played with this before, and I am purely using my memory to answer, slight corrections maybe needed).

I found fatdog's sfs loading system more aofasticated as it givea me option to run scripts on manual sfs load/unload, also on system load/unload (shutdown/reboot).

But that's another topic.

Hope this helps.
Back to top
View user's profile Send private message 
Mike Walsh


Joined: 28 Jun 2014
Posts: 3800
Location: King's Lynn, UK.

PostPosted: Sat 10 Mar 2018, 13:41    Post subject:  

Hi, DJ.

Mm. I know where you're coming from; that'll put a 'clickable' icon in the left-side 'launcher' area.....which is not quite what I want.

According to /root/.jwmrc-tray, I need my icon to be over on the right-hand side, among all that <Swallow> and 'Blinky' stuff (which I can't make head or tail of, I'm afraid).....

What I'm after is the method by which a GTK app will place an icon in the 'system' tray area, on the right-hand side of the tray. Scripting is not my strong point, though I'm slowly getting there..!


Mike. Wink

_________________
MY PUPPY PACKAGES | 'Thanks' are always appreciated!
--------------------------------------

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


Joined: 24 May 2015
Posts: 897

PostPosted: Sat 10 Mar 2018, 13:48    Post subject:  

Make the code as in left side area and put it in the swallow area before the code for clock.
And you will get the icon there. That's what I remember.

I will be going home in half hour, but it will be midnight, so will check tomorrow morning and report back to you.
Back to top
View user's profile Send private message 
jafadmin

Joined: 19 Mar 2009
Posts: 808

PostPosted: Sat 10 Mar 2018, 20:24    Post subject:  

Here's a demo in 'C' (freememaplet)that Barry did back in the day. It covers the basic concepts. It is what I started with. The other one is the absolute bare bones "hello world" kind of a demo ..
skeleton.c.tar.gz
Description 
gz

 Download 
Filename  skeleton.c.tar.gz 
Filesize  600 Bytes 
Downloaded  35 Time(s) 
freememapplet_tray-2.4.tar.gz
Description 
gz

 Download 
Filename  freememapplet_tray-2.4.tar.gz 
Filesize  7.09 KB 
Downloaded  35 Time(s) 
Back to top
View user's profile Send private message 
musher0


Joined: 04 Jan 2009
Posts: 12324
Location: Gatineau (Qc), Canada

PostPosted: Sat 10 Mar 2018, 21:38    Post subject:  

Hello, Mike_Walsh.

IMO, all you need is the Yad utility, which all recent Puppies offer:
Code:
yad --notification --command='/path/of/your/script' --image=/path/of/your/png_icon 2>/dev/null

You can create a wrapper script for the one-liner above and save it in
/root/Startup. Then, at every boot, your script will be available from the system
tray area by clicking on the icon you chose for it.

I am not sure if Yad versions before 0.12.4 have that "--notification" capacity.

~~~~~~~~~~~~~~

For the record, "many" years ago, technosaurus (et al.) worked on a tray icon
utility with right-click and left-click, so you could call two apps with it. It is hiding
well in a froum thread which I cannot find at the moment -- but which I was able
to find two weeks ago! It was called "sit", like the dog command.

Heads up:
Even the latest version of "sit" is in an incomplete state, IMO. I say that because I
("me", "moi", "ego") was not able to make "heads or tails" of it, speaking of
which... Then I discovered the "--notification" feature in yad.

I am writing the novelette above in the hope that one of our C devs will pick up
the hint and finish the promising job that technosaurus has started -- with a good
how-to would not hurt a bit either!

IHTH.

_________________
musher0
~~~~~~~~~~
"Logical entities must not be multiplied beyond necessity." | |
« Il ne faut pas multiplier les entités logiques sans nécessité. » (Ockham)
Back to top
View user's profile Send private message 
fredx181


Joined: 11 Dec 2013
Posts: 3105
Location: holland

PostPosted: Sun 11 Mar 2018, 05:34    Post subject:  

Hi Mike, indeed as musher0 said, yad works well for it, here's simple script, just change path for TRAY_ICON, POPUP_TEXT and /path/to/program (in the function on_click)
(can be extended also with right-click menu, but then becomes a little more complicated)

Code:
#!/bin/bash

# Set the path to tray icon and set popup text
TRAY_ICON="/usr/share/pixmaps/disc.png"
POPUP_TEXT="Click Me"

function on_click() {
# Execute program
/path/to/program
## ... do some more if desired
}
export -f on_click

function on_exit() {
echo "quit" >&3
rm -f $PIPE
}
export -f on_exit

trap on_exit EXIT

export PIPE=$(mktemp -u /tmp/${0##*/}.XXXXXXXX)  # EDITED
mkfifo $PIPE
exec 3<> $PIPE
## Run yad and tell it to read its stdin from the file descriptor ####
yad --notification --text="$POPUP_TEXT" --listen \
--image="$TRAY_ICON" \
--text="$POPUP_TEXT" \
--command="bash -c on_click" <&3


EDIT: changed the export PIPE=... line to:
Code:
export PIPE=$(mktemp -u /tmp/${0##*/}.XXXXXXXX)

see also here: http://murga-linux.com/puppy/viewtopic.php?p=985272#985272

Fred

_________________
Dog Linux website

Last edited by fredx181 on Mon 12 Mar 2018, 08:52; edited 2 times in total
Back to top
View user's profile Send private message 
Mike Walsh


Joined: 28 Jun 2014
Posts: 3800
Location: King's Lynn, UK.

PostPosted: Sun 11 Mar 2018, 06:47    Post subject:  

@jafadmin, musher0, fredx181:-

Wow. Thanks for the responses, guys; that little lot will give me something to chew on for a wee while..!

I have to confess, I've rather gotten used to small apps/utilities that 'run from the tray'. Yes, you can make a MenuEntry for them, then put it in the JWM 'launcher area', on the left hand side.....but it's more technically 'satisfying' to have 'em appear in the correct place, in the system tray.

This small utility I'm working on will only need a single-click upon it to execute it. It works 100% already.....but I'd like to get this 'systray' bit nailed-down, since I may wish to utilise this same trick in future.

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

@ jafadmin:-

Thanks for the demo. I'll have a gander at it later on this afternoon, when family are out of the way (it's Mother's Day here in the UK!)

@musher:-

Yes, I too had forgotten about 'yad'. I've not really experimented much with it, but I've seen no end of mentions about it in recent years. It does sound like what I want; easy-to-use and simple. I'll have to have a play around with it.

Come to that, of course, there's 'zenity', too, isn't there? I'll have to hunt down the usage instructions for that.....see if it'll support executable tray icons, etc.

@fredx181:-

That looks.....complicated, Fred..! (Although I'll own, I wouldn't mind being able to incorporate a right-click menu as well at some point.) I'll try this out, and see what it does... Good example, though. Cheers.

One query, while I think about it. How does any of this stuff differentiate between a left-clk and a rt-clk, anyway? What triggers it?

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

Thanks, everybody!


Mike. Wink

_________________
MY PUPPY PACKAGES | 'Thanks' are always appreciated!
--------------------------------------

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


Joined: 11 Dec 2013
Posts: 3105
Location: holland

PostPosted: Sun 11 Mar 2018, 14:43    Post subject:  

Hi Mike, for menu you can add this for example before the 'yad --notification ...' command:
Code:
echo "menu:Edit!geany!gtk-edit|File manager!rox!gtk-home|Quit!quit!gtk-quit" >&3

It's in the form of: echo "menu:<Name>!<command>!<icon>|<Name>!<command>!<icon>|.... etc...
So then becomes:
Code:
#!/bin/bash

# Set the path to tray icon and set popup text
TRAY_ICON="/usr/share/pixmaps/disc.png"
POPUP_TEXT="Click Me"

function on_click() {
# Execute program
/path/to/program
## ... do some more if desired
}
export -f on_click

function on_exit() {
echo "quit" >&3
rm -f $PIPE
}
export -f on_exit

trap 'on_exit' EXIT

export PIPE=$(mktemp -u /tmp/${0##*/}.XXXXXXXX) # EDITED, see below
mkfifo $PIPE
exec 3<> $PIPE

# Example right-click menu
echo "menu:Edit!geany!gtk-edit|File manager!rox!gtk-home|Quit!quit!gtk-quit" >&3

yad --notification --kill-parent --text="$POPUP_TEXT" --listen \
--image="$TRAY_ICON" \
--text="$POPUP_TEXT" \
--command="bash -c on_click" <&3


EDIT: changed the export PIPE=... line to:
Code:
export PIPE=$(mktemp -u /tmp/${0##*/}.XXXXXXXX)

see also here: http://murga-linux.com/puppy/viewtopic.php?p=985272#985272

Fred

_________________
Dog Linux website

Last edited by fredx181 on Mon 12 Mar 2018, 08:52; edited 2 times in total
Back to top
View user's profile Send private message 
Mike Walsh


Joined: 28 Jun 2014
Posts: 3800
Location: King's Lynn, UK.

PostPosted: Sun 11 Mar 2018, 16:05    Post subject:  

@fredx181:-

Now then, mate; hold your horses a mo!

As your script stands, it puts an icon in the tray, with the 'popup'. It won't put my chosen icon in the tray, despite using the full path (insists on using a little green flask; YAD trademark, or something?) in the tray....but the first part works. Sort of.... Confused

As for 'click-to-execute' the program, clicking on the icon after starting the script doesn't actually do anything. It doesn't appear to execute my own script at all. (The script itself works fine; clicking on the script in /usr/bin executes it perfectly, but your script, which I've placed in /root/Startup, seems to 'stall' after putting its own icon in the tray...)

(*shrug*)

Any suggestions? You obviously know a darn sight more about this scripting business than I do..!

BTW, middle-click 'exits'. That sound about right?

Currently, it reads as follows:-

Code:
#!/bin/bash

# Set the path to tray icon and set popup text
TRAY_ICON="/usr/share/pixmaps/green-tick.png"
POPUP_TEXT="Spot2Root - download transfer"

function on_click() {
# Execute program
/usr/bin/spot-to-root
## ... do some more if desired
}
export -f on_click

function on_exit() {
echo "quit" >&3
rm -f $PIPE
}
export -f on_exit

trap on_exit EXIT

export PIPE=$(mktemp -u --tmpdir ${0##*/}.XXXXXXXX)
mkfifo $PIPE
exec 3<> $PIPE
## Run yad and tell it to read its stdin from the file descriptor ####
yad --notification --text="$POPUP_TEXT" --listen \
--image="$TRAY_ICON" \
--text="$POPUP_TEXT" \
--command="bash -c on_click" <&3



.....but neither executes /usr/bin/spot-to-root, nor uses /usr/share/pixmaps/green-tick.png. (uses a little green 'flask' instead ???)

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

Yep, looks like it.



The little green 'flask' symbol does indeed appear to be YAD's 'trademark', So why won't it use my icon.....or doesn't it like PNGs? Rolling Eyes Hmm....

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

Out of curiosity, what does that final stanza do?

Would this be anything to do with the version of yad in use, BTW? I get this:-

Code:
# yad --version
0.38.0 (GTK+ 2.24.10)


(Sorry for all the questions, mate...)


Mike. Wink

_________________
MY PUPPY PACKAGES | 'Thanks' are always appreciated!
--------------------------------------

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


Joined: 04 Jan 2009
Posts: 12324
Location: Gatineau (Qc), Canada

PostPosted: Sun 11 Mar 2018, 18:54    Post subject:  

Hi Mike_Walsh.

I believe yad dislikes strngs. I would suggest that you edit your script to indicate
the direct targets for the executable and the icon. Also, what are those "lonely"
forward slashes doing there? Wink Does bash really understand them? I never got
them to work.

About zenity: my xenialPup-7.0.6 has yad version 0.12.4, and I read somewhere in
its docs that this version supersedes zenity. (Unless my old brain is inventing
things because Puppy Linux is not stimulating it enough. [Ha!])

This is what I have for a mini-aemenu offering access to my mounted partitions and
to a "compass" through the Puppy hierarchy.
Code:
#!/bin/sh
# /root/Startup/yadBoussPart.sh
# Objectif : créer une icône dans le panier pour le script d'aemenu « Boussole-e
# à /root/.aewm/ae/Boussole-et-Partitions.sh.
# (c) musher0, 2018/02/25 20:06. GPL3. Rev.: 2018-03-11.
####
cd /root/.aewm/ae
# echo "Le script yadBoussPart.sh est utilisé. | ############ (Was useful
# Script yadBoussPart.sh is being used" > /tmp/yadBoussPart # during test.)
sleep 0.5s
yad --notification --command='/root/.aewm/ae/Boussole-et-Partitions-yad.sh' --image=/root/.aewm/ae/boussole_4a-28x.png 2>/dev/null
# Note -- # yad n'aime pas le fion ~ pour /root.
That last sentence means "yad does not like the wave sign ~ for /root." It wants the path written in full.

Illustration attached.

IHTH.
~~~~~~~~~~
PS. (everning) -- Full yad command line now provided. I had truncated it inavertently
when I pasted it here. the first time. Sorry about that.
yad-compass.jpg
 Description   
 Filesize   37.64 KB
 Viewed   191 Time(s)

yad-compass.jpg


_________________
musher0
~~~~~~~~~~
"Logical entities must not be multiplied beyond necessity." | |
« Il ne faut pas multiplier les entités logiques sans nécessité. » (Ockham)

Last edited by musher0 on Sun 11 Mar 2018, 21:56; edited 1 time in total
Back to top
View user's profile Send private message 
some1

Joined: 17 Jan 2013
Posts: 81

PostPosted: Sun 11 Mar 2018, 19:57    Post subject:  

Mike Walsh

You are right - I was wrong.

But ...
Using this:
Code:
TRAY_ICON="/usr/local/share/icons/default_left_ptr.png"

Your code/Yad displays the specified icon in the task-bar.

Last edited by some1 on Sun 11 Mar 2018, 20:53; edited 1 time in total
Back to top
View user's profile Send private message 
Mike Walsh


Joined: 28 Jun 2014
Posts: 3800
Location: King's Lynn, UK.

PostPosted: Sun 11 Mar 2018, 20:45    Post subject:  

@musher0:-

Frankly, mate, I don't see how I can get much more direct than

Code:
/usr/share/pixmaps/green-tick.png


...for the icon, and

Code:
/usr/bin/spot-to-root


...for the executable. Tell me how that can be improved upon...

As for those 'lonely' backslashes.....search me, mate. It's mostly Greek to me, I'm sorry to say. Scripting is not my strong point..!

(See my reply to some1, below).

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

@ some1:-

TBH, I'm using the script pretty much as Fred offered it to me.....with the exception of changing the necessary paths for my own. But for the sake of propriety, I did check beyond those continuation backslashes. The spaces are there.

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

And it can't be anything to do with the version of yad in use. I downloaded the latest version from SourceForge, and compiled it earlier this evening. The system's now running

Code:
# yad --version
0.40.0 (GTK+ 2.24.10)


So I very much doubt that's got owt to do with it...


Mike. Wink

_________________
MY PUPPY PACKAGES | 'Thanks' are always appreciated!
--------------------------------------

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

Joined: 17 Jan 2013
Posts: 81

PostPosted: Sun 11 Mar 2018, 22:09    Post subject:  

Hi
Mike -
Try the attached file.

Its your code -adapted a bit,so that it works for me.
Main thing:I deleted trailing spaces after the continuation backslashes.
Laughing
MW_fake.gz
Description 
gz

 Download 
Filename  MW_fake.gz 
Filesize  785 Bytes 
Downloaded  29 Time(s) 
Back to top
View user's profile Send private message 
musher0


Joined: 04 Jan 2009
Posts: 12324
Location: Gatineau (Qc), Canada

PostPosted: Mon 12 Mar 2018, 00:05    Post subject:  

Hello, Mike_Walsh.

Here is my take on it. I adapted fredx' original.

I did learn a few things along the way, e.g. how he uses the file descriptors. I had read
the theory of it, but had always wondered how to do it in practice; now I know.
Thanks, fredx.

This is the tree of the attached pet:
Quote:
forMW-0.1
[ 108] forMW-0.1/pet.specs
[4.0K] forMW-0.1/root
[4.0K] forMW-0.1/root/my-applications
[4.0K] forMW-0.1/root/my-applications/bin
[5.0K] forMW-0.1/root/my-applications/bin/playsound_simple
[1.0K] forMW-0.1/root/my-applications/bin/yad-fredx-mod.sh
[4.0K] forMW-0.1/root/my-documents
[4.0K] forMW-0.1/root/my-documents/icons
[2.9K] forMW-0.1/root/my-documents/icons/application_view_list-32x-orange.png
[4.0K] forMW-0.1/usr
[4.0K] forMW-0.1/usr/share
[4.0K] forMW-0.1/usr/share/audio
[ 35K] forMW-0.1/usr/share/audio/sonnette-velo2.mp3
8 directories, 5 files

I put a bicycle chime for the on_click function.

It took me a while to find out that that function was for LEFT-CLICK ONLY. It is
independent from what exists on the "echo line" further down, which is the menu proper,
activated by RIGHT-CLICK.

So when you will do a LEFT click on the icon, it will chime. When you will do a RIGHT
click on the icon, the mini-menu will show up. I have also replaced fredx' original calls on
the "echo line" with two Puppy default executables, with parameter. That works fine; no
need, for either the initial double commands or the full path.

As you can see from the above tree, also included is a tiny mp3 player (I think forum
member technosaurus wrote it) , and an orangy list icon.

~~~~~~~~~~~~~~~~

This is fredx' script modified by me. Constructive feedback appreciated: this is how
we learn.
Code:
#!/bin/bash
# par fredx # modifié par musher0
# Source: http://murga-linux.com/puppy/viewtopic.php?p=985208&sort=lastpost#985208
# Relevé le 2018/03/11 22:00
####
# Set the path to tray icon and set popup text
TRAY_ICON="/root/my-documents/icons/application_view_list-32x-orange.png"
# "/usr/share/pixmaps/disc.png"
POPUP_TEXT="Click Me"
SounD="/usr/share/audio/sonnette-velo2.mp3"
function on_click() {
# Execute program # on LEFT CLICK!!!
# /path/to/program
/root/my-applications/bin/playsound_simple /usr/share/audio/sonnette-velo2.mp3
## ... do some more if desired
}
export -f on_click

function on_exit() {
echo "quit" >&3
rm -f $PIPE
}
export -f on_exit

trap 'on_exit' EXIT

export PIPE=$(mktemp -u --tmpdir ${0##*/}.XXXXXXXX)
mkfifo $PIPE
exec 3<> $PIPE

# Example right-click menu
echo "menu:Edit!defaulttextviewer new.txt|File manager!defaultfilemanager /root|Quit!quit" >&3

yad --notification --kill-parent --text="$POPUP_TEXT" --listen \
--image="$TRAY_ICON" \
--text="$POPUP_TEXT" \
--command="bash -c on_click" <&3 2>/dev/null

~~~~~~~~~~~~~~~~~

The pet archive is attached. I don't know if any of this will help you, but there goes!

BFN.
forMW-0.1.pet
Description 
pet

 Download 
Filename  forMW-0.1.pet 
Filesize  40.35 KB 
Downloaded  34 Time(s) 

_________________
musher0
~~~~~~~~~~
"Logical entities must not be multiplied beyond necessity." | |
« Il ne faut pas multiplier les entités logiques sans nécessité. » (Ockham)

Last edited by musher0 on Mon 12 Mar 2018, 03:49; edited 1 time in total
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 4 [50 Posts]   Goto page: 1, 2, 3, 4 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.0863s ][ Queries: 12 (0.0111s) ][ GZIP on ]