Yad sytem tray right click menu

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
stu91
Posts: 145
Joined: Mon 06 Aug 2012, 15:11
Location: England. Dpup. Dell Inspiron 1501

Yad sytem tray right click menu

#1 Post by stu91 »

Here is an example script of a yad system tray right click menu:

Image

Code: Select all

#!/bin/bash
## yad simple system tray right click menu ##
## menu file example in plain text file name!command ##
#Terminal!urxvt
#Paint!mtpaint

## Application menu file ###############################################

GET_MENU="$@"

########################################################################

function START_MENU () {

## MENU items ##########################################################

MENU_ITEMS="` cat "$GET_MENU" | tr '\n' '|' | sed '$s/.$//' `"

## Defaults ############################################################

TRAY_ICON="/usr/share/icons/hicolor/24x24/apps/yad.png"
POPUP_TEXT="system tray menu"
PIPE_FIFO=$(mktemp -u /tmp/menutray.XXXXXXXX)

## Action on left mouse click ###########################################
  function LEFT_CLICK () {
	exec 3<> $PIPE_FIFO
    echo "quit" >&3
    rm -f $PIPE_FIFO
}
  
  export -f LEFT_CLICK
  export PIPE_FIFO

## 1 Create PIPE_FIFO file #############################################
  mkfifo $PIPE_FIFO

## 2 Attach a filedescriptor to this PIPE_FIFO #########################
  exec 3<> $PIPE_FIFO
 
## 3 Run yad and tell it to read its stdin from the file descriptor ####
GUI=$(yad --notification --kill-parent --listen \
--image="$TRAY_ICON" \
--text="$POPUP_TEXT" \
--command="bash -c LEFT_CLICK" <&3 ) & 

## 4 Write menu to file descriptor to generate MENU ####################
 echo "menu:$MENU_ITEMS" >&3
}

## Check if menu file is provided ######################################
 
  if [ -z "$GET_MENU" ]; then 
  echo "traymenu usage: $0 /path/to/menu/file" && exit
  else
  START_MENU
  fi

######################################################################## 
Tray icon and popup text can be customised in script:
TRAY_ICON=
POPUP_TEXT=


Usage: is with a separate menu file which contains menu item name ! menu item command (see below, left is name - right is command - menu order top is first)

Code: Select all

Terminal! urxvt
Paint! mtpaint
Text Edit! geany
Media! gnome-mplayer
Home! rox /root
Sda2! rox /mnt/sda2
To run: /path/to/script /path/to/menu/file

cheers.
Attachments
traymenu.gz
remove fake .gz and make executable
(1.62 KiB) Downloaded 1004 times

User avatar
don570
Posts: 5528
Joined: Wed 10 Mar 2010, 19:58
Location: Ontario

#2 Post by don570 »

It worked when I tried it in Precise.

It would be more useful if running the terminal command
wasn't necessary each time the menu file was changed.

__________________________________________

User avatar
stu91
Posts: 145
Joined: Mon 06 Aug 2012, 15:11
Location: England. Dpup. Dell Inspiron 1501

#3 Post by stu91 »

don570 wrote:It worked when I tried it in Precise.

It would be more useful if running the terminal command
wasn't necessary each time the menu file was changed.

__________________________________________
Hi don570,
Thanks for testing and feedback 8)

Im not quite sure i understand what you mean in the second lines of your post, could you give an example?

You do not need to use a menu file instead the menu could be put in the script by changing:

GET_MENU="$@"

to

GET_MENU='Terminal! urxvt
Paint! mtpaint
Text Edit! geany
Media! gnome-mplayer
Home! rox /root
Sda2! rox /mnt/sda2
'

User avatar
don570
Posts: 5528
Joined: Wed 10 Mar 2010, 19:58
Location: Ontario

#4 Post by don570 »

I was referring to a menu editor. (A couple already exist for Puppy)


So the user filled in fields rather than create a file.
Geany can open a document for example ---> so two fields
would be needed for each app

and maybe a button to click so previous tray icons quit.

Probably too much work.

__________

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

Yad sytem tray right click menu

#5 Post by L18L »

Hi stu9x

I have have been playing with your script

TRAY_ICON="/usr/share/doc/puppylogo48.png"
POPUP_TEXT="one of my special mini menus "


Using
GET_MENU='Terminal! urxvt
Paint! mtpaint
'
MENU_ITEMS= has to be changed to
MENU_ITEMS="` echo "$GET_MENU" | tr '\n' '|' | sed '$s/.$//' `"

Having different TRAY_ICON and POPUP_TEXT for each menu now
Launched by Startup in precise

Very cool 8)
though most of that code is "all Greek" to me
Attachments
tray_menu.png
(3.24 KiB) Downloaded 3305 times

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#6 Post by technosaurus »

the way I got around all of the complexity in sit (simple icon tray) was to use user defined commands for the left and right click menus ... these can be simulated in gtkdialog by setting window-placement="2" in the <window> tag (I forget what it is in yad, but most dialog apps including Xdialog have similar near mouse window positioning abilities)
Also in sit all tooltips and icons get automagically refreshed if the image or tooltip file is changed and since the user defines the click actions, those can be changed on the fly too. so changing behavior is as simple as copying one icon over another icon, echoing to a tooltip text file or modifying the right/left-click action script/function/executable. The number of icons is unlimited, so AFAIK sit covers 99% of needs for creating tray apps and is only ~5kb

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

There are also a lot of tips scattered throughout the thread for generating simple yet useful svg images within scripts as well as some examples for parsing data in a way that is useful for tray apps.
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

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

#7 Post by Argolance »

Bonjour,
This Yad sytem tray right click menu is great and very useful.
Thanks!

I would like to know if it is possible to get small icons at the head of the entries of this right click menu? And if yes, how?
I succeeded in making such a menu using gtkdialog and by setting window-placement="2" in the <window> tag but:
  • - the bottom of the menu is hidden behind the JWM task bar.
    - the icon is in the quick launch part of the JWM task bar
:(

Cordialement.
Attachments
130909_114605_525x237_easyshot.png
Small gui running from an icon inside the quick launch part of the JWM task bar
(30.24 KiB) Downloaded 2571 times

User avatar
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

#8 Post by mikeb »

oops I wish I could read but updating the menu is just a case of echoing to the pipe on >3 by whatever convenient means

mike

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

#9 Post by Argolance »

oops I wish I could read but updating the menu is just a case of echoing to the pipe on >3 by whatever convenient means
Sorry, I don't understand what you mean! :oops:
Is it to say that such a menu exists, but simplier, without the "echoing to the pipe on >3". If yes where could I find it?

Cordialement.

User avatar
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

#10 Post by mikeb »

Sorry to confuse It was more a general reply to yad usage plus I messed up my post and quickly edited it... hence the 'oops'
It would be more useful if running the terminal command
wasn't necessary each time the menu file was changed.
rather than an answer to your question Argolance.

As for Icons the yad wiki might be helpful to you

http://code.google.com/p/yad/wiki/NotificationIcon

regards

Mike
Last edited by mikeb on Mon 09 Sep 2013, 12:21, edited 1 time in total.

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

#11 Post by Argolance »

OK, thanks!

Post Reply