Version 8 of gnocl Popup Menus

Updated 2008-05-09 18:42:59 by ZB

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.


ZB 09.05.2008 - I suppose, that it would be better, when every example were prepared using "regular", release version, present in most Linux distros, BSD-s and so on. And currently it's still version 9.90 (not even 9.91). Just because gnocl is a bit "grumpy" to compile on one's own - it does need a lot of libraries. And, for example, under Debian Etch there were so much trouble with installing still more and more developer libraries (and in particular versions, not just any can be used), that in the end I gave up, and installed gnocl just by converting a rpm package for Fedora Core (gnocl 9.90) using "alien".


WJG 09/05/08 It's curious to hear that you've had problems compiling gnocl. My Linux box presently runs SUSE 10.3 and I've never encountered any difficulties. The only extra libraries needed are those for Tcl and GTK development. Just for convenience, please find a snapshot of my current gnocl src directory here: [L1 ] The archive contains the compiled packages so simply download, open a terminal, login as root and type 'make install'!


ZB 09.05.2008 - You're using "bleeding edge"-oriented distro (as much newest version, as possible) - "Debian stable" (Etch - for today, beginning of next year: Lenny) is much more conservative. And even, if you think it's curious, believe me: it was a problem. "Been there, done that". The versions needed are making a problem. Even on the OpenBSD 4.2 I had less trouble (despite the need to modify Makefile-s "by hand").

So, if you want to persuade anybody to take a closer look at gnocl, it'll be easier, when your examples will be usable at this version of gnocl, which anybody can have without much problem. Currently it's 9.90.


enter categories here