gnocl Popup Menus

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 gnocl 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

 # 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 "!"

 gnocl::window -title "Editor" -child $text

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) - but "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.

About the compiled modules: they are unusable for me. They have been compiled against much newer versions of some libraries. Tried it a minute ago - it doesn't work in Debian Etch. And so is the problem with any shared library: pay attention, that the others may have not exactly the latest ones.

tb 2008-05-09 - @WJG: Ok, I tried your version and got it working by packaging and wrapping it into a starkit. From there I loaded your example and nothing happened :)

I had to add these two lines of code to make it a working example:

 gnocl::window -title "Editor" -child $text

Oh, on a fresh Ubuntu 8.04 I had to install libglitz manually to make it work.

WJG 10/05/08 I'm glad that you got it to work, and apologies for those last two rather important lines of code being missing. They've now been added. ;-) Thanks too for the interest in gnocl. I'll update the docs to reflect the additional options I've added. By the way, are you using Gnocl for any special purpose, or just curiosity?

tb 2008-05-10 - Yes, first I created a tcl package of your binaries (.so) and then I wrapped it to a starkit. For now I can only run it with a tclkit 8.4, but it works and looking into the code of your text.c was quite enlightening :) - I use gnocl to do some Gnome compatible tcl scripting on my machine at home. To me Tcl/Tk is the scripting machine per se :)

[tb] 2008-11-27 - HI, just downloaded the latest 0.9.92 from sourceforge. It compiles well under Ubuntu 8.04 and custom popup menus work well on text widgets now :)

One question: I saw preparations for GtkSourceView in your source tree. That would be my next favorite for implementation. Are there plans?

[WJG} (27/11/08) I currently have an 'pre-alpha' implementation of the gnocl::sourceView widget. As you might expect, this is pretty basic at the moment but I hope to have more complete version ready for the next release of Gnocl which I hope won't be too far away. At the moment I'm still pretty well focused on expanding the support of the basic text widget. But, of course, most of this work can ported over to the sourceView widget too! The sourceView widget has lots of excellent features so I can understand the need for it. What are you using gnocl for?