Fixed the password dialog to use a password control.

This commit is contained in:
Jack Jansen 1999-12-13 16:07:01 +00:00
parent a4deef82d5
commit 60429e055e
1 changed files with 26 additions and 50 deletions

View File

@ -20,8 +20,10 @@ import QuickDraw
import Dialogs
import Windows
import Dlg,Win,Evt,Events # sdm7g
import Ctl
import MacOS
import string
from ControlAccessor import * # Also import Controls constants
def cr2lf(text):
if '\r' in text:
@ -97,7 +99,7 @@ def AskString(prompt, default = "", id=261, ok=None, cancel=None):
return cr2lf(GetDialogItemText(h))
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.
The string is displayed as bullets only.
@ -114,58 +116,28 @@ def AskPassword(prompt, default='', id=264):
if not d:
print "Can't get DLOG resource with id =", id
return
h = d.GetDialogItemAsControl(3) # STATIC TEXT ITEM <= prompt
h = d.GetDialogItemAsControl(3)
SetDialogItemText(h, lf2cr(prompt))
h = d.GetDialogItemAsControl(4) # EDIT TEXT ITEM
pwd = d.GetDialogItemAsControl(4)
bullets = '\245'*len(default)
SetDialogItemText(h, bullets )
d.SelectDialogItemText(4, 999, 999)
## SetControlData(pwd, kControlEditTextPart, kControlEditTextTextTag, bullets)
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.SetDialogCancelItem(Dialogs.cancel)
string = default
oldschedparams = MacOS.SchedParams(0,0)
while 1:
ready,ev = Evt.WaitNextEvent(Events.everyEvent, 6)
if not ready: continue
what,msg,when,where,mod = ev
if what == 0 : Dlg.DialogSelect(ev) # for blinking caret
elif Dlg.IsDialogEvent(ev):
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
n = ModalDialog(None)
if n == 1:
h = d.GetDialogItemAsControl(4)
return cr2lf(GetControlData(pwd, kControlEditTextPart, kControlEditTextPasswordTag))
if n == 2: return None
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.
@ -302,10 +274,14 @@ def test():
Message("Testing EasyDialogs.")
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:
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..." ,
"So far, so good!", "Keep on truckin'" )
bar = ProgressBar("Progress, progress...", 100)