Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 60429e0

Browse files
committed
Fixed the password dialog to use a password control.
1 parent a4deef8 commit 60429e0

1 file changed

Lines changed: 26 additions & 50 deletions

File tree

Mac/Lib/EasyDialogs.py

Lines changed: 26 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
import Dialogs
2121
import Windows
2222
import Dlg,Win,Evt,Events # sdm7g
23+
import Ctl
2324
import MacOS
2425
import string
26+
from ControlAccessor import * # Also import Controls constants
2527

2628
def cr2lf(text):
2729
if '\r' in text:
@@ -97,7 +99,7 @@ def AskString(prompt, default = "", id=261, ok=None, cancel=None):
9799
return cr2lf(GetDialogItemText(h))
98100
if n == 2: return None
99101

100-
def AskPassword(prompt, default='', id=264):
102+
def AskPassword(prompt, default='', id=264, ok=None, cancel=None):
101103
"""Display a PROMPT string and a text entry field with a DEFAULT string.
102104
The string is displayed as bullets only.
103105
@@ -114,58 +116,28 @@ def AskPassword(prompt, default='', id=264):
114116
if not d:
115117
print "Can't get DLOG resource with id =", id
116118
return
117-
h = d.GetDialogItemAsControl(3) # STATIC TEXT ITEM <= prompt
119+
h = d.GetDialogItemAsControl(3)
118120
SetDialogItemText(h, lf2cr(prompt))
119-
h = d.GetDialogItemAsControl(4) # EDIT TEXT ITEM
121+
pwd = d.GetDialogItemAsControl(4)
120122
bullets = '\245'*len(default)
121-
SetDialogItemText(h, bullets )
122-
d.SelectDialogItemText(4, 999, 999)
123+
## SetControlData(pwd, kControlEditTextPart, kControlEditTextTextTag, bullets)
124+
SetControlData(pwd, kControlEditTextPart, kControlEditTextPasswordTag, default)
125+
d.SelectDialogItemText(4, 0, 999)
126+
Ctl.SetKeyboardFocus(d, pwd, kControlEditTextPart)
127+
if ok != None:
128+
h = d.GetDialogItemAsControl(1)
129+
h.SetControlTitle(ok)
130+
if cancel != None:
131+
h = d.GetDialogItemAsControl(2)
132+
h.SetControlTitle(cancel)
123133
d.SetDialogDefaultItem(Dialogs.ok)
124134
d.SetDialogCancelItem(Dialogs.cancel)
125-
string = default
126-
oldschedparams = MacOS.SchedParams(0,0)
127135
while 1:
128-
ready,ev = Evt.WaitNextEvent(Events.everyEvent, 6)
129-
if not ready: continue
130-
what,msg,when,where,mod = ev
131-
if what == 0 : Dlg.DialogSelect(ev) # for blinking caret
132-
elif Dlg.IsDialogEvent(ev):
133-
if what in (Events.keyDown, Events.autoKey):
134-
charcode = msg & Events.charCodeMask
135-
if ( mod & Events.cmdKey ):
136-
MacOS.SysBeep()
137-
continue # don't do cut & paste commands
138-
else:
139-
if charcode == Events.kReturnCharCode:
140-
break
141-
elif charcode == Events.kEscapeCharCode:
142-
string = None
143-
break
144-
elif charcode in (Events.kLeftArrowCharCode,
145-
Events.kBackspaceCharCode):
146-
string = string[:-1]
147-
else:
148-
string = string + chr(charcode)
149-
msg = 0245 # Octal code for bullet
150-
ev = (what,msg,when,where,mod)
151-
rs, win, item = Dlg.DialogSelect(ev)
152-
if item == Dialogs.ok :
153-
break
154-
elif item == Dialogs.cancel :
155-
string = None
156-
break
157-
elif what == Events.mouseDown:
158-
part, win = Win.FindWindow(where)
159-
if part == Windows.inDrag and win:
160-
win.DragWindow(where, screenbounds)
161-
elif part == Windows.inMenuBar:
162-
MacOS.HandleEvent(ev)
163-
else:
164-
MacOS.SysBeep() # Cannot handle selections, unfortunately
165-
166-
elif what == Events.updateEvt: MacOS.HandleEvent(ev)
167-
apply(MacOS.SchedParams, oldschedparams)
168-
return string
136+
n = ModalDialog(None)
137+
if n == 1:
138+
h = d.GetDialogItemAsControl(4)
139+
return cr2lf(GetControlData(pwd, kControlEditTextPart, kControlEditTextPasswordTag))
140+
if n == 2: return None
169141

170142
def AskYesNoCancel(question, default = 0, yes=None, no=None, cancel=None, id=262):
171143
"""Display a QUESTION string which can be answered with Yes or No.
@@ -302,10 +274,14 @@ def test():
302274

303275
Message("Testing EasyDialogs.")
304276
ok = AskYesNoCancel("Do you want to proceed?")
305-
ok = AskYesNoCancel("Do you want to identify?", yes="Indentify", no="Don't identify")
277+
ok = AskYesNoCancel("Do you want to identify?", yes="Identify", no="No")
306278
if ok > 0:
307279
s = AskString("Enter your first name", "Joe")
308-
Message("Thank you,\n%s" % `s`)
280+
s2 = AskPassword("Okay %s, tell us your nickname"%s, s, cancel="None")
281+
if not s2:
282+
Message("%s has no secret nickname"%s)
283+
else:
284+
Message("Hello everybody!!\nThe secret nickname of %s is %s!!!"%(s, s2))
309285
text = ( "Working Hard...", "Hardly Working..." ,
310286
"So far, so good!", "Keep on truckin'" )
311287
bar = ProgressBar("Progress, progress...", 100)

0 commit comments

Comments
 (0)