-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
180 additions
and
80 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
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 |
---|---|---|
@@ -1,10 +1,53 @@ | ||
# nvPY: cross-platform note-taking app with simplenote syncing | ||
# copyright 2012 by Charl P. Botha <cpbotha@vxlabs.com> | ||
# new BSD license | ||
|
||
# Tkinter and ttk documentation recommend pulling all symbols into client | ||
# module namespace. I don't like that, so first pulling into this module | ||
# tk, then can use tk.whatever in main module. | ||
|
||
from Tkinter import * | ||
from ttk import * | ||
# nvPY: cross-platform note-taking app with simplenote syncing | ||
# copyright 2012 by Charl P. Botha <cpbotha@vxlabs.com> | ||
# new BSD license | ||
|
||
# Tkinter and ttk documentation recommend pulling all symbols into client | ||
# module namespace. I don't like that, so first pulling into this module | ||
# tk, then can use tk.whatever in main module. | ||
|
||
from Tkinter import * | ||
from ttk import * | ||
|
||
|
||
class Ucs4NotSupportedError(BaseException): | ||
def __init__(self, char): | ||
self.char = char | ||
|
||
def __str__(self): | ||
return ( | ||
'non-BMP character {} is not supported. ' | ||
'Please rebuild python interpreter and libraries with UCS-4 support. ' | ||
'See https://github.com/cpbotha/nvpy/blob/master/docs/ucs-4.rst' | ||
).format(self.char) | ||
|
||
|
||
def with_ucs4_error_handling(fn): | ||
""" Catch the non-BMP character error and reraise the Ucs4NotSupportedError. """ | ||
import functools | ||
|
||
@functools.wraps(fn) | ||
def wrapper(*args, **kwargs): | ||
try: | ||
return fn(*args, **kwargs) | ||
except TclError as e: | ||
import re | ||
result = re.match(r'character (U\+[0-9a-f]+) is above the range \(U\+0000-U\+FFFF\) allowed by Tcl', str(e)) | ||
if result: | ||
char = result.group(1) | ||
raise Ucs4NotSupportedError(char) | ||
raise | ||
|
||
return wrapper | ||
|
||
|
||
######################################################################## | ||
# Apply the monkey patches for convert TclError to Ucs4NotSupportedError | ||
|
||
_Text = Text | ||
|
||
|
||
class Text(_Text): | ||
@with_ucs4_error_handling | ||
def insert(self, *args, **kwargs): | ||
return _Text.insert(self, *args, **kwargs) |
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
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