From: Mike D. <mi...@cs...> - 2005-12-04 14:12:11
|
Hi, I've been using gtk2hs to write an interactive Haskell GUI in the vein of WinHugs. I'm using the TextView widget to display the output of expression evaluation, and I'd like to be able to add clickable hyperlinks to some of the output text. As I understand it (*), the normal way to implement this in GTK would be to attach a GtkTextTag to the text, and then attach an event handler to the TextTag which would catch mouse-button events from the user. However, I can't see how to attach an event handler to a TextTag. You can't use 'onButtonPress', as a TextTag isn't a subclass of Widget. Is it possible to do this some other way in gtk2hs? Any advice would be appreciated. regards, Mike Dodds. (* from e.g here: http://www.daa.com.au/pipermail/pygtk/2005-March/009708.html ) |
From: Axel S. <A....@ke...> - 2005-12-05 09:40:09
|
On Sun, 2005-12-04 at 14:11 +0000, Mike Dodds wrote: > Hi, > > I've been using gtk2hs to write an interactive Haskell GUI in the vein > of WinHugs. I'm using the TextView widget to display the output of > expression evaluation, and I'd like to be able to add clickable > hyperlinks to some of the output text. As I understand it (*), the > normal way to implement this in GTK would be to attach a GtkTextTag to > the text, and then attach an event handler to the TextTag which would > catch mouse-button events from the user. However, I can't see how to > attach an event handler to a TextTag. You can't use 'onButtonPress', as > a TextTag isn't a subclass of Widget. Is it possible to do this some > other way in gtk2hs? Any advice would be appreciated. It's easy to get an iterator. This is what I did: cursorToLocation ... Button { eventX = x, eventY = y, eventModifier = [], eventButton = LeftButton, eventClick = SingleClick } = [..] (bufX, bufY) <- textViewWindowToBufferCoords view TextWindowText (round x, round y) (iter,_) <- textViewGetLineAtY view bufY line <- textIterGetLine iter But then you need to find the right tag. There is an example in gtk- demo. I think the best they came up with there is to iterate through all TextTags and check if the iterator lies within the tag. > (* from e.g here: > http://www.daa.com.au/pipermail/pygtk/2005-March/009708.html ) > I'll look at this (later - got a meeting right now). Axel. |