Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New hyperlink manager to handle opening .rcf files
- Loading branch information
bcorfman
committed
Jan 18, 2011
1 parent
5c199c0
commit bf307b7
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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', '<Enter>', self._enter) | ||
self.txt.tag_bind('hyper', '<Leave>', self._leave) | ||
self.txt.tag_bind('hyper', '<Button-1>', 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 |