annotate Lib/plat-mac/EasyDialogs.py @ 79675:c0a2294de787 2.7

Issue #16199: Backport 2to3 typo fix from 3.2.
author Chris Jerdonek <chris.jerdonek@gmail.com>
date Thu, 11 Oct 2012 16:15:46 -0700
parents f6785bce54b5
children cfdb4598c935
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1 """Easy to use dialogs.
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
2
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
3 Message(msg) -- display a message and an OK button.
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
4 AskString(prompt, default) -- ask for a string, display OK and Cancel buttons.
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
5 AskPassword(prompt, default) -- like AskString(), but shows text as bullets.
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
6 AskYesNoCancel(question, default) -- display a question and Yes, No and Cancel buttons.
27326
44e352d7d52f Spell out the arguments to AskFileForOpen and friends, so help() gives useful
Jack Jansen <jack.jansen@cwi.nl>
parents: 27324
diff changeset
7 GetArgv(optionlist, commandlist) -- fill a sys.argv-like list using a dialog
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 28400
diff changeset
8 AskFileForOpen(...) -- Ask the user for an existing file
27326
44e352d7d52f Spell out the arguments to AskFileForOpen and friends, so help() gives useful
Jack Jansen <jack.jansen@cwi.nl>
parents: 27324
diff changeset
9 AskFileForSave(...) -- Ask the user for an output file
44e352d7d52f Spell out the arguments to AskFileForOpen and friends, so help() gives useful
Jack Jansen <jack.jansen@cwi.nl>
parents: 27324
diff changeset
10 AskFolder(...) -- Ask the user to select a folder
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
11 bar = Progress(label, maxvalue) -- Display a progress bar
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
12 bar.set(value) -- Set value
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
13 bar.inc( *amount ) -- increment value by amount (default=1)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 28400
diff changeset
14 bar.label( *newlabel ) -- get or set text label.
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
15
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
16 More documentation in each function.
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
17 This module uses DLOG resources 260 and on.
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
18 Based upon STDWIN dialogs with the same names and functions.
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
19 """
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
20
46967
6df0394abbf1 Add warnings to and deprecated all those Mac modules
Benjamin Peterson <benjamin@python.org>
parents: 46197
diff changeset
21 from warnings import warnpy3k
47958
e7a6a4515ab0 fix test_py3kwarns
Benjamin Peterson <benjamin@python.org>
parents: 46967
diff changeset
22 warnpy3k("In 3.x, the EasyDialogs module is removed.", stacklevel=2)
46967
6df0394abbf1 Add warnings to and deprecated all those Mac modules
Benjamin Peterson <benjamin@python.org>
parents: 46197
diff changeset
23
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
24 from Carbon.Dlg import GetNewDialog, SetDialogItemText, GetDialogItemText, ModalDialog
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
25 from Carbon import Qd
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
26 from Carbon import QuickDraw
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
27 from Carbon import Dialogs
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
28 from Carbon import Windows
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
29 from Carbon import Dlg,Win,Evt,Events # sdm7g
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
30 from Carbon import Ctl
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
31 from Carbon import Controls
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
32 from Carbon import Menu
28143
8889654c0dd5 Call AEInteractWithUser() before bringing up any of the dialogs (with the
Jack Jansen <jack.jansen@cwi.nl>
parents: 28022
diff changeset
33 from Carbon import AE
27276
9da43cde8a16 Added methods AskFileForOpen(), AskFileForSave() and AskFolder(). These
Jack Jansen <jack.jansen@cwi.nl>
parents: 26884
diff changeset
34 import Nav
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
35 import MacOS
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
36 import string
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 28400
diff changeset
37 from Carbon.ControlAccessor import * # Also import Controls constants
27276
9da43cde8a16 Added methods AskFileForOpen(), AskFileForSave() and AskFolder(). These
Jack Jansen <jack.jansen@cwi.nl>
parents: 26884
diff changeset
38 import Carbon.File
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
39 import macresource
27287
88faa985d98c Fixed the first two bugs in the new file dialogs (found by Just):
Jack Jansen <jack.jansen@cwi.nl>
parents: 27276
diff changeset
40 import os
27402
e945a03ee56c FSRef and EasyDialogs pathname support was pretty much broken in MacPython-OS9. Fixed.
Jack Jansen <jack.jansen@cwi.nl>
parents: 27334
diff changeset
41 import sys
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
42
27326
44e352d7d52f Spell out the arguments to AskFileForOpen and friends, so help() gives useful
Jack Jansen <jack.jansen@cwi.nl>
parents: 27324
diff changeset
43 __all__ = ['Message', 'AskString', 'AskPassword', 'AskYesNoCancel',
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
44 'GetArgv', 'AskFileForOpen', 'AskFileForSave', 'AskFolder',
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
45 'ProgressBar']
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 28400
diff changeset
46
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
47 _initialized = 0
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
48
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
49 def _initialize():
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
50 global _initialized
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
51 if _initialized: return
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
52 macresource.need("DLOG", 260, "dialogs.rsrc", __name__)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 28400
diff changeset
53
28143
8889654c0dd5 Call AEInteractWithUser() before bringing up any of the dialogs (with the
Jack Jansen <jack.jansen@cwi.nl>
parents: 28022
diff changeset
54 def _interact():
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
55 """Make sure the application is in the foreground"""
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
56 AE.AEInteractWithUser(50000000)
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
57
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
58 def cr2lf(text):
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
59 if '\r' in text:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
60 text = string.join(string.split(text, '\r'), '\n')
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
61 return text
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
62
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
63 def lf2cr(text):
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
64 if '\n' in text:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
65 text = string.join(string.split(text, '\n'), '\r')
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
66 if len(text) > 253:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
67 text = text[:253] + '\311'
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
68 return text
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
69
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
70 def Message(msg, id=260, ok=None):
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
71 """Display a MESSAGE string.
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 28400
diff changeset
72
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
73 Return when the user clicks the OK button or presses Return.
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 28400
diff changeset
74
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
75 The MESSAGE string can be at most 255 characters long.
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
76 """
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
77 _initialize()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
78 _interact()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
79 d = GetNewDialog(id, -1)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
80 if not d:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
81 print "EasyDialogs: Can't get DLOG resource with id =", id, " (missing resource file?)"
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
82 return
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
83 h = d.GetDialogItemAsControl(2)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
84 SetDialogItemText(h, lf2cr(msg))
46197
01a7e66525c2 #2503 make singletons compared with "is" not == or !=
Benjamin Peterson <benjamin@python.org>
parents: 38627
diff changeset
85 if ok is not None:
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
86 h = d.GetDialogItemAsControl(1)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
87 h.SetControlTitle(ok)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
88 d.SetDialogDefaultItem(1)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
89 d.AutoSizeDialog()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
90 d.GetDialogWindow().ShowWindow()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
91 while 1:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
92 n = ModalDialog(None)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
93 if n == 1:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
94 return
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
95
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
96
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
97 def AskString(prompt, default = "", id=261, ok=None, cancel=None):
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
98 """Display a PROMPT string and a text entry field with a DEFAULT string.
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 28400
diff changeset
99
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
100 Return the contents of the text entry field when the user clicks the
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
101 OK button or presses Return.
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
102 Return None when the user clicks the Cancel button.
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 28400
diff changeset
103
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
104 If omitted, DEFAULT is empty.
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 28400
diff changeset
105
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
106 The PROMPT and DEFAULT strings, as well as the return value,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
107 can be at most 255 characters long.
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
108 """
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 28400
diff changeset
109
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
110 _initialize()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
111 _interact()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
112 d = GetNewDialog(id, -1)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
113 if not d:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
114 print "EasyDialogs: Can't get DLOG resource with id =", id, " (missing resource file?)"
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
115 return
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
116 h = d.GetDialogItemAsControl(3)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
117 SetDialogItemText(h, lf2cr(prompt))
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
118 h = d.GetDialogItemAsControl(4)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
119 SetDialogItemText(h, lf2cr(default))
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
120 d.SelectDialogItemText(4, 0, 999)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 28400
diff changeset
121 # d.SetDialogItem(4, 0, 255)
46197
01a7e66525c2 #2503 make singletons compared with "is" not == or !=
Benjamin Peterson <benjamin@python.org>
parents: 38627
diff changeset
122 if ok is not None:
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
123 h = d.GetDialogItemAsControl(1)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
124 h.SetControlTitle(ok)
46197
01a7e66525c2 #2503 make singletons compared with "is" not == or !=
Benjamin Peterson <benjamin@python.org>
parents: 38627
diff changeset
125 if cancel is not None:
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
126 h = d.GetDialogItemAsControl(2)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
127 h.SetControlTitle(cancel)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
128 d.SetDialogDefaultItem(1)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
129 d.SetDialogCancelItem(2)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
130 d.AutoSizeDialog()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
131 d.GetDialogWindow().ShowWindow()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
132 while 1:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
133 n = ModalDialog(None)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
134 if n == 1:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
135 h = d.GetDialogItemAsControl(4)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
136 return cr2lf(GetDialogItemText(h))
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
137 if n == 2: return None
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
138
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 28400
diff changeset
139 def AskPassword(prompt, default='', id=264, ok=None, cancel=None):
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
140 """Display a PROMPT string and a text entry field with a DEFAULT string.
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
141 The string is displayed as bullets only.
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 28400
diff changeset
142
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
143 Return the contents of the text entry field when the user clicks the
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
144 OK button or presses Return.
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
145 Return None when the user clicks the Cancel button.
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 28400
diff changeset
146
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
147 If omitted, DEFAULT is empty.
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 28400
diff changeset
148
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
149 The PROMPT and DEFAULT strings, as well as the return value,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
150 can be at most 255 characters long.
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
151 """
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
152 _initialize()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
153 _interact()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
154 d = GetNewDialog(id, -1)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
155 if not d:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
156 print "EasyDialogs: Can't get DLOG resource with id =", id, " (missing resource file?)"
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
157 return
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
158 h = d.GetDialogItemAsControl(3)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
159 SetDialogItemText(h, lf2cr(prompt))
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
160 pwd = d.GetDialogItemAsControl(4)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
161 bullets = '\245'*len(default)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 28400
diff changeset
162 ## SetControlData(pwd, kControlEditTextPart, kControlEditTextTextTag, bullets)
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
163 SetControlData(pwd, kControlEditTextPart, kControlEditTextPasswordTag, default)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
164 d.SelectDialogItemText(4, 0, 999)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
165 Ctl.SetKeyboardFocus(d.GetDialogWindow(), pwd, kControlEditTextPart)
46197
01a7e66525c2 #2503 make singletons compared with "is" not == or !=
Benjamin Peterson <benjamin@python.org>
parents: 38627
diff changeset
166 if ok is not None:
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
167 h = d.GetDialogItemAsControl(1)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
168 h.SetControlTitle(ok)
46197
01a7e66525c2 #2503 make singletons compared with "is" not == or !=
Benjamin Peterson <benjamin@python.org>
parents: 38627
diff changeset
169 if cancel is not None:
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
170 h = d.GetDialogItemAsControl(2)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
171 h.SetControlTitle(cancel)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
172 d.SetDialogDefaultItem(Dialogs.ok)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
173 d.SetDialogCancelItem(Dialogs.cancel)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
174 d.AutoSizeDialog()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
175 d.GetDialogWindow().ShowWindow()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
176 while 1:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
177 n = ModalDialog(None)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
178 if n == 1:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
179 h = d.GetDialogItemAsControl(4)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
180 return cr2lf(GetControlData(pwd, kControlEditTextPart, kControlEditTextPasswordTag))
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
181 if n == 2: return None
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
182
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
183 def AskYesNoCancel(question, default = 0, yes=None, no=None, cancel=None, id=262):
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
184 """Display a QUESTION string which can be answered with Yes or No.
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 28400
diff changeset
185
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
186 Return 1 when the user clicks the Yes button.
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
187 Return 0 when the user clicks the No button.
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
188 Return -1 when the user clicks the Cancel button.
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 28400
diff changeset
189
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
190 When the user presses Return, the DEFAULT value is returned.
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
191 If omitted, this is 0 (No).
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 28400
diff changeset
192
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
193 The QUESTION string can be at most 255 characters.
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
194 """
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 28400
diff changeset
195
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
196 _initialize()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
197 _interact()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
198 d = GetNewDialog(id, -1)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
199 if not d:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
200 print "EasyDialogs: Can't get DLOG resource with id =", id, " (missing resource file?)"
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
201 return
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
202 # Button assignments:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
203 # 1 = default (invisible)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
204 # 2 = Yes
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
205 # 3 = No
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
206 # 4 = Cancel
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
207 # The question string is item 5
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
208 h = d.GetDialogItemAsControl(5)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
209 SetDialogItemText(h, lf2cr(question))
46197
01a7e66525c2 #2503 make singletons compared with "is" not == or !=
Benjamin Peterson <benjamin@python.org>
parents: 38627
diff changeset
210 if yes is not None:
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
211 if yes == '':
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
212 d.HideDialogItem(2)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
213 else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
214 h = d.GetDialogItemAsControl(2)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
215 h.SetControlTitle(yes)
46197
01a7e66525c2 #2503 make singletons compared with "is" not == or !=
Benjamin Peterson <benjamin@python.org>
parents: 38627
diff changeset
216 if no is not None:
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
217 if no == '':
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
218 d.HideDialogItem(3)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
219 else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
220 h = d.GetDialogItemAsControl(3)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
221 h.SetControlTitle(no)
46197
01a7e66525c2 #2503 make singletons compared with "is" not == or !=
Benjamin Peterson <benjamin@python.org>
parents: 38627
diff changeset
222 if cancel is not None:
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
223 if cancel == '':
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
224 d.HideDialogItem(4)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
225 else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
226 h = d.GetDialogItemAsControl(4)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
227 h.SetControlTitle(cancel)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
228 d.SetDialogCancelItem(4)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
229 if default == 1:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
230 d.SetDialogDefaultItem(2)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
231 elif default == 0:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
232 d.SetDialogDefaultItem(3)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
233 elif default == -1:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
234 d.SetDialogDefaultItem(4)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
235 d.AutoSizeDialog()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
236 d.GetDialogWindow().ShowWindow()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
237 while 1:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
238 n = ModalDialog(None)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
239 if n == 1: return default
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
240 if n == 2: return 1
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
241 if n == 3: return 0
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
242 if n == 4: return -1
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
243
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
244
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 28400
diff changeset
245
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
246
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
247 screenbounds = Qd.GetQDGlobalsScreenBits().bounds
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
248 screenbounds = screenbounds[0]+4, screenbounds[1]+4, \
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
249 screenbounds[2]-4, screenbounds[3]-4
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
250
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 28400
diff changeset
251 kControlProgressBarIndeterminateTag = 'inde' # from Controls.py
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
252
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
253
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
254 class ProgressBar:
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
255 def __init__(self, title="Working...", maxval=0, label="", id=263):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
256 self.w = None
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
257 self.d = None
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
258 _initialize()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
259 self.d = GetNewDialog(id, -1)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
260 self.w = self.d.GetDialogWindow()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
261 self.label(label)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
262 self.title(title)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
263 self.set(0, maxval)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
264 self.d.AutoSizeDialog()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
265 self.w.ShowWindow()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
266 self.d.DrawDialog()
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
267
38627
98e81af40007 Normalized a few cases of whitespace in function declarations.
Martin Blais <blais@furius.ca>
parents: 32736
diff changeset
268 def __del__(self):
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
269 if self.w:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
270 self.w.BringToFront()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
271 self.w.HideWindow()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
272 del self.w
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
273 del self.d
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 28400
diff changeset
274
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
275 def title(self, newstr=""):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
276 """title(text) - Set title of progress window"""
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
277 self.w.BringToFront()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
278 self.w.SetWTitle(newstr)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 28400
diff changeset
279
38627
98e81af40007 Normalized a few cases of whitespace in function declarations.
Martin Blais <blais@furius.ca>
parents: 32736
diff changeset
280 def label(self, *newstr):
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
281 """label(text) - Set text in progress box"""
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
282 self.w.BringToFront()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
283 if newstr:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
284 self._label = lf2cr(newstr[0])
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
285 text_h = self.d.GetDialogItemAsControl(2)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
286 SetDialogItemText(text_h, self._label)
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
287
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
288 def _update(self, value):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
289 maxval = self.maxval
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
290 if maxval == 0: # an indeterminate bar
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
291 Ctl.IdleControls(self.w) # spin the barber pole
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
292 else: # a determinate bar
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
293 if maxval > 32767:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
294 value = int(value/(maxval/32767.0))
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
295 maxval = 32767
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
296 maxval = int(maxval)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
297 value = int(value)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
298 progbar = self.d.GetDialogItemAsControl(3)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
299 progbar.SetControlMaximum(maxval)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
300 progbar.SetControlValue(value) # set the bar length
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
301
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
302 # Test for cancel button
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
303 ready, ev = Evt.WaitNextEvent( Events.mDownMask, 1 )
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
304 if ready :
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
305 what,msg,when,where,mod = ev
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
306 part = Win.FindWindow(where)[0]
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
307 if Dlg.IsDialogEvent(ev):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
308 ds = Dlg.DialogSelect(ev)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
309 if ds[0] and ds[1] == self.d and ds[-1] == 1:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
310 self.w.HideWindow()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
311 self.w = None
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
312 self.d = None
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
313 raise KeyboardInterrupt, ev
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
314 else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
315 if part == 4: # inDrag
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
316 self.w.DragWindow(where, screenbounds)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
317 else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
318 MacOS.HandleEvent(ev)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 28400
diff changeset
319
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
320
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
321 def set(self, value, max=None):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
322 """set(value) - Set progress bar position"""
46197
01a7e66525c2 #2503 make singletons compared with "is" not == or !=
Benjamin Peterson <benjamin@python.org>
parents: 38627
diff changeset
323 if max is not None:
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
324 self.maxval = max
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
325 bar = self.d.GetDialogItemAsControl(3)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
326 if max <= 0: # indeterminate bar
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
327 bar.SetControlData(0,kControlProgressBarIndeterminateTag,'\x01')
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
328 else: # determinate bar
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
329 bar.SetControlData(0,kControlProgressBarIndeterminateTag,'\x00')
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
330 if value < 0:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
331 value = 0
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
332 elif value > self.maxval:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
333 value = self.maxval
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
334 self.curval = value
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
335 self._update(value)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 28400
diff changeset
336
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
337 def inc(self, n=1):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
338 """inc(amt) - Increment progress bar position"""
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
339 self.set(self.curval + n)
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
340
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
341 ARGV_ID=265
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
342 ARGV_ITEM_OK=1
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
343 ARGV_ITEM_CANCEL=2
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
344 ARGV_OPTION_GROUP=3
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
345 ARGV_OPTION_EXPLAIN=4
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
346 ARGV_OPTION_VALUE=5
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
347 ARGV_OPTION_ADD=6
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
348 ARGV_COMMAND_GROUP=7
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
349 ARGV_COMMAND_EXPLAIN=8
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
350 ARGV_COMMAND_ADD=9
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
351 ARGV_ADD_OLDFILE=10
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
352 ARGV_ADD_NEWFILE=11
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
353 ARGV_ADD_FOLDER=12
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
354 ARGV_CMDLINE_GROUP=13
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
355 ARGV_CMDLINE_DATA=14
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
356
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
357 ##def _myModalDialog(d):
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 28400
diff changeset
358 ## while 1:
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
359 ## ready, ev = Evt.WaitNextEvent(0xffff, -1)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
360 ## print 'DBG: WNE', ready, ev
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
361 ## if ready :
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
362 ## what,msg,when,where,mod = ev
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
363 ## part, window = Win.FindWindow(where)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
364 ## if Dlg.IsDialogEvent(ev):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
365 ## didit, dlgdone, itemdone = Dlg.DialogSelect(ev)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
366 ## print 'DBG: DialogSelect', didit, dlgdone, itemdone, d
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
367 ## if didit and dlgdone == d:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
368 ## return itemdone
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
369 ## elif window == d.GetDialogWindow():
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
370 ## d.GetDialogWindow().SelectWindow()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
371 ## if part == 4: # inDrag
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
372 ## d.DragWindow(where, screenbounds)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
373 ## else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
374 ## MacOS.HandleEvent(ev)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
375 ## else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
376 ## MacOS.HandleEvent(ev)
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
377 ##
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
378 def _setmenu(control, items):
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31515
diff changeset
379 mhandle = control.GetControlData_Handle(Controls.kControlMenuPart,
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31515
diff changeset
380 Controls.kControlPopupButtonMenuHandleTag)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31515
diff changeset
381 menu = Menu.as_Menu(mhandle)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31515
diff changeset
382 for item in items:
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31515
diff changeset
383 if type(item) == type(()):
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31515
diff changeset
384 label = item[0]
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31515
diff changeset
385 else:
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31515
diff changeset
386 label = item
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31515
diff changeset
387 if label[-1] == '=' or label[-1] == ':':
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31515
diff changeset
388 label = label[:-1]
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31515
diff changeset
389 menu.AppendMenu(label)
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
390 ## mhandle, mid = menu.getpopupinfo()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
391 ## control.SetControlData_Handle(Controls.kControlMenuPart,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
392 ## Controls.kControlPopupButtonMenuHandleTag, mhandle)
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31515
diff changeset
393 control.SetControlMinimum(1)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31515
diff changeset
394 control.SetControlMaximum(len(items)+1)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 28400
diff changeset
395
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
396 def _selectoption(d, optionlist, idx):
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
397 if idx < 0 or idx >= len(optionlist):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
398 MacOS.SysBeep()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
399 return
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
400 option = optionlist[idx]
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
401 if type(option) == type(()):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
402 if len(option) == 4:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
403 help = option[2]
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
404 elif len(option) > 1:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
405 help = option[-1]
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 28400
diff changeset
406 else:
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
407 help = ''
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
408 else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
409 help = ''
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
410 h = d.GetDialogItemAsControl(ARGV_OPTION_EXPLAIN)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
411 if help and len(help) > 250:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
412 help = help[:250] + '...'
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
413 Dlg.SetDialogItemText(h, help)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
414 hasvalue = 0
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
415 if type(option) == type(()):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
416 label = option[0]
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
417 else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
418 label = option
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
419 if label[-1] == '=' or label[-1] == ':':
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
420 hasvalue = 1
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
421 h = d.GetDialogItemAsControl(ARGV_OPTION_VALUE)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
422 Dlg.SetDialogItemText(h, '')
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
423 if hasvalue:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
424 d.ShowDialogItem(ARGV_OPTION_VALUE)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
425 d.SelectDialogItemText(ARGV_OPTION_VALUE, 0, 0)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
426 else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
427 d.HideDialogItem(ARGV_OPTION_VALUE)
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
428
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
429
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
430 def GetArgv(optionlist=None, commandlist=None, addoldfile=1, addnewfile=1, addfolder=1, id=ARGV_ID):
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
431 _initialize()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
432 _interact()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
433 d = GetNewDialog(id, -1)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
434 if not d:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
435 print "EasyDialogs: Can't get DLOG resource with id =", id, " (missing resource file?)"
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
436 return
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 28400
diff changeset
437 # h = d.GetDialogItemAsControl(3)
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 28400
diff changeset
438 # SetDialogItemText(h, lf2cr(prompt))
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 28400
diff changeset
439 # h = d.GetDialogItemAsControl(4)
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 28400
diff changeset
440 # SetDialogItemText(h, lf2cr(default))
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 28400
diff changeset
441 # d.SelectDialogItemText(4, 0, 999)
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 28400
diff changeset
442 # d.SetDialogItem(4, 0, 255)
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
443 if optionlist:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
444 _setmenu(d.GetDialogItemAsControl(ARGV_OPTION_GROUP), optionlist)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
445 _selectoption(d, optionlist, 0)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
446 else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
447 d.GetDialogItemAsControl(ARGV_OPTION_GROUP).DeactivateControl()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
448 if commandlist:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
449 _setmenu(d.GetDialogItemAsControl(ARGV_COMMAND_GROUP), commandlist)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
450 if type(commandlist[0]) == type(()) and len(commandlist[0]) > 1:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
451 help = commandlist[0][-1]
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
452 h = d.GetDialogItemAsControl(ARGV_COMMAND_EXPLAIN)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
453 Dlg.SetDialogItemText(h, help)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
454 else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
455 d.GetDialogItemAsControl(ARGV_COMMAND_GROUP).DeactivateControl()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
456 if not addoldfile:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
457 d.GetDialogItemAsControl(ARGV_ADD_OLDFILE).DeactivateControl()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
458 if not addnewfile:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
459 d.GetDialogItemAsControl(ARGV_ADD_NEWFILE).DeactivateControl()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
460 if not addfolder:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
461 d.GetDialogItemAsControl(ARGV_ADD_FOLDER).DeactivateControl()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
462 d.SetDialogDefaultItem(ARGV_ITEM_OK)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
463 d.SetDialogCancelItem(ARGV_ITEM_CANCEL)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
464 d.GetDialogWindow().ShowWindow()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
465 d.DrawDialog()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
466 if hasattr(MacOS, 'SchedParams'):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
467 appsw = MacOS.SchedParams(1, 0)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
468 try:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
469 while 1:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
470 stringstoadd = []
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
471 n = ModalDialog(None)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
472 if n == ARGV_ITEM_OK:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
473 break
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
474 elif n == ARGV_ITEM_CANCEL:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
475 raise SystemExit
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
476 elif n == ARGV_OPTION_GROUP:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
477 idx = d.GetDialogItemAsControl(ARGV_OPTION_GROUP).GetControlValue()-1
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
478 _selectoption(d, optionlist, idx)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
479 elif n == ARGV_OPTION_VALUE:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
480 pass
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
481 elif n == ARGV_OPTION_ADD:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
482 idx = d.GetDialogItemAsControl(ARGV_OPTION_GROUP).GetControlValue()-1
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
483 if 0 <= idx < len(optionlist):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
484 option = optionlist[idx]
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
485 if type(option) == type(()):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
486 option = option[0]
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
487 if option[-1] == '=' or option[-1] == ':':
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
488 option = option[:-1]
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
489 h = d.GetDialogItemAsControl(ARGV_OPTION_VALUE)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
490 value = Dlg.GetDialogItemText(h)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
491 else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
492 value = ''
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
493 if len(option) == 1:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
494 stringtoadd = '-' + option
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
495 else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
496 stringtoadd = '--' + option
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
497 stringstoadd = [stringtoadd]
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
498 if value:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
499 stringstoadd.append(value)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
500 else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
501 MacOS.SysBeep()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
502 elif n == ARGV_COMMAND_GROUP:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
503 idx = d.GetDialogItemAsControl(ARGV_COMMAND_GROUP).GetControlValue()-1
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
504 if 0 <= idx < len(commandlist) and type(commandlist[idx]) == type(()) and \
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
505 len(commandlist[idx]) > 1:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
506 help = commandlist[idx][-1]
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
507 h = d.GetDialogItemAsControl(ARGV_COMMAND_EXPLAIN)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
508 Dlg.SetDialogItemText(h, help)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
509 elif n == ARGV_COMMAND_ADD:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
510 idx = d.GetDialogItemAsControl(ARGV_COMMAND_GROUP).GetControlValue()-1
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
511 if 0 <= idx < len(commandlist):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
512 command = commandlist[idx]
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
513 if type(command) == type(()):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
514 command = command[0]
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
515 stringstoadd = [command]
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
516 else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
517 MacOS.SysBeep()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
518 elif n == ARGV_ADD_OLDFILE:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
519 pathname = AskFileForOpen()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
520 if pathname:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
521 stringstoadd = [pathname]
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
522 elif n == ARGV_ADD_NEWFILE:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
523 pathname = AskFileForSave()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
524 if pathname:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
525 stringstoadd = [pathname]
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
526 elif n == ARGV_ADD_FOLDER:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
527 pathname = AskFolder()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
528 if pathname:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
529 stringstoadd = [pathname]
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
530 elif n == ARGV_CMDLINE_DATA:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
531 pass # Nothing to do
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
532 else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
533 raise RuntimeError, "Unknown dialog item %d"%n
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 28400
diff changeset
534
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
535 for stringtoadd in stringstoadd:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
536 if '"' in stringtoadd or "'" in stringtoadd or " " in stringtoadd:
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 29575
diff changeset
537 stringtoadd = repr(stringtoadd)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 28400
diff changeset
538 h = d.GetDialogItemAsControl(ARGV_CMDLINE_DATA)
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 28400
diff changeset
539 oldstr = GetDialogItemText(h)
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
540 if oldstr and oldstr[-1] != ' ':
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
541 oldstr = oldstr + ' '
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
542 oldstr = oldstr + stringtoadd
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
543 if oldstr[-1] != ' ':
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
544 oldstr = oldstr + ' '
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
545 SetDialogItemText(h, oldstr)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
546 d.SelectDialogItemText(ARGV_CMDLINE_DATA, 0x7fff, 0x7fff)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
547 h = d.GetDialogItemAsControl(ARGV_CMDLINE_DATA)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
548 oldstr = GetDialogItemText(h)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
549 tmplist = string.split(oldstr)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
550 newlist = []
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
551 while tmplist:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
552 item = tmplist[0]
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
553 del tmplist[0]
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
554 if item[0] == '"':
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
555 while item[-1] != '"':
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
556 if not tmplist:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
557 raise RuntimeError, "Unterminated quoted argument"
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
558 item = item + ' ' + tmplist[0]
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
559 del tmplist[0]
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
560 item = item[1:-1]
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
561 if item[0] == "'":
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
562 while item[-1] != "'":
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
563 if not tmplist:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
564 raise RuntimeError, "Unterminated quoted argument"
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
565 item = item + ' ' + tmplist[0]
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
566 del tmplist[0]
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
567 item = item[1:-1]
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
568 newlist.append(item)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
569 return newlist
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
570 finally:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
571 if hasattr(MacOS, 'SchedParams'):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
572 MacOS.SchedParams(*appsw)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
573 del d
27276
9da43cde8a16 Added methods AskFileForOpen(), AskFileForSave() and AskFolder(). These
Jack Jansen <jack.jansen@cwi.nl>
parents: 26884
diff changeset
574
27326
44e352d7d52f Spell out the arguments to AskFileForOpen and friends, so help() gives useful
Jack Jansen <jack.jansen@cwi.nl>
parents: 27324
diff changeset
575 def _process_Nav_args(dftflags, **args):
50522
ee9ced92843a Merged revisions 68133-68134,68141-68142,68145-68146,68148-68149,68159-68162,68166,68171-68174,68179,68195-68196,68210,68214-68215,68217-68222 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47958
diff changeset
576 import Carbon.AppleEvents
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
577 import Carbon.AE
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
578 import Carbon.File
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
579 for k in args.keys():
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
580 if args[k] is None:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
581 del args[k]
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
582 # Set some defaults, and modify some arguments
60278
e29a2e03e739 Silence DeprecationWarnings from uses of has_key and <> in plat-mac.
Mark Dickinson <dickinsm@gmail.com>
parents: 50522
diff changeset
583 if 'dialogOptionFlags' not in args:
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
584 args['dialogOptionFlags'] = dftflags
60278
e29a2e03e739 Silence DeprecationWarnings from uses of has_key and <> in plat-mac.
Mark Dickinson <dickinsm@gmail.com>
parents: 50522
diff changeset
585 if 'defaultLocation' in args and \
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
586 not isinstance(args['defaultLocation'], Carbon.AE.AEDesc):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
587 defaultLocation = args['defaultLocation']
50522
ee9ced92843a Merged revisions 68133-68134,68141-68142,68145-68146,68148-68149,68159-68162,68166,68171-68174,68179,68195-68196,68210,68214-68215,68217-68222 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47958
diff changeset
588 if isinstance(defaultLocation, Carbon.File.FSSpec):
ee9ced92843a Merged revisions 68133-68134,68141-68142,68145-68146,68148-68149,68159-68162,68166,68171-68174,68179,68195-68196,68210,68214-68215,68217-68222 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47958
diff changeset
589 args['defaultLocation'] = Carbon.AE.AECreateDesc(
ee9ced92843a Merged revisions 68133-68134,68141-68142,68145-68146,68148-68149,68159-68162,68166,68171-68174,68179,68195-68196,68210,68214-68215,68217-68222 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47958
diff changeset
590 Carbon.AppleEvents.typeFSS, defaultLocation.data)
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
591 else:
50522
ee9ced92843a Merged revisions 68133-68134,68141-68142,68145-68146,68148-68149,68159-68162,68166,68171-68174,68179,68195-68196,68210,68214-68215,68217-68222 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47958
diff changeset
592 if not isinstance(defaultLocation, Carbon.File.FSRef):
ee9ced92843a Merged revisions 68133-68134,68141-68142,68145-68146,68148-68149,68159-68162,68166,68171-68174,68179,68195-68196,68210,68214-68215,68217-68222 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47958
diff changeset
593 defaultLocation = Carbon.File.FSRef(defaultLocation)
ee9ced92843a Merged revisions 68133-68134,68141-68142,68145-68146,68148-68149,68159-68162,68166,68171-68174,68179,68195-68196,68210,68214-68215,68217-68222 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47958
diff changeset
594 args['defaultLocation'] = Carbon.AE.AECreateDesc(
ee9ced92843a Merged revisions 68133-68134,68141-68142,68145-68146,68148-68149,68159-68162,68166,68171-68174,68179,68195-68196,68210,68214-68215,68217-68222 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47958
diff changeset
595 Carbon.AppleEvents.typeFSRef, defaultLocation.data)
60278
e29a2e03e739 Silence DeprecationWarnings from uses of has_key and <> in plat-mac.
Mark Dickinson <dickinsm@gmail.com>
parents: 50522
diff changeset
596 if 'typeList' in args and not isinstance(args['typeList'], Carbon.Res.ResourceType):
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
597 typeList = args['typeList'][:]
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
598 # Workaround for OSX typeless files:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
599 if 'TEXT' in typeList and not '\0\0\0\0' in typeList:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
600 typeList = typeList + ('\0\0\0\0',)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
601 data = 'Pyth' + struct.pack("hh", 0, len(typeList))
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
602 for type in typeList:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
603 data = data+type
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
604 args['typeList'] = Carbon.Res.Handle(data)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
605 tpwanted = str
60278
e29a2e03e739 Silence DeprecationWarnings from uses of has_key and <> in plat-mac.
Mark Dickinson <dickinsm@gmail.com>
parents: 50522
diff changeset
606 if 'wanted' in args:
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
607 tpwanted = args['wanted']
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
608 del args['wanted']
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
609 return args, tpwanted
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 28400
diff changeset
610
27751
c7cf1b5d471b Made AskFile* dialogs movable-modal by default, by providing a dummy
Jack Jansen <jack.jansen@cwi.nl>
parents: 27402
diff changeset
611 def _dummy_Nav_eventproc(msg, data):
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
612 pass
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 28400
diff changeset
613
27751
c7cf1b5d471b Made AskFile* dialogs movable-modal by default, by providing a dummy
Jack Jansen <jack.jansen@cwi.nl>
parents: 27402
diff changeset
614 _default_Nav_eventproc = _dummy_Nav_eventproc
c7cf1b5d471b Made AskFile* dialogs movable-modal by default, by providing a dummy
Jack Jansen <jack.jansen@cwi.nl>
parents: 27402
diff changeset
615
c7cf1b5d471b Made AskFile* dialogs movable-modal by default, by providing a dummy
Jack Jansen <jack.jansen@cwi.nl>
parents: 27402
diff changeset
616 def SetDefaultEventProc(proc):
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
617 global _default_Nav_eventproc
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
618 rv = _default_Nav_eventproc
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
619 if proc is None:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
620 proc = _dummy_Nav_eventproc
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
621 _default_Nav_eventproc = proc
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
622 return rv
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 28400
diff changeset
623
27326
44e352d7d52f Spell out the arguments to AskFileForOpen and friends, so help() gives useful
Jack Jansen <jack.jansen@cwi.nl>
parents: 27324
diff changeset
624 def AskFileForOpen(
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
625 message=None,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
626 typeList=None,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
627 # From here on the order is not documented
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
628 version=None,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
629 defaultLocation=None,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
630 dialogOptionFlags=None,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
631 location=None,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
632 clientName=None,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
633 windowTitle=None,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
634 actionButtonLabel=None,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
635 cancelButtonLabel=None,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
636 preferenceKey=None,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
637 popupExtension=None,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
638 eventProc=_dummy_Nav_eventproc,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
639 previewProc=None,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
640 filterProc=None,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
641 wanted=None,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
642 multiple=None):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
643 """Display a dialog asking the user for a file to open.
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 28400
diff changeset
644
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
645 wanted is the return type wanted: FSSpec, FSRef, unicode or string (default)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
646 the other arguments can be looked up in Apple's Navigation Services documentation"""
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 28400
diff changeset
647
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
648 default_flags = 0x56 # Or 0xe4?
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
649 args, tpwanted = _process_Nav_args(default_flags, version=version,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
650 defaultLocation=defaultLocation, dialogOptionFlags=dialogOptionFlags,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
651 location=location,clientName=clientName,windowTitle=windowTitle,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
652 actionButtonLabel=actionButtonLabel,cancelButtonLabel=cancelButtonLabel,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
653 message=message,preferenceKey=preferenceKey,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
654 popupExtension=popupExtension,eventProc=eventProc,previewProc=previewProc,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
655 filterProc=filterProc,typeList=typeList,wanted=wanted,multiple=multiple)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
656 _interact()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
657 try:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
658 rr = Nav.NavChooseFile(args)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
659 good = 1
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
660 except Nav.error, arg:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
661 if arg[0] != -128: # userCancelledErr
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
662 raise Nav.error, arg
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
663 return None
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
664 if not rr.validRecord or not rr.selection:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
665 return None
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
666 if issubclass(tpwanted, Carbon.File.FSRef):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
667 return tpwanted(rr.selection_fsr[0])
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
668 if issubclass(tpwanted, Carbon.File.FSSpec):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
669 return tpwanted(rr.selection[0])
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
670 if issubclass(tpwanted, str):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
671 return tpwanted(rr.selection_fsr[0].as_pathname())
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
672 if issubclass(tpwanted, unicode):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
673 return tpwanted(rr.selection_fsr[0].as_pathname(), 'utf8')
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
674 raise TypeError, "Unknown value for argument 'wanted': %s" % repr(tpwanted)
27276
9da43cde8a16 Added methods AskFileForOpen(), AskFileForSave() and AskFolder(). These
Jack Jansen <jack.jansen@cwi.nl>
parents: 26884
diff changeset
675
27326
44e352d7d52f Spell out the arguments to AskFileForOpen and friends, so help() gives useful
Jack Jansen <jack.jansen@cwi.nl>
parents: 27324
diff changeset
676 def AskFileForSave(
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
677 message=None,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
678 savedFileName=None,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
679 # From here on the order is not documented
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
680 version=None,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
681 defaultLocation=None,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
682 dialogOptionFlags=None,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
683 location=None,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
684 clientName=None,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
685 windowTitle=None,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
686 actionButtonLabel=None,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
687 cancelButtonLabel=None,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
688 preferenceKey=None,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
689 popupExtension=None,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
690 eventProc=_dummy_Nav_eventproc,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
691 fileType=None,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
692 fileCreator=None,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
693 wanted=None,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
694 multiple=None):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
695 """Display a dialog asking the user for a filename to save to.
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 28400
diff changeset
696
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
697 wanted is the return type wanted: FSSpec, FSRef, unicode or string (default)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
698 the other arguments can be looked up in Apple's Navigation Services documentation"""
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 28400
diff changeset
699
27326
44e352d7d52f Spell out the arguments to AskFileForOpen and friends, so help() gives useful
Jack Jansen <jack.jansen@cwi.nl>
parents: 27324
diff changeset
700
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
701 default_flags = 0x07
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
702 args, tpwanted = _process_Nav_args(default_flags, version=version,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
703 defaultLocation=defaultLocation, dialogOptionFlags=dialogOptionFlags,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
704 location=location,clientName=clientName,windowTitle=windowTitle,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
705 actionButtonLabel=actionButtonLabel,cancelButtonLabel=cancelButtonLabel,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
706 savedFileName=savedFileName,message=message,preferenceKey=preferenceKey,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
707 popupExtension=popupExtension,eventProc=eventProc,fileType=fileType,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
708 fileCreator=fileCreator,wanted=wanted,multiple=multiple)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
709 _interact()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
710 try:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
711 rr = Nav.NavPutFile(args)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
712 good = 1
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
713 except Nav.error, arg:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
714 if arg[0] != -128: # userCancelledErr
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
715 raise Nav.error, arg
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
716 return None
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
717 if not rr.validRecord or not rr.selection:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
718 return None
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
719 if issubclass(tpwanted, Carbon.File.FSRef):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
720 raise TypeError, "Cannot pass wanted=FSRef to AskFileForSave"
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
721 if issubclass(tpwanted, Carbon.File.FSSpec):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
722 return tpwanted(rr.selection[0])
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
723 if issubclass(tpwanted, (str, unicode)):
61258
f6785bce54b5 In a number of places code still revers
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 60278
diff changeset
724 # This is gross, and probably incorrect too
f6785bce54b5 In a number of places code still revers
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 60278
diff changeset
725 vrefnum, dirid, name = rr.selection[0].as_tuple()
f6785bce54b5 In a number of places code still revers
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 60278
diff changeset
726 pardir_fss = Carbon.File.FSSpec((vrefnum, dirid, ''))
f6785bce54b5 In a number of places code still revers
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 60278
diff changeset
727 pardir_fsr = Carbon.File.FSRef(pardir_fss)
f6785bce54b5 In a number of places code still revers
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 60278
diff changeset
728 pardir_path = pardir_fsr.FSRefMakePath() # This is utf-8
f6785bce54b5 In a number of places code still revers
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 60278
diff changeset
729 name_utf8 = unicode(name, 'macroman').encode('utf8')
f6785bce54b5 In a number of places code still revers
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 60278
diff changeset
730 fullpath = os.path.join(pardir_path, name_utf8)
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
731 if issubclass(tpwanted, unicode):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
732 return unicode(fullpath, 'utf8')
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
733 return tpwanted(fullpath)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
734 raise TypeError, "Unknown value for argument 'wanted': %s" % repr(tpwanted)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 28400
diff changeset
735
27326
44e352d7d52f Spell out the arguments to AskFileForOpen and friends, so help() gives useful
Jack Jansen <jack.jansen@cwi.nl>
parents: 27324
diff changeset
736 def AskFolder(
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
737 message=None,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
738 # From here on the order is not documented
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
739 version=None,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
740 defaultLocation=None,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
741 dialogOptionFlags=None,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
742 location=None,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
743 clientName=None,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
744 windowTitle=None,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
745 actionButtonLabel=None,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
746 cancelButtonLabel=None,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
747 preferenceKey=None,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
748 popupExtension=None,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
749 eventProc=_dummy_Nav_eventproc,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
750 filterProc=None,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
751 wanted=None,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
752 multiple=None):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
753 """Display a dialog asking the user for select a folder.
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 28400
diff changeset
754
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
755 wanted is the return type wanted: FSSpec, FSRef, unicode or string (default)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
756 the other arguments can be looked up in Apple's Navigation Services documentation"""
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 28400
diff changeset
757
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
758 default_flags = 0x17
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
759 args, tpwanted = _process_Nav_args(default_flags, version=version,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
760 defaultLocation=defaultLocation, dialogOptionFlags=dialogOptionFlags,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
761 location=location,clientName=clientName,windowTitle=windowTitle,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
762 actionButtonLabel=actionButtonLabel,cancelButtonLabel=cancelButtonLabel,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
763 message=message,preferenceKey=preferenceKey,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
764 popupExtension=popupExtension,eventProc=eventProc,filterProc=filterProc,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
765 wanted=wanted,multiple=multiple)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
766 _interact()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
767 try:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
768 rr = Nav.NavChooseFolder(args)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
769 good = 1
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
770 except Nav.error, arg:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
771 if arg[0] != -128: # userCancelledErr
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
772 raise Nav.error, arg
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
773 return None
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
774 if not rr.validRecord or not rr.selection:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
775 return None
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
776 if issubclass(tpwanted, Carbon.File.FSRef):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
777 return tpwanted(rr.selection_fsr[0])
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
778 if issubclass(tpwanted, Carbon.File.FSSpec):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
779 return tpwanted(rr.selection[0])
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
780 if issubclass(tpwanted, str):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
781 return tpwanted(rr.selection_fsr[0].as_pathname())
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
782 if issubclass(tpwanted, unicode):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
783 return tpwanted(rr.selection_fsr[0].as_pathname(), 'utf8')
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
784 raise TypeError, "Unknown value for argument 'wanted': %s" % repr(tpwanted)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 28400
diff changeset
785
27276
9da43cde8a16 Added methods AskFileForOpen(), AskFileForSave() and AskFolder(). These
Jack Jansen <jack.jansen@cwi.nl>
parents: 26884
diff changeset
786
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
787 def test():
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
788 import time
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
789
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
790 Message("Testing EasyDialogs.")
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
791 optionlist = (('v', 'Verbose'), ('verbose', 'Verbose as long option'),
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
792 ('flags=', 'Valued option'), ('f:', 'Short valued option'))
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
793 commandlist = (('start', 'Start something'), ('stop', 'Stop something'))
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
794 argv = GetArgv(optionlist=optionlist, commandlist=commandlist, addoldfile=0)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
795 Message("Command line: %s"%' '.join(argv))
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
796 for i in range(len(argv)):
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 29575
diff changeset
797 print 'arg[%d] = %r' % (i, argv[i])
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
798 ok = AskYesNoCancel("Do you want to proceed?")
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
799 ok = AskYesNoCancel("Do you want to identify?", yes="Identify", no="No")
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
800 if ok > 0:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
801 s = AskString("Enter your first name", "Joe")
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
802 s2 = AskPassword("Okay %s, tell us your nickname"%s, s, cancel="None")
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
803 if not s2:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
804 Message("%s has no secret nickname"%s)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 28400
diff changeset
805 else:
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
806 Message("Hello everybody!!\nThe secret nickname of %s is %s!!!"%(s, s2))
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
807 else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
808 s = 'Anonymous'
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
809 rv = AskFileForOpen(message="Gimme a file, %s"%s, wanted=Carbon.File.FSSpec)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
810 Message("rv: %s"%rv)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
811 rv = AskFileForSave(wanted=Carbon.File.FSRef, savedFileName="%s.txt"%s)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
812 Message("rv.as_pathname: %s"%rv.as_pathname())
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
813 rv = AskFolder()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
814 Message("Folder name: %s"%rv)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
815 text = ( "Working Hard...", "Hardly Working..." ,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
816 "So far, so good!", "Keep on truckin'" )
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
817 bar = ProgressBar("Progress, progress...", 0, label="Ramping up...")
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
818 try:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
819 if hasattr(MacOS, 'SchedParams'):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
820 appsw = MacOS.SchedParams(1, 0)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
821 for i in xrange(20):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
822 bar.inc()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
823 time.sleep(0.05)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
824 bar.set(0,100)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
825 for i in xrange(100):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
826 bar.set(i)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
827 time.sleep(0.05)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
828 if i % 10 == 0:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
829 bar.label(text[(i/10) % 4])
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
830 bar.label("Done.")
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
831 time.sleep(1.0) # give'em a chance to see "Done."
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
832 finally:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
833 del bar
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
834 if hasattr(MacOS, 'SchedParams'):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
835 MacOS.SchedParams(*appsw)
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
836
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
837 if __name__ == '__main__':
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
838 try:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
839 test()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
840 except KeyboardInterrupt:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 29183
diff changeset
841 Message("Operation Canceled.")