summaryrefslogtreecommitdiffstats
path: root/Mac/Lib
diff options
context:
space:
mode:
authorJack Jansen <jack.jansen@cwi.nl>1999-12-13 16:07:01 (GMT)
committerJack Jansen <jack.jansen@cwi.nl>1999-12-13 16:07:01 (GMT)
commit60429e055ef92d63347018d239c717d7cc65d174 (patch)
treeec5dd4abfdcfe0cb96b381f7c0ffe863f66f5859 /Mac/Lib
parenta4deef82d5b5d68bf02f6950021741502849fd47 (diff)
downloadcpython-60429e055ef92d63347018d239c717d7cc65d174.zip
cpython-60429e055ef92d63347018d239c717d7cc65d174.tar.gz
cpython-60429e055ef92d63347018d239c717d7cc65d174.tar.bz2
Fixed the password dialog to use a password control.
Diffstat (limited to 'Mac/Lib')
-rw-r--r--Mac/Lib/EasyDialogs.py76
1 files changed, 26 insertions, 50 deletions
diff --git a/Mac/Lib/EasyDialogs.py b/Mac/Lib/EasyDialogs.py
index 1ac39b3..6574336 100644
--- a/Mac/Lib/EasyDialogs.py
+++ b/Mac/Lib/EasyDialogs.py
@@ -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)