From 709cf5b468987ff743eadd9f562ddcaffb3b50fb Mon Sep 17 00:00:00 2001 From: Daniel Evans Date: Sun, 2 Dec 2018 15:39:05 -0800 Subject: [PATCH] add secure text field --- rumps/rumps.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/rumps/rumps.py b/rumps/rumps.py index 092cd1e..6e43ac6 100644 --- a/rumps/rumps.py +++ b/rumps/rumps.py @@ -14,7 +14,7 @@ from Foundation import (NSDate, NSTimer, NSRunLoop, NSDefaultRunLoopMode, NSSearchPathForDirectoriesInDomains, NSMakeRect, NSLog, NSObject) -from AppKit import NSApplication, NSStatusBar, NSMenu, NSMenuItem, NSAlert, NSTextField, NSImage +from AppKit import NSApplication, NSStatusBar, NSMenu, NSMenuItem, NSAlert, NSTextField, NSSecureTextField, NSImage from PyObjCTools import AppHelper import inspect @@ -754,9 +754,11 @@ class Window(object): evaluates to ``True``, will create a button with text "Cancel". Otherwise, this button will not be created. :param dimensions: the size of the editable textbox. Must be sequence with a length of 2. + :param secure: should the text field be secured or not. With True the window can be used for passwords. """ - def __init__(self, message='', title='', default_text='', ok=None, cancel=None, dimensions=(320, 160)): + def __init__(self, message='', title='', default_text='', ok=None, cancel=None, dimensions=(320, 160), + secure=False): message = text_type(message) message = message.replace('%', '%%') title = text_type(title) @@ -772,7 +774,8 @@ def __init__(self, message='', title='', default_text='', ok=None, cancel=None, title, ok, cancel, None, message) self._alert.setAlertStyle_(0) # informational style - self._textfield = NSTextField.alloc().initWithFrame_(NSMakeRect(0, 0, *dimensions)) + text_field_type = NSSecureTextField if secure else NSTextField + self._textfield = text_field_type.alloc().initWithFrame_(NSMakeRect(0, 0, *dimensions)) self._textfield.setSelectable_(True) self._alert.setAccessoryView_(self._textfield)