mirror of https://github.com/python/cpython
Fixed the password dialog to use a password control.
This commit is contained in:
parent
a4deef82d5
commit
60429e055e
|
@ -20,8 +20,10 @@ import QuickDraw
|
||||||
import Dialogs
|
import Dialogs
|
||||||
import Windows
|
import Windows
|
||||||
import Dlg,Win,Evt,Events # sdm7g
|
import Dlg,Win,Evt,Events # sdm7g
|
||||||
|
import Ctl
|
||||||
import MacOS
|
import MacOS
|
||||||
import string
|
import string
|
||||||
|
from ControlAccessor import * # Also import Controls constants
|
||||||
|
|
||||||
def cr2lf(text):
|
def cr2lf(text):
|
||||||
if '\r' in text:
|
if '\r' in text:
|
||||||
|
@ -97,7 +99,7 @@ def AskString(prompt, default = "", id=261, ok=None, cancel=None):
|
||||||
return cr2lf(GetDialogItemText(h))
|
return cr2lf(GetDialogItemText(h))
|
||||||
if n == 2: return None
|
if n == 2: return None
|
||||||
|
|
||||||
def AskPassword(prompt, default='', id=264):
|
def AskPassword(prompt, default='', id=264, ok=None, cancel=None):
|
||||||
"""Display a PROMPT string and a text entry field with a DEFAULT string.
|
"""Display a PROMPT string and a text entry field with a DEFAULT string.
|
||||||
The string is displayed as bullets only.
|
The string is displayed as bullets only.
|
||||||
|
|
||||||
|
@ -114,58 +116,28 @@ def AskPassword(prompt, default='', id=264):
|
||||||
if not d:
|
if not d:
|
||||||
print "Can't get DLOG resource with id =", id
|
print "Can't get DLOG resource with id =", id
|
||||||
return
|
return
|
||||||
h = d.GetDialogItemAsControl(3) # STATIC TEXT ITEM <= prompt
|
h = d.GetDialogItemAsControl(3)
|
||||||
SetDialogItemText(h, lf2cr(prompt))
|
SetDialogItemText(h, lf2cr(prompt))
|
||||||
h = d.GetDialogItemAsControl(4) # EDIT TEXT ITEM
|
pwd = d.GetDialogItemAsControl(4)
|
||||||
bullets = '\245'*len(default)
|
bullets = '\245'*len(default)
|
||||||
SetDialogItemText(h, bullets )
|
## SetControlData(pwd, kControlEditTextPart, kControlEditTextTextTag, bullets)
|
||||||
d.SelectDialogItemText(4, 999, 999)
|
SetControlData(pwd, kControlEditTextPart, kControlEditTextPasswordTag, default)
|
||||||
|
d.SelectDialogItemText(4, 0, 999)
|
||||||
|
Ctl.SetKeyboardFocus(d, pwd, kControlEditTextPart)
|
||||||
|
if ok != None:
|
||||||
|
h = d.GetDialogItemAsControl(1)
|
||||||
|
h.SetControlTitle(ok)
|
||||||
|
if cancel != None:
|
||||||
|
h = d.GetDialogItemAsControl(2)
|
||||||
|
h.SetControlTitle(cancel)
|
||||||
d.SetDialogDefaultItem(Dialogs.ok)
|
d.SetDialogDefaultItem(Dialogs.ok)
|
||||||
d.SetDialogCancelItem(Dialogs.cancel)
|
d.SetDialogCancelItem(Dialogs.cancel)
|
||||||
string = default
|
|
||||||
oldschedparams = MacOS.SchedParams(0,0)
|
|
||||||
while 1:
|
while 1:
|
||||||
ready,ev = Evt.WaitNextEvent(Events.everyEvent, 6)
|
n = ModalDialog(None)
|
||||||
if not ready: continue
|
if n == 1:
|
||||||
what,msg,when,where,mod = ev
|
h = d.GetDialogItemAsControl(4)
|
||||||
if what == 0 : Dlg.DialogSelect(ev) # for blinking caret
|
return cr2lf(GetControlData(pwd, kControlEditTextPart, kControlEditTextPasswordTag))
|
||||||
elif Dlg.IsDialogEvent(ev):
|
if n == 2: return None
|
||||||
if what in (Events.keyDown, Events.autoKey):
|
|
||||||
charcode = msg & Events.charCodeMask
|
|
||||||
if ( mod & Events.cmdKey ):
|
|
||||||
MacOS.SysBeep()
|
|
||||||
continue # don't do cut & paste commands
|
|
||||||
else:
|
|
||||||
if charcode == Events.kReturnCharCode:
|
|
||||||
break
|
|
||||||
elif charcode == Events.kEscapeCharCode:
|
|
||||||
string = None
|
|
||||||
break
|
|
||||||
elif charcode in (Events.kLeftArrowCharCode,
|
|
||||||
Events.kBackspaceCharCode):
|
|
||||||
string = string[:-1]
|
|
||||||
else:
|
|
||||||
string = string + chr(charcode)
|
|
||||||
msg = 0245 # Octal code for bullet
|
|
||||||
ev = (what,msg,when,where,mod)
|
|
||||||
rs, win, item = Dlg.DialogSelect(ev)
|
|
||||||
if item == Dialogs.ok :
|
|
||||||
break
|
|
||||||
elif item == Dialogs.cancel :
|
|
||||||
string = None
|
|
||||||
break
|
|
||||||
elif what == Events.mouseDown:
|
|
||||||
part, win = Win.FindWindow(where)
|
|
||||||
if part == Windows.inDrag and win:
|
|
||||||
win.DragWindow(where, screenbounds)
|
|
||||||
elif part == Windows.inMenuBar:
|
|
||||||
MacOS.HandleEvent(ev)
|
|
||||||
else:
|
|
||||||
MacOS.SysBeep() # Cannot handle selections, unfortunately
|
|
||||||
|
|
||||||
elif what == Events.updateEvt: MacOS.HandleEvent(ev)
|
|
||||||
apply(MacOS.SchedParams, oldschedparams)
|
|
||||||
return string
|
|
||||||
|
|
||||||
def AskYesNoCancel(question, default = 0, yes=None, no=None, cancel=None, id=262):
|
def AskYesNoCancel(question, default = 0, yes=None, no=None, cancel=None, id=262):
|
||||||
"""Display a QUESTION string which can be answered with Yes or No.
|
"""Display a QUESTION string which can be answered with Yes or No.
|
||||||
|
@ -302,10 +274,14 @@ def test():
|
||||||
|
|
||||||
Message("Testing EasyDialogs.")
|
Message("Testing EasyDialogs.")
|
||||||
ok = AskYesNoCancel("Do you want to proceed?")
|
ok = AskYesNoCancel("Do you want to proceed?")
|
||||||
ok = AskYesNoCancel("Do you want to identify?", yes="Indentify", no="Don't identify")
|
ok = AskYesNoCancel("Do you want to identify?", yes="Identify", no="No")
|
||||||
if ok > 0:
|
if ok > 0:
|
||||||
s = AskString("Enter your first name", "Joe")
|
s = AskString("Enter your first name", "Joe")
|
||||||
Message("Thank you,\n%s" % `s`)
|
s2 = AskPassword("Okay %s, tell us your nickname"%s, s, cancel="None")
|
||||||
|
if not s2:
|
||||||
|
Message("%s has no secret nickname"%s)
|
||||||
|
else:
|
||||||
|
Message("Hello everybody!!\nThe secret nickname of %s is %s!!!"%(s, s2))
|
||||||
text = ( "Working Hard...", "Hardly Working..." ,
|
text = ( "Working Hard...", "Hardly Working..." ,
|
||||||
"So far, so good!", "Keep on truckin'" )
|
"So far, so good!", "Keep on truckin'" )
|
||||||
bar = ProgressBar("Progress, progress...", 100)
|
bar = ProgressBar("Progress, progress...", 100)
|
||||||
|
|
Loading…
Reference in New Issue