From bf307b7dc7d7d7374b30f8710cefbee20a02b523 Mon Sep 17 00:00:00 2001 From: bcorfman Date: Tue, 18 Jan 2011 13:19:41 -0500 Subject: [PATCH] New hyperlink manager to handle opening .rcf files --- hyperlinkmgr.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 hyperlinkmgr.py diff --git a/hyperlinkmgr.py b/hyperlinkmgr.py new file mode 100644 index 0000000..4af5d2f --- /dev/null +++ b/hyperlinkmgr.py @@ -0,0 +1,33 @@ +from Tkinter import * + +class HyperlinkManager(object): + def __init__(self, textWidget, linkFunc): + self.txt = textWidget + self.linkfunc = linkFunc + self.txt.tag_config('hyper', foreground='blue', underline=1) + self.txt.tag_bind('hyper', '', self._enter) + self.txt.tag_bind('hyper', '', self._leave) + self.txt.tag_bind('hyper', '', self._click) + self.reset() + + def reset(self): + self.filenames = {} + + def add(self, filename): + # Add a link with associated filename. The link function returns tags + # to use in the associated text widget. + tag = 'hyper-%d' % len(self.filenames) + self.filenames[tag] = filename + return 'hyper', tag + + def _enter(self, event): + self.txt.config(cursor='hand2') + + def _leave(self, event): + self.txt.config(cursor='') + + def _click(self, event): + for tag in self.txt.tag_names(CURRENT): + if tag.startswith('hyper-'): + self.linkfunc(self.filenames[tag]) + return