Page 1 of 1

gtkdialog_menu-0.3

Posted: Sun 05 Sep 2010, 06:06
by zigbert
Gtkdialog_menu
Gtkdialog_menu allows the use of external menus in gtkdialog.

Image

Code: Select all

# gtkdialog_menu -h
Usage: gtkdialog_menu [OPTION] "stock-icon1,menuitem1" "stock-icon2,menuitem2" ...
example: gtkdialog_menu -m middle "gtk-open,Open file" "seperator" "gtk-quit,Quit"
Options
  -h         Show this information
  -m CLICK   Activate menu by clicking mousebutton
             This uses $BUTTON from main gtkdialog gui
                left
                middle
                right (default)
Download
username:puppy
password:linux

gtkdialog_menu-0.3.pet

Example how to use it: (line 4 makes the call to gtkdialog_menu)

Code: Select all

#!/bin/sh

external_menu(){
   OUTPUT="`gtkdialog_menu "gtk-apply,Set theme" "gtk-convert,Show JWM_switcher" "seperator" "gtk-quit,Quit"`"
   case $OUTPUT in
      'Set theme')
         cp -f /root/.jwm/themes/${JWM_THEME}-jwmrc /root/.jwm/jwmrc-theme
         cp -f /root/.jwm/themes/${JWM_THEME}-colors /root/.jwm/jwm_colors
         jwm -restart
         ;;
      'Show JWM_switcher')
         /usr/local/jwmconfig2/theme_switcher
         ;;
      'Quit')
         for I in `ps | grep -w "MAIN_DIALOG" | awk '{print $1}'`; do kill -9 $I; done
         exit 0
         ;;
   esac
}
export -f external_menu

#this builds the list for the <tree> widget
for THEME in `ls -1 /root/.jwm/themes/ | grep 'jwmrc' | sed -e 's/-jwmrc//' | tr '\n' ' '`; do
   THEME="`basename $THEME`"
   ITEMS="$ITEMS<item>$THEME</item>"
done

export MAIN_DIALOG='<vbox height-request="250">
  <text><label>Example of an right-click-menu with gtkdialog</label></text>
  <tree hover-selection="true">
    <label>JWM themes</label>
    <variable>JWM_THEME</variable>
    '$ITEMS'
    <action signal="button-press-event">external_menu</action>
  </tree>
  <hbox><button ok></button></hbox>
</vbox>'
gtkdialog3 -p MAIN_DIALOG 

Posted: Thu 16 Sep 2010, 18:19
by zigbert
Version 0.3
- uses active gtk-theme
- seperators
- autoscales width

Posted: Sat 10 Sep 2011, 07:48
by Argolance
Hello,
@zigbert
... Thanks for this very useful code lines.

Question:
I tried many combinations but didn't succeed in making variables working in the script! :oops:)
What is the right way to replace "Set theme" (and so on...) with variables ($VARIABLE) (calling, for example, translated words of a localization *.mo file?)
VARIABLE="Changer le thème"

external_menu(){
OUTPUT="`gtkdialog_menu "gtk-apply,=>?$VARIABLE" "gtk-convert,Show JWM_switcher" "seperator" "gtk-quit,Quit"`"
case $OUTPUT in
=>?$VARIABLE)
cp -f /root/.jwm/themes/${JWM_THEME}-jwmrc /root/.jwm/jwmrc-theme
cp -f /root/.jwm/themes/${JWM_THEME}-colors /root/.jwm/jwm_colors
jwm -restart
;;
'Show JWM_switcher')
/usr/local/jwmconfig2/theme_switcher
;;
'Quit')
for I in `ps | grep -w "MAIN_DIALOG" | awk '{print $1}'`; do kill -9 $I; done
exit 0
;;
esac
Thank you a lot for your attention.

Regards.

Posted: Sat 10 Sep 2011, 16:53
by Argolance
Nobody to help me? :cry:

Posted: Sat 10 Sep 2011, 17:09
by zigbert
Argolance wrote:Nobody to help me? :cry:
:D Of course, but right now, I don't have much time......

It is a much better solution if you can hardcode the right-click-menu instead of using this code. Pmusic does it, and you'll find the code from line 126 in /usr/local/pmusic/func. This way you have full control and it will act faster. Also the code in Pmusic is better ... in the way that it uses the new features in the latest gtkdialog.


Sigmund

Posted: Sat 10 Sep 2011, 17:50
by Argolance
Hello zigbert,
:D Of course, but right now, I don't have much time......
Sorry to be so impatient!
It is a much better solution if you can hardcode the right-click-menu instead of using this code...
That's OK! I will have a look and try to "hardcode" (though this "simple" code was working so well!) :wink:...

Thank you.
Best regards.

Posted: Sat 10 Sep 2011, 18:22
by sc0ttman
nice, I am gonna try using xdotool and this to create right click options for the VLC playback window, when loaded through VLC-GTK.. Then it'll be really nice :)

Posted: Sun 11 Sep 2011, 08:24
by Argolance
Hello,
I guess I was a bit left wanting more. All the same, I would have liked to know if there is a way to set these variables for them to work properly inside this script: I missed here a good occasion to learn something I probably will encounter later elsewhere....

Cordialement.

Posted: Sun 11 Sep 2011, 09:00
by Argolance
Hello,
I found what was going wrong, with the original script... as well as with the part of the script of pmusic I finally adapted for mine: $OUTPUT variables calling more than one word won't work!!! :shock:
I thought this should help!

Now all is right. :D

Cordialement.

please help

Posted: Wed 13 Aug 2014, 22:13
by Scooby
Not solved

Actually when I exchange focus-out-event with leave-notify-event which I thought
worked I cannot select a menu item, the event is fired as soon as mouse leaves current widget and enters another label or icon

any input


------------- WORKS == SOLVED ------------------------------------------------------------
also I hacked in a parameter to be able to set wanted stock-icon-size
defaults to 1, I use 5 for icons and labels to line up nicely
-------------------------------------------------------------------------------------------------------

I'm using

Code: Select all

 > gtkdialog --version
gtkdialog version 0.8.4 release (C) 2003-2007 Laszlo Pere, 2011-2012 Thunor
Built with support for: GTK+ 3.
I'm on alphaOS

I tried this and it works however I don't seem to get the
focus out event so right-click menu doesn't exit of I move mousepointer
out of pop-up menu

Code: Select all

<action signal="focus-out-event">EXIT:exit</action>
any input on this?
doesn't it work with gtk3?

also icons don't line up with labels

Posted: Thu 14 Aug 2014, 16:15
by zigbert
Scooby
This thread is really old, and codelines has changed since 2011.... Sorry about that.

pMusic uses many right-click menus, so if you can right-click on a track in the playqueue, you know it can work for you.
The menu-code is found in /usr/local/pmusic/menu_playqueue


Sigmund