Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #150 from cbenhagen/paste
Allow copy, paste etc.
- Loading branch information
Showing
2 changed files
with
36 additions
and
3 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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from AppKit import NSApplication, NSTextField, NSSecureTextField, NSKeyDown, NSCommandKeyMask | ||
|
||
|
||
class Editing(NSTextField): | ||
"""NSTextField with cut, copy, paste, undo and selectAll""" | ||
def performKeyEquivalent_(self, event): | ||
return _perform_key_equivalent(self, event) | ||
|
||
|
||
class SecureEditing(NSSecureTextField): | ||
"""NSSecureTextField with cut, copy, paste, undo and selectAll""" | ||
def performKeyEquivalent_(self, event): | ||
return _perform_key_equivalent(self, event) | ||
|
||
|
||
def _perform_key_equivalent(self, event): | ||
if event.type() == NSKeyDown and event.modifierFlags() & NSCommandKeyMask: | ||
if event.charactersIgnoringModifiers() == "x": | ||
NSApplication.sharedApplication().sendAction_to_from_("cut:", None, self) | ||
return True | ||
elif event.charactersIgnoringModifiers() == "c": | ||
NSApplication.sharedApplication().sendAction_to_from_("copy:", None, self) | ||
return True | ||
elif event.charactersIgnoringModifiers() == "v": | ||
NSApplication.sharedApplication().sendAction_to_from_("paste:", None, self) | ||
return True | ||
elif event.charactersIgnoringModifiers() == "z": | ||
NSApplication.sharedApplication().sendAction_to_from_("undo:", None, self) | ||
return True | ||
elif event.charactersIgnoringModifiers() == "a": | ||
NSApplication.sharedApplication().sendAction_to_from_("selectAll:", None, self) | ||
return True |