Version 2 of gnocl Popup Menus

Updated 2008-05-09 09:01:27 by wjg

WJG (29/03/08) Although the default GTK text offering lacks some of the flexibility of its Tk counterpart, none-the-less it is still quite a useful widget. In this example, clicking Button-3 over the tagged text will result in a placing a popup menu over the tag, with a few choices that will enable the colour of the tag to be changes. A Button-3 click elsewhere will result in the default Gtk popup menu. A feature which the GTK widget has that the Tk counterpart doesn't is the cut and past of rich text.

 #---------------
 # popup.tcl
 #---------------

 #!/bin/sh
 # the next line restarts using tclsh \
 exec tclsh "$0" "$@"

 package require Gnocl 

 #---------------
 # create a menu, can be used as a popup
 #---------------
 set menu [gnocl::menu -title "menuCheckItem" -tearoff 0]
 $menu add [gnocl::menuItem -text "%_Red" -onClicked {setClr $text red} ]
 $menu add [gnocl::menuItem -text "%_Green" -onClicked {setClr $text green} ]
 $menu add [gnocl::menuItem -text "%_Blue" -onClicked {setClr $text blue} ]

 #---------------
 # somthing for our menus to do when selected
 #---------------
 proc setClr {w clr} {
   $w tag configure bold -foreground $clr
 }

 #---------------
 # create a sample window and insert some tagged text
 #---------------
 set text [gnocl::text  ]
 $text tag create bold \
   -fontWeight bold \
   -foreground blue \
   -onEvent {
      # the GTk text widget tag only returns a limited range of events
      # ie. mouse button three, this will override the Gnome default popup
      if {%b == "3"} {$menu popup} 
      }

 $text insert end "This is "
 $text insert end "Gnocl" -tags bold
 $text insert end "!"

tb 2008-05-08 - Hi! - I just tried this with gnocl-0.9.91 from sourceforge, but it doesn't work. It complains about -onEvent being not an option for tag create.


WJG 09/05/08. Yes, that's true. I've got a pre-release 0.9.92 version. So you want a copy? I can email it to you.


enter categories here