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

Skip to content

Commit b92268a

Browse files
committed
Added AskPassword() with same interface as AskString. By Steve Majewski with some mods by me (SchedParams call, default value). Selects are still impossible, though, and the cursor doesn't blink.
1 parent eef0486 commit b92268a

1 file changed

Lines changed: 71 additions & 0 deletions

File tree

Mac/Lib/EasyDialogs.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
from Dlg import GetNewDialog, SetDialogItemText, GetDialogItemText, ModalDialog
1717
import Qd
1818
import QuickDraw
19+
import Dialogs
20+
import Windows
1921
import Dlg,Win,Evt,Events # sdm7g
2022
import MacOS
2123
import string
@@ -86,6 +88,75 @@ def AskString(prompt, default = "", id=257):
8688
return cr2lf(GetDialogItemText(h))
8789
if n == 2: return None
8890

91+
def AskPassword(prompt, default='', id=257):
92+
"""Display a PROMPT string and a text entry field with a DEFAULT string.
93+
The string is displayed as bullets only.
94+
95+
Return the contents of the text entry field when the user clicks the
96+
OK button or presses Return.
97+
Return None when the user clicks the Cancel button.
98+
99+
If omitted, DEFAULT is empty.
100+
101+
The PROMPT and DEFAULT strings, as well as the return value,
102+
can be at most 255 characters long.
103+
"""
104+
d = GetNewDialog(id, -1)
105+
if not d:
106+
print "Can't get DLOG resource with id =", id
107+
return
108+
tp, h, rect = d.GetDialogItem(3) # STATIC TEXT ITEM <= prompt
109+
SetDialogItemText(h, lf2cr(prompt))
110+
tp, h, rect = d.GetDialogItem(4) # EDIT TEXT ITEM
111+
bullets = '\245'*len(default)
112+
SetDialogItemText(h, bullets )
113+
d.SelectDialogItemText(4, 999, 999)
114+
d.SetDialogDefaultItem(Dialogs.ok)
115+
d.SetDialogCancelItem(Dialogs.cancel)
116+
string = default
117+
oldschedparams = MacOS.SchedParams(0,0)
118+
while 1:
119+
ready,ev = Evt.WaitNextEvent( -1, 6 )
120+
if not ready: continue
121+
what,msg,when,where,mod = ev
122+
if what == 0 : Dlg.DialogSelect(ev) # for blinking caret
123+
elif Dlg.IsDialogEvent(ev):
124+
if what == Events.keyDown:
125+
charcode = msg & Events.charCodeMask
126+
if ( mod & Events.cmdKey ):
127+
MacOS.SysBeep()
128+
continue # don't do cut & paste commands
129+
else:
130+
if charcode == Events.kReturnCharCode:
131+
break
132+
elif charcode == Events.kEscapeCharCode:
133+
string = None
134+
break
135+
elif charcode in (Events.kLeftArrowCharCode,
136+
Events.kBackspaceCharCode):
137+
string = string[:-1]
138+
else:
139+
string = string + chr(charcode)
140+
msg = 0245 # Octal code for bullet
141+
ev = (what,msg,when,where,mod)
142+
rs, win, item = Dlg.DialogSelect(ev)
143+
if item == Dialogs.ok :
144+
break
145+
elif item == Dialogs.cancel :
146+
string = None
147+
break
148+
elif what == Events.mouseDown:
149+
part, win = Win.FindWindow(where)
150+
if part == Windows.inDrag and win:
151+
win.DragWindow(where, screenbounds)
152+
elif part == Windows.inMenuBar:
153+
MacOS.HandleEvent(ev)
154+
else:
155+
MacOS.SysBeep() # Cannot handle selections, unfortunately
156+
157+
elif what == Events.updateEvt: MacOS.HandleEvent(ev)
158+
apply(MacOS.SchedParams, oldschedparams)
159+
return string
89160

90161
def AskYesNoCancel(question, default = 0, yes=None, no=None, cancel=None, id=258):
91162
## """Display a QUESTION string which can be answered with Yes or No.

0 commit comments

Comments
 (0)