resize password label and field to adjust for localization

This commit is contained in:
Greg Neagle
2017-04-24 11:04:39 -07:00
parent 7fd8ccb508
commit bbeb4bae89
2 changed files with 16 additions and 5 deletions

View File

@@ -35,6 +35,7 @@ class MSCPasswordAlertController(NSObject):
def promptForPasswordForAuthRestart(self):
'''Set up and display our alert that prompts for password'''
# Set up all the fields and buttons with localized text
alert = NSAlert.alloc().init()
alert.addButtonWithTitle_(
NSLocalizedString(u"Allow", u"Allow button text"))
@@ -50,7 +51,16 @@ class MSCPasswordAlertController(NSObject):
alert.setAccessoryView_(self.passwordView)
self.passwordLabel.setStringValue_(NSLocalizedString(
u"Password:",u"Password label"))
self.passwordField.setStringValue_("")
self.passwordField.setStringValue_(u"")
# resize label to fit the text
self.passwordLabel.sizeToFit()
# resize the password field to use the rest of the available space
viewWidth = self.passwordView.frame().size.width
labelWidth = self.passwordLabel.frame().size.width
fieldFrame = self.passwordField.frame()
fieldFrame.origin.x = labelWidth + 8
fieldFrame.size.width = viewWidth - labelWidth - 8
self.passwordField.setFrame_(fieldFrame)
# add esc as a key equivilent for the Deny button
alert.buttons().objectAtIndex_(1).setKeyEquivalent_(chr(27))
# change the Allow button to call our password validation method
@@ -59,9 +69,10 @@ class MSCPasswordAlertController(NSObject):
allowButton.setAction_(self.verifyPassword_)
# make sure our password field is ready to accept input
alert.window().setInitialFirstResponder_(self.passwordField)
# we can finally run the alert!
result = alert.runModal()
if result == NSAlertFirstButtonReturn:
# they clicked "Allow"
# they clicked "Allow". We handled it in the verifyPassword method
msclog.log("user", "stored password for auth restart")
if result == NSAlertSecondButtonReturn:
# they clicked "Deny"

View File

@@ -537,7 +537,7 @@
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<secureTextField wantsLayer="YES" verticalHuggingPriority="750" id="RBe-5Z-jso">
<rect key="frame" x="104" y="0.0" width="213" height="22"/>
<rect key="frame" x="75" y="0.0" width="242" height="22"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
<secureTextFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" drawsBackground="YES" usesSingleLineMode="YES" id="675-6Y-zrc">
<font key="font" metaFont="system"/>
@@ -549,9 +549,9 @@
</secureTextFieldCell>
</secureTextField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" id="X5P-3t-HRa">
<rect key="frame" x="1" y="3" width="97" height="17"/>
<rect key="frame" x="1" y="3" width="76" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="right" title="Password:" id="Ef8-fO-Dm6">
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="left" title="Password:" id="Ef8-fO-Dm6">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>