Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
ff41c48a
Commit
ff41c48a
authored
Apr 06, 2003
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SF patch #701494: more apply removals
parent
50c61d5a
Changes
23
Hide whitespace changes
Inline
Side-by-side
Showing
23 changed files
with
2460 additions
and
2472 deletions
+2460
-2472
Lib/compiler/transformer.py
Lib/compiler/transformer.py
+1
-1
Lib/curses/wrapper.py
Lib/curses/wrapper.py
+1
-1
Lib/lib-tk/Canvas.py
Lib/lib-tk/Canvas.py
+10
-10
Lib/lib-tk/Dialog.py
Lib/lib-tk/Dialog.py
+5
-5
Lib/lib-tk/ScrolledText.py
Lib/lib-tk/ScrolledText.py
+2
-2
Lib/lib-tk/Tix.py
Lib/lib-tk/Tix.py
+39
-53
Lib/lib-tk/Tkinter.py
Lib/lib-tk/Tkinter.py
+274
-275
Lib/lib-tk/tkColorChooser.py
Lib/lib-tk/tkColorChooser.py
+1
-1
Lib/lib-tk/tkCommonDialog.py
Lib/lib-tk/tkCommonDialog.py
+1
-1
Lib/lib-tk/tkFont.py
Lib/lib-tk/tkFont.py
+4
-4
Lib/lib-tk/tkMessageBox.py
Lib/lib-tk/tkMessageBox.py
+8
-8
Lib/lib-tk/tkSimpleDialog.py
Lib/lib-tk/tkSimpleDialog.py
+3
-3
Lib/lib-tk/turtle.py
Lib/lib-tk/turtle.py
+2
-2
Lib/plat-mac/Carbon/MediaDescr.py
Lib/plat-mac/Carbon/MediaDescr.py
+72
-72
Lib/plat-mac/EasyDialogs.py
Lib/plat-mac/EasyDialogs.py
+741
-741
Lib/plat-mac/FrameWork.py
Lib/plat-mac/FrameWork.py
+1009
-1009
Lib/plat-mac/MiniAEFrame.py
Lib/plat-mac/MiniAEFrame.py
+166
-166
Lib/plat-mac/argvemulator.py
Lib/plat-mac/argvemulator.py
+99
-99
Lib/plat-mac/icopen.py
Lib/plat-mac/icopen.py
+14
-14
Lib/test/reperf.py
Lib/test/reperf.py
+1
-1
Lib/test/test_curses.py
Lib/test/test_curses.py
+1
-1
Lib/xml/dom/minidom.py
Lib/xml/dom/minidom.py
+2
-2
Python/bltinmodule.c
Python/bltinmodule.c
+4
-1
No files found.
Lib/compiler/transformer.py
View file @
ff41c48a
...
@@ -72,7 +72,7 @@ def Node(*args):
...
@@ -72,7 +72,7 @@ def Node(*args):
kind
=
args
[
0
]
kind
=
args
[
0
]
if
nodes
.
has_key
(
kind
):
if
nodes
.
has_key
(
kind
):
try
:
try
:
return
apply
(
nodes
[
kind
],
args
[
1
:])
return
nodes
[
kind
](
*
args
[
1
:])
except
TypeError
:
except
TypeError
:
print
nodes
[
kind
],
len
(
args
),
args
print
nodes
[
kind
],
len
(
args
),
args
raise
raise
...
...
Lib/curses/wrapper.py
View file @
ff41c48a
...
@@ -41,7 +41,7 @@ def wrapper(func, *rest):
...
@@ -41,7 +41,7 @@ def wrapper(func, *rest):
except
:
except
:
pass
pass
res
=
apply
(
func
,
(
stdscr
,)
+
rest
)
res
=
func
(
stdscr
,
*
rest
)
except
:
except
:
# In the event of an error, restore the terminal
# In the event of an error, restore the terminal
# to a sane state.
# to a sane state.
...
...
Lib/lib-tk/Canvas.py
View file @
ff41c48a
...
@@ -55,7 +55,7 @@ class CanvasItem:
...
@@ -55,7 +55,7 @@ class CanvasItem:
def
coords
(
self
,
pts
=
()):
def
coords
(
self
,
pts
=
()):
flat
=
()
flat
=
()
for
x
,
y
in
pts
:
flat
=
flat
+
(
x
,
y
)
for
x
,
y
in
pts
:
flat
=
flat
+
(
x
,
y
)
return
apply
(
self
.
canvas
.
coords
,
(
self
.
id
,)
+
flat
)
return
self
.
canvas
.
coords
(
self
.
id
,
*
flat
)
def
dchars
(
self
,
first
,
last
=
None
):
def
dchars
(
self
,
first
,
last
=
None
):
self
.
canvas
.
dchars
(
self
.
id
,
first
,
last
)
self
.
canvas
.
dchars
(
self
.
id
,
first
,
last
)
def
dtag
(
self
,
ttd
):
def
dtag
(
self
,
ttd
):
...
@@ -84,40 +84,40 @@ class CanvasItem:
...
@@ -84,40 +84,40 @@ class CanvasItem:
class
Arc
(
CanvasItem
):
class
Arc
(
CanvasItem
):
def
__init__
(
self
,
canvas
,
*
args
,
**
kw
):
def
__init__
(
self
,
canvas
,
*
args
,
**
kw
):
apply
(
CanvasItem
.
__init__
,
(
self
,
canvas
,
'arc'
)
+
args
,
kw
)
CanvasItem
.
__init__
(
self
,
canvas
,
'arc'
,
*
args
,
**
kw
)
class
Bitmap
(
CanvasItem
):
class
Bitmap
(
CanvasItem
):
def
__init__
(
self
,
canvas
,
*
args
,
**
kw
):
def
__init__
(
self
,
canvas
,
*
args
,
**
kw
):
apply
(
CanvasItem
.
__init__
,
(
self
,
canvas
,
'bitmap'
)
+
args
,
kw
)
CanvasItem
.
__init__
(
self
,
canvas
,
'bitmap'
,
*
args
,
**
kw
)
class
ImageItem
(
CanvasItem
):
class
ImageItem
(
CanvasItem
):
def
__init__
(
self
,
canvas
,
*
args
,
**
kw
):
def
__init__
(
self
,
canvas
,
*
args
,
**
kw
):
apply
(
CanvasItem
.
__init__
,
(
self
,
canvas
,
'image'
)
+
args
,
kw
)
CanvasItem
.
__init__
(
self
,
canvas
,
'image'
,
*
args
,
**
kw
)
class
Line
(
CanvasItem
):
class
Line
(
CanvasItem
):
def
__init__
(
self
,
canvas
,
*
args
,
**
kw
):
def
__init__
(
self
,
canvas
,
*
args
,
**
kw
):
apply
(
CanvasItem
.
__init__
,
(
self
,
canvas
,
'line'
)
+
args
,
kw
)
CanvasItem
.
__init__
(
self
,
canvas
,
'line'
,
*
args
,
**
kw
)
class
Oval
(
CanvasItem
):
class
Oval
(
CanvasItem
):
def
__init__
(
self
,
canvas
,
*
args
,
**
kw
):
def
__init__
(
self
,
canvas
,
*
args
,
**
kw
):
apply
(
CanvasItem
.
__init__
,
(
self
,
canvas
,
'oval'
)
+
args
,
kw
)
CanvasItem
.
__init__
(
self
,
canvas
,
'oval'
,
*
args
,
**
kw
)
class
Polygon
(
CanvasItem
):
class
Polygon
(
CanvasItem
):
def
__init__
(
self
,
canvas
,
*
args
,
**
kw
):
def
__init__
(
self
,
canvas
,
*
args
,
**
kw
):
apply
(
CanvasItem
.
__init__
,
(
self
,
canvas
,
'polygon'
)
+
args
,
kw
)
CanvasItem
.
__init__
(
self
,
canvas
,
'polygon'
,
*
args
,
**
kw
)
class
Rectangle
(
CanvasItem
):
class
Rectangle
(
CanvasItem
):
def
__init__
(
self
,
canvas
,
*
args
,
**
kw
):
def
__init__
(
self
,
canvas
,
*
args
,
**
kw
):
apply
(
CanvasItem
.
__init__
,
(
self
,
canvas
,
'rectangle'
)
+
args
,
kw
)
CanvasItem
.
__init__
(
self
,
canvas
,
'rectangle'
,
*
args
,
**
kw
)
# XXX "Text" is taken by the Text widget...
# XXX "Text" is taken by the Text widget...
class
CanvasText
(
CanvasItem
):
class
CanvasText
(
CanvasItem
):
def
__init__
(
self
,
canvas
,
*
args
,
**
kw
):
def
__init__
(
self
,
canvas
,
*
args
,
**
kw
):
apply
(
CanvasItem
.
__init__
,
(
self
,
canvas
,
'text'
)
+
args
,
kw
)
CanvasItem
.
__init__
(
self
,
canvas
,
'text'
,
*
args
,
**
kw
)
class
Window
(
CanvasItem
):
class
Window
(
CanvasItem
):
def
__init__
(
self
,
canvas
,
*
args
,
**
kw
):
def
__init__
(
self
,
canvas
,
*
args
,
**
kw
):
apply
(
CanvasItem
.
__init__
,
(
self
,
canvas
,
'window'
)
+
args
,
kw
)
CanvasItem
.
__init__
(
self
,
canvas
,
'window'
,
*
args
,
**
kw
)
class
Group
:
class
Group
:
def
__init__
(
self
,
canvas
,
tag
=
None
):
def
__init__
(
self
,
canvas
,
tag
=
None
):
...
...
Lib/lib-tk/Dialog.py
View file @
ff41c48a
...
@@ -15,11 +15,11 @@ class Dialog(Widget):
...
@@ -15,11 +15,11 @@ class Dialog(Widget):
self
.
widgetName
=
'__dialog__'
self
.
widgetName
=
'__dialog__'
Widget
.
_setup
(
self
,
master
,
cnf
)
Widget
.
_setup
(
self
,
master
,
cnf
)
self
.
num
=
self
.
tk
.
getint
(
self
.
num
=
self
.
tk
.
getint
(
apply
(
self
.
tk
.
call
,
self
.
tk
.
call
(
(
'tk_dialog'
,
self
.
_w
,
'tk_dialog'
,
self
.
_w
,
cnf
[
'title'
],
cnf
[
'text'
],
cnf
[
'title'
],
cnf
[
'text'
],
cnf
[
'bitmap'
],
cnf
[
'default'
])
cnf
[
'bitmap'
],
cnf
[
'default'
],
+
cnf
[
'strings'
]))
*
cnf
[
'strings'
]))
try
:
Widget
.
destroy
(
self
)
try
:
Widget
.
destroy
(
self
)
except
TclError
:
pass
except
TclError
:
pass
def
destroy
(
self
):
pass
def
destroy
(
self
):
pass
...
...
Lib/lib-tk/ScrolledText.py
View file @
ff41c48a
...
@@ -24,11 +24,11 @@ class ScrolledText(Text):
...
@@ -24,11 +24,11 @@ class ScrolledText(Text):
if
type
(
k
)
==
ClassType
or
k
==
'name'
:
if
type
(
k
)
==
ClassType
or
k
==
'name'
:
fcnf
[
k
]
=
cnf
[
k
]
fcnf
[
k
]
=
cnf
[
k
]
del
cnf
[
k
]
del
cnf
[
k
]
self
.
frame
=
apply
(
Frame
,
(
master
,),
fcnf
)
self
.
frame
=
Frame
(
master
,
**
fcnf
)
self
.
vbar
=
Scrollbar
(
self
.
frame
,
name
=
'vbar'
)
self
.
vbar
=
Scrollbar
(
self
.
frame
,
name
=
'vbar'
)
self
.
vbar
.
pack
(
side
=
RIGHT
,
fill
=
Y
)
self
.
vbar
.
pack
(
side
=
RIGHT
,
fill
=
Y
)
cnf
[
'name'
]
=
'text'
cnf
[
'name'
]
=
'text'
apply
(
Text
.
__init__
,
(
self
,
self
.
frame
),
cnf
)
Text
.
__init__
(
self
,
self
.
frame
,
**
cnf
)
self
.
pack
(
side
=
LEFT
,
fill
=
BOTH
,
expand
=
1
)
self
.
pack
(
side
=
LEFT
,
fill
=
BOTH
,
expand
=
1
)
self
[
'yscrollcommand'
]
=
self
.
vbar
.
set
self
[
'yscrollcommand'
]
=
self
.
vbar
.
set
self
.
vbar
[
'command'
]
=
self
.
yview
self
.
vbar
[
'command'
]
=
self
.
yview
...
...
Lib/lib-tk/Tix.py
View file @
ff41c48a
...
@@ -222,7 +222,7 @@ class Form:
...
@@ -222,7 +222,7 @@ class Form:
See Tix documentation for complete details"""
See Tix documentation for complete details"""
def
config
(
self
,
cnf
=
{},
**
kw
):
def
config
(
self
,
cnf
=
{},
**
kw
):
apply
(
self
.
tk
.
call
,
(
'tixForm'
,
self
.
_w
)
+
self
.
_options
(
cnf
,
kw
))
self
.
tk
.
call
(
'tixForm'
,
self
.
_w
,
*
self
.
_options
(
cnf
,
kw
))
form
=
config
form
=
config
...
@@ -292,7 +292,7 @@ class TixWidget(Tkinter.Widget):
...
@@ -292,7 +292,7 @@ class TixWidget(Tkinter.Widget):
static_options
.
append
(
'options'
)
static_options
.
append
(
'options'
)
else
:
else
:
static_options
=
[
'options'
]
static_options
=
[
'options'
]
for
k
,
v
in
cnf
.
items
()[:]:
for
k
,
v
in
cnf
.
items
()[:]:
if
k
in
static_options
:
if
k
in
static_options
:
extra
=
extra
+
(
'-'
+
k
,
v
)
extra
=
extra
+
(
'-'
+
k
,
v
)
...
@@ -304,7 +304,7 @@ class TixWidget(Tkinter.Widget):
...
@@ -304,7 +304,7 @@ class TixWidget(Tkinter.Widget):
# If widgetName is None, this is a dummy creation call where the
# If widgetName is None, this is a dummy creation call where the
# corresponding Tk widget has already been created by Tix
# corresponding Tk widget has already been created by Tix
if
widgetName
:
if
widgetName
:
apply
(
self
.
tk
.
call
,
(
widgetName
,
self
.
_w
)
+
extra
)
self
.
tk
.
call
(
widgetName
,
self
.
_w
,
*
extra
)
# Non-static options - to be done via a 'config' command
# Non-static options - to be done via a 'config' command
if
cnf
:
if
cnf
:
...
@@ -474,8 +474,8 @@ class DisplayStyle:
...
@@ -474,8 +474,8 @@ class DisplayStyle:
elif
not
master
and
kw
.
has_key
(
'refwindow'
):
master
=
kw
[
'refwindow'
]
elif
not
master
and
kw
.
has_key
(
'refwindow'
):
master
=
kw
[
'refwindow'
]
elif
not
master
:
raise
RuntimeError
,
"Too early to create display style: no root window"
elif
not
master
:
raise
RuntimeError
,
"Too early to create display style: no root window"
self
.
tk
=
master
.
tk
self
.
tk
=
master
.
tk
self
.
stylename
=
apply
(
self
.
tk
.
call
,
(
'tixDisplayStyle'
,
itemtype
)
+
self
.
stylename
=
self
.
tk
.
call
(
'tixDisplayStyle'
,
itemtype
,
self
.
_options
(
cnf
,
kw
)
)
*
self
.
_options
(
cnf
,
kw
)
)
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
stylename
return
self
.
stylename
...
@@ -499,8 +499,8 @@ class DisplayStyle:
...
@@ -499,8 +499,8 @@ class DisplayStyle:
def
config
(
self
,
cnf
=
{},
**
kw
):
def
config
(
self
,
cnf
=
{},
**
kw
):
return
_lst2dict
(
return
_lst2dict
(
self
.
tk
.
split
(
self
.
tk
.
split
(
apply
(
self
.
tk
.
call
,
self
.
tk
.
call
(
(
self
.
stylename
,
'configure'
)
+
self
.
_options
(
cnf
,
kw
))))
self
.
stylename
,
'configure'
,
*
self
.
_options
(
cnf
,
kw
))))
def
__getitem__
(
self
,
key
):
def
__getitem__
(
self
,
key
):
return
self
.
tk
.
call
(
self
.
stylename
,
'cget'
,
'-%s'
%
key
)
return
self
.
tk
.
call
(
self
.
stylename
,
'cget'
,
'-%s'
%
key
)
...
@@ -532,8 +532,7 @@ class Balloon(TixWidget):
...
@@ -532,8 +532,7 @@ class Balloon(TixWidget):
def
bind_widget
(
self
,
widget
,
cnf
=
{},
**
kw
):
def
bind_widget
(
self
,
widget
,
cnf
=
{},
**
kw
):
"""Bind balloon widget to another.
"""Bind balloon widget to another.
One balloon widget may be bound to several widgets at the same time"""
One balloon widget may be bound to several widgets at the same time"""
apply
(
self
.
tk
.
call
,
self
.
tk
.
call
(
self
.
_w
,
'bind'
,
widget
.
_w
,
*
self
.
_options
(
cnf
,
kw
))
(
self
.
_w
,
'bind'
,
widget
.
_w
)
+
self
.
_options
(
cnf
,
kw
))
def
unbind_widget
(
self
,
widget
):
def
unbind_widget
(
self
,
widget
):
self
.
tk
.
call
(
self
.
_w
,
'unbind'
,
widget
.
_w
)
self
.
tk
.
call
(
self
.
_w
,
'unbind'
,
widget
.
_w
)
...
@@ -549,8 +548,7 @@ class ButtonBox(TixWidget):
...
@@ -549,8 +548,7 @@ class ButtonBox(TixWidget):
def
add
(
self
,
name
,
cnf
=
{},
**
kw
):
def
add
(
self
,
name
,
cnf
=
{},
**
kw
):
"""Add a button with given name to box."""
"""Add a button with given name to box."""
btn
=
apply
(
self
.
tk
.
call
,
btn
=
self
.
tk
.
call
(
self
.
_w
,
'add'
,
name
,
*
self
.
_options
(
cnf
,
kw
))
(
self
.
_w
,
'add'
,
name
)
+
self
.
_options
(
cnf
,
kw
))
self
.
subwidget_list
[
name
]
=
_dummyButton
(
self
,
name
)
self
.
subwidget_list
[
name
]
=
_dummyButton
(
self
,
name
)
return
btn
return
btn
...
@@ -589,7 +587,7 @@ class ComboBox(TixWidget):
...
@@ -589,7 +587,7 @@ class ComboBox(TixWidget):
pass
pass
# align
# align
def
add_history
(
self
,
str
):
def
add_history
(
self
,
str
):
self
.
tk
.
call
(
self
.
_w
,
'addhistory'
,
str
)
self
.
tk
.
call
(
self
.
_w
,
'addhistory'
,
str
)
...
@@ -862,14 +860,13 @@ class HList(TixWidget):
...
@@ -862,14 +860,13 @@ class HList(TixWidget):
[
'columns'
,
'options'
],
cnf
,
kw
)
[
'columns'
,
'options'
],
cnf
,
kw
)
def
add
(
self
,
entry
,
cnf
=
{},
**
kw
):
def
add
(
self
,
entry
,
cnf
=
{},
**
kw
):
return
apply
(
self
.
tk
.
call
,
return
self
.
tk
.
call
(
self
.
_w
,
'add'
,
entry
,
*
self
.
_options
(
cnf
,
kw
))
(
self
.
_w
,
'add'
,
entry
)
+
self
.
_options
(
cnf
,
kw
))
def
add_child
(
self
,
parent
=
None
,
cnf
=
{},
**
kw
):
def
add_child
(
self
,
parent
=
None
,
cnf
=
{},
**
kw
):
if
not
parent
:
if
not
parent
:
parent
=
''
parent
=
''
return
apply
(
self
.
tk
.
call
,
return
self
.
tk
.
call
(
(
self
.
_w
,
'addchild'
,
parent
)
+
self
.
_options
(
cnf
,
kw
))
self
.
_w
,
'addchild'
,
parent
,
*
self
.
_options
(
cnf
,
kw
))
def
anchor_set
(
self
,
entry
):
def
anchor_set
(
self
,
entry
):
self
.
tk
.
call
(
self
.
_w
,
'anchor'
,
'set'
,
entry
)
self
.
tk
.
call
(
self
.
_w
,
'anchor'
,
'set'
,
entry
)
...
@@ -909,16 +906,15 @@ class HList(TixWidget):
...
@@ -909,16 +906,15 @@ class HList(TixWidget):
self
.
tk
.
call
(
self
.
_w
,
'dropsite'
,
'clear'
)
self
.
tk
.
call
(
self
.
_w
,
'dropsite'
,
'clear'
)
def
header_create
(
self
,
col
,
cnf
=
{},
**
kw
):
def
header_create
(
self
,
col
,
cnf
=
{},
**
kw
):
apply
(
self
.
tk
.
call
,
self
.
tk
.
call
(
self
.
_w
,
'header'
,
'create'
,
col
,
*
self
.
_options
(
cnf
,
kw
))
(
self
.
_w
,
'header'
,
'create'
,
col
)
+
self
.
_options
(
cnf
,
kw
))
def
header_configure
(
self
,
col
,
cnf
=
{},
**
kw
):
def
header_configure
(
self
,
col
,
cnf
=
{},
**
kw
):
if
cnf
is
None
:
if
cnf
is
None
:
return
_lst2dict
(
return
_lst2dict
(
self
.
tk
.
split
(
self
.
tk
.
split
(
self
.
tk
.
call
(
self
.
_w
,
'header'
,
'configure'
,
col
)))
self
.
tk
.
call
(
self
.
_w
,
'header'
,
'configure'
,
col
)))
apply
(
self
.
tk
.
call
,
(
self
.
_w
,
'header'
,
'configure'
,
col
)
self
.
tk
.
call
(
self
.
_w
,
'header'
,
'configure'
,
col
,
+
self
.
_options
(
cnf
,
kw
))
*
self
.
_options
(
cnf
,
kw
))
def
header_cget
(
self
,
col
,
opt
):
def
header_cget
(
self
,
col
,
opt
):
return
self
.
tk
.
call
(
self
.
_w
,
'header'
,
'cget'
,
col
,
opt
)
return
self
.
tk
.
call
(
self
.
_w
,
'header'
,
'cget'
,
col
,
opt
)
...
@@ -936,16 +932,16 @@ class HList(TixWidget):
...
@@ -936,16 +932,16 @@ class HList(TixWidget):
self
.
tk
.
call
(
self
.
_w
,
'hide'
,
'entry'
,
entry
)
self
.
tk
.
call
(
self
.
_w
,
'hide'
,
'entry'
,
entry
)
def
indicator_create
(
self
,
entry
,
cnf
=
{},
**
kw
):
def
indicator_create
(
self
,
entry
,
cnf
=
{},
**
kw
):
apply
(
self
.
tk
.
call
,
self
.
tk
.
call
(
(
self
.
_w
,
'indicator'
,
'create'
,
entry
)
+
self
.
_options
(
cnf
,
kw
))
self
.
_w
,
'indicator'
,
'create'
,
entry
,
*
self
.
_options
(
cnf
,
kw
))
def
indicator_configure
(
self
,
entry
,
cnf
=
{},
**
kw
):
def
indicator_configure
(
self
,
entry
,
cnf
=
{},
**
kw
):
if
cnf
is
None
:
if
cnf
is
None
:
return
_lst2dict
(
return
_lst2dict
(
self
.
tk
.
split
(
self
.
tk
.
split
(
self
.
tk
.
call
(
self
.
_w
,
'indicator'
,
'configure'
,
entry
)))
self
.
tk
.
call
(
self
.
_w
,
'indicator'
,
'configure'
,
entry
)))
apply
(
self
.
tk
.
call
,
self
.
tk
.
call
(
(
self
.
_w
,
'indicator'
,
'configure'
,
entry
)
+
self
.
_options
(
cnf
,
kw
))
self
.
_w
,
'indicator'
,
'configure'
,
entry
,
*
self
.
_options
(
cnf
,
kw
))
def
indicator_cget
(
self
,
entry
,
opt
):
def
indicator_cget
(
self
,
entry
,
opt
):
return
self
.
tk
.
call
(
self
.
_w
,
'indicator'
,
'cget'
,
entry
,
opt
)
return
self
.
tk
.
call
(
self
.
_w
,
'indicator'
,
'cget'
,
entry
,
opt
)
...
@@ -996,12 +992,12 @@ class HList(TixWidget):
...
@@ -996,12 +992,12 @@ class HList(TixWidget):
return
_lst2dict
(
return
_lst2dict
(
self
.
tk
.
split
(
self
.
tk
.
split
(
self
.
tk
.
call
(
self
.
_w
,
'item'
,
'configure'
,
entry
,
col
)))
self
.
tk
.
call
(
self
.
_w
,
'item'
,
'configure'
,
entry
,
col
)))
apply
(
self
.
tk
.
call
,
(
self
.
_w
,
'item'
,
'configure'
,
entry
,
col
)
+
self
.
tk
.
call
(
self
.
_w
,
'item'
,
'configure'
,
entry
,
col
,
self
.
_options
(
cnf
,
kw
))
*
self
.
_options
(
cnf
,
kw
))
def
item_create
(
self
,
entry
,
col
,
cnf
=
{},
**
kw
):
def
item_create
(
self
,
entry
,
col
,
cnf
=
{},
**
kw
):
apply
(
self
.
tk
.
call
,
self
.
tk
.
call
(
(
self
.
_w
,
'item'
,
'create'
,
entry
,
col
)
+
self
.
_options
(
cnf
,
kw
))
self
.
_w
,
'item'
,
'create'
,
entry
,
col
,
*
self
.
_options
(
cnf
,
kw
))
def
item_exists
(
self
,
entry
,
col
):
def
item_exists
(
self
,
entry
,
col
):
return
self
.
tk
.
call
(
self
.
_w
,
'item'
,
'exists'
,
entry
,
col
)
return
self
.
tk
.
call
(
self
.
_w
,
'item'
,
'exists'
,
entry
,
col
)
...
@@ -1016,8 +1012,7 @@ class HList(TixWidget):
...
@@ -1016,8 +1012,7 @@ class HList(TixWidget):
self
.
tk
.
call
(
self
.
_w
,
'see'
,
entry
)
self
.
tk
.
call
(
self
.
_w
,
'see'
,
entry
)
def
selection_clear
(
self
,
cnf
=
{},
**
kw
):
def
selection_clear
(
self
,
cnf
=
{},
**
kw
):
apply
(
self
.
tk
.
call
,
self
.
tk
.
call
(
self
.
_w
,
'selection'
,
'clear'
,
*
self
.
_options
(
cnf
,
kw
))
(
self
.
_w
,
'selection'
,
'clear'
)
+
self
.
_options
(
cnf
,
kw
))
def
selection_includes
(
self
,
entry
):
def
selection_includes
(
self
,
entry
):
return
self
.
tk
.
call
(
self
.
_w
,
'selection'
,
'includes'
,
entry
)
return
self
.
tk
.
call
(
self
.
_w
,
'selection'
,
'includes'
,
entry
)
...
@@ -1029,10 +1024,10 @@ class HList(TixWidget):
...
@@ -1029,10 +1024,10 @@ class HList(TixWidget):
return
self
.
tk
.
call
(
self
.
_w
,
'show'
,
'entry'
,
entry
)
return
self
.
tk
.
call
(
self
.
_w
,
'show'
,
'entry'
,
entry
)
def
xview
(
self
,
*
args
):
def
xview
(
self
,
*
args
):
apply
(
self
.
tk
.
call
,
(
self
.
_w
,
'xview'
)
+
args
)
self
.
tk
.
call
(
self
.
_w
,
'xview'
,
*
args
)
def
yview
(
self
,
*
args
):
def
yview
(
self
,
*
args
):
apply
(
self
.
tk
.
call
,
(
self
.
_w
,
'yview'
)
+
args
)
self
.
tk
.
call
(
self
.
_w
,
'yview'
,
*
args
)
class
InputOnly
(
TixWidget
):
class
InputOnly
(
TixWidget
):
"""InputOnly - Invisible widget. Unix only.
"""InputOnly - Invisible widget. Unix only.
...
@@ -1093,8 +1088,7 @@ class ListNoteBook(TixWidget):
...
@@ -1093,8 +1088,7 @@ class ListNoteBook(TixWidget):
self
.
subwidget_list
[
'shlist'
]
=
_dummyScrolledHList
(
self
,
'shlist'
)
self
.
subwidget_list
[
'shlist'
]
=
_dummyScrolledHList
(
self
,
'shlist'
)
def
add
(
self
,
name
,
cnf
=
{},
**
kw
):
def
add
(
self
,
name
,
cnf
=
{},
**
kw
):
apply
(
self
.
tk
.
call
,
self
.
tk
.
call
(
self
.
_w
,
'add'
,
name
,
*
self
.
_options
(
cnf
,
kw
))
(
self
.
_w
,
'add'
,
name
)
+
self
.
_options
(
cnf
,
kw
))
self
.
subwidget_list
[
name
]
=
TixSubWidget
(
self
,
name
)
self
.
subwidget_list
[
name
]
=
TixSubWidget
(
self
,
name
)
return
self
.
subwidget_list
[
name
]
return
self
.
subwidget_list
[
name
]
...
@@ -1135,8 +1129,7 @@ class NoteBook(TixWidget):
...
@@ -1135,8 +1129,7 @@ class NoteBook(TixWidget):
destroy_physically
=
0
)
destroy_physically
=
0
)
def
add
(
self
,
name
,
cnf
=
{},
**
kw
):
def
add
(
self
,
name
,
cnf
=
{},
**
kw
):
apply
(
self
.
tk
.
call
,
self
.
tk
.
call
(
self
.
_w
,
'add'
,
name
,
*
self
.
_options
(
cnf
,
kw
))
(
self
.
_w
,
'add'
,
name
)
+
self
.
_options
(
cnf
,
kw
))
self
.
subwidget_list
[
name
]
=
TixSubWidget
(
self
,
name
)
self
.
subwidget_list
[
name
]
=
TixSubWidget
(
self
,
name
)
return
self
.
subwidget_list
[
name
]
return
self
.
subwidget_list
[
name
]
...
@@ -1180,12 +1173,10 @@ class OptionMenu(TixWidget):
...
@@ -1180,12 +1173,10 @@ class OptionMenu(TixWidget):
self
.
subwidget_list
[
'menu'
]
=
_dummyMenu
(
self
,
'menu'
)
self
.
subwidget_list
[
'menu'
]
=
_dummyMenu
(
self
,
'menu'
)
def
add_command
(
self
,
name
,
cnf
=
{},
**
kw
):
def
add_command
(
self
,
name
,
cnf
=
{},
**
kw
):
apply
(
self
.
tk
.
call
,
self
.
tk
.
call
(
self
.
_w
,
'add'
,
'command'
,
name
,
*
self
.
_options
(
cnf
,
kw
))
(
self
.
_w
,
'add'
,
'command'
,
name
)
+
self
.
_options
(
cnf
,
kw
))
def
add_separator
(
self
,
name
,
cnf
=
{},
**
kw
):
def
add_separator
(
self
,
name
,
cnf
=
{},
**
kw
):
apply
(
self
.
tk
.
call
,
self
.
tk
.
call
(
self
.
_w
,
'add'
,
'separator'
,
name
,
*
self
.
_options
(
cnf
,
kw
))
(
self
.
_w
,
'add'
,
'separator'
,
name
)
+
self
.
_options
(
cnf
,
kw
))
def
delete
(
self
,
name
):
def
delete
(
self
,
name
):
self
.
tk
.
call
(
self
.
_w
,
'delete'
,
name
)
self
.
tk
.
call
(
self
.
_w
,
'delete'
,
name
)
...
@@ -1212,8 +1203,7 @@ class PanedWindow(TixWidget):
...
@@ -1212,8 +1203,7 @@ class PanedWindow(TixWidget):
# add delete forget panecget paneconfigure panes setsize
# add delete forget panecget paneconfigure panes setsize
def
add
(
self
,
name
,
cnf
=
{},
**
kw
):
def
add
(
self
,
name
,
cnf
=
{},
**
kw
):
apply
(
self
.
tk
.
call
,
self
.
tk
.
call
(
self
.
_w
,
'add'
,
name
,
*
self
.
_options
(
cnf
,
kw
))
(
self
.
_w
,
'add'
,
name
)
+
self
.
_options
(
cnf
,
kw
))
self
.
subwidget_list
[
name
]
=
TixSubWidget
(
self
,
name
,
self
.
subwidget_list
[
name
]
=
TixSubWidget
(
self
,
name
,
check_intermediate
=
0
)
check_intermediate
=
0
)
return
self
.
subwidget_list
[
name
]
return
self
.
subwidget_list
[
name
]
...
@@ -1234,8 +1224,7 @@ class PanedWindow(TixWidget):
...
@@ -1234,8 +1224,7 @@ class PanedWindow(TixWidget):
return
_lst2dict
(
return
_lst2dict
(
self
.
tk
.
split
(
self
.
tk
.
split
(
self
.
tk
.
call
(
self
.
_w
,
'paneconfigure'
,
entry
)))
self
.
tk
.
call
(
self
.
_w
,
'paneconfigure'
,
entry
)))
apply
(
self
.
tk
.
call
,
self
.
tk
.
call
(
self
.
_w
,
'paneconfigure'
,
entry
,
*
self
.
_options
(
cnf
,
kw
))
(
self
.
_w
,
'paneconfigure'
,
entry
)
+
self
.
_options
(
cnf
,
kw
))
def
panes
(
self
):
def
panes
(
self
):
names
=
self
.
tk
.
call
(
self
.
_w
,
'panes'
)
names
=
self
.
tk
.
call
(
self
.
_w
,
'panes'
)
...
@@ -1361,8 +1350,7 @@ class Select(TixWidget):
...
@@ -1361,8 +1350,7 @@ class Select(TixWidget):
self
.
subwidget_list
[
'label'
]
=
_dummyLabel
(
self
,
'label'
)
self
.
subwidget_list
[
'label'
]
=
_dummyLabel
(
self
,
'label'
)
def
add
(
self
,
name
,
cnf
=
{},
**
kw
):
def
add
(
self
,
name
,
cnf
=
{},
**
kw
):
apply
(
self
.
tk
.
call
,
self
.
tk
.
call
(
self
.
_w
,
'add'
,
name
,
*
self
.
_options
(
cnf
,
kw
))
(
self
.
_w
,
'add'
,
name
)
+
self
.
_options
(
cnf
,
kw
))
self
.
subwidget_list
[
name
]
=
_dummyButton
(
self
,
name
)
self
.
subwidget_list
[
name
]
=
_dummyButton
(
self
,
name
)
return
self
.
subwidget_list
[
name
]
return
self
.
subwidget_list
[
name
]
...
@@ -1458,8 +1446,7 @@ class TList(TixWidget):
...
@@ -1458,8 +1446,7 @@ class TList(TixWidget):
self
.
tk
.
call
(
self
.
_w
,
'dropsite'
,
'clear'
)
self
.
tk
.
call
(
self
.
_w
,
'dropsite'
,
'clear'
)
def
insert
(
self
,
index
,
cnf
=
{},
**
kw
):
def
insert
(
self
,
index
,
cnf
=
{},
**
kw
):
apply
(
self
.
tk
.
call
,
self
.
tk
.
call
(
self
.
_w
,
'insert'
,
index
,
*
self
.
_options
(
cnf
,
kw
))
(
self
.
_w
,
'insert'
,
index
)
+
self
.
_options
(
cnf
,
kw
))
def
info_active
(
self
):
def
info_active
(
self
):
return
self
.
tk
.
call
(
self
.
_w
,
'info'
,
'active'
)
return
self
.
tk
.
call
(
self
.
_w
,
'info'
,
'active'
)
...
@@ -1493,8 +1480,7 @@ class TList(TixWidget):
...
@@ -1493,8 +1480,7 @@ class TList(TixWidget):
self
.
tk
.
call
(
self
.
_w
,
'see'
,
index
)
self
.
tk
.
call
(
self
.
_w
,
'see'
,
index
)
def
selection_clear
(
self
,
cnf
=
{},
**
kw
):
def
selection_clear
(
self
,
cnf
=
{},
**
kw
):
apply
(
self
.
tk
.
call
,
self
.
tk
.
call
(
self
.
_w
,
'selection'
,
'clear'
,
*
self
.
_options
(
cnf
,
kw
))
(
self
.
_w
,
'selection'
,
'clear'
)
+
self
.
_options
(
cnf
,
kw
))
def
selection_includes
(
self
,
index
):
def
selection_includes
(
self
,
index
):
return
self
.
tk
.
call
(
self
.
_w
,
'selection'
,
'includes'
,
index
)
return
self
.
tk
.
call
(
self
.
_w
,
'selection'
,
'includes'
,
index
)
...
@@ -1503,10 +1489,10 @@ class TList(TixWidget):
...
@@ -1503,10 +1489,10 @@ class TList(TixWidget):
self
.
tk
.
call
(
self
.
_w
,
'selection'
,
'set'
,
first
,
last
)
self
.
tk
.
call
(
self
.
_w
,
'selection'
,
'set'
,
first
,
last
)
def
xview
(
self
,
*
args
):
def
xview
(
self
,
*
args
):
apply
(
self
.
tk
.
call
,
(
self
.
_w
,
'xview'
)
+
args
)
self
.
tk
.
call
(
self
.
_w
,
'xview'
,
*
args
)
def
yview
(
self
,
*
args
):
def
yview
(
self
,
*
args
):
apply
(
self
.
tk
.
call
,
(
self
.
_w
,
'yview'
)
+
args
)
self
.
tk
.
call
(
self
.
_w
,
'yview'
,
*
args
)
class
Tree
(
TixWidget
):
class
Tree
(
TixWidget
):
"""Tree - The tixTree widget can be used to display hierachical
"""Tree - The tixTree widget can be used to display hierachical
...
@@ -1807,7 +1793,7 @@ class Grid(TixWidget):
...
@@ -1807,7 +1793,7 @@ class Grid(TixWidget):
# def unset x y
# def unset x y
# def xview
# def xview
# def yview
# def yview
class
ScrolledGrid
(
TixWidget
):
class
ScrolledGrid
(
TixWidget
):
'''Scrolled Grid widgets'''
'''Scrolled Grid widgets'''
...
...
Lib/lib-tk/Tkinter.py
View file @
ff41c48a
...
@@ -4,10 +4,10 @@ Tkinter provides classes which allow the display, positioning and
...
@@ -4,10 +4,10 @@ Tkinter provides classes which allow the display, positioning and
control of widgets. Toplevel widgets are Tk and Toplevel. Other
control of widgets. Toplevel widgets are Tk and Toplevel. Other
widgets are Frame, Label, Entry, Text, Canvas, Button, Radiobutton,
widgets are Frame, Label, Entry, Text, Canvas, Button, Radiobutton,
Checkbutton, Scale, Listbox, Scrollbar, OptionMenu, Spinbox
Checkbutton, Scale, Listbox, Scrollbar, OptionMenu, Spinbox
LabelFrame and PanedWindow.
LabelFrame and PanedWindow.
Properties of the widgets are specified with keyword arguments.
Properties of the widgets are specified with keyword arguments.
Keyword arguments have the same name as the corresponding resource
Keyword arguments have the same name as the corresponding resource
under Tk.
under Tk.
Widgets are positioned with one of the geometry managers Place, Pack
Widgets are positioned with one of the geometry managers Place, Pack
...
@@ -444,7 +444,7 @@ class Misc:
...
@@ -444,7 +444,7 @@ class Misc:
tmp
=
[]
tmp
=
[]
def
callit
(
func
=
func
,
args
=
args
,
self
=
self
,
tmp
=
tmp
):
def
callit
(
func
=
func
,
args
=
args
,
self
=
self
,
tmp
=
tmp
):
try
:
try
:
apply
(
func
,
args
)
func
(
*
args
)
finally
:
finally
:
try
:
try
:
self
.
deletecommand
(
tmp
[
0
])
self
.
deletecommand
(
tmp
[
0
])
...
@@ -459,7 +459,7 @@ class Misc:
...
@@ -459,7 +459,7 @@ class Misc:
Return an identifier to cancel the scheduling with
Return an identifier to cancel the scheduling with
after_cancel."""
after_cancel."""
return
apply
(
self
.
after
,
(
'idle'
,
func
)
+
args
)
return
self
.
after
(
'idle'
,
func
,
*
args
)
def
after_cancel
(
self
,
id
):
def
after_cancel
(
self
,
id
):
"""Cancel scheduling of function identified with ID.
"""Cancel scheduling of function identified with ID.
...
@@ -1182,7 +1182,7 @@ class Misc:
...
@@ -1182,7 +1182,7 @@ class Misc:
args
=
args
+
(
column
,
row
)
args
=
args
+
(
column
,
row
)
if
col2
is
not
None
and
row2
is
not
None
:
if
col2
is
not
None
and
row2
is
not
None
:
args
=
args
+
(
col2
,
row2
)
args
=
args
+
(
col2
,
row2
)
return
self
.
_getints
(
apply
(
self
.
tk
.
call
,
args
))
or
None
return
self
.
_getints
(
self
.
tk
.
call
(
*
args
))
or
None
bbox
=
grid_bbox
bbox
=
grid_bbox
def
_grid_configure
(
self
,
command
,
index
,
cnf
,
kw
):
def
_grid_configure
(
self
,
command
,
index
,
cnf
,
kw
):
...
@@ -1324,8 +1324,8 @@ class CallWrapper:
...
@@ -1324,8 +1324,8 @@ class CallWrapper:
"""Apply first function SUBST to arguments, than FUNC."""
"""Apply first function SUBST to arguments, than FUNC."""
try
:
try
:
if
self
.
subst
:
if
self
.
subst
:
args
=
apply
(
self
.
subst
,
args
)
args
=
self
.
subst
(
*
args
)
return
apply
(
self
.
func
,
args
)
return
self
.
func
(
*
args
)
except
SystemExit
,
msg
:
except
SystemExit
,
msg
:
raise
SystemExit
,
msg
raise
SystemExit
,
msg
except
:
except
:
...
@@ -1334,7 +1334,7 @@ class CallWrapper:
...
@@ -1334,7 +1334,7 @@ class CallWrapper:
class
Wm
:
class
Wm
:
"""Provides functions for the communication with the window manager."""
"""Provides functions for the communication with the window manager."""
def
wm_aspect
(
self
,
def
wm_aspect
(
self
,
minNumer
=
None
,
minDenom
=
None
,
minNumer
=
None
,
minDenom
=
None
,
maxNumer
=
None
,
maxDenom
=
None
):
maxNumer
=
None
,
maxDenom
=
None
):
...
@@ -1346,29 +1346,29 @@ class Wm:
...
@@ -1346,29 +1346,29 @@ class Wm:
minNumer
,
minDenom
,
minNumer
,
minDenom
,
maxNumer
,
maxDenom
))
maxNumer
,
maxDenom
))
aspect
=
wm_aspect
aspect
=
wm_aspect
def
wm_attributes
(
self
,
*
args
):
def
wm_attributes
(
self
,
*
args
):
"""This subcommand returns or sets platform specific attributes
"""This subcommand returns or sets platform specific attributes
The first form returns a list of the platform specific flags and
The first form returns a list of the platform specific flags and
their values. The second form returns the value for the specific
their values. The second form returns the value for the specific
option. The third form sets one or more of the values. The values
option. The third form sets one or more of the values. The values
are as follows:
are as follows:
On Windows, -disabled gets or sets whether the window is in a
On Windows, -disabled gets or sets whether the window is in a
disabled state. -toolwindow gets or sets the style of the window
disabled state. -toolwindow gets or sets the style of the window
to toolwindow (as defined in the MSDN). -topmost gets or sets
to toolwindow (as defined in the MSDN). -topmost gets or sets
whether this is a topmost window (displays above all other
whether this is a topmost window (displays above all other
windows).
windows).
On Macintosh, XXXXX
On Macintosh, XXXXX
On Unix, there are currently no special attribute values.
On Unix, there are currently no special attribute values.
"""
"""
args
=
(
'wm'
,
'attributes'
,
self
.
_w
)
+
args
args
=
(
'wm'
,
'attributes'
,
self
.
_w
)
+
args
return
self
.
tk
.
call
(
args
)
return
self
.
tk
.
call
(
args
)
attributes
=
wm_attributes
attributes
=
wm_attributes
def
wm_client
(
self
,
name
=
None
):
def
wm_client
(
self
,
name
=
None
):
"""Store NAME in WM_CLIENT_MACHINE property of this widget. Return
"""Store NAME in WM_CLIENT_MACHINE property of this widget. Return
current value."""
current value."""
...
@@ -1868,56 +1868,56 @@ class Button(Widget):
...
@@ -1868,56 +1868,56 @@ class Button(Widget):
"""Button widget."""
"""Button widget."""
def
__init__
(
self
,
master
=
None
,
cnf
=
{},
**
kw
):
def
__init__
(
self
,
master
=
None
,
cnf
=
{},
**
kw
):
"""Construct a button widget with the parent MASTER.
"""Construct a button widget with the parent MASTER.
STANDARD OPTIONS
STANDARD OPTIONS
activebackground, activeforeground, anchor,
activebackground, activeforeground, anchor,
background, bitmap, borderwidth, cursor,
background, bitmap, borderwidth, cursor,
disabledforeground, font, foreground
disabledforeground, font, foreground
highlightbackground, highlightcolor,
highlightbackground, highlightcolor,
highlightthickness, image, justify,
highlightthickness, image, justify,
padx, pady, relief, repeatdelay,
padx, pady, relief, repeatdelay,
repeatinterval, takefocus, text,
repeatinterval, takefocus, text,
textvariable, underline, wraplength
textvariable, underline, wraplength
WIDGET-SPECIFIC OPTIONS
WIDGET-SPECIFIC OPTIONS
command, compound, default, height,
command, compound, default, height,
overrelief, state, width
overrelief, state, width
"""
"""
Widget
.
__init__
(
self
,
master
,
'button'
,
cnf
,
kw
)
Widget
.
__init__
(
self
,
master
,
'button'
,
cnf
,
kw
)
def
tkButtonEnter
(
self
,
*
dummy
):
def
tkButtonEnter
(
self
,
*
dummy
):
self
.
tk
.
call
(
'tkButtonEnter'
,
self
.
_w
)
self
.
tk
.
call
(
'tkButtonEnter'
,
self
.
_w
)
def
tkButtonLeave
(
self
,
*
dummy
):
def
tkButtonLeave
(
self
,
*
dummy
):
self
.
tk
.
call
(
'tkButtonLeave'
,
self
.
_w
)
self
.
tk
.
call
(
'tkButtonLeave'
,
self
.
_w
)
def
tkButtonDown
(
self
,
*
dummy
):
def
tkButtonDown
(
self
,
*
dummy
):
self
.
tk
.
call
(
'tkButtonDown'
,
self
.
_w
)
self
.
tk
.
call
(
'tkButtonDown'
,
self
.
_w
)
def
tkButtonUp
(
self
,
*
dummy
):
def
tkButtonUp
(
self
,
*
dummy
):
self
.
tk
.
call
(
'tkButtonUp'
,
self
.
_w
)
self
.
tk
.
call
(
'tkButtonUp'
,
self
.
_w
)
def
tkButtonInvoke
(
self
,
*
dummy
):
def
tkButtonInvoke
(
self
,
*
dummy
):
self
.
tk
.
call
(
'tkButtonInvoke'
,
self
.
_w
)
self
.
tk
.
call
(
'tkButtonInvoke'
,
self
.
_w
)
def
flash
(
self
):
def
flash
(
self
):
"""Flash the button.
"""Flash the button.
This is accomplished by redisplaying
This is accomplished by redisplaying
the button several times, alternating between active and
the button several times, alternating between active and
normal colors. At the end of the flash the button is left
normal colors. At the end of the flash the button is left
in the same normal/active state as when the command was
in the same normal/active state as when the command was
invoked. This command is ignored if the button's state is
invoked. This command is ignored if the button's state is
disabled.
disabled.
"""
"""
self
.
tk
.
call
(
self
.
_w
,
'flash'
)
self
.
tk
.
call
(
self
.
_w
,
'flash'
)
def
invoke
(
self
):
def
invoke
(
self
):
"""Invoke the command associated with the button.
"""Invoke the command associated with the button.
The return value is the return value from the command,
The return value is the return value from the command,
or an empty string if there is no command associated with
or an empty string if there is no command associated with
the button. This command is ignored if the button's state
the button. This command is ignored if the button's state
is disabled.
is disabled.
...
@@ -2028,10 +2028,9 @@ class Canvas(Widget):
...
@@ -2028,10 +2028,9 @@ class Canvas(Widget):
args
=
args
[:
-
1
]
args
=
args
[:
-
1
]
else
:
else
:
cnf
=
{}
cnf
=
{}
return
getint
(
apply
(
return
getint
(
self
.
tk
.
call
(
self
.
tk
.
call
,
self
.
_w
,
'create'
,
itemType
,
(
self
.
_w
,
'create'
,
itemType
)
*
(
args
+
self
.
_options
(
cnf
,
kw
))))
+
args
+
self
.
_options
(
cnf
,
kw
)))
def
create_arc
(
self
,
*
args
,
**
kw
):
def
create_arc
(
self
,
*
args
,
**
kw
):
"""Create arc shaped region with coordinates x1,y1,x2,y2."""
"""Create arc shaped region with coordinates x1,y1,x2,y2."""
return
self
.
_create
(
'arc'
,
args
,
kw
)
return
self
.
_create
(
'arc'
,
args
,
kw
)
...
@@ -2334,21 +2333,21 @@ class Label(Widget):
...
@@ -2334,21 +2333,21 @@ class Label(Widget):
"""Label widget which can display text and bitmaps."""
"""Label widget which can display text and bitmaps."""
def
__init__
(
self
,
master
=
None
,
cnf
=
{},
**
kw
):
def
__init__
(
self
,
master
=
None
,
cnf
=
{},
**
kw
):
"""Construct a label widget with the parent MASTER.
"""Construct a label widget with the parent MASTER.
STANDARD OPTIONS
STANDARD OPTIONS
activebackground, activeforeground, anchor,
activebackground, activeforeground, anchor,
background, bitmap, borderwidth, cursor,
background, bitmap, borderwidth, cursor,
disabledforeground, font, foreground,
disabledforeground, font, foreground,
highlightbackground, highlightcolor,
highlightbackground, highlightcolor,
highlightthickness, image, justify,
highlightthickness, image, justify,
padx, pady, relief, takefocus, text,
padx, pady, relief, takefocus, text,
textvariable, underline, wraplength
textvariable, underline, wraplength
WIDGET-SPECIFIC OPTIONS
WIDGET-SPECIFIC OPTIONS
height, state, width
height, state, width
"""
"""
Widget
.
__init__
(
self
,
master
,
'label'
,
cnf
,
kw
)
Widget
.
__init__
(
self
,
master
,
'label'
,
cnf
,
kw
)
...
@@ -2686,33 +2685,33 @@ class Scrollbar(Widget):
...
@@ -2686,33 +2685,33 @@ class Scrollbar(Widget):
"""Set the fractional values of the slider position (upper and
"""Set the fractional values of the slider position (upper and
lower ends as value between 0 and 1)."""
lower ends as value between 0 and 1)."""
self
.
tk
.
call
((
self
.
_w
,
'set'
)
+
args
)
self
.
tk
.
call
((
self
.
_w
,
'set'
)
+
args
)
class
Text
(
Widget
):
class
Text
(
Widget
):
"""Text widget which can display text in various forms."""
"""Text widget which can display text in various forms."""
def
__init__
(
self
,
master
=
None
,
cnf
=
{},
**
kw
):
def
__init__
(
self
,
master
=
None
,
cnf
=
{},
**
kw
):
"""Construct a text widget with the parent MASTER.
"""Construct a text widget with the parent MASTER.
STANDARD OPTIONS
STANDARD OPTIONS
background, borderwidth, cursor,
background, borderwidth, cursor,
exportselection, font, foreground,
exportselection, font, foreground,
highlightbackground, highlightcolor,
highlightbackground, highlightcolor,
highlightthickness, insertbackground,
highlightthickness, insertbackground,
insertborderwidth, insertofftime,
insertborderwidth, insertofftime,
insertontime, insertwidth, padx, pady,
insertontime, insertwidth, padx, pady,
relief, selectbackground,
relief, selectbackground,
selectborderwidth, selectforeground,
selectborderwidth, selectforeground,
setgrid, takefocus,
setgrid, takefocus,
xscrollcommand, yscrollcommand,
xscrollcommand, yscrollcommand,
WIDGET-SPECIFIC OPTIONS
WIDGET-SPECIFIC OPTIONS
autoseparators, height, maxundo,
autoseparators, height, maxundo,
spacing1, spacing2, spacing3,
spacing1, spacing2, spacing3,
state, tabs, undo, width, wrap,
state, tabs, undo, width, wrap,
"""
"""
Widget
.
__init__
(
self
,
master
,
'text'
,
cnf
,
kw
)
Widget
.
__init__
(
self
,
master
,
'text'
,
cnf
,
kw
)
def
bbox
(
self
,
*
args
):
def
bbox
(
self
,
*
args
):
...
@@ -2748,13 +2747,13 @@ class Text(Widget):
...
@@ -2748,13 +2747,13 @@ class Text(Widget):
return
self
.
_getints
(
self
.
tk
.
call
(
self
.
_w
,
'dlineinfo'
,
index
))
return
self
.
_getints
(
self
.
tk
.
call
(
self
.
_w
,
'dlineinfo'
,
index
))
def
dump
(
self
,
index1
,
index2
=
None
,
command
=
None
,
**
kw
):
def
dump
(
self
,
index1
,
index2
=
None
,
command
=
None
,
**
kw
):
"""Return the contents of the widget between index1 and index2.
"""Return the contents of the widget between index1 and index2.
The type of contents returned in filtered based on the keyword
The type of contents returned in filtered based on the keyword
parameters; if 'all', 'image', 'mark', 'tag', 'text', or 'window' are
parameters; if 'all', 'image', 'mark', 'tag', 'text', or 'window' are
given and true, then the corresponding items are returned. The result
given and true, then the corresponding items are returned. The result
is a list of triples of the form (key, value, index). If none of the
is a list of triples of the form (key, value, index). If none of the
keywords are true then 'all' is used by default.
keywords are true then 'all' is used by default.
If the 'command' argument is given, it is called once for each element
If the 'command' argument is given, it is called once for each element
of the list of triples, with the values of each triple serving as the
of the list of triples, with the values of each triple serving as the
arguments to the function. In this case the list is not returned."""
arguments to the function. In this case the list is not returned."""
...
@@ -2784,68 +2783,68 @@ class Text(Widget):
...
@@ -2784,68 +2783,68 @@ class Text(Widget):
finally
:
finally
:
if
func_name
:
if
func_name
:
self
.
deletecommand
(
func_name
)
self
.
deletecommand
(
func_name
)
## new in tk8.4
## new in tk8.4
def
edit
(
self
,
*
args
):
def
edit
(
self
,
*
args
):
"""Internal method
"""Internal method
This method controls the undo mechanism and
This method controls the undo mechanism and
the modified flag. The exact behavior of the
the modified flag. The exact behavior of the
command depends on the option argument that
command depends on the option argument that
follows the edit argument. The following forms
follows the edit argument. The following forms
of the command are currently supported:
of the command are currently supported:
edit_modified, edit_redo, edit_reset, edit_separator
edit_modified, edit_redo, edit_reset, edit_separator
and edit_undo
and edit_undo
"""
"""
return
self
.
_getints
(
return
self
.
_getints
(
self
.
tk
.
call
((
self
.
_w
,
'edit'
)
+
args
))
or
()
self
.
tk
.
call
((
self
.
_w
,
'edit'
)
+
args
))
or
()
def
edit_modified
(
self
,
arg
=
None
):
def
edit_modified
(
self
,
arg
=
None
):
"""Get or Set the modified flag
"""Get or Set the modified flag
If arg is not specified, returns the modified
If arg is not specified, returns the modified
flag of the widget. The insert, delete, edit undo and
flag of the widget. The insert, delete, edit undo and
edit redo commands or the user can set or clear the
edit redo commands or the user can set or clear the
modified flag. If boolean is specified, sets the
modified flag. If boolean is specified, sets the
modified flag of the widget to arg.
modified flag of the widget to arg.
"""
"""
return
self
.
edit
(
"modified"
,
arg
)
return
self
.
edit
(
"modified"
,
arg
)
def
edit_redo
(
self
):
def
edit_redo
(
self
):
"""Redo the last undone edit
"""Redo the last undone edit
When the undo option is true, reapplies the last
When the undo option is true, reapplies the last
undone edits provided no other edits were done since
undone edits provided no other edits were done since
then. Generates an error when the redo stack is empty.
then. Generates an error when the redo stack is empty.
Does nothing when the undo option is false.
Does nothing when the undo option is false.
"""
"""
return
self
.
edit
(
"redo"
)
return
self
.
edit
(
"redo"
)
def
edit_reset
(
self
):
def
edit_reset
(
self
):
"""Clears the undo and redo stacks
"""Clears the undo and redo stacks
"""
"""
return
self
.
edit
(
"reset"
)
return
self
.
edit
(
"reset"
)
def
edit_separator
(
self
):
def
edit_separator
(
self
):
"""Inserts a separator (boundary) on the undo stack.
"""Inserts a separator (boundary) on the undo stack.
Does nothing when the undo option is false
Does nothing when the undo option is false
"""
"""
return
self
.
edit
(
"separator"
)
return
self
.
edit
(
"separator"
)
def
edit_undo
(
self
):
def
edit_undo
(
self
):
"""Undoes the last edit action
"""Undoes the last edit action
If the undo option is true. An edit action is defined
If the undo option is true. An edit action is defined
as all the insert and delete commands that are recorded
as all the insert and delete commands that are recorded
on the undo stack in between two separators. Generates
on the undo stack in between two separators. Generates
an error when the undo stack is empty. Does nothing
an error when the undo stack is empty. Does nothing
when the undo option is false
when the undo option is false
"""
"""
return
self
.
edit
(
"undo"
)
return
self
.
edit
(
"undo"
)
def
get
(
self
,
index1
,
index2
=
None
):
def
get
(
self
,
index1
,
index2
=
None
):
"""Return the text from INDEX1 to INDEX2 (not included)."""
"""Return the text from INDEX1 to INDEX2 (not included)."""
return
self
.
tk
.
call
(
self
.
_w
,
'get'
,
index1
,
index2
)
return
self
.
tk
.
call
(
self
.
_w
,
'get'
,
index1
,
index2
)
...
@@ -2862,9 +2861,9 @@ class Text(Widget):
...
@@ -2862,9 +2861,9 @@ class Text(Widget):
return
self
.
_configure
((
'image'
,
'configure'
,
index
),
cnf
,
kw
)
return
self
.
_configure
((
'image'
,
'configure'
,
index
),
cnf
,
kw
)
def
image_create
(
self
,
index
,
cnf
=
{},
**
kw
):
def
image_create
(
self
,
index
,
cnf
=
{},
**
kw
):
"""Create an embedded image at INDEX."""
"""Create an embedded image at INDEX."""
return
apply
(
self
.
tk
.
call
,
return
self
.
tk
.
call
(
(
self
.
_w
,
"image"
,
"create"
,
index
)
self
.
_w
,
"image"
,
"create"
,
index
,
+
self
.
_options
(
cnf
,
kw
))
*
self
.
_options
(
cnf
,
kw
))
def
image_names
(
self
):
def
image_names
(
self
):
"""Return all names of embedded images in this widget."""
"""Return all names of embedded images in this widget."""
return
self
.
tk
.
call
(
self
.
_w
,
"image"
,
"names"
)
return
self
.
tk
.
call
(
self
.
_w
,
"image"
,
"names"
)
...
@@ -3050,7 +3049,7 @@ class _setit:
...
@@ -3050,7 +3049,7 @@ class _setit:
def
__call__
(
self
,
*
args
):
def
__call__
(
self
,
*
args
):
self
.
__var
.
set
(
self
.
__value
)
self
.
__var
.
set
(
self
.
__value
)
if
self
.
__callback
:
if
self
.
__callback
:
apply
(
self
.
__callback
,
(
self
.
__value
,)
+
args
)
self
.
__callback
(
self
.
__value
,
*
args
)
class
OptionMenu
(
Menubutton
):
class
OptionMenu
(
Menubutton
):
"""OptionMenu which allows the user to select a value from a menu."""
"""OptionMenu which allows the user to select a value from a menu."""
...
@@ -3156,7 +3155,7 @@ class PhotoImage(Image):
...
@@ -3156,7 +3155,7 @@ class PhotoImage(Image):
Valid resource names: data, format, file, gamma, height, palette,
Valid resource names: data, format, file, gamma, height, palette,
width."""
width."""
apply
(
Image
.
__init__
,
(
self
,
'photo'
,
name
,
cnf
,
master
),
kw
)
Image
.
__init__
(
self
,
'photo'
,
name
,
cnf
,
master
,
**
kw
)
def
blank
(
self
):
def
blank
(
self
):
"""Display a transparent image."""
"""Display a transparent image."""
self
.
tk
.
call
(
self
.
name
,
'blank'
)
self
.
tk
.
call
(
self
.
name
,
'blank'
)
...
@@ -3215,7 +3214,7 @@ class BitmapImage(Image):
...
@@ -3215,7 +3214,7 @@ class BitmapImage(Image):
"""Create a bitmap with NAME.
"""Create a bitmap with NAME.
Valid resource names: background, data, file, foreground, maskdata, maskfile."""
Valid resource names: background, data, file, foreground, maskdata, maskfile."""
apply
(
Image
.
__init__
,
(
self
,
'bitmap'
,
name
,
cnf
,
master
),
kw
)
Image
.
__init__
(
self
,
'bitmap'
,
name
,
cnf
,
master
,
**
kw
)
def
image_names
():
return
_default_root
.
tk
.
call
(
'image'
,
'names'
)
def
image_names
():
return
_default_root
.
tk
.
call
(
'image'
,
'names'
)
def
image_types
():
return
_default_root
.
tk
.
call
(
'image'
,
'types'
)
def
image_types
():
return
_default_root
.
tk
.
call
(
'image'
,
'types'
)
...
@@ -3225,154 +3224,154 @@ class Spinbox(Widget):
...
@@ -3225,154 +3224,154 @@ class Spinbox(Widget):
"""spinbox widget."""
"""spinbox widget."""
def
__init__
(
self
,
master
=
None
,
cnf
=
{},
**
kw
):
def
__init__
(
self
,
master
=
None
,
cnf
=
{},
**
kw
):
"""Construct a spinbox widget with the parent MASTER.
"""Construct a spinbox widget with the parent MASTER.
STANDARD OPTIONS
STANDARD OPTIONS
activebackground, background, borderwidth,
activebackground, background, borderwidth,
cursor, exportselection, font, foreground,
cursor, exportselection, font, foreground,
highlightbackground, highlightcolor,
highlightbackground, highlightcolor,
highlightthickness, insertbackground,
highlightthickness, insertbackground,
insertborderwidth, insertofftime,
insertborderwidth, insertofftime,
insertontime, insertwidth, justify, relief,
insertontime, insertwidth, justify, relief,
repeatdelay, repeatinterval,
repeatdelay, repeatinterval,
selectbackground, selectborderwidth
selectbackground, selectborderwidth
selectforeground, takefocus, textvariable
selectforeground, takefocus, textvariable
xscrollcommand.
xscrollcommand.
WIDGET-SPECIFIC OPTIONS
WIDGET-SPECIFIC OPTIONS
buttonbackground, buttoncursor,
buttonbackground, buttoncursor,
buttondownrelief, buttonuprelief,
buttondownrelief, buttonuprelief,
command, disabledbackground,
command, disabledbackground,
disabledforeground, format, from,
disabledforeground, format, from,
invalidcommand, increment,
invalidcommand, increment,
readonlybackground, state, to,
readonlybackground, state, to,
validate, validatecommand values,
validate, validatecommand values,
width, wrap,
width, wrap,
"""
"""
Widget
.
__init__
(
self
,
master
,
'spinbox'
,
cnf
,
kw
)
Widget
.
__init__
(
self
,
master
,
'spinbox'
,
cnf
,
kw
)
def
bbox
(
self
,
index
):
def
bbox
(
self
,
index
):
"""Return a tuple of X1,Y1,X2,Y2 coordinates for a
"""Return a tuple of X1,Y1,X2,Y2 coordinates for a
rectangle which encloses the character given by index.
rectangle which encloses the character given by index.
The first two elements of the list give the x and y
The first two elements of the list give the x and y
coordinates of the upper-left corner of the screen
coordinates of the upper-left corner of the screen
area covered by the character (in pixels relative
area covered by the character (in pixels relative
to the widget) and the last two elements give the
to the widget) and the last two elements give the
width and height of the character, in pixels. The
width and height of the character, in pixels. The
bounding box may refer to a region outside the
bounding box may refer to a region outside the
visible area of the window.
visible area of the window.
"""
"""
return
self
.
tk
.
call
(
self
.
_w
,
'bbox'
,
index
)
return
self
.
tk
.
call
(
self
.
_w
,
'bbox'
,
index
)
def
delete
(
self
,
first
,
last
=
None
):
def
delete
(
self
,
first
,
last
=
None
):
"""Delete one or more elements of the spinbox.
"""Delete one or more elements of the spinbox.
First is the index of the first character to delete,
First is the index of the first character to delete,
and last is the index of the character just after
and last is the index of the character just after
the last one to delete. If last isn't specified it
the last one to delete. If last isn't specified it
defaults to first+1, i.e. a single character is
defaults to first+1, i.e. a single character is
deleted. This command returns an empty string.
deleted. This command returns an empty string.
"""
"""
return
self
.
tk
.
call
(
self
.
_w
,
'delete'
,
first
,
last
)
return
self
.
tk
.
call
(
self
.
_w
,
'delete'
,
first
,
last
)
def
get
(
self
):
def
get
(
self
):
"""Returns the spinbox's string"""
"""Returns the spinbox's string"""
return
self
.
tk
.
call
(
self
.
_w
,
'get'
)
return
self
.
tk
.
call
(
self
.
_w
,
'get'
)
def
icursor
(
self
,
index
):
def
icursor
(
self
,
index
):
"""Alter the position of the insertion cursor.
"""Alter the position of the insertion cursor.
The insertion cursor will be displayed just before
The insertion cursor will be displayed just before
the character given by index. Returns an empty string
the character given by index. Returns an empty string
"""
"""
return
self
.
tk
.
call
(
self
.
_w
,
'icursor'
,
index
)
return
self
.
tk
.
call
(
self
.
_w
,
'icursor'
,
index
)
def
identify
(
self
,
x
,
y
):
def
identify
(
self
,
x
,
y
):
"""Returns the name of the widget at position x, y
"""Returns the name of the widget at position x, y
Return value is one of: none, buttondown, buttonup, entry
Return value is one of: none, buttondown, buttonup, entry
"""
"""
return
self
.
tk
.
call
(
self
.
_w
,
'identify'
,
x
,
y
)
return
self
.
tk
.
call
(
self
.
_w
,
'identify'
,
x
,
y
)
def
index
(
self
,
index
):
def
index
(
self
,
index
):
"""Returns the numerical index corresponding to index
"""Returns the numerical index corresponding to index
"""
"""
return
self
.
tk
.
call
(
self
.
_w
,
'index'
,
index
)
return
self
.
tk
.
call
(
self
.
_w
,
'index'
,
index
)
def
insert
(
self
,
index
,
s
):
def
insert
(
self
,
index
,
s
):
"""Insert string s at index
"""Insert string s at index
Returns an empty string.
Returns an empty string.
"""
"""
return
self
.
tk
.
call
(
self
.
_w
,
'insert'
,
index
,
s
)
return
self
.
tk
.
call
(
self
.
_w
,
'insert'
,
index
,
s
)
def
invoke
(
self
,
element
):
def
invoke
(
self
,
element
):
"""Causes the specified element to be invoked
"""Causes the specified element to be invoked
The element could be buttondown or buttonup
The element could be buttondown or buttonup
triggering the action associated with it.
triggering the action associated with it.
"""
"""
return
self
.
tk
.
call
(
self
.
_w
,
'invoke'
,
element
)
return
self
.
tk
.
call
(
self
.
_w
,
'invoke'
,
element
)
def
scan
(
self
,
*
args
):
def
scan
(
self
,
*
args
):
"""Internal function."""
"""Internal function."""
return
self
.
_getints
(
return
self
.
_getints
(
self
.
tk
.
call
((
self
.
_w
,
'scan'
)
+
args
))
or
()
self
.
tk
.
call
((
self
.
_w
,
'scan'
)
+
args
))
or
()
def
scan_mark
(
self
,
x
):
def
scan_mark
(
self
,
x
):
"""Records x and the current view in the spinbox window;
"""Records x and the current view in the spinbox window;
used in conjunction with later scan dragto commands.
used in conjunction with later scan dragto commands.
Typically this command is associated with a mouse button
Typically this command is associated with a mouse button
press in the widget. It returns an empty string.
press in the widget. It returns an empty string.
"""
"""
return
self
.
scan
(
"mark"
,
x
)
return
self
.
scan
(
"mark"
,
x
)
def
scan_dragto
(
self
,
x
):
def
scan_dragto
(
self
,
x
):
"""Compute the difference between the given x argument
"""Compute the difference between the given x argument
and the x argument to the last scan mark command
and the x argument to the last scan mark command
It then adjusts the view left or right by 10 times the
It then adjusts the view left or right by 10 times the
difference in x-coordinates. This command is typically
difference in x-coordinates. This command is typically
associated with mouse motion events in the widget, to
associated with mouse motion events in the widget, to
produce the effect of dragging the spinbox at high speed
produce the effect of dragging the spinbox at high speed
through the window. The return value is an empty string.
through the window. The return value is an empty string.
"""
"""
return
self
.
scan
(
"dragto"
,
x
)
return
self
.
scan
(
"dragto"
,
x
)
def
selection
(
self
,
*
args
):
def
selection
(
self
,
*
args
):
"""Internal function."""
"""Internal function."""
return
self
.
_getints
(
return
self
.
_getints
(
self
.
tk
.
call
((
self
.
_w
,
'selection'
)
+
args
))
or
()
self
.
tk
.
call
((
self
.
_w
,
'selection'
)
+
args
))
or
()
def
selection_adjust
(
self
,
index
):
def
selection_adjust
(
self
,
index
):
"""Locate the end of the selection nearest to the character
"""Locate the end of the selection nearest to the character
given by index,
given by index,
Then adjust that end of the selection to be at index
Then adjust that end of the selection to be at index
(i.e including but not going beyond index). The other
(i.e including but not going beyond index). The other
end of the selection is made the anchor point for future
end of the selection is made the anchor point for future
select to commands. If the selection isn't currently in
select to commands. If the selection isn't currently in
the spinbox, then a new selection is created to include
the spinbox, then a new selection is created to include
the characters between index and the most recent selection
the characters between index and the most recent selection
anchor point, inclusive. Returns an empty string.
anchor point, inclusive. Returns an empty string.
"""
"""
return
self
.
selection
(
"adjust"
,
index
)
return
self
.
selection
(
"adjust"
,
index
)
def
selection_clear
(
self
):
def
selection_clear
(
self
):
"""Clear the selection
"""Clear the selection
If the selection isn't in this widget then the
If the selection isn't in this widget then the
command has no effect. Returns an empty string.
command has no effect. Returns an empty string.
"""
"""
return
self
.
selection
(
"clear"
)
return
self
.
selection
(
"clear"
)
def
selection_element
(
self
,
element
=
None
):
def
selection_element
(
self
,
element
=
None
):
"""Sets or gets the currently selected element.
"""Sets or gets the currently selected element.
If a spinbutton element is specified, it will be
If a spinbutton element is specified, it will be
displayed depressed
displayed depressed
"""
"""
return
self
.
selection
(
"element"
,
element
)
return
self
.
selection
(
"element"
,
element
)
...
@@ -3383,198 +3382,198 @@ class LabelFrame(Widget):
...
@@ -3383,198 +3382,198 @@ class LabelFrame(Widget):
"""labelframe widget."""
"""labelframe widget."""
def
__init__
(
self
,
master
=
None
,
cnf
=
{},
**
kw
):
def
__init__
(
self
,
master
=
None
,
cnf
=
{},
**
kw
):
"""Construct a labelframe widget with the parent MASTER.
"""Construct a labelframe widget with the parent MASTER.
STANDARD OPTIONS
STANDARD OPTIONS
borderwidth, cursor, font, foreground,
borderwidth, cursor, font, foreground,
highlightbackground, highlightcolor,
highlightbackground, highlightcolor,
highlightthickness, padx, pady, relief,
highlightthickness, padx, pady, relief,
takefocus, text
takefocus, text
WIDGET-SPECIFIC OPTIONS
WIDGET-SPECIFIC OPTIONS
background, class, colormap, container,
background, class, colormap, container,
height, labelanchor, labelwidget,
height, labelanchor, labelwidget,
visual, width
visual, width
"""
"""
Widget
.
__init__
(
self
,
master
,
'labelframe'
,
cnf
,
kw
)
Widget
.
__init__
(
self
,
master
,
'labelframe'
,
cnf
,
kw
)
########################################################################
########################################################################
class
PanedWindow
(
Widget
):
class
PanedWindow
(
Widget
):
"""panedwindow widget."""
"""panedwindow widget."""
def
__init__
(
self
,
master
=
None
,
cnf
=
{},
**
kw
):
def
__init__
(
self
,
master
=
None
,
cnf
=
{},
**
kw
):
"""Construct a panedwindow widget with the parent MASTER.
"""Construct a panedwindow widget with the parent MASTER.
STANDARD OPTIONS
STANDARD OPTIONS
background, borderwidth, cursor, height,
background, borderwidth, cursor, height,
orient, relief, width
orient, relief, width
WIDGET-SPECIFIC OPTIONS
WIDGET-SPECIFIC OPTIONS
handlepad, handlesize, opaqueresize,
handlepad, handlesize, opaqueresize,
sashcursor, sashpad, sashrelief,
sashcursor, sashpad, sashrelief,
sashwidth, showhandle,
sashwidth, showhandle,
"""
"""
Widget
.
__init__
(
self
,
master
,
'panedwindow'
,
cnf
,
kw
)
Widget
.
__init__
(
self
,
master
,
'panedwindow'
,
cnf
,
kw
)
def
add
(
self
,
child
,
**
kw
):
def
add
(
self
,
child
,
**
kw
):
"""Add a child widget to the panedwindow in a new pane.
"""Add a child widget to the panedwindow in a new pane.
The child argument is the name of the child widget
The child argument is the name of the child widget
followed by pairs of arguments that specify how to
followed by pairs of arguments that specify how to
manage the windows. Options may have any of the values
manage the windows. Options may have any of the values
accepted by the configure subcommand.
accepted by the configure subcommand.
"""
"""
self
.
tk
.
call
((
self
.
_w
,
'add'
,
child
)
+
self
.
_options
(
kw
))
self
.
tk
.
call
((
self
.
_w
,
'add'
,
child
)
+
self
.
_options
(
kw
))
def
remove
(
self
,
child
):
def
remove
(
self
,
child
):
"""Remove the pane containing child from the panedwindow
"""Remove the pane containing child from the panedwindow
All geometry management options for child will be forgotten.
All geometry management options for child will be forgotten.
"""
"""
self
.
tk
.
call
(
self
.
_w
,
'forget'
,
child
)
self
.
tk
.
call
(
self
.
_w
,
'forget'
,
child
)
forget
=
remove
forget
=
remove
def
identify
(
self
,
x
,
y
):
def
identify
(
self
,
x
,
y
):
"""Identify the panedwindow component at point x, y
"""Identify the panedwindow component at point x, y
If the point is over a sash or a sash handle, the result
If the point is over a sash or a sash handle, the result
is a two element list containing the index of the sash or
is a two element list containing the index of the sash or
handle, and a word indicating whether it is over a sash
handle, and a word indicating whether it is over a sash
or a handle, such as {0 sash} or {2 handle}. If the point
or a handle, such as {0 sash} or {2 handle}. If the point
is over any other part of the panedwindow, the result is
is over any other part of the panedwindow, the result is
an empty list.
an empty list.
"""
"""
return
self
.
tk
.
call
(
self
.
_w
,
'identify'
,
x
,
y
)
return
self
.
tk
.
call
(
self
.
_w
,
'identify'
,
x
,
y
)
def
proxy
(
self
,
*
args
):
def
proxy
(
self
,
*
args
):
"""Internal function."""
"""Internal function."""
return
self
.
_getints
(
return
self
.
_getints
(
self
.
tk
.
call
((
self
.
_w
,
'proxy'
)
+
args
))
or
()
self
.
tk
.
call
((
self
.
_w
,
'proxy'
)
+
args
))
or
()
def
proxy_coord
(
self
):
def
proxy_coord
(
self
):
"""Return the x and y pair of the most recent proxy location
"""Return the x and y pair of the most recent proxy location
"""
"""
return
self
.
proxy
(
"coord"
)
return
self
.
proxy
(
"coord"
)
def
proxy_forget
(
self
):
def
proxy_forget
(
self
):
"""Remove the proxy from the display.
"""Remove the proxy from the display.
"""
"""
return
self
.
proxy
(
"forget"
)
return
self
.
proxy
(
"forget"
)
def
proxy_place
(
self
,
x
,
y
):
def
proxy_place
(
self
,
x
,
y
):
"""Place the proxy at the given x and y coordinates.
"""Place the proxy at the given x and y coordinates.
"""
"""
return
self
.
proxy
(
"place"
,
x
,
y
)
return
self
.
proxy
(
"place"
,
x
,
y
)
def
sash
(
self
,
*
args
):
def
sash
(
self
,
*
args
):
"""Internal function."""
"""Internal function."""
return
self
.
_getints
(
return
self
.
_getints
(
self
.
tk
.
call
((
self
.
_w
,
'sash'
)
+
args
))
or
()
self
.
tk
.
call
((
self
.
_w
,
'sash'
)
+
args
))
or
()
def
sash_coord
(
self
,
index
):
def
sash_coord
(
self
,
index
):
"""Return the current x and y pair for the sash given by index.
"""Return the current x and y pair for the sash given by index.
Index must be an integer between 0 and 1 less than the
Index must be an integer between 0 and 1 less than the
number of panes in the panedwindow. The coordinates given are
number of panes in the panedwindow. The coordinates given are
those of the top left corner of the region containing the sash.
those of the top left corner of the region containing the sash.
pathName sash dragto index x y This command computes the
pathName sash dragto index x y This command computes the
difference between the given coordinates and the coordinates
difference between the given coordinates and the coordinates
given to the last sash coord command for the given sash. It then
given to the last sash coord command for the given sash. It then
moves that sash the computed difference. The return value is the
moves that sash the computed difference. The return value is the
empty string.
empty string.
"""
"""
return
self
.
sash
(
"coord"
,
index
)
return
self
.
sash
(
"coord"
,
index
)
def
sash_mark
(
self
,
index
):
def
sash_mark
(
self
,
index
):
"""Records x and y for the sash given by index;
"""Records x and y for the sash given by index;
Used in conjunction with later dragto commands to move the sash.
Used in conjunction with later dragto commands to move the sash.
"""
"""
return
self
.
sash
(
"mark"
,
index
)
return
self
.
sash
(
"mark"
,
index
)
def
sash_place
(
self
,
index
,
x
,
y
):
def
sash_place
(
self
,
index
,
x
,
y
):
"""Place the sash given by index at the given coordinates
"""Place the sash given by index at the given coordinates
"""
"""
return
self
.
sash
(
"place"
,
index
,
x
,
y
)
return
self
.
sash
(
"place"
,
index
,
x
,
y
)
def
panecget
(
self
,
child
,
option
):
def
panecget
(
self
,
child
,
option
):
"""Query a management option for window.
"""Query a management option for window.
Option may be any value allowed by the paneconfigure subcommand
Option may be any value allowed by the paneconfigure subcommand
"""
"""
return
self
.
tk
.
call
(
return
self
.
tk
.
call
(
(
self
.
_w
,
'panecget'
)
+
(
child
,
'-'
+
option
))
(
self
.
_w
,
'panecget'
)
+
(
child
,
'-'
+
option
))
def
paneconfigure
(
self
,
tagOrId
,
cnf
=
None
,
**
kw
):
def
paneconfigure
(
self
,
tagOrId
,
cnf
=
None
,
**
kw
):
"""Query or modify the management options for window.
"""Query or modify the management options for window.
If no option is specified, returns a list describing all
If no option is specified, returns a list describing all
of the available options for pathName. If option is
of the available options for pathName. If option is
specified with no value, then the command returns a list
specified with no value, then the command returns a list
describing the one named option (this list will be identical
describing the one named option (this list will be identical
to the corresponding sublist of the value returned if no
to the corresponding sublist of the value returned if no
option is specified). If one or more option-value pairs are
option is specified). If one or more option-value pairs are
specified, then the command modifies the given widget
specified, then the command modifies the given widget
option(s) to have the given value(s); in this case the
option(s) to have the given value(s); in this case the
command returns an empty string. The following options
command returns an empty string. The following options
are supported:
are supported:
after window
after window
Insert the window after the window specified. window
Insert the window after the window specified. window
should be the name of a window already managed by pathName.
should be the name of a window already managed by pathName.
before window
before window
Insert the window before the window specified. window
Insert the window before the window specified. window
should be the name of a window already managed by pathName.
should be the name of a window already managed by pathName.
height size
height size
Specify a height for the window. The height will be the
Specify a height for the window. The height will be the
outer dimension of the window including its border, if
outer dimension of the window including its border, if
any. If size is an empty string, or if -height is not
any. If size is an empty string, or if -height is not
specified, then the height requested internally by the
specified, then the height requested internally by the
window will be used initially; the height may later be
window will be used initially; the height may later be
adjusted by the movement of sashes in the panedwindow.
adjusted by the movement of sashes in the panedwindow.
Size may be any value accepted by Tk_GetPixels.
Size may be any value accepted by Tk_GetPixels.
minsize n
minsize n
Specifies that the size of the window cannot be made
Specifies that the size of the window cannot be made
less than n. This constraint only affects the size of
less than n. This constraint only affects the size of
the widget in the paned dimension -- the x dimension
the widget in the paned dimension -- the x dimension
for horizontal panedwindows, the y dimension for
for horizontal panedwindows, the y dimension for
vertical panedwindows. May be any value accepted by
vertical panedwindows. May be any value accepted by
Tk_GetPixels.
Tk_GetPixels.
padx n
padx n
Specifies a non-negative value indicating how much
Specifies a non-negative value indicating how much
extra space to leave on each side of the window in
extra space to leave on each side of the window in
the X-direction. The value may have any of the forms
the X-direction. The value may have any of the forms
accepted by Tk_GetPixels.
accepted by Tk_GetPixels.
pady n
pady n
Specifies a non-negative value indicating how much
Specifies a non-negative value indicating how much
extra space to leave on each side of the window in
extra space to leave on each side of the window in
the Y-direction. The value may have any of the forms
the Y-direction. The value may have any of the forms
accepted by Tk_GetPixels.
accepted by Tk_GetPixels.
sticky style
sticky style
If a window's pane is larger than the requested
If a window's pane is larger than the requested
dimensions of the window, this option may be used
dimensions of the window, this option may be used
to position (or stretch) the window within its pane.
to position (or stretch) the window within its pane.
Style is a string that contains zero or more of the
Style is a string that contains zero or more of the
characters n, s, e or w. The string can optionally
characters n, s, e or w. The string can optionally
contains spaces or commas, but they are ignored. Each
contains spaces or commas, but they are ignored. Each
letter refers to a side (north, south, east, or west)
letter refers to a side (north, south, east, or west)
that the window will "stick" to. If both n and s
that the window will "stick" to. If both n and s
(or e and w) are specified, the window will be
(or e and w) are specified, the window will be
stretched to fill the entire height (or width) of
stretched to fill the entire height (or width) of
its cavity.
its cavity.
width size
width size
Specify a width for the window. The width will be
Specify a width for the window. The width will be
the outer dimension of the window including its
the outer dimension of the window including its
border, if any. If size is an empty string, or
border, if any. If size is an empty string, or
if -width is not specified, then the width requested
if -width is not specified, then the width requested
internally by the window will be used initially; the
internally by the window will be used initially; the
width may later be adjusted by the movement of sashes
width may later be adjusted by the movement of sashes
in the panedwindow. Size may be any value accepted by
in the panedwindow. Size may be any value accepted by
Tk_GetPixels.
Tk_GetPixels.
"""
"""
if
cnf
is
None
and
not
kw
:
if
cnf
is
None
and
not
kw
:
cnf
=
{}
cnf
=
{}
...
...
Lib/lib-tk/tkColorChooser.py
View file @
ff41c48a
...
@@ -63,7 +63,7 @@ def askcolor(color = None, **options):
...
@@ -63,7 +63,7 @@ def askcolor(color = None, **options):
options
=
options
.
copy
()
options
=
options
.
copy
()
options
[
"initialcolor"
]
=
color
options
[
"initialcolor"
]
=
color
return
apply
(
Chooser
,
(),
options
).
show
()
return
Chooser
(
**
options
).
show
()
# --------------------------------------------------------------------
# --------------------------------------------------------------------
...
...
Lib/lib-tk/tkCommonDialog.py
View file @
ff41c48a
...
@@ -49,7 +49,7 @@ class Dialog:
...
@@ -49,7 +49,7 @@ class Dialog:
try
:
try
:
s
=
apply
(
w
.
tk
.
call
,
(
self
.
command
,)
+
w
.
_options
(
self
.
options
))
s
=
w
.
tk
.
call
(
self
.
command
,
*
w
.
_options
(
self
.
options
))
s
=
self
.
_fixresult
(
w
,
s
)
s
=
self
.
_fixresult
(
w
,
s
)
...
...
Lib/lib-tk/tkFont.py
View file @
ff41c48a
...
@@ -73,7 +73,7 @@ class Font:
...
@@ -73,7 +73,7 @@ class Font:
if
not
name
:
if
not
name
:
name
=
"font"
+
str
(
id
(
self
))
name
=
"font"
+
str
(
id
(
self
))
self
.
name
=
name
self
.
name
=
name
apply
(
root
.
tk
.
call
,
(
"font"
,
"create"
,
name
)
+
font
)
root
.
tk
.
call
(
"font"
,
"create"
,
name
,
*
font
)
# backlinks!
# backlinks!
self
.
_root
=
root
self
.
_root
=
root
self
.
_split
=
root
.
tk
.
splitlist
self
.
_split
=
root
.
tk
.
splitlist
...
@@ -90,7 +90,7 @@ class Font:
...
@@ -90,7 +90,7 @@ class Font:
def
copy
(
self
):
def
copy
(
self
):
"Return a distinct copy of the current font"
"Return a distinct copy of the current font"
return
apply
(
Font
,
(
self
.
_root
,),
self
.
actual
())
return
Font
(
self
.
_root
,
**
self
.
actual
())
def
actual
(
self
,
option
=
None
):
def
actual
(
self
,
option
=
None
):
"Return actual font attributes"
"Return actual font attributes"
...
@@ -108,8 +108,8 @@ class Font:
...
@@ -108,8 +108,8 @@ class Font:
def
config
(
self
,
**
options
):
def
config
(
self
,
**
options
):
"Modify font attributes"
"Modify font attributes"
if
options
:
if
options
:
apply
(
self
.
_call
,
(
"font"
,
"config"
,
self
.
name
)
+
self
.
_call
(
"font"
,
"config"
,
self
.
name
,
self
.
_set
(
options
))
*
self
.
_set
(
options
))
else
:
else
:
return
self
.
_mkdict
(
return
self
.
_mkdict
(
self
.
_split
(
self
.
_call
(
"font"
,
"config"
,
self
.
name
))
self
.
_split
(
self
.
_call
(
"font"
,
"config"
,
self
.
name
))
...
...
Lib/lib-tk/tkMessageBox.py
View file @
ff41c48a
...
@@ -72,37 +72,37 @@ def _show(title=None, message=None, icon=None, type=None, **options):
...
@@ -72,37 +72,37 @@ def _show(title=None, message=None, icon=None, type=None, **options):
if
type
:
options
[
"type"
]
=
type
if
type
:
options
[
"type"
]
=
type
if
title
:
options
[
"title"
]
=
title
if
title
:
options
[
"title"
]
=
title
if
message
:
options
[
"message"
]
=
message
if
message
:
options
[
"message"
]
=
message
return
apply
(
Message
,
(),
options
).
show
()
return
Message
(
**
options
).
show
()
def
showinfo
(
title
=
None
,
message
=
None
,
**
options
):
def
showinfo
(
title
=
None
,
message
=
None
,
**
options
):
"Show an info message"
"Show an info message"
return
apply
(
_show
,
(
title
,
message
,
INFO
,
OK
),
options
)
return
_show
(
title
,
message
,
INFO
,
OK
,
**
options
)
def
showwarning
(
title
=
None
,
message
=
None
,
**
options
):
def
showwarning
(
title
=
None
,
message
=
None
,
**
options
):
"Show a warning message"
"Show a warning message"
return
apply
(
_show
,
(
title
,
message
,
WARNING
,
OK
),
options
)
return
_show
(
title
,
message
,
WARNING
,
OK
,
**
options
)
def
showerror
(
title
=
None
,
message
=
None
,
**
options
):
def
showerror
(
title
=
None
,
message
=
None
,
**
options
):
"Show an error message"
"Show an error message"
return
apply
(
_show
,
(
title
,
message
,
ERROR
,
OK
),
options
)
return
_show
(
title
,
message
,
ERROR
,
OK
,
**
options
)
def
askquestion
(
title
=
None
,
message
=
None
,
**
options
):
def
askquestion
(
title
=
None
,
message
=
None
,
**
options
):
"Ask a question"
"Ask a question"
return
apply
(
_show
,
(
title
,
message
,
QUESTION
,
YESNO
),
options
)
return
_show
(
title
,
message
,
QUESTION
,
YESNO
,
**
options
)
def
askokcancel
(
title
=
None
,
message
=
None
,
**
options
):
def
askokcancel
(
title
=
None
,
message
=
None
,
**
options
):
"Ask if operation should proceed; return true if the answer is ok"
"Ask if operation should proceed; return true if the answer is ok"
s
=
apply
(
_show
,
(
title
,
message
,
QUESTION
,
OKCANCEL
),
options
)
s
=
_show
(
title
,
message
,
QUESTION
,
OKCANCEL
,
**
options
)
return
s
==
OK
return
s
==
OK
def
askyesno
(
title
=
None
,
message
=
None
,
**
options
):
def
askyesno
(
title
=
None
,
message
=
None
,
**
options
):
"Ask a question; return true if the answer is yes"
"Ask a question; return true if the answer is yes"
s
=
apply
(
_show
,
(
title
,
message
,
QUESTION
,
YESNO
),
options
)
s
=
_show
(
title
,
message
,
QUESTION
,
YESNO
,
**
options
)
return
s
==
YES
return
s
==
YES
def
askretrycancel
(
title
=
None
,
message
=
None
,
**
options
):
def
askretrycancel
(
title
=
None
,
message
=
None
,
**
options
):
"Ask if operation should be retried; return true if the answer is yes"
"Ask if operation should be retried; return true if the answer is yes"
s
=
apply
(
_show
,
(
title
,
message
,
WARNING
,
RETRYCANCEL
),
options
)
s
=
_show
(
title
,
message
,
WARNING
,
RETRYCANCEL
,
**
options
)
return
s
==
RETRY
return
s
==
RETRY
...
...
Lib/lib-tk/tkSimpleDialog.py
View file @
ff41c48a
...
@@ -249,7 +249,7 @@ def askinteger(title, prompt, **kw):
...
@@ -249,7 +249,7 @@ def askinteger(title, prompt, **kw):
Return value is an integer
Return value is an integer
'''
'''
d
=
apply
(
_QueryInteger
,
(
title
,
prompt
),
kw
)
d
=
_QueryInteger
(
title
,
prompt
,
**
kw
)
return
d
.
result
return
d
.
result
class
_QueryFloat
(
_QueryDialog
):
class
_QueryFloat
(
_QueryDialog
):
...
@@ -268,7 +268,7 @@ def askfloat(title, prompt, **kw):
...
@@ -268,7 +268,7 @@ def askfloat(title, prompt, **kw):
Return value is a float
Return value is a float
'''
'''
d
=
apply
(
_QueryFloat
,
(
title
,
prompt
),
kw
)
d
=
_QueryFloat
(
title
,
prompt
,
**
kw
)
return
d
.
result
return
d
.
result
class
_QueryString
(
_QueryDialog
):
class
_QueryString
(
_QueryDialog
):
...
@@ -300,7 +300,7 @@ def askstring(title, prompt, **kw):
...
@@ -300,7 +300,7 @@ def askstring(title, prompt, **kw):
Return value is a string
Return value is a string
'''
'''
d
=
apply
(
_QueryString
,
(
title
,
prompt
),
kw
)
d
=
_QueryString
(
title
,
prompt
,
**
kw
)
return
d
.
result
return
d
.
result
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
...
...
Lib/lib-tk/turtle.py
View file @
ff41c48a
...
@@ -354,11 +354,11 @@ def right(angle): _getpen().right(angle)
...
@@ -354,11 +354,11 @@ def right(angle): _getpen().right(angle)
def
up
():
_getpen
().
up
()
def
up
():
_getpen
().
up
()
def
down
():
_getpen
().
down
()
def
down
():
_getpen
().
down
()
def
width
(
width
):
_getpen
().
width
(
width
)
def
width
(
width
):
_getpen
().
width
(
width
)
def
color
(
*
args
):
apply
(
_getpen
().
color
,
args
)
def
color
(
*
args
):
_getpen
().
color
(
*
args
)
def
write
(
arg
,
move
=
0
):
_getpen
().
write
(
arg
,
move
)
def
write
(
arg
,
move
=
0
):
_getpen
().
write
(
arg
,
move
)
def
fill
(
flag
):
_getpen
().
fill
(
flag
)
def
fill
(
flag
):
_getpen
().
fill
(
flag
)
def
circle
(
radius
,
extent
=
None
):
_getpen
().
circle
(
radius
,
extent
)
def
circle
(
radius
,
extent
=
None
):
_getpen
().
circle
(
radius
,
extent
)
def
goto
(
*
args
):
apply
(
_getpen
().
goto
,
args
)
def
goto
(
*
args
):
_getpen
().
goto
(
*
args
)
def
heading
():
return
_getpen
().
heading
()
def
heading
():
return
_getpen
().
heading
()
def
setheading
(
angle
):
_getpen
().
setheading
(
angle
)
def
setheading
(
angle
):
_getpen
().
setheading
(
angle
)
def
position
():
return
_getpen
().
position
()
def
position
():
return
_getpen
().
position
()
...
...
Lib/plat-mac/Carbon/MediaDescr.py
View file @
ff41c48a
...
@@ -4,94 +4,94 @@ import struct
...
@@ -4,94 +4,94 @@ import struct
Error
=
'MediaDescr.Error'
Error
=
'MediaDescr.Error'
class
_MediaDescriptionCodec
:
class
_MediaDescriptionCodec
:
def
__init__
(
self
,
trunc
,
size
,
names
,
fmt
):
def
__init__
(
self
,
trunc
,
size
,
names
,
fmt
):
self
.
trunc
=
trunc
self
.
trunc
=
trunc
self
.
size
=
size
self
.
size
=
size
self
.
names
=
names
self
.
names
=
names
self
.
fmt
=
fmt
self
.
fmt
=
fmt
def
decode
(
self
,
data
):
def
decode
(
self
,
data
):
if
self
.
trunc
:
if
self
.
trunc
:
data
=
data
[:
self
.
size
]
data
=
data
[:
self
.
size
]
values
=
struct
.
unpack
(
self
.
fmt
,
data
)
values
=
struct
.
unpack
(
self
.
fmt
,
data
)
if
len
(
values
)
!=
len
(
self
.
names
):
if
len
(
values
)
!=
len
(
self
.
names
):
raise
Error
,
(
'Format length does not match number of names'
,
descr
)
raise
Error
,
(
'Format length does not match number of names'
,
descr
)
rv
=
{}
rv
=
{}
for
i
in
range
(
len
(
values
)):
for
i
in
range
(
len
(
values
)):
name
=
self
.
names
[
i
]
name
=
self
.
names
[
i
]
value
=
values
[
i
]
value
=
values
[
i
]
if
type
(
name
)
==
type
(()):
if
type
(
name
)
==
type
(()):
name
,
cod
,
dec
=
name
name
,
cod
,
dec
=
name
value
=
dec
(
value
)
value
=
dec
(
value
)
rv
[
name
]
=
value
rv
[
name
]
=
value
return
rv
return
rv
def
encode
(
dict
):
def
encode
(
dict
):
list
=
[
self
.
fmt
]
list
=
[
self
.
fmt
]
for
name
in
self
.
names
:
for
name
in
self
.
names
:
if
type
(
name
)
==
type
(()):
if
type
(
name
)
==
type
(()):
name
,
cod
,
dec
=
name
name
,
cod
,
dec
=
name
else
:
else
:
cod
=
dec
=
None
cod
=
dec
=
None
value
=
dict
[
name
]
value
=
dict
[
name
]
if
cod
:
if
cod
:
value
=
cod
(
value
)
value
=
cod
(
value
)
list
.
append
(
value
)
list
.
append
(
value
)
rv
=
apply
(
struct
.
pack
,
tuple
(
list
)
)
rv
=
struct
.
pack
(
*
list
)
return
rv
return
rv
# Helper functions
# Helper functions
def
_tofixed
(
float
):
def
_tofixed
(
float
):
hi
=
int
(
float
)
hi
=
int
(
float
)
lo
=
int
(
float
*
0x10000
)
&
0xffff
lo
=
int
(
float
*
0x10000
)
&
0xffff
return
(
hi
<<
16
)
|
lo
return
(
hi
<<
16
)
|
lo
def
_fromfixed
(
fixed
):
def
_fromfixed
(
fixed
):
hi
=
(
fixed
>>
16
)
&
0xffff
hi
=
(
fixed
>>
16
)
&
0xffff
lo
=
(
fixed
&
0xffff
)
lo
=
(
fixed
&
0xffff
)
return
hi
+
(
lo
/
float
(
0x10000
))
return
hi
+
(
lo
/
float
(
0x10000
))
def
_tostr31
(
str
):
def
_tostr31
(
str
):
return
chr
(
len
(
str
))
+
str
+
'
\
0
'
*
(
31
-
len
(
str
))
return
chr
(
len
(
str
))
+
str
+
'
\
0
'
*
(
31
-
len
(
str
))
def
_fromstr31
(
str31
):
def
_fromstr31
(
str31
):
return
str31
[
1
:
1
+
ord
(
str31
[
0
])]
return
str31
[
1
:
1
+
ord
(
str31
[
0
])]
SampleDescription
=
_MediaDescriptionCodec
(
SampleDescription
=
_MediaDescriptionCodec
(
1
,
# May be longer, truncate
1
,
# May be longer, truncate
16
,
# size
16
,
# size
(
'descSize'
,
'dataFormat'
,
'resvd1'
,
'resvd2'
,
'dataRefIndex'
),
# Attributes
(
'descSize'
,
'dataFormat'
,
'resvd1'
,
'resvd2'
,
'dataRefIndex'
),
# Attributes
"l4slhh"
# Format
"l4slhh"
# Format
)
)
SoundDescription
=
_MediaDescriptionCodec
(
SoundDescription
=
_MediaDescriptionCodec
(
1
,
1
,
36
,
36
,
(
'descSize'
,
'dataFormat'
,
'resvd1'
,
'resvd2'
,
'dataRefIndex'
,
(
'descSize'
,
'dataFormat'
,
'resvd1'
,
'resvd2'
,
'dataRefIndex'
,
'version'
,
'revlevel'
,
'vendor'
,
'numChannels'
,
'sampleSize'
,
'version'
,
'revlevel'
,
'vendor'
,
'numChannels'
,
'sampleSize'
,
'compressionID'
,
'packetSize'
,
(
'sampleRate'
,
_tofixed
,
_fromfixed
)),
'compressionID'
,
'packetSize'
,
(
'sampleRate'
,
_tofixed
,
_fromfixed
)),
"l4slhhhh4shhhhl"
# Format
"l4slhhhh4shhhhl"
# Format
)
)
SoundDescriptionV1
=
_MediaDescriptionCodec
(
SoundDescriptionV1
=
_MediaDescriptionCodec
(
1
,
1
,
52
,
52
,
(
'descSize'
,
'dataFormat'
,
'resvd1'
,
'resvd2'
,
'dataRefIndex'
,
(
'descSize'
,
'dataFormat'
,
'resvd1'
,
'resvd2'
,
'dataRefIndex'
,
'version'
,
'revlevel'
,
'vendor'
,
'numChannels'
,
'sampleSize'
,
'version'
,
'revlevel'
,
'vendor'
,
'numChannels'
,
'sampleSize'
,
'compressionID'
,
'packetSize'
,
(
'sampleRate'
,
_tofixed
,
_fromfixed
),
'samplesPerPacket'
,
'compressionID'
,
'packetSize'
,
(
'sampleRate'
,
_tofixed
,
_fromfixed
),
'samplesPerPacket'
,
'bytesPerPacket'
,
'bytesPerFrame'
,
'bytesPerSample'
),
'bytesPerPacket'
,
'bytesPerFrame'
,
'bytesPerSample'
),
"l4slhhhh4shhhhlllll"
# Format
"l4slhhhh4shhhhlllll"
# Format
)
)
ImageDescription
=
_MediaDescriptionCodec
(
ImageDescription
=
_MediaDescriptionCodec
(
1
,
# May be longer, truncate
1
,
# May be longer, truncate
86
,
# size
86
,
# size
(
'idSize'
,
'cType'
,
'resvd1'
,
'resvd2'
,
'dataRefIndex'
,
'version'
,
(
'idSize'
,
'cType'
,
'resvd1'
,
'resvd2'
,
'dataRefIndex'
,
'version'
,
'revisionLevel'
,
'vendor'
,
'temporalQuality'
,
'spatialQuality'
,
'revisionLevel'
,
'vendor'
,
'temporalQuality'
,
'spatialQuality'
,
'width'
,
'height'
,
(
'hRes'
,
_tofixed
,
_fromfixed
),
(
'vRes'
,
_tofixed
,
_fromfixed
),
'width'
,
'height'
,
(
'hRes'
,
_tofixed
,
_fromfixed
),
(
'vRes'
,
_tofixed
,
_fromfixed
),
'dataSize'
,
'frameCount'
,
(
'name'
,
_tostr31
,
_fromstr31
),
'dataSize'
,
'frameCount'
,
(
'name'
,
_tostr31
,
_fromstr31
),
'depth'
,
'clutID'
),
'depth'
,
'clutID'
),
'l4slhhhh4sllhhlllh32shh'
,
'l4slhhhh4sllhhlllh32shh'
,
)
)
# XXXX Others, like TextDescription and such, remain to be done.
# XXXX Others, like TextDescription and such, remain to be done.
Lib/plat-mac/EasyDialogs.py
View file @
ff41c48a
...
@@ -5,13 +5,13 @@ AskString(prompt, default) -- ask for a string, display OK and Cancel buttons.
...
@@ -5,13 +5,13 @@ AskString(prompt, default) -- ask for a string, display OK and Cancel buttons.
AskPassword(prompt, default) -- like AskString(), but shows text as bullets.
AskPassword(prompt, default) -- like AskString(), but shows text as bullets.
AskYesNoCancel(question, default) -- display a question and Yes, No and Cancel buttons.
AskYesNoCancel(question, default) -- display a question and Yes, No and Cancel buttons.
GetArgv(optionlist, commandlist) -- fill a sys.argv-like list using a dialog
GetArgv(optionlist, commandlist) -- fill a sys.argv-like list using a dialog
AskFileForOpen(...) -- Ask the user for an existing file
AskFileForOpen(...) -- Ask the user for an existing file
AskFileForSave(...) -- Ask the user for an output file
AskFileForSave(...) -- Ask the user for an output file
AskFolder(...) -- Ask the user to select a folder
AskFolder(...) -- Ask the user to select a folder
bar = Progress(label, maxvalue) -- Display a progress bar
bar = Progress(label, maxvalue) -- Display a progress bar
bar.set(value) -- Set value
bar.set(value) -- Set value
bar.inc( *amount ) -- increment value by amount (default=1)
bar.inc( *amount ) -- increment value by amount (default=1)
bar.label( *newlabel ) -- get or set text label.
bar.label( *newlabel ) -- get or set text label.
More documentation in each function.
More documentation in each function.
This module uses DLOG resources 260 and on.
This module uses DLOG resources 260 and on.
...
@@ -31,309 +31,309 @@ from Carbon import AE
...
@@ -31,309 +31,309 @@ from Carbon import AE
import
Nav
import
Nav
import
MacOS
import
MacOS
import
string
import
string
from
Carbon.ControlAccessor
import
*
# Also import Controls constants
from
Carbon.ControlAccessor
import
*
# Also import Controls constants
import
Carbon.File
import
Carbon.File
import
macresource
import
macresource
import
os
import
os
import
sys
import
sys
__all__
=
[
'Message'
,
'AskString'
,
'AskPassword'
,
'AskYesNoCancel'
,
__all__
=
[
'Message'
,
'AskString'
,
'AskPassword'
,
'AskYesNoCancel'
,
'GetArgv'
,
'AskFileForOpen'
,
'AskFileForSave'
,
'AskFolder'
,
'GetArgv'
,
'AskFileForOpen'
,
'AskFileForSave'
,
'AskFolder'
,
'Progress'
]
'Progress'
]
_initialized
=
0
_initialized
=
0
def
_initialize
():
def
_initialize
():
global
_initialized
global
_initialized
if
_initialized
:
return
if
_initialized
:
return
macresource
.
need
(
"DLOG"
,
260
,
"dialogs.rsrc"
,
__name__
)
macresource
.
need
(
"DLOG"
,
260
,
"dialogs.rsrc"
,
__name__
)
def
_interact
():
def
_interact
():
"""Make sure the application is in the foreground"""
"""Make sure the application is in the foreground"""
AE
.
AEInteractWithUser
(
50000000
)
AE
.
AEInteractWithUser
(
50000000
)
def
cr2lf
(
text
):
def
cr2lf
(
text
):
if
'
\
r
'
in
text
:
if
'
\
r
'
in
text
:
text
=
string
.
join
(
string
.
split
(
text
,
'
\
r
'
),
'
\
n
'
)
text
=
string
.
join
(
string
.
split
(
text
,
'
\
r
'
),
'
\
n
'
)
return
text
return
text
def
lf2cr
(
text
):
def
lf2cr
(
text
):
if
'
\
n
'
in
text
:
if
'
\
n
'
in
text
:
text
=
string
.
join
(
string
.
split
(
text
,
'
\
n
'
),
'
\
r
'
)
text
=
string
.
join
(
string
.
split
(
text
,
'
\
n
'
),
'
\
r
'
)
if
len
(
text
)
>
253
:
if
len
(
text
)
>
253
:
text
=
text
[:
253
]
+
'
\
311
'
text
=
text
[:
253
]
+
'
\
311
'
return
text
return
text
def
Message
(
msg
,
id
=
260
,
ok
=
None
):
def
Message
(
msg
,
id
=
260
,
ok
=
None
):
"""Display a MESSAGE string.
"""Display a MESSAGE string.
Return when the user clicks the OK button or presses Return.
Return when the user clicks the OK button or presses Return.
The MESSAGE string can be at most 255 characters long.
The MESSAGE string can be at most 255 characters long.
"""
"""
_initialize
()
_initialize
()
_interact
()
_interact
()
d
=
GetNewDialog
(
id
,
-
1
)
d
=
GetNewDialog
(
id
,
-
1
)
if
not
d
:
if
not
d
:
print
"EasyDialogs: Can't get DLOG resource with id ="
,
id
,
" (missing resource file?)"
print
"EasyDialogs: Can't get DLOG resource with id ="
,
id
,
" (missing resource file?)"
return
return
h
=
d
.
GetDialogItemAsControl
(
2
)
h
=
d
.
GetDialogItemAsControl
(
2
)
SetDialogItemText
(
h
,
lf2cr
(
msg
))
SetDialogItemText
(
h
,
lf2cr
(
msg
))
if
ok
!=
None
:
if
ok
!=
None
:
h
=
d
.
GetDialogItemAsControl
(
1
)
h
=
d
.
GetDialogItemAsControl
(
1
)
h
.
SetControlTitle
(
ok
)
h
.
SetControlTitle
(
ok
)
d
.
SetDialogDefaultItem
(
1
)
d
.
SetDialogDefaultItem
(
1
)
d
.
AutoSizeDialog
()
d
.
AutoSizeDialog
()
d
.
GetDialogWindow
().
ShowWindow
()
d
.
GetDialogWindow
().
ShowWindow
()
while
1
:
while
1
:
n
=
ModalDialog
(
None
)
n
=
ModalDialog
(
None
)
if
n
==
1
:
if
n
==
1
:
return
return
def
AskString
(
prompt
,
default
=
""
,
id
=
261
,
ok
=
None
,
cancel
=
None
):
def
AskString
(
prompt
,
default
=
""
,
id
=
261
,
ok
=
None
,
cancel
=
None
):
"""Display a PROMPT string and a text entry field with a DEFAULT string.
"""Display a PROMPT string and a text entry field with a DEFAULT string.
Return the contents of the text entry field when the user clicks the
Return the contents of the text entry field when the user clicks the
OK button or presses Return.
OK button or presses Return.
Return None when the user clicks the Cancel button.
Return None when the user clicks the Cancel button.
If omitted, DEFAULT is empty.
If omitted, DEFAULT is empty.
The PROMPT and DEFAULT strings, as well as the return value,
The PROMPT and DEFAULT strings, as well as the return value,
can be at most 255 characters long.
can be at most 255 characters long.
"""
"""
_initialize
()
_initialize
()
_interact
()
_interact
()
d
=
GetNewDialog
(
id
,
-
1
)
d
=
GetNewDialog
(
id
,
-
1
)
if
not
d
:
if
not
d
:
print
"EasyDialogs: Can't get DLOG resource with id ="
,
id
,
" (missing resource file?)"
print
"EasyDialogs: Can't get DLOG resource with id ="
,
id
,
" (missing resource file?)"
return
return
h
=
d
.
GetDialogItemAsControl
(
3
)
h
=
d
.
GetDialogItemAsControl
(
3
)
SetDialogItemText
(
h
,
lf2cr
(
prompt
))
SetDialogItemText
(
h
,
lf2cr
(
prompt
))
h
=
d
.
GetDialogItemAsControl
(
4
)
h
=
d
.
GetDialogItemAsControl
(
4
)
SetDialogItemText
(
h
,
lf2cr
(
default
))
SetDialogItemText
(
h
,
lf2cr
(
default
))
d
.
SelectDialogItemText
(
4
,
0
,
999
)
d
.
SelectDialogItemText
(
4
,
0
,
999
)
#
d.SetDialogItem(4, 0, 255)
#
d.SetDialogItem(4, 0, 255)
if
ok
!=
None
:
if
ok
!=
None
:
h
=
d
.
GetDialogItemAsControl
(
1
)
h
=
d
.
GetDialogItemAsControl
(
1
)
h
.
SetControlTitle
(
ok
)
h
.
SetControlTitle
(
ok
)
if
cancel
!=
None
:
if
cancel
!=
None
:
h
=
d
.
GetDialogItemAsControl
(
2
)
h
=
d
.
GetDialogItemAsControl
(
2
)
h
.
SetControlTitle
(
cancel
)
h
.
SetControlTitle
(
cancel
)
d
.
SetDialogDefaultItem
(
1
)
d
.
SetDialogDefaultItem
(
1
)
d
.
SetDialogCancelItem
(
2
)
d
.
SetDialogCancelItem
(
2
)
d
.
AutoSizeDialog
()
d
.
AutoSizeDialog
()
d
.
GetDialogWindow
().
ShowWindow
()
d
.
GetDialogWindow
().
ShowWindow
()
while
1
:
while
1
:
n
=
ModalDialog
(
None
)
n
=
ModalDialog
(
None
)
if
n
==
1
:
if
n
==
1
:
h
=
d
.
GetDialogItemAsControl
(
4
)
h
=
d
.
GetDialogItemAsControl
(
4
)
return
cr2lf
(
GetDialogItemText
(
h
))
return
cr2lf
(
GetDialogItemText
(
h
))
if
n
==
2
:
return
None
if
n
==
2
:
return
None
def
AskPassword
(
prompt
,
default
=
''
,
id
=
264
,
ok
=
None
,
cancel
=
None
):
def
AskPassword
(
prompt
,
default
=
''
,
id
=
264
,
ok
=
None
,
cancel
=
None
):
"""Display a PROMPT string and a text entry field with a DEFAULT string.
"""Display a PROMPT string and a text entry field with a DEFAULT string.
The string is displayed as bullets only.
The string is displayed as bullets only.
Return the contents of the text entry field when the user clicks the
Return the contents of the text entry field when the user clicks the
OK button or presses Return.
OK button or presses Return.
Return None when the user clicks the Cancel button.
Return None when the user clicks the Cancel button.
If omitted, DEFAULT is empty.
If omitted, DEFAULT is empty.
The PROMPT and DEFAULT strings, as well as the return value,
The PROMPT and DEFAULT strings, as well as the return value,
can be at most 255 characters long.
can be at most 255 characters long.
"""
"""
_initialize
()
_initialize
()
_interact
()
_interact
()
d
=
GetNewDialog
(
id
,
-
1
)
d
=
GetNewDialog
(
id
,
-
1
)
if
not
d
:
if
not
d
:
print
"EasyDialogs: Can't get DLOG resource with id ="
,
id
,
" (missing resource file?)"
print
"EasyDialogs: Can't get DLOG resource with id ="
,
id
,
" (missing resource file?)"
return
return
h
=
d
.
GetDialogItemAsControl
(
3
)
h
=
d
.
GetDialogItemAsControl
(
3
)
SetDialogItemText
(
h
,
lf2cr
(
prompt
))
SetDialogItemText
(
h
,
lf2cr
(
prompt
))
pwd
=
d
.
GetDialogItemAsControl
(
4
)
pwd
=
d
.
GetDialogItemAsControl
(
4
)
bullets
=
'
\
245
'
*
len
(
default
)
bullets
=
'
\
245
'
*
len
(
default
)
##
SetControlData(pwd, kControlEditTextPart, kControlEditTextTextTag, bullets)
##
SetControlData(pwd, kControlEditTextPart, kControlEditTextTextTag, bullets)
SetControlData
(
pwd
,
kControlEditTextPart
,
kControlEditTextPasswordTag
,
default
)
SetControlData
(
pwd
,
kControlEditTextPart
,
kControlEditTextPasswordTag
,
default
)
d
.
SelectDialogItemText
(
4
,
0
,
999
)
d
.
SelectDialogItemText
(
4
,
0
,
999
)
Ctl
.
SetKeyboardFocus
(
d
.
GetDialogWindow
(),
pwd
,
kControlEditTextPart
)
Ctl
.
SetKeyboardFocus
(
d
.
GetDialogWindow
(),
pwd
,
kControlEditTextPart
)
if
ok
!=
None
:
if
ok
!=
None
:
h
=
d
.
GetDialogItemAsControl
(
1
)
h
=
d
.
GetDialogItemAsControl
(
1
)
h
.
SetControlTitle
(
ok
)
h
.
SetControlTitle
(
ok
)
if
cancel
!=
None
:
if
cancel
!=
None
:
h
=
d
.
GetDialogItemAsControl
(
2
)
h
=
d
.
GetDialogItemAsControl
(
2
)
h
.
SetControlTitle
(
cancel
)
h
.
SetControlTitle
(
cancel
)
d
.
SetDialogDefaultItem
(
Dialogs
.
ok
)
d
.
SetDialogDefaultItem
(
Dialogs
.
ok
)
d
.
SetDialogCancelItem
(
Dialogs
.
cancel
)
d
.
SetDialogCancelItem
(
Dialogs
.
cancel
)
d
.
AutoSizeDialog
()
d
.
AutoSizeDialog
()
d
.
GetDialogWindow
().
ShowWindow
()
d
.
GetDialogWindow
().
ShowWindow
()
while
1
:
while
1
:
n
=
ModalDialog
(
None
)
n
=
ModalDialog
(
None
)
if
n
==
1
:
if
n
==
1
:
h
=
d
.
GetDialogItemAsControl
(
4
)
h
=
d
.
GetDialogItemAsControl
(
4
)
return
cr2lf
(
GetControlData
(
pwd
,
kControlEditTextPart
,
kControlEditTextPasswordTag
))
return
cr2lf
(
GetControlData
(
pwd
,
kControlEditTextPart
,
kControlEditTextPasswordTag
))
if
n
==
2
:
return
None
if
n
==
2
:
return
None
def
AskYesNoCancel
(
question
,
default
=
0
,
yes
=
None
,
no
=
None
,
cancel
=
None
,
id
=
262
):
def
AskYesNoCancel
(
question
,
default
=
0
,
yes
=
None
,
no
=
None
,
cancel
=
None
,
id
=
262
):
"""Display a QUESTION string which can be answered with Yes or No.
"""Display a QUESTION string which can be answered with Yes or No.
Return 1 when the user clicks the Yes button.
Return 1 when the user clicks the Yes button.
Return 0 when the user clicks the No button.
Return 0 when the user clicks the No button.
Return -1 when the user clicks the Cancel button.
Return -1 when the user clicks the Cancel button.
When the user presses Return, the DEFAULT value is returned.
When the user presses Return, the DEFAULT value is returned.
If omitted, this is 0 (No).
If omitted, this is 0 (No).
The QUESTION string can be at most 255 characters.
The QUESTION string can be at most 255 characters.
"""
"""
_initialize
()
_initialize
()
_interact
()
_interact
()
d
=
GetNewDialog
(
id
,
-
1
)
d
=
GetNewDialog
(
id
,
-
1
)
if
not
d
:
if
not
d
:
print
"EasyDialogs: Can't get DLOG resource with id ="
,
id
,
" (missing resource file?)"
print
"EasyDialogs: Can't get DLOG resource with id ="
,
id
,
" (missing resource file?)"
return
return
# Button assignments:
# Button assignments:
# 1 = default (invisible)
# 1 = default (invisible)
# 2 = Yes
# 2 = Yes
# 3 = No
# 3 = No
# 4 = Cancel
# 4 = Cancel
# The question string is item 5
# The question string is item 5
h
=
d
.
GetDialogItemAsControl
(
5
)
h
=
d
.
GetDialogItemAsControl
(
5
)
SetDialogItemText
(
h
,
lf2cr
(
question
))
SetDialogItemText
(
h
,
lf2cr
(
question
))
if
yes
!=
None
:
if
yes
!=
None
:
if
yes
==
''
:
if
yes
==
''
:
d
.
HideDialogItem
(
2
)
d
.
HideDialogItem
(
2
)
else
:
else
:
h
=
d
.
GetDialogItemAsControl
(
2
)
h
=
d
.
GetDialogItemAsControl
(
2
)
h
.
SetControlTitle
(
yes
)
h
.
SetControlTitle
(
yes
)
if
no
!=
None
:
if
no
!=
None
:
if
no
==
''
:
if
no
==
''
:
d
.
HideDialogItem
(
3
)
d
.
HideDialogItem
(
3
)
else
:
else
:
h
=
d
.
GetDialogItemAsControl
(
3
)
h
=
d
.
GetDialogItemAsControl
(
3
)
h
.
SetControlTitle
(
no
)
h
.
SetControlTitle
(
no
)
if
cancel
!=
None
:
if
cancel
!=
None
:
if
cancel
==
''
:
if
cancel
==
''
:
d
.
HideDialogItem
(
4
)
d
.
HideDialogItem
(
4
)
else
:
else
:
h
=
d
.
GetDialogItemAsControl
(
4
)
h
=
d
.
GetDialogItemAsControl
(
4
)
h
.
SetControlTitle
(
cancel
)
h
.
SetControlTitle
(
cancel
)
d
.
SetDialogCancelItem
(
4
)
d
.
SetDialogCancelItem
(
4
)
if
default
==
1
:
if
default
==
1
:
d
.
SetDialogDefaultItem
(
2
)
d
.
SetDialogDefaultItem
(
2
)
elif
default
==
0
:
elif
default
==
0
:
d
.
SetDialogDefaultItem
(
3
)
d
.
SetDialogDefaultItem
(
3
)
elif
default
==
-
1
:
elif
default
==
-
1
:
d
.
SetDialogDefaultItem
(
4
)
d
.
SetDialogDefaultItem
(
4
)
d
.
AutoSizeDialog
()
d
.
AutoSizeDialog
()
d
.
GetDialogWindow
().
ShowWindow
()
d
.
GetDialogWindow
().
ShowWindow
()
while
1
:
while
1
:
n
=
ModalDialog
(
None
)
n
=
ModalDialog
(
None
)
if
n
==
1
:
return
default
if
n
==
1
:
return
default
if
n
==
2
:
return
1
if
n
==
2
:
return
1
if
n
==
3
:
return
0
if
n
==
3
:
return
0
if
n
==
4
:
return
-
1
if
n
==
4
:
return
-
1
screenbounds
=
Qd
.
GetQDGlobalsScreenBits
().
bounds
screenbounds
=
Qd
.
GetQDGlobalsScreenBits
().
bounds
screenbounds
=
screenbounds
[
0
]
+
4
,
screenbounds
[
1
]
+
4
,
\
screenbounds
=
screenbounds
[
0
]
+
4
,
screenbounds
[
1
]
+
4
,
\
screenbounds
[
2
]
-
4
,
screenbounds
[
3
]
-
4
screenbounds
[
2
]
-
4
,
screenbounds
[
3
]
-
4
kControlProgressBarIndeterminateTag
=
'inde'
# from Controls.py
kControlProgressBarIndeterminateTag
=
'inde'
# from Controls.py
class
ProgressBar
:
class
ProgressBar
:
def
__init__
(
self
,
title
=
"Working..."
,
maxval
=
0
,
label
=
""
,
id
=
263
):
def
__init__
(
self
,
title
=
"Working..."
,
maxval
=
0
,
label
=
""
,
id
=
263
):
self
.
w
=
None
self
.
w
=
None
self
.
d
=
None
self
.
d
=
None
_initialize
()
_initialize
()
self
.
d
=
GetNewDialog
(
id
,
-
1
)
self
.
d
=
GetNewDialog
(
id
,
-
1
)
self
.
w
=
self
.
d
.
GetDialogWindow
()
self
.
w
=
self
.
d
.
GetDialogWindow
()
self
.
label
(
label
)
self
.
label
(
label
)
self
.
title
(
title
)
self
.
title
(
title
)
self
.
set
(
0
,
maxval
)
self
.
set
(
0
,
maxval
)
self
.
d
.
AutoSizeDialog
()
self
.
d
.
AutoSizeDialog
()
self
.
w
.
ShowWindow
()
self
.
w
.
ShowWindow
()
self
.
d
.
DrawDialog
()
self
.
d
.
DrawDialog
()
def
__del__
(
self
):
def
__del__
(
self
):
if
self
.
w
:
if
self
.
w
:
self
.
w
.
BringToFront
()
self
.
w
.
BringToFront
()
self
.
w
.
HideWindow
()
self
.
w
.
HideWindow
()
del
self
.
w
del
self
.
w
del
self
.
d
del
self
.
d
def
title
(
self
,
newstr
=
""
):
def
title
(
self
,
newstr
=
""
):
"""title(text) - Set title of progress window"""
"""title(text) - Set title of progress window"""
self
.
w
.
BringToFront
()
self
.
w
.
BringToFront
()
self
.
w
.
SetWTitle
(
newstr
)
self
.
w
.
SetWTitle
(
newstr
)
def
label
(
self
,
*
newstr
):
def
label
(
self
,
*
newstr
):
"""label(text) - Set text in progress box"""
"""label(text) - Set text in progress box"""
self
.
w
.
BringToFront
()
self
.
w
.
BringToFront
()
if
newstr
:
if
newstr
:
self
.
_label
=
lf2cr
(
newstr
[
0
])
self
.
_label
=
lf2cr
(
newstr
[
0
])
text_h
=
self
.
d
.
GetDialogItemAsControl
(
2
)
text_h
=
self
.
d
.
GetDialogItemAsControl
(
2
)
SetDialogItemText
(
text_h
,
self
.
_label
)
SetDialogItemText
(
text_h
,
self
.
_label
)
def
_update
(
self
,
value
):
def
_update
(
self
,
value
):
maxval
=
self
.
maxval
maxval
=
self
.
maxval
if
maxval
==
0
:
# an indeterminate bar
if
maxval
==
0
:
# an indeterminate bar
Ctl
.
IdleControls
(
self
.
w
)
# spin the barber pole
Ctl
.
IdleControls
(
self
.
w
)
# spin the barber pole
else
:
# a determinate bar
else
:
# a determinate bar
if
maxval
>
32767
:
if
maxval
>
32767
:
value
=
int
(
value
/
(
maxval
/
32767.0
))
value
=
int
(
value
/
(
maxval
/
32767.0
))
maxval
=
32767
maxval
=
32767
maxval
=
int
(
maxval
)
maxval
=
int
(
maxval
)
value
=
int
(
value
)
value
=
int
(
value
)
progbar
=
self
.
d
.
GetDialogItemAsControl
(
3
)
progbar
=
self
.
d
.
GetDialogItemAsControl
(
3
)
progbar
.
SetControlMaximum
(
maxval
)
progbar
.
SetControlMaximum
(
maxval
)
progbar
.
SetControlValue
(
value
)
# set the bar length
progbar
.
SetControlValue
(
value
)
# set the bar length
# Test for cancel button
# Test for cancel button
ready
,
ev
=
Evt
.
WaitNextEvent
(
Events
.
mDownMask
,
1
)
ready
,
ev
=
Evt
.
WaitNextEvent
(
Events
.
mDownMask
,
1
)
if
ready
:
if
ready
:
what
,
msg
,
when
,
where
,
mod
=
ev
what
,
msg
,
when
,
where
,
mod
=
ev
part
=
Win
.
FindWindow
(
where
)[
0
]
part
=
Win
.
FindWindow
(
where
)[
0
]
if
Dlg
.
IsDialogEvent
(
ev
):
if
Dlg
.
IsDialogEvent
(
ev
):
ds
=
Dlg
.
DialogSelect
(
ev
)
ds
=
Dlg
.
DialogSelect
(
ev
)
if
ds
[
0
]
and
ds
[
1
]
==
self
.
d
and
ds
[
-
1
]
==
1
:
if
ds
[
0
]
and
ds
[
1
]
==
self
.
d
and
ds
[
-
1
]
==
1
:
self
.
w
.
HideWindow
()
self
.
w
.
HideWindow
()
self
.
w
=
None
self
.
w
=
None
self
.
d
=
None
self
.
d
=
None
raise
KeyboardInterrupt
,
ev
raise
KeyboardInterrupt
,
ev
else
:
else
:
if
part
==
4
:
# inDrag
if
part
==
4
:
# inDrag
self
.
w
.
DragWindow
(
where
,
screenbounds
)
self
.
w
.
DragWindow
(
where
,
screenbounds
)
else
:
else
:
MacOS
.
HandleEvent
(
ev
)
MacOS
.
HandleEvent
(
ev
)
def
set
(
self
,
value
,
max
=
None
):
def
set
(
self
,
value
,
max
=
None
):
"""set(value) - Set progress bar position"""
"""set(value) - Set progress bar position"""
if
max
!=
None
:
if
max
!=
None
:
self
.
maxval
=
max
self
.
maxval
=
max
bar
=
self
.
d
.
GetDialogItemAsControl
(
3
)
bar
=
self
.
d
.
GetDialogItemAsControl
(
3
)
if
max
<=
0
:
# indeterminate bar
if
max
<=
0
:
# indeterminate bar
bar
.
SetControlData
(
0
,
kControlProgressBarIndeterminateTag
,
'
\
x01
'
)
bar
.
SetControlData
(
0
,
kControlProgressBarIndeterminateTag
,
'
\
x01
'
)
else
:
# determinate bar
else
:
# determinate bar
bar
.
SetControlData
(
0
,
kControlProgressBarIndeterminateTag
,
'
\
x00
'
)
bar
.
SetControlData
(
0
,
kControlProgressBarIndeterminateTag
,
'
\
x00
'
)
if
value
<
0
:
if
value
<
0
:
value
=
0
value
=
0
elif
value
>
self
.
maxval
:
elif
value
>
self
.
maxval
:
value
=
self
.
maxval
value
=
self
.
maxval
self
.
curval
=
value
self
.
curval
=
value
self
.
_update
(
value
)
self
.
_update
(
value
)
def
inc
(
self
,
n
=
1
):
def
inc
(
self
,
n
=
1
):
"""inc(amt) - Increment progress bar position"""
"""inc(amt) - Increment progress bar position"""
self
.
set
(
self
.
curval
+
n
)
self
.
set
(
self
.
curval
+
n
)
ARGV_ID
=
265
ARGV_ID
=
265
ARGV_ITEM_OK
=
1
ARGV_ITEM_OK
=
1
...
@@ -352,488 +352,488 @@ ARGV_CMDLINE_GROUP=13
...
@@ -352,488 +352,488 @@ ARGV_CMDLINE_GROUP=13
ARGV_CMDLINE_DATA
=
14
ARGV_CMDLINE_DATA
=
14
##def _myModalDialog(d):
##def _myModalDialog(d):
##
while 1:
##
while 1:
##
ready, ev = Evt.WaitNextEvent(0xffff, -1)
##
ready, ev = Evt.WaitNextEvent(0xffff, -1)
##
print 'DBG: WNE', ready, ev
##
print 'DBG: WNE', ready, ev
##
if ready :
##
if ready :
##
what,msg,when,where,mod = ev
##
what,msg,when,where,mod = ev
##
part, window = Win.FindWindow(where)
##
part, window = Win.FindWindow(where)
##
if Dlg.IsDialogEvent(ev):
##
if Dlg.IsDialogEvent(ev):
##
didit, dlgdone, itemdone = Dlg.DialogSelect(ev)
##
didit, dlgdone, itemdone = Dlg.DialogSelect(ev)
##
print 'DBG: DialogSelect', didit, dlgdone, itemdone, d
##
print 'DBG: DialogSelect', didit, dlgdone, itemdone, d
##
if didit and dlgdone == d:
##
if didit and dlgdone == d:
##
return itemdone
##
return itemdone
##
elif window == d.GetDialogWindow():
##
elif window == d.GetDialogWindow():
##
d.GetDialogWindow().SelectWindow()
##
d.GetDialogWindow().SelectWindow()
##
if part == 4: # inDrag
##
if part == 4: # inDrag
##
d.DragWindow(where, screenbounds)
##
d.DragWindow(where, screenbounds)
##
else:
##
else:
##
MacOS.HandleEvent(ev)
##
MacOS.HandleEvent(ev)
##
else:
##
else:
##
MacOS.HandleEvent(ev)
##
MacOS.HandleEvent(ev)
##
##
def
_setmenu
(
control
,
items
):
def
_setmenu
(
control
,
items
):
mhandle
=
control
.
GetControlData_Handle
(
Controls
.
kControlMenuPart
,
mhandle
=
control
.
GetControlData_Handle
(
Controls
.
kControlMenuPart
,
Controls
.
kControlPopupButtonMenuHandleTag
)
Controls
.
kControlPopupButtonMenuHandleTag
)
menu
=
Menu
.
as_Menu
(
mhandle
)
menu
=
Menu
.
as_Menu
(
mhandle
)
for
item
in
items
:
for
item
in
items
:
if
type
(
item
)
==
type
(()):
if
type
(
item
)
==
type
(()):
label
=
item
[
0
]
label
=
item
[
0
]
else
:
else
:
label
=
item
label
=
item
if
label
[
-
1
]
==
'='
or
label
[
-
1
]
==
':'
:
if
label
[
-
1
]
==
'='
or
label
[
-
1
]
==
':'
:
label
=
label
[:
-
1
]
label
=
label
[:
-
1
]
menu
.
AppendMenu
(
label
)
menu
.
AppendMenu
(
label
)
##
mhandle, mid = menu.getpopupinfo()
##
mhandle, mid = menu.getpopupinfo()
##
control.SetControlData_Handle(Controls.kControlMenuPart,
##
control.SetControlData_Handle(Controls.kControlMenuPart,
##
Controls.kControlPopupButtonMenuHandleTag, mhandle)
##
Controls.kControlPopupButtonMenuHandleTag, mhandle)
control
.
SetControlMinimum
(
1
)
control
.
SetControlMinimum
(
1
)
control
.
SetControlMaximum
(
len
(
items
)
+
1
)
control
.
SetControlMaximum
(
len
(
items
)
+
1
)
def
_selectoption
(
d
,
optionlist
,
idx
):
def
_selectoption
(
d
,
optionlist
,
idx
):
if
idx
<
0
or
idx
>=
len
(
optionlist
):
if
idx
<
0
or
idx
>=
len
(
optionlist
):
MacOS
.
SysBeep
()
MacOS
.
SysBeep
()
return
return
option
=
optionlist
[
idx
]
option
=
optionlist
[
idx
]
if
type
(
option
)
==
type
(()):
if
type
(
option
)
==
type
(()):
if
len
(
option
)
==
4
:
if
len
(
option
)
==
4
:
help
=
option
[
2
]
help
=
option
[
2
]
elif
len
(
option
)
>
1
:
elif
len
(
option
)
>
1
:
help
=
option
[
-
1
]
help
=
option
[
-
1
]
else
:
else
:
help
=
''
help
=
''
else
:
else
:
help
=
''
help
=
''
h
=
d
.
GetDialogItemAsControl
(
ARGV_OPTION_EXPLAIN
)
h
=
d
.
GetDialogItemAsControl
(
ARGV_OPTION_EXPLAIN
)
if
help
and
len
(
help
)
>
250
:
if
help
and
len
(
help
)
>
250
:
help
=
help
[:
250
]
+
'...'
help
=
help
[:
250
]
+
'...'
Dlg
.
SetDialogItemText
(
h
,
help
)
Dlg
.
SetDialogItemText
(
h
,
help
)
hasvalue
=
0
hasvalue
=
0
if
type
(
option
)
==
type
(()):
if
type
(
option
)
==
type
(()):
label
=
option
[
0
]
label
=
option
[
0
]
else
:
else
:
label
=
option
label
=
option
if
label
[
-
1
]
==
'='
or
label
[
-
1
]
==
':'
:
if
label
[
-
1
]
==
'='
or
label
[
-
1
]
==
':'
:
hasvalue
=
1
hasvalue
=
1
h
=
d
.
GetDialogItemAsControl
(
ARGV_OPTION_VALUE
)
h
=
d
.
GetDialogItemAsControl
(
ARGV_OPTION_VALUE
)
Dlg
.
SetDialogItemText
(
h
,
''
)
Dlg
.
SetDialogItemText
(
h
,
''
)
if
hasvalue
:
if
hasvalue
:
d
.
ShowDialogItem
(
ARGV_OPTION_VALUE
)
d
.
ShowDialogItem
(
ARGV_OPTION_VALUE
)
d
.
SelectDialogItemText
(
ARGV_OPTION_VALUE
,
0
,
0
)
d
.
SelectDialogItemText
(
ARGV_OPTION_VALUE
,
0
,
0
)
else
:
else
:
d
.
HideDialogItem
(
ARGV_OPTION_VALUE
)
d
.
HideDialogItem
(
ARGV_OPTION_VALUE
)
def
GetArgv
(
optionlist
=
None
,
commandlist
=
None
,
addoldfile
=
1
,
addnewfile
=
1
,
addfolder
=
1
,
id
=
ARGV_ID
):
def
GetArgv
(
optionlist
=
None
,
commandlist
=
None
,
addoldfile
=
1
,
addnewfile
=
1
,
addfolder
=
1
,
id
=
ARGV_ID
):
_initialize
()
_initialize
()
_interact
()
_interact
()
d
=
GetNewDialog
(
id
,
-
1
)
d
=
GetNewDialog
(
id
,
-
1
)
if
not
d
:
if
not
d
:
print
"EasyDialogs: Can't get DLOG resource with id ="
,
id
,
" (missing resource file?)"
print
"EasyDialogs: Can't get DLOG resource with id ="
,
id
,
" (missing resource file?)"
return
return
#
h = d.GetDialogItemAsControl(3)
#
h = d.GetDialogItemAsControl(3)
#
SetDialogItemText(h, lf2cr(prompt))
#
SetDialogItemText(h, lf2cr(prompt))
#
h = d.GetDialogItemAsControl(4)
#
h = d.GetDialogItemAsControl(4)
#
SetDialogItemText(h, lf2cr(default))
#
SetDialogItemText(h, lf2cr(default))
#
d.SelectDialogItemText(4, 0, 999)
#
d.SelectDialogItemText(4, 0, 999)
#
d.SetDialogItem(4, 0, 255)
#
d.SetDialogItem(4, 0, 255)
if
optionlist
:
if
optionlist
:
_setmenu
(
d
.
GetDialogItemAsControl
(
ARGV_OPTION_GROUP
),
optionlist
)
_setmenu
(
d
.
GetDialogItemAsControl
(
ARGV_OPTION_GROUP
),
optionlist
)
_selectoption
(
d
,
optionlist
,
0
)
_selectoption
(
d
,
optionlist
,
0
)
else
:
else
:
d
.
GetDialogItemAsControl
(
ARGV_OPTION_GROUP
).
DeactivateControl
()
d
.
GetDialogItemAsControl
(
ARGV_OPTION_GROUP
).
DeactivateControl
()
if
commandlist
:
if
commandlist
:
_setmenu
(
d
.
GetDialogItemAsControl
(
ARGV_COMMAND_GROUP
),
commandlist
)
_setmenu
(
d
.
GetDialogItemAsControl
(
ARGV_COMMAND_GROUP
),
commandlist
)
if
type
(
commandlist
[
0
])
==
type
(())
and
len
(
commandlist
[
0
])
>
1
:
if
type
(
commandlist
[
0
])
==
type
(())
and
len
(
commandlist
[
0
])
>
1
:
help
=
commandlist
[
0
][
-
1
]
help
=
commandlist
[
0
][
-
1
]
h
=
d
.
GetDialogItemAsControl
(
ARGV_COMMAND_EXPLAIN
)
h
=
d
.
GetDialogItemAsControl
(
ARGV_COMMAND_EXPLAIN
)
Dlg
.
SetDialogItemText
(
h
,
help
)
Dlg
.
SetDialogItemText
(
h
,
help
)
else
:
else
:
d
.
GetDialogItemAsControl
(
ARGV_COMMAND_GROUP
).
DeactivateControl
()
d
.
GetDialogItemAsControl
(
ARGV_COMMAND_GROUP
).
DeactivateControl
()
if
not
addoldfile
:
if
not
addoldfile
:
d
.
GetDialogItemAsControl
(
ARGV_ADD_OLDFILE
).
DeactivateControl
()
d
.
GetDialogItemAsControl
(
ARGV_ADD_OLDFILE
).
DeactivateControl
()
if
not
addnewfile
:
if
not
addnewfile
:
d
.
GetDialogItemAsControl
(
ARGV_ADD_NEWFILE
).
DeactivateControl
()
d
.
GetDialogItemAsControl
(
ARGV_ADD_NEWFILE
).
DeactivateControl
()
if
not
addfolder
:
if
not
addfolder
:
d
.
GetDialogItemAsControl
(
ARGV_ADD_FOLDER
).
DeactivateControl
()
d
.
GetDialogItemAsControl
(
ARGV_ADD_FOLDER
).
DeactivateControl
()
d
.
SetDialogDefaultItem
(
ARGV_ITEM_OK
)
d
.
SetDialogDefaultItem
(
ARGV_ITEM_OK
)
d
.
SetDialogCancelItem
(
ARGV_ITEM_CANCEL
)
d
.
SetDialogCancelItem
(
ARGV_ITEM_CANCEL
)
d
.
GetDialogWindow
().
ShowWindow
()
d
.
GetDialogWindow
().
ShowWindow
()
d
.
DrawDialog
()
d
.
DrawDialog
()
if
hasattr
(
MacOS
,
'SchedParams'
):
if
hasattr
(
MacOS
,
'SchedParams'
):
appsw
=
MacOS
.
SchedParams
(
1
,
0
)
appsw
=
MacOS
.
SchedParams
(
1
,
0
)
try
:
try
:
while
1
:
while
1
:
stringstoadd
=
[]
stringstoadd
=
[]
n
=
ModalDialog
(
None
)
n
=
ModalDialog
(
None
)
if
n
==
ARGV_ITEM_OK
:
if
n
==
ARGV_ITEM_OK
:
break
break
elif
n
==
ARGV_ITEM_CANCEL
:
elif
n
==
ARGV_ITEM_CANCEL
:
raise
SystemExit
raise
SystemExit
elif
n
==
ARGV_OPTION_GROUP
:
elif
n
==
ARGV_OPTION_GROUP
:
idx
=
d
.
GetDialogItemAsControl
(
ARGV_OPTION_GROUP
).
GetControlValue
()
-
1
idx
=
d
.
GetDialogItemAsControl
(
ARGV_OPTION_GROUP
).
GetControlValue
()
-
1
_selectoption
(
d
,
optionlist
,
idx
)
_selectoption
(
d
,
optionlist
,
idx
)
elif
n
==
ARGV_OPTION_VALUE
:
elif
n
==
ARGV_OPTION_VALUE
:
pass
pass
elif
n
==
ARGV_OPTION_ADD
:
elif
n
==
ARGV_OPTION_ADD
:
idx
=
d
.
GetDialogItemAsControl
(
ARGV_OPTION_GROUP
).
GetControlValue
()
-
1
idx
=
d
.
GetDialogItemAsControl
(
ARGV_OPTION_GROUP
).
GetControlValue
()
-
1
if
0
<=
idx
<
len
(
optionlist
):
if
0
<=
idx
<
len
(
optionlist
):
option
=
optionlist
[
idx
]
option
=
optionlist
[
idx
]
if
type
(
option
)
==
type
(()):
if
type
(
option
)
==
type
(()):
option
=
option
[
0
]
option
=
option
[
0
]
if
option
[
-
1
]
==
'='
or
option
[
-
1
]
==
':'
:
if
option
[
-
1
]
==
'='
or
option
[
-
1
]
==
':'
:
option
=
option
[:
-
1
]
option
=
option
[:
-
1
]
h
=
d
.
GetDialogItemAsControl
(
ARGV_OPTION_VALUE
)
h
=
d
.
GetDialogItemAsControl
(
ARGV_OPTION_VALUE
)
value
=
Dlg
.
GetDialogItemText
(
h
)
value
=
Dlg
.
GetDialogItemText
(
h
)
else
:
else
:
value
=
''
value
=
''
if
len
(
option
)
==
1
:
if
len
(
option
)
==
1
:
stringtoadd
=
'-'
+
option
stringtoadd
=
'-'
+
option
else
:
else
:
stringtoadd
=
'--'
+
option
stringtoadd
=
'--'
+
option
stringstoadd
=
[
stringtoadd
]
stringstoadd
=
[
stringtoadd
]
if
value
:
if
value
:
stringstoadd
.
append
(
value
)
stringstoadd
.
append
(
value
)
else
:
else
:
MacOS
.
SysBeep
()
MacOS
.
SysBeep
()
elif
n
==
ARGV_COMMAND_GROUP
:
elif
n
==
ARGV_COMMAND_GROUP
:
idx
=
d
.
GetDialogItemAsControl
(
ARGV_COMMAND_GROUP
).
GetControlValue
()
-
1
idx
=
d
.
GetDialogItemAsControl
(
ARGV_COMMAND_GROUP
).
GetControlValue
()
-
1
if
0
<=
idx
<
len
(
commandlist
)
and
type
(
commandlist
[
idx
])
==
type
(())
and
\
if
0
<=
idx
<
len
(
commandlist
)
and
type
(
commandlist
[
idx
])
==
type
(())
and
\
len
(
commandlist
[
idx
])
>
1
:
len
(
commandlist
[
idx
])
>
1
:
help
=
commandlist
[
idx
][
-
1
]
help
=
commandlist
[
idx
][
-
1
]
h
=
d
.
GetDialogItemAsControl
(
ARGV_COMMAND_EXPLAIN
)
h
=
d
.
GetDialogItemAsControl
(
ARGV_COMMAND_EXPLAIN
)
Dlg
.
SetDialogItemText
(
h
,
help
)
Dlg
.
SetDialogItemText
(
h
,
help
)
elif
n
==
ARGV_COMMAND_ADD
:
elif
n
==
ARGV_COMMAND_ADD
:
idx
=
d
.
GetDialogItemAsControl
(
ARGV_COMMAND_GROUP
).
GetControlValue
()
-
1
idx
=
d
.
GetDialogItemAsControl
(
ARGV_COMMAND_GROUP
).
GetControlValue
()
-
1
if
0
<=
idx
<
len
(
commandlist
):
if
0
<=
idx
<
len
(
commandlist
):
command
=
commandlist
[
idx
]
command
=
commandlist
[
idx
]
if
type
(
command
)
==
type
(()):
if
type
(
command
)
==
type
(()):
command
=
command
[
0
]
command
=
command
[
0
]
stringstoadd
=
[
command
]
stringstoadd
=
[
command
]
else
:
else
:
MacOS
.
SysBeep
()
MacOS
.
SysBeep
()
elif
n
==
ARGV_ADD_OLDFILE
:
elif
n
==
ARGV_ADD_OLDFILE
:
pathname
=
AskFileForOpen
()
pathname
=
AskFileForOpen
()
if
pathname
:
if
pathname
:
stringstoadd
=
[
pathname
]
stringstoadd
=
[
pathname
]
elif
n
==
ARGV_ADD_NEWFILE
:
elif
n
==
ARGV_ADD_NEWFILE
:
pathname
=
AskFileForSave
()
pathname
=
AskFileForSave
()
if
pathname
:
if
pathname
:
stringstoadd
=
[
pathname
]
stringstoadd
=
[
pathname
]
elif
n
==
ARGV_ADD_FOLDER
:
elif
n
==
ARGV_ADD_FOLDER
:
pathname
=
AskFolder
()
pathname
=
AskFolder
()
if
pathname
:
if
pathname
:
stringstoadd
=
[
pathname
]
stringstoadd
=
[
pathname
]
elif
n
==
ARGV_CMDLINE_DATA
:
elif
n
==
ARGV_CMDLINE_DATA
:
pass
# Nothing to do
pass
# Nothing to do
else
:
else
:
raise
RuntimeError
,
"Unknown dialog item %d"
%
n
raise
RuntimeError
,
"Unknown dialog item %d"
%
n
for
stringtoadd
in
stringstoadd
:
for
stringtoadd
in
stringstoadd
:
if
'"'
in
stringtoadd
or
"'"
in
stringtoadd
or
" "
in
stringtoadd
:
if
'"'
in
stringtoadd
or
"'"
in
stringtoadd
or
" "
in
stringtoadd
:
stringtoadd
=
`stringtoadd`
stringtoadd
=
`stringtoadd`
h
=
d
.
GetDialogItemAsControl
(
ARGV_CMDLINE_DATA
)
h
=
d
.
GetDialogItemAsControl
(
ARGV_CMDLINE_DATA
)
oldstr
=
GetDialogItemText
(
h
)
oldstr
=
GetDialogItemText
(
h
)
if
oldstr
and
oldstr
[
-
1
]
!=
' '
:
if
oldstr
and
oldstr
[
-
1
]
!=
' '
:
oldstr
=
oldstr
+
' '
oldstr
=
oldstr
+
' '
oldstr
=
oldstr
+
stringtoadd
oldstr
=
oldstr
+
stringtoadd
if
oldstr
[
-
1
]
!=
' '
:
if
oldstr
[
-
1
]
!=
' '
:
oldstr
=
oldstr
+
' '
oldstr
=
oldstr
+
' '
SetDialogItemText
(
h
,
oldstr
)
SetDialogItemText
(
h
,
oldstr
)
d
.
SelectDialogItemText
(
ARGV_CMDLINE_DATA
,
0x7fff
,
0x7fff
)
d
.
SelectDialogItemText
(
ARGV_CMDLINE_DATA
,
0x7fff
,
0x7fff
)
h
=
d
.
GetDialogItemAsControl
(
ARGV_CMDLINE_DATA
)
h
=
d
.
GetDialogItemAsControl
(
ARGV_CMDLINE_DATA
)
oldstr
=
GetDialogItemText
(
h
)
oldstr
=
GetDialogItemText
(
h
)
tmplist
=
string
.
split
(
oldstr
)
tmplist
=
string
.
split
(
oldstr
)
newlist
=
[]
newlist
=
[]
while
tmplist
:
while
tmplist
:
item
=
tmplist
[
0
]
item
=
tmplist
[
0
]
del
tmplist
[
0
]
del
tmplist
[
0
]
if
item
[
0
]
==
'"'
:
if
item
[
0
]
==
'"'
:
while
item
[
-
1
]
!=
'"'
:
while
item
[
-
1
]
!=
'"'
:
if
not
tmplist
:
if
not
tmplist
:
raise
RuntimeError
,
"Unterminated quoted argument"
raise
RuntimeError
,
"Unterminated quoted argument"
item
=
item
+
' '
+
tmplist
[
0
]
item
=
item
+
' '
+
tmplist
[
0
]
del
tmplist
[
0
]
del
tmplist
[
0
]
item
=
item
[
1
:
-
1
]
item
=
item
[
1
:
-
1
]
if
item
[
0
]
==
"'"
:
if
item
[
0
]
==
"'"
:
while
item
[
-
1
]
!=
"'"
:
while
item
[
-
1
]
!=
"'"
:
if
not
tmplist
:
if
not
tmplist
:
raise
RuntimeError
,
"Unterminated quoted argument"
raise
RuntimeError
,
"Unterminated quoted argument"
item
=
item
+
' '
+
tmplist
[
0
]
item
=
item
+
' '
+
tmplist
[
0
]
del
tmplist
[
0
]
del
tmplist
[
0
]
item
=
item
[
1
:
-
1
]
item
=
item
[
1
:
-
1
]
newlist
.
append
(
item
)
newlist
.
append
(
item
)
return
newlist
return
newlist
finally
:
finally
:
if
hasattr
(
MacOS
,
'SchedParams'
):
if
hasattr
(
MacOS
,
'SchedParams'
):
apply
(
MacOS
.
SchedParams
,
appsw
)
MacOS
.
SchedParams
(
*
appsw
)
del
d
del
d
def
_process_Nav_args
(
dftflags
,
**
args
):
def
_process_Nav_args
(
dftflags
,
**
args
):
import
aepack
import
aepack
import
Carbon.AE
import
Carbon.AE
import
Carbon.File
import
Carbon.File
for
k
in
args
.
keys
():
for
k
in
args
.
keys
():
if
args
[
k
]
is
None
:
if
args
[
k
]
is
None
:
del
args
[
k
]
del
args
[
k
]
# Set some defaults, and modify some arguments
# Set some defaults, and modify some arguments
if
not
args
.
has_key
(
'dialogOptionFlags'
):
if
not
args
.
has_key
(
'dialogOptionFlags'
):
args
[
'dialogOptionFlags'
]
=
dftflags
args
[
'dialogOptionFlags'
]
=
dftflags
if
args
.
has_key
(
'defaultLocation'
)
and
\
if
args
.
has_key
(
'defaultLocation'
)
and
\
not
isinstance
(
args
[
'defaultLocation'
],
Carbon
.
AE
.
AEDesc
):
not
isinstance
(
args
[
'defaultLocation'
],
Carbon
.
AE
.
AEDesc
):
defaultLocation
=
args
[
'defaultLocation'
]
defaultLocation
=
args
[
'defaultLocation'
]
if
isinstance
(
defaultLocation
,
(
Carbon
.
File
.
FSSpec
,
Carbon
.
File
.
FSRef
)):
if
isinstance
(
defaultLocation
,
(
Carbon
.
File
.
FSSpec
,
Carbon
.
File
.
FSRef
)):
args
[
'defaultLocation'
]
=
aepack
.
pack
(
defaultLocation
)
args
[
'defaultLocation'
]
=
aepack
.
pack
(
defaultLocation
)
else
:
else
:
defaultLocation
=
Carbon
.
File
.
FSRef
(
defaultLocation
)
defaultLocation
=
Carbon
.
File
.
FSRef
(
defaultLocation
)
args
[
'defaultLocation'
]
=
aepack
.
pack
(
defaultLocation
)
args
[
'defaultLocation'
]
=
aepack
.
pack
(
defaultLocation
)
if
args
.
has_key
(
'typeList'
)
and
not
isinstance
(
args
[
'typeList'
],
Carbon
.
Res
.
ResourceType
):
if
args
.
has_key
(
'typeList'
)
and
not
isinstance
(
args
[
'typeList'
],
Carbon
.
Res
.
ResourceType
):
typeList
=
args
[
'typeList'
][:]
typeList
=
args
[
'typeList'
][:]
# Workaround for OSX typeless files:
# Workaround for OSX typeless files:
if
'TEXT'
in
typeList
and
not
'
\
0
\
0
\
0
\
0
'
in
typeList
:
if
'TEXT'
in
typeList
and
not
'
\
0
\
0
\
0
\
0
'
in
typeList
:
typeList
=
typeList
+
(
'
\
0
\
0
\
0
\
0
'
,)
typeList
=
typeList
+
(
'
\
0
\
0
\
0
\
0
'
,)
data
=
'Pyth'
+
struct
.
pack
(
"hh"
,
0
,
len
(
typeList
))
data
=
'Pyth'
+
struct
.
pack
(
"hh"
,
0
,
len
(
typeList
))
for
type
in
typeList
:
for
type
in
typeList
:
data
=
data
+
type
data
=
data
+
type
args
[
'typeList'
]
=
Carbon
.
Res
.
Handle
(
data
)
args
[
'typeList'
]
=
Carbon
.
Res
.
Handle
(
data
)
tpwanted
=
str
tpwanted
=
str
if
args
.
has_key
(
'wanted'
):
if
args
.
has_key
(
'wanted'
):
tpwanted
=
args
[
'wanted'
]
tpwanted
=
args
[
'wanted'
]
del
args
[
'wanted'
]
del
args
[
'wanted'
]
return
args
,
tpwanted
return
args
,
tpwanted
def
_dummy_Nav_eventproc
(
msg
,
data
):
def
_dummy_Nav_eventproc
(
msg
,
data
):
pass
pass
_default_Nav_eventproc
=
_dummy_Nav_eventproc
_default_Nav_eventproc
=
_dummy_Nav_eventproc
def
SetDefaultEventProc
(
proc
):
def
SetDefaultEventProc
(
proc
):
global
_default_Nav_eventproc
global
_default_Nav_eventproc
rv
=
_default_Nav_eventproc
rv
=
_default_Nav_eventproc
if
proc
is
None
:
if
proc
is
None
:
proc
=
_dummy_Nav_eventproc
proc
=
_dummy_Nav_eventproc
_default_Nav_eventproc
=
proc
_default_Nav_eventproc
=
proc
return
rv
return
rv
def
AskFileForOpen
(
def
AskFileForOpen
(
message
=
None
,
message
=
None
,
typeList
=
None
,
typeList
=
None
,
# From here on the order is not documented
# From here on the order is not documented
version
=
None
,
version
=
None
,
defaultLocation
=
None
,
defaultLocation
=
None
,
dialogOptionFlags
=
None
,
dialogOptionFlags
=
None
,
location
=
None
,
location
=
None
,
clientName
=
None
,
clientName
=
None
,
windowTitle
=
None
,
windowTitle
=
None
,
actionButtonLabel
=
None
,
actionButtonLabel
=
None
,
cancelButtonLabel
=
None
,
cancelButtonLabel
=
None
,
preferenceKey
=
None
,
preferenceKey
=
None
,
popupExtension
=
None
,
popupExtension
=
None
,
eventProc
=
_dummy_Nav_eventproc
,
eventProc
=
_dummy_Nav_eventproc
,
previewProc
=
None
,
previewProc
=
None
,
filterProc
=
None
,
filterProc
=
None
,
wanted
=
None
,
wanted
=
None
,
multiple
=
None
):
multiple
=
None
):
"""Display a dialog asking the user for a file to open.
"""Display a dialog asking the user for a file to open.
wanted is the return type wanted: FSSpec, FSRef, unicode or string (default)
wanted is the return type wanted: FSSpec, FSRef, unicode or string (default)
the other arguments can be looked up in Apple's Navigation Services documentation"""
the other arguments can be looked up in Apple's Navigation Services documentation"""
default_flags
=
0x56
# Or 0xe4?
default_flags
=
0x56
# Or 0xe4?
args
,
tpwanted
=
_process_Nav_args
(
default_flags
,
version
=
version
,
args
,
tpwanted
=
_process_Nav_args
(
default_flags
,
version
=
version
,
defaultLocation
=
defaultLocation
,
dialogOptionFlags
=
dialogOptionFlags
,
defaultLocation
=
defaultLocation
,
dialogOptionFlags
=
dialogOptionFlags
,
location
=
location
,
clientName
=
clientName
,
windowTitle
=
windowTitle
,
location
=
location
,
clientName
=
clientName
,
windowTitle
=
windowTitle
,
actionButtonLabel
=
actionButtonLabel
,
cancelButtonLabel
=
cancelButtonLabel
,
actionButtonLabel
=
actionButtonLabel
,
cancelButtonLabel
=
cancelButtonLabel
,
message
=
message
,
preferenceKey
=
preferenceKey
,
message
=
message
,
preferenceKey
=
preferenceKey
,
popupExtension
=
popupExtension
,
eventProc
=
eventProc
,
previewProc
=
previewProc
,
popupExtension
=
popupExtension
,
eventProc
=
eventProc
,
previewProc
=
previewProc
,
filterProc
=
filterProc
,
typeList
=
typeList
,
wanted
=
wanted
,
multiple
=
multiple
)
filterProc
=
filterProc
,
typeList
=
typeList
,
wanted
=
wanted
,
multiple
=
multiple
)
_interact
()
_interact
()
try
:
try
:
rr
=
Nav
.
NavChooseFile
(
args
)
rr
=
Nav
.
NavChooseFile
(
args
)
good
=
1
good
=
1
except
Nav
.
error
,
arg
:
except
Nav
.
error
,
arg
:
if
arg
[
0
]
!=
-
128
:
# userCancelledErr
if
arg
[
0
]
!=
-
128
:
# userCancelledErr
raise
Nav
.
error
,
arg
raise
Nav
.
error
,
arg
return
None
return
None
if
not
rr
.
validRecord
or
not
rr
.
selection
:
if
not
rr
.
validRecord
or
not
rr
.
selection
:
return
None
return
None
if
issubclass
(
tpwanted
,
Carbon
.
File
.
FSRef
):
if
issubclass
(
tpwanted
,
Carbon
.
File
.
FSRef
):
return
tpwanted
(
rr
.
selection_fsr
[
0
])
return
tpwanted
(
rr
.
selection_fsr
[
0
])
if
issubclass
(
tpwanted
,
Carbon
.
File
.
FSSpec
):
if
issubclass
(
tpwanted
,
Carbon
.
File
.
FSSpec
):
return
tpwanted
(
rr
.
selection
[
0
])
return
tpwanted
(
rr
.
selection
[
0
])
if
issubclass
(
tpwanted
,
str
):
if
issubclass
(
tpwanted
,
str
):
return
tpwanted
(
rr
.
selection_fsr
[
0
].
as_pathname
())
return
tpwanted
(
rr
.
selection_fsr
[
0
].
as_pathname
())
if
issubclass
(
tpwanted
,
unicode
):
if
issubclass
(
tpwanted
,
unicode
):
return
tpwanted
(
rr
.
selection_fsr
[
0
].
as_pathname
(),
'utf8'
)
return
tpwanted
(
rr
.
selection_fsr
[
0
].
as_pathname
(),
'utf8'
)
raise
TypeError
,
"Unknown value for argument 'wanted': %s"
%
repr
(
tpwanted
)
raise
TypeError
,
"Unknown value for argument 'wanted': %s"
%
repr
(
tpwanted
)
def
AskFileForSave
(
def
AskFileForSave
(
message
=
None
,
message
=
None
,
savedFileName
=
None
,
savedFileName
=
None
,
# From here on the order is not documented
# From here on the order is not documented
version
=
None
,
version
=
None
,
defaultLocation
=
None
,
defaultLocation
=
None
,
dialogOptionFlags
=
None
,
dialogOptionFlags
=
None
,
location
=
None
,
location
=
None
,
clientName
=
None
,
clientName
=
None
,
windowTitle
=
None
,
windowTitle
=
None
,
actionButtonLabel
=
None
,
actionButtonLabel
=
None
,
cancelButtonLabel
=
None
,
cancelButtonLabel
=
None
,
preferenceKey
=
None
,
preferenceKey
=
None
,
popupExtension
=
None
,
popupExtension
=
None
,
eventProc
=
_dummy_Nav_eventproc
,
eventProc
=
_dummy_Nav_eventproc
,
fileType
=
None
,
fileType
=
None
,
fileCreator
=
None
,
fileCreator
=
None
,
wanted
=
None
,
wanted
=
None
,
multiple
=
None
):
multiple
=
None
):
"""Display a dialog asking the user for a filename to save to.
"""Display a dialog asking the user for a filename to save to.
wanted is the return type wanted: FSSpec, FSRef, unicode or string (default)
wanted is the return type wanted: FSSpec, FSRef, unicode or string (default)
the other arguments can be looked up in Apple's Navigation Services documentation"""
the other arguments can be looked up in Apple's Navigation Services documentation"""
default_flags
=
0x07
default_flags
=
0x07
args
,
tpwanted
=
_process_Nav_args
(
default_flags
,
version
=
version
,
args
,
tpwanted
=
_process_Nav_args
(
default_flags
,
version
=
version
,
defaultLocation
=
defaultLocation
,
dialogOptionFlags
=
dialogOptionFlags
,
defaultLocation
=
defaultLocation
,
dialogOptionFlags
=
dialogOptionFlags
,
location
=
location
,
clientName
=
clientName
,
windowTitle
=
windowTitle
,
location
=
location
,
clientName
=
clientName
,
windowTitle
=
windowTitle
,
actionButtonLabel
=
actionButtonLabel
,
cancelButtonLabel
=
cancelButtonLabel
,
actionButtonLabel
=
actionButtonLabel
,
cancelButtonLabel
=
cancelButtonLabel
,
savedFileName
=
savedFileName
,
message
=
message
,
preferenceKey
=
preferenceKey
,
savedFileName
=
savedFileName
,
message
=
message
,
preferenceKey
=
preferenceKey
,
popupExtension
=
popupExtension
,
eventProc
=
eventProc
,
fileType
=
fileType
,
popupExtension
=
popupExtension
,
eventProc
=
eventProc
,
fileType
=
fileType
,
fileCreator
=
fileCreator
,
wanted
=
wanted
,
multiple
=
multiple
)
fileCreator
=
fileCreator
,
wanted
=
wanted
,
multiple
=
multiple
)
_interact
()
_interact
()
try
:
try
:
rr
=
Nav
.
NavPutFile
(
args
)
rr
=
Nav
.
NavPutFile
(
args
)
good
=
1
good
=
1
except
Nav
.
error
,
arg
:
except
Nav
.
error
,
arg
:
if
arg
[
0
]
!=
-
128
:
# userCancelledErr
if
arg
[
0
]
!=
-
128
:
# userCancelledErr
raise
Nav
.
error
,
arg
raise
Nav
.
error
,
arg
return
None
return
None
if
not
rr
.
validRecord
or
not
rr
.
selection
:
if
not
rr
.
validRecord
or
not
rr
.
selection
:
return
None
return
None
if
issubclass
(
tpwanted
,
Carbon
.
File
.
FSRef
):
if
issubclass
(
tpwanted
,
Carbon
.
File
.
FSRef
):
raise
TypeError
,
"Cannot pass wanted=FSRef to AskFileForSave"
raise
TypeError
,
"Cannot pass wanted=FSRef to AskFileForSave"
if
issubclass
(
tpwanted
,
Carbon
.
File
.
FSSpec
):
if
issubclass
(
tpwanted
,
Carbon
.
File
.
FSSpec
):
return
tpwanted
(
rr
.
selection
[
0
])
return
tpwanted
(
rr
.
selection
[
0
])
if
issubclass
(
tpwanted
,
(
str
,
unicode
)):
if
issubclass
(
tpwanted
,
(
str
,
unicode
)):
if
sys
.
platform
==
'mac'
:
if
sys
.
platform
==
'mac'
:
fullpath
=
rr
.
selection
[
0
].
as_pathname
()
fullpath
=
rr
.
selection
[
0
].
as_pathname
()
else
:
else
:
# This is gross, and probably incorrect too
# This is gross, and probably incorrect too
vrefnum
,
dirid
,
name
=
rr
.
selection
[
0
].
as_tuple
()
vrefnum
,
dirid
,
name
=
rr
.
selection
[
0
].
as_tuple
()
pardir_fss
=
Carbon
.
File
.
FSSpec
((
vrefnum
,
dirid
,
''
))
pardir_fss
=
Carbon
.
File
.
FSSpec
((
vrefnum
,
dirid
,
''
))
pardir_fsr
=
Carbon
.
File
.
FSRef
(
pardir_fss
)
pardir_fsr
=
Carbon
.
File
.
FSRef
(
pardir_fss
)
pardir_path
=
pardir_fsr
.
FSRefMakePath
()
# This is utf-8
pardir_path
=
pardir_fsr
.
FSRefMakePath
()
# This is utf-8
name_utf8
=
unicode
(
name
,
'macroman'
).
encode
(
'utf8'
)
name_utf8
=
unicode
(
name
,
'macroman'
).
encode
(
'utf8'
)
fullpath
=
os
.
path
.
join
(
pardir_path
,
name_utf8
)
fullpath
=
os
.
path
.
join
(
pardir_path
,
name_utf8
)
if
issubclass
(
tpwanted
,
unicode
):
if
issubclass
(
tpwanted
,
unicode
):
return
unicode
(
fullpath
,
'utf8'
)
return
unicode
(
fullpath
,
'utf8'
)
return
tpwanted
(
fullpath
)
return
tpwanted
(
fullpath
)
raise
TypeError
,
"Unknown value for argument 'wanted': %s"
%
repr
(
tpwanted
)
raise
TypeError
,
"Unknown value for argument 'wanted': %s"
%
repr
(
tpwanted
)
def
AskFolder
(
def
AskFolder
(
message
=
None
,
message
=
None
,
# From here on the order is not documented
# From here on the order is not documented
version
=
None
,
version
=
None
,
defaultLocation
=
None
,
defaultLocation
=
None
,
dialogOptionFlags
=
None
,
dialogOptionFlags
=
None
,
location
=
None
,
location
=
None
,
clientName
=
None
,
clientName
=
None
,
windowTitle
=
None
,
windowTitle
=
None
,
actionButtonLabel
=
None
,
actionButtonLabel
=
None
,
cancelButtonLabel
=
None
,
cancelButtonLabel
=
None
,
preferenceKey
=
None
,
preferenceKey
=
None
,
popupExtension
=
None
,
popupExtension
=
None
,
eventProc
=
_dummy_Nav_eventproc
,
eventProc
=
_dummy_Nav_eventproc
,
filterProc
=
None
,
filterProc
=
None
,
wanted
=
None
,
wanted
=
None
,
multiple
=
None
):
multiple
=
None
):
"""Display a dialog asking the user for select a folder.
"""Display a dialog asking the user for select a folder.
wanted is the return type wanted: FSSpec, FSRef, unicode or string (default)
wanted is the return type wanted: FSSpec, FSRef, unicode or string (default)
the other arguments can be looked up in Apple's Navigation Services documentation"""
the other arguments can be looked up in Apple's Navigation Services documentation"""
default_flags
=
0x17
default_flags
=
0x17
args
,
tpwanted
=
_process_Nav_args
(
default_flags
,
version
=
version
,
args
,
tpwanted
=
_process_Nav_args
(
default_flags
,
version
=
version
,
defaultLocation
=
defaultLocation
,
dialogOptionFlags
=
dialogOptionFlags
,
defaultLocation
=
defaultLocation
,
dialogOptionFlags
=
dialogOptionFlags
,
location
=
location
,
clientName
=
clientName
,
windowTitle
=
windowTitle
,
location
=
location
,
clientName
=
clientName
,
windowTitle
=
windowTitle
,
actionButtonLabel
=
actionButtonLabel
,
cancelButtonLabel
=
cancelButtonLabel
,
actionButtonLabel
=
actionButtonLabel
,
cancelButtonLabel
=
cancelButtonLabel
,
message
=
message
,
preferenceKey
=
preferenceKey
,
message
=
message
,
preferenceKey
=
preferenceKey
,
popupExtension
=
popupExtension
,
eventProc
=
eventProc
,
filterProc
=
filterProc
,
popupExtension
=
popupExtension
,
eventProc
=
eventProc
,
filterProc
=
filterProc
,
wanted
=
wanted
,
multiple
=
multiple
)
wanted
=
wanted
,
multiple
=
multiple
)
_interact
()
_interact
()
try
:
try
:
rr
=
Nav
.
NavChooseFolder
(
args
)
rr
=
Nav
.
NavChooseFolder
(
args
)
good
=
1
good
=
1
except
Nav
.
error
,
arg
:
except
Nav
.
error
,
arg
:
if
arg
[
0
]
!=
-
128
:
# userCancelledErr
if
arg
[
0
]
!=
-
128
:
# userCancelledErr
raise
Nav
.
error
,
arg
raise
Nav
.
error
,
arg
return
None
return
None
if
not
rr
.
validRecord
or
not
rr
.
selection
:
if
not
rr
.
validRecord
or
not
rr
.
selection
:
return
None
return
None
if
issubclass
(
tpwanted
,
Carbon
.
File
.
FSRef
):
if
issubclass
(
tpwanted
,
Carbon
.
File
.
FSRef
):
return
tpwanted
(
rr
.
selection_fsr
[
0
])
return
tpwanted
(
rr
.
selection_fsr
[
0
])
if
issubclass
(
tpwanted
,
Carbon
.
File
.
FSSpec
):
if
issubclass
(
tpwanted
,
Carbon
.
File
.
FSSpec
):
return
tpwanted
(
rr
.
selection
[
0
])
return
tpwanted
(
rr
.
selection
[
0
])
if
issubclass
(
tpwanted
,
str
):
if
issubclass
(
tpwanted
,
str
):
return
tpwanted
(
rr
.
selection_fsr
[
0
].
as_pathname
())
return
tpwanted
(
rr
.
selection_fsr
[
0
].
as_pathname
())
if
issubclass
(
tpwanted
,
unicode
):
if
issubclass
(
tpwanted
,
unicode
):
return
tpwanted
(
rr
.
selection_fsr
[
0
].
as_pathname
(),
'utf8'
)
return
tpwanted
(
rr
.
selection_fsr
[
0
].
as_pathname
(),
'utf8'
)
raise
TypeError
,
"Unknown value for argument 'wanted': %s"
%
repr
(
tpwanted
)
raise
TypeError
,
"Unknown value for argument 'wanted': %s"
%
repr
(
tpwanted
)
def
test
():
def
test
():
import
time
import
time
Message
(
"Testing EasyDialogs."
)
Message
(
"Testing EasyDialogs."
)
optionlist
=
((
'v'
,
'Verbose'
),
(
'verbose'
,
'Verbose as long option'
),
optionlist
=
((
'v'
,
'Verbose'
),
(
'verbose'
,
'Verbose as long option'
),
(
'flags='
,
'Valued option'
),
(
'f:'
,
'Short valued option'
))
(
'flags='
,
'Valued option'
),
(
'f:'
,
'Short valued option'
))
commandlist
=
((
'start'
,
'Start something'
),
(
'stop'
,
'Stop something'
))
commandlist
=
((
'start'
,
'Start something'
),
(
'stop'
,
'Stop something'
))
argv
=
GetArgv
(
optionlist
=
optionlist
,
commandlist
=
commandlist
,
addoldfile
=
0
)
argv
=
GetArgv
(
optionlist
=
optionlist
,
commandlist
=
commandlist
,
addoldfile
=
0
)
Message
(
"Command line: %s"
%
' '
.
join
(
argv
))
Message
(
"Command line: %s"
%
' '
.
join
(
argv
))
for
i
in
range
(
len
(
argv
)):
for
i
in
range
(
len
(
argv
)):
print
'arg[%d] = %s'
%
(
i
,
`argv[i]`
)
print
'arg[%d] = %s'
%
(
i
,
`argv[i]`
)
ok
=
AskYesNoCancel
(
"Do you want to proceed?"
)
ok
=
AskYesNoCancel
(
"Do you want to proceed?"
)
ok
=
AskYesNoCancel
(
"Do you want to identify?"
,
yes
=
"Identify"
,
no
=
"No"
)
ok
=
AskYesNoCancel
(
"Do you want to identify?"
,
yes
=
"Identify"
,
no
=
"No"
)
if
ok
>
0
:
if
ok
>
0
:
s
=
AskString
(
"Enter your first name"
,
"Joe"
)
s
=
AskString
(
"Enter your first name"
,
"Joe"
)
s2
=
AskPassword
(
"Okay %s, tell us your nickname"
%
s
,
s
,
cancel
=
"None"
)
s2
=
AskPassword
(
"Okay %s, tell us your nickname"
%
s
,
s
,
cancel
=
"None"
)
if
not
s2
:
if
not
s2
:
Message
(
"%s has no secret nickname"
%
s
)
Message
(
"%s has no secret nickname"
%
s
)
else
:
else
:
Message
(
"Hello everybody!!
\
n
The secret nickname of %s is %s!!!"
%
(
s
,
s2
))
Message
(
"Hello everybody!!
\
n
The secret nickname of %s is %s!!!"
%
(
s
,
s2
))
else
:
else
:
s
=
'Anonymous'
s
=
'Anonymous'
rv
=
AskFileForOpen
(
message
=
"Gimme a file, %s"
%
s
,
wanted
=
Carbon
.
File
.
FSSpec
)
rv
=
AskFileForOpen
(
message
=
"Gimme a file, %s"
%
s
,
wanted
=
Carbon
.
File
.
FSSpec
)
Message
(
"rv: %s"
%
rv
)
Message
(
"rv: %s"
%
rv
)
rv
=
AskFileForSave
(
wanted
=
Carbon
.
File
.
FSRef
,
savedFileName
=
"%s.txt"
%
s
)
rv
=
AskFileForSave
(
wanted
=
Carbon
.
File
.
FSRef
,
savedFileName
=
"%s.txt"
%
s
)
Message
(
"rv.as_pathname: %s"
%
rv
.
as_pathname
())
Message
(
"rv.as_pathname: %s"
%
rv
.
as_pathname
())
rv
=
AskFolder
()
rv
=
AskFolder
()
Message
(
"Folder name: %s"
%
rv
)
Message
(
"Folder name: %s"
%
rv
)
text
=
(
"Working Hard..."
,
"Hardly Working..."
,
text
=
(
"Working Hard..."
,
"Hardly Working..."
,
"So far, so good!"
,
"Keep on truckin'"
)
"So far, so good!"
,
"Keep on truckin'"
)
bar
=
ProgressBar
(
"Progress, progress..."
,
0
,
label
=
"Ramping up..."
)
bar
=
ProgressBar
(
"Progress, progress..."
,
0
,
label
=
"Ramping up..."
)
try
:
try
:
if
hasattr
(
MacOS
,
'SchedParams'
):
if
hasattr
(
MacOS
,
'SchedParams'
):
appsw
=
MacOS
.
SchedParams
(
1
,
0
)
appsw
=
MacOS
.
SchedParams
(
1
,
0
)
for
i
in
xrange
(
20
):
for
i
in
xrange
(
20
):
bar
.
inc
()
bar
.
inc
()
time
.
sleep
(
0.05
)
time
.
sleep
(
0.05
)
bar
.
set
(
0
,
100
)
bar
.
set
(
0
,
100
)
for
i
in
xrange
(
100
):
for
i
in
xrange
(
100
):
bar
.
set
(
i
)
bar
.
set
(
i
)
time
.
sleep
(
0.05
)
time
.
sleep
(
0.05
)
if
i
%
10
==
0
:
if
i
%
10
==
0
:
bar
.
label
(
text
[(
i
/
10
)
%
4
])
bar
.
label
(
text
[(
i
/
10
)
%
4
])
bar
.
label
(
"Done."
)
bar
.
label
(
"Done."
)
time
.
sleep
(
1.0
)
# give'em a chance to see "Done."
time
.
sleep
(
1.0
)
# give'em a chance to see "Done."
finally
:
finally
:
del
bar
del
bar
if
hasattr
(
MacOS
,
'SchedParams'
):
if
hasattr
(
MacOS
,
'SchedParams'
):
apply
(
MacOS
.
SchedParams
,
appsw
)
MacOS
.
SchedParams
(
*
appsw
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
try
:
try
:
test
()
test
()
except
KeyboardInterrupt
:
except
KeyboardInterrupt
:
Message
(
"Operation Canceled."
)
Message
(
"Operation Canceled."
)
Lib/plat-mac/FrameWork.py
View file @
ff41c48a
...
@@ -29,12 +29,12 @@ import types
...
@@ -29,12 +29,12 @@ import types
import
EasyDialogs
import
EasyDialogs
try
:
try
:
MyFrontWindow
=
FrontNonFloatingWindow
MyFrontWindow
=
FrontNonFloatingWindow
except
NameError
:
except
NameError
:
MyFrontWindow
=
FrontWindow
MyFrontWindow
=
FrontWindow
kHighLevelEvent
=
23
# Don't know what header file this should come from
kHighLevelEvent
=
23
# Don't know what header file this should come from
SCROLLBARWIDTH
=
16
# Again, not a clue...
SCROLLBARWIDTH
=
16
# Again, not a clue...
# Trick to forestall a set of SIOUX menus being added to our menubar
# Trick to forestall a set of SIOUX menus being added to our menubar
SIOUX_APPLEMENU_ID
=
32000
SIOUX_APPLEMENU_ID
=
32000
...
@@ -67,1057 +67,1057 @@ partname[8] = 'inZoomOut'
...
@@ -67,1057 +67,1057 @@ partname[8] = 'inZoomOut'
#
#
# The useable portion of the screen
# The useable portion of the screen
#
## but what happens with multiple screens? jvr
#
## but what happens with multiple screens? jvr
screenbounds
=
GetQDGlobalsScreenBits
().
bounds
screenbounds
=
GetQDGlobalsScreenBits
().
bounds
screenbounds
=
screenbounds
[
0
]
+
4
,
screenbounds
[
1
]
+
4
,
\
screenbounds
=
screenbounds
[
0
]
+
4
,
screenbounds
[
1
]
+
4
,
\
screenbounds
[
2
]
-
4
,
screenbounds
[
3
]
-
4
screenbounds
[
2
]
-
4
,
screenbounds
[
3
]
-
4
next_window_x
=
16
# jvr
next_window_x
=
16
# jvr
next_window_y
=
44
# jvr
next_window_y
=
44
# jvr
def
windowbounds
(
width
,
height
):
def
windowbounds
(
width
,
height
):
"Return sensible window bounds"
"Return sensible window bounds"
global
next_window_x
,
next_window_y
global
next_window_x
,
next_window_y
r
,
b
=
next_window_x
+
width
,
next_window_y
+
height
r
,
b
=
next_window_x
+
width
,
next_window_y
+
height
if
r
>
screenbounds
[
2
]:
if
r
>
screenbounds
[
2
]:
next_window_x
=
16
next_window_x
=
16
if
b
>
screenbounds
[
3
]:
if
b
>
screenbounds
[
3
]:
next_window_y
=
44
next_window_y
=
44
l
,
t
=
next_window_x
,
next_window_y
l
,
t
=
next_window_x
,
next_window_y
r
,
b
=
next_window_x
+
width
,
next_window_y
+
height
r
,
b
=
next_window_x
+
width
,
next_window_y
+
height
next_window_x
,
next_window_y
=
next_window_x
+
8
,
next_window_y
+
20
# jvr
next_window_x
,
next_window_y
=
next_window_x
+
8
,
next_window_y
+
20
# jvr
return
l
,
t
,
r
,
b
return
l
,
t
,
r
,
b
_watch
=
None
_watch
=
None
def
setwatchcursor
():
def
setwatchcursor
():
global
_watch
global
_watch
if
_watch
==
None
:
if
_watch
==
None
:
_watch
=
GetCursor
(
4
).
data
_watch
=
GetCursor
(
4
).
data
SetCursor
(
_watch
)
SetCursor
(
_watch
)
def
setarrowcursor
():
def
setarrowcursor
():
SetCursor
(
GetQDGlobalsArrow
())
SetCursor
(
GetQDGlobalsArrow
())
class
Application
:
class
Application
:
"Application framework -- your application should be a derived class"
"Application framework -- your application should be a derived class"
def
__init__
(
self
,
nomenubar
=
0
):
def
__init__
(
self
,
nomenubar
=
0
):
self
.
_doing_asyncevents
=
0
self
.
_doing_asyncevents
=
0
self
.
quitting
=
0
self
.
quitting
=
0
self
.
needmenubarredraw
=
0
self
.
needmenubarredraw
=
0
self
.
_windows
=
{}
self
.
_windows
=
{}
self
.
_helpmenu
=
None
self
.
_helpmenu
=
None
if
nomenubar
:
if
nomenubar
:
self
.
menubar
=
None
self
.
menubar
=
None
else
:
else
:
self
.
makemenubar
()
self
.
makemenubar
()
def
__del__
(
self
):
def
__del__
(
self
):
if
self
.
_doing_asyncevents
:
if
self
.
_doing_asyncevents
:
self
.
_doing_asyncevents
=
0
self
.
_doing_asyncevents
=
0
MacOS
.
SetEventHandler
()
MacOS
.
SetEventHandler
()
def
makemenubar
(
self
):
def
makemenubar
(
self
):
self
.
menubar
=
MenuBar
(
self
)
self
.
menubar
=
MenuBar
(
self
)
AppleMenu
(
self
.
menubar
,
self
.
getabouttext
(),
self
.
do_about
)
AppleMenu
(
self
.
menubar
,
self
.
getabouttext
(),
self
.
do_about
)
self
.
makeusermenus
()
self
.
makeusermenus
()
def
makeusermenus
(
self
):
def
makeusermenus
(
self
):
self
.
filemenu
=
m
=
Menu
(
self
.
menubar
,
"File"
)
self
.
filemenu
=
m
=
Menu
(
self
.
menubar
,
"File"
)
self
.
_quititem
=
MenuItem
(
m
,
"Quit"
,
"Q"
,
self
.
_quit
)
self
.
_quititem
=
MenuItem
(
m
,
"Quit"
,
"Q"
,
self
.
_quit
)
def
gethelpmenu
(
self
):
def
gethelpmenu
(
self
):
if
self
.
_helpmenu
==
None
:
if
self
.
_helpmenu
==
None
:
self
.
_helpmenu
=
HelpMenu
(
self
.
menubar
)
self
.
_helpmenu
=
HelpMenu
(
self
.
menubar
)
return
self
.
_helpmenu
return
self
.
_helpmenu
def
_quit
(
self
,
*
args
):
def
_quit
(
self
,
*
args
):
self
.
quitting
=
1
self
.
quitting
=
1
def
cleanup
(
self
):
def
cleanup
(
self
):
for
w
in
self
.
_windows
.
values
():
for
w
in
self
.
_windows
.
values
():
w
.
do_close
()
w
.
do_close
()
return
self
.
_windows
==
{}
return
self
.
_windows
==
{}
def
appendwindow
(
self
,
wid
,
window
):
def
appendwindow
(
self
,
wid
,
window
):
self
.
_windows
[
wid
]
=
window
self
.
_windows
[
wid
]
=
window
def
removewindow
(
self
,
wid
):
def
removewindow
(
self
,
wid
):
del
self
.
_windows
[
wid
]
del
self
.
_windows
[
wid
]
def
getabouttext
(
self
):
def
getabouttext
(
self
):
return
"About %s..."
%
self
.
__class__
.
__name__
return
"About %s..."
%
self
.
__class__
.
__name__
def
do_about
(
self
,
id
,
item
,
window
,
event
):
def
do_about
(
self
,
id
,
item
,
window
,
event
):
EasyDialogs
.
Message
(
"Hello, world!"
+
"
\
015
(%s)"
%
self
.
__class__
.
__name__
)
EasyDialogs
.
Message
(
"Hello, world!"
+
"
\
015
(%s)"
%
self
.
__class__
.
__name__
)
# The main event loop is broken up in several simple steps.
# The main event loop is broken up in several simple steps.
# This is done so you can override each individual part,
# This is done so you can override each individual part,
# if you have a need to do extra processing independent of the
# if you have a need to do extra processing independent of the
# event type.
# event type.
# Normally, however, you'd just define handlers for individual
# Normally, however, you'd just define handlers for individual
# events.
# events.
schedparams
=
(
0
,
0
)
# By default disable Python's event handling
schedparams
=
(
0
,
0
)
# By default disable Python's event handling
default_wait
=
None
# By default we wait GetCaretTime in WaitNextEvent
default_wait
=
None
# By default we wait GetCaretTime in WaitNextEvent
def
mainloop
(
self
,
mask
=
everyEvent
,
wait
=
None
):
def
mainloop
(
self
,
mask
=
everyEvent
,
wait
=
None
):
self
.
quitting
=
0
self
.
quitting
=
0
if
hasattr
(
MacOS
,
'SchedParams'
):
if
hasattr
(
MacOS
,
'SchedParams'
):
saveparams
=
apply
(
MacOS
.
SchedParams
,
self
.
schedparams
)
saveparams
=
MacOS
.
SchedParams
(
*
self
.
schedparams
)
try
:
try
:
while
not
self
.
quitting
:
while
not
self
.
quitting
:
try
:
try
:
self
.
do1event
(
mask
,
wait
)
self
.
do1event
(
mask
,
wait
)
except
(
Application
,
SystemExit
):
except
(
Application
,
SystemExit
):
# Note: the raising of "self" is old-fashioned idiom to
# Note: the raising of "self" is old-fashioned idiom to
# exit the mainloop. Calling _quit() is better for new
# exit the mainloop. Calling _quit() is better for new
# applications.
# applications.
break
break
finally
:
finally
:
if
hasattr
(
MacOS
,
'SchedParams'
):
if
hasattr
(
MacOS
,
'SchedParams'
):
apply
(
MacOS
.
SchedParams
,
saveparams
)
MacOS
.
SchedParams
(
*
saveparams
)
def
dopendingevents
(
self
,
mask
=
everyEvent
):
def
dopendingevents
(
self
,
mask
=
everyEvent
):
"""dopendingevents - Handle all pending events"""
"""dopendingevents - Handle all pending events"""
while
self
.
do1event
(
mask
,
wait
=
0
):
while
self
.
do1event
(
mask
,
wait
=
0
):
pass
pass
def
do1event
(
self
,
mask
=
everyEvent
,
wait
=
None
):
def
do1event
(
self
,
mask
=
everyEvent
,
wait
=
None
):
ok
,
event
=
self
.
getevent
(
mask
,
wait
)
ok
,
event
=
self
.
getevent
(
mask
,
wait
)
if
IsDialogEvent
(
event
):
if
IsDialogEvent
(
event
):
if
self
.
do_dialogevent
(
event
):
if
self
.
do_dialogevent
(
event
):
return
return
if
ok
:
if
ok
:
self
.
dispatch
(
event
)
self
.
dispatch
(
event
)
else
:
else
:
self
.
idle
(
event
)
self
.
idle
(
event
)
def
idle
(
self
,
event
):
def
idle
(
self
,
event
):
pass
pass
def
getevent
(
self
,
mask
=
everyEvent
,
wait
=
None
):
def
getevent
(
self
,
mask
=
everyEvent
,
wait
=
None
):
if
self
.
needmenubarredraw
:
if
self
.
needmenubarredraw
:
DrawMenuBar
()
DrawMenuBar
()
self
.
needmenubarredraw
=
0
self
.
needmenubarredraw
=
0
if
wait
is
None
:
if
wait
is
None
:
wait
=
self
.
default_wait
wait
=
self
.
default_wait
if
wait
is
None
:
if
wait
is
None
:
wait
=
GetCaretTime
()
wait
=
GetCaretTime
()
ok
,
event
=
WaitNextEvent
(
mask
,
wait
)
ok
,
event
=
WaitNextEvent
(
mask
,
wait
)
return
ok
,
event
return
ok
,
event
def
dispatch
(
self
,
event
):
def
dispatch
(
self
,
event
):
# The following appears to be double work (already done in do1event)
# The following appears to be double work (already done in do1event)
# but we need it for asynchronous event handling
# but we need it for asynchronous event handling
if
IsDialogEvent
(
event
):
if
IsDialogEvent
(
event
):
if
self
.
do_dialogevent
(
event
):
if
self
.
do_dialogevent
(
event
):
return
return
(
what
,
message
,
when
,
where
,
modifiers
)
=
event
(
what
,
message
,
when
,
where
,
modifiers
)
=
event
if
eventname
.
has_key
(
what
):
if
eventname
.
has_key
(
what
):
name
=
"do_"
+
eventname
[
what
]
name
=
"do_"
+
eventname
[
what
]
else
:
else
:
name
=
"do_%d"
%
what
name
=
"do_%d"
%
what
try
:
try
:
handler
=
getattr
(
self
,
name
)
handler
=
getattr
(
self
,
name
)
except
AttributeError
:
except
AttributeError
:
handler
=
self
.
do_unknownevent
handler
=
self
.
do_unknownevent
handler
(
event
)
handler
(
event
)
def
asyncevents
(
self
,
onoff
):
def
asyncevents
(
self
,
onoff
):
"""asyncevents - Set asynchronous event handling on or off"""
"""asyncevents - Set asynchronous event handling on or off"""
if
MacOS
.
runtimemodel
==
'macho'
:
if
MacOS
.
runtimemodel
==
'macho'
:
raise
'Unsupported in MachoPython'
raise
'Unsupported in MachoPython'
old
=
self
.
_doing_asyncevents
old
=
self
.
_doing_asyncevents
if
old
:
if
old
:
MacOS
.
SetEventHandler
()
MacOS
.
SetEventHandler
()
apply
(
MacOS
.
SchedParams
,
self
.
schedparams
)
MacOS
.
SchedParams
(
*
self
.
schedparams
)
if
onoff
:
if
onoff
:
MacOS
.
SetEventHandler
(
self
.
dispatch
)
MacOS
.
SetEventHandler
(
self
.
dispatch
)
doint
,
dummymask
,
benice
,
howoften
,
bgyield
=
\
doint
,
dummymask
,
benice
,
howoften
,
bgyield
=
\
self
.
schedparams
self
.
schedparams
MacOS
.
SchedParams
(
doint
,
everyEvent
,
benice
,
MacOS
.
SchedParams
(
doint
,
everyEvent
,
benice
,
howoften
,
bgyield
)
howoften
,
bgyield
)
self
.
_doing_asyncevents
=
onoff
self
.
_doing_asyncevents
=
onoff
return
old
return
old
def
do_dialogevent
(
self
,
event
):
def
do_dialogevent
(
self
,
event
):
gotone
,
dlg
,
item
=
DialogSelect
(
event
)
gotone
,
dlg
,
item
=
DialogSelect
(
event
)
if
gotone
:
if
gotone
:
window
=
dlg
.
GetDialogWindow
()
window
=
dlg
.
GetDialogWindow
()
if
self
.
_windows
.
has_key
(
window
):
if
self
.
_windows
.
has_key
(
window
):
self
.
_windows
[
window
].
do_itemhit
(
item
,
event
)
self
.
_windows
[
window
].
do_itemhit
(
item
,
event
)
else
:
else
:
print
'Dialog event for unknown dialog'
print
'Dialog event for unknown dialog'
return
1
return
1
return
0
return
0
def
do_mouseDown
(
self
,
event
):
def
do_mouseDown
(
self
,
event
):
(
what
,
message
,
when
,
where
,
modifiers
)
=
event
(
what
,
message
,
when
,
where
,
modifiers
)
=
event
partcode
,
wid
=
FindWindow
(
where
)
partcode
,
wid
=
FindWindow
(
where
)
#
#
# Find the correct name.
# Find the correct name.
#
#
if
partname
.
has_key
(
partcode
):
if
partname
.
has_key
(
partcode
):
name
=
"do_"
+
partname
[
partcode
]
name
=
"do_"
+
partname
[
partcode
]
else
:
else
:
name
=
"do_%d"
%
partcode
name
=
"do_%d"
%
partcode
if
wid
==
None
:
if
wid
==
None
:
# No window, or a non-python window
# No window, or a non-python window
try
:
try
:
handler
=
getattr
(
self
,
name
)
handler
=
getattr
(
self
,
name
)
except
AttributeError
:
except
AttributeError
:
# Not menubar or something, so assume someone
# Not menubar or something, so assume someone
# else's window
# else's window
if
hasattr
(
MacOS
,
'HandleEvent'
):
if
hasattr
(
MacOS
,
'HandleEvent'
):
MacOS
.
HandleEvent
(
event
)
MacOS
.
HandleEvent
(
event
)
return
return
elif
self
.
_windows
.
has_key
(
wid
):
elif
self
.
_windows
.
has_key
(
wid
):
# It is a window. Hand off to correct window.
# It is a window. Hand off to correct window.
window
=
self
.
_windows
[
wid
]
window
=
self
.
_windows
[
wid
]
try
:
try
:
handler
=
getattr
(
window
,
name
)
handler
=
getattr
(
window
,
name
)
except
AttributeError
:
except
AttributeError
:
handler
=
self
.
do_unknownpartcode
handler
=
self
.
do_unknownpartcode
else
:
else
:
# It is a python-toolbox window, but not ours.
# It is a python-toolbox window, but not ours.
handler
=
self
.
do_unknownwindow
handler
=
self
.
do_unknownwindow
handler
(
partcode
,
wid
,
event
)
handler
(
partcode
,
wid
,
event
)
def
do_inSysWindow
(
self
,
partcode
,
window
,
event
):
def
do_inSysWindow
(
self
,
partcode
,
window
,
event
):
if
hasattr
(
MacOS
,
'HandleEvent'
):
if
hasattr
(
MacOS
,
'HandleEvent'
):
MacOS
.
HandleEvent
(
event
)
MacOS
.
HandleEvent
(
event
)
def
do_inDesk
(
self
,
partcode
,
window
,
event
):
def
do_inDesk
(
self
,
partcode
,
window
,
event
):
if
hasattr
(
MacOS
,
'HandleEvent'
):
if
hasattr
(
MacOS
,
'HandleEvent'
):
MacOS
.
HandleEvent
(
event
)
MacOS
.
HandleEvent
(
event
)
def
do_inMenuBar
(
self
,
partcode
,
window
,
event
):
def
do_inMenuBar
(
self
,
partcode
,
window
,
event
):
if
not
self
.
menubar
:
if
not
self
.
menubar
:
if
hasattr
(
MacOS
,
'HandleEvent'
):
if
hasattr
(
MacOS
,
'HandleEvent'
):
MacOS
.
HandleEvent
(
event
)
MacOS
.
HandleEvent
(
event
)
return
return
(
what
,
message
,
when
,
where
,
modifiers
)
=
event
(
what
,
message
,
when
,
where
,
modifiers
)
=
event
result
=
MenuSelect
(
where
)
result
=
MenuSelect
(
where
)
id
=
(
result
>>
16
)
&
0xffff
# Hi word
id
=
(
result
>>
16
)
&
0xffff
# Hi word
if
id
>=
0x8000
:
if
id
>=
0x8000
:
id
=
-
65536
+
id
id
=
-
65536
+
id
item
=
result
&
0xffff
# Lo word
item
=
result
&
0xffff
# Lo word
self
.
do_rawmenu
(
id
,
item
,
window
,
event
)
self
.
do_rawmenu
(
id
,
item
,
window
,
event
)
def
do_rawmenu
(
self
,
id
,
item
,
window
,
event
):
def
do_rawmenu
(
self
,
id
,
item
,
window
,
event
):
try
:
try
:
self
.
do_menu
(
id
,
item
,
window
,
event
)
self
.
do_menu
(
id
,
item
,
window
,
event
)
finally
:
finally
:
HiliteMenu
(
0
)
HiliteMenu
(
0
)
def
do_menu
(
self
,
id
,
item
,
window
,
event
):
def
do_menu
(
self
,
id
,
item
,
window
,
event
):
if
hasattr
(
MacOS
,
'OutputSeen'
):
if
hasattr
(
MacOS
,
'OutputSeen'
):
MacOS
.
OutputSeen
()
MacOS
.
OutputSeen
()
self
.
menubar
.
dispatch
(
id
,
item
,
window
,
event
)
self
.
menubar
.
dispatch
(
id
,
item
,
window
,
event
)
def
do_unknownpartcode
(
self
,
partcode
,
window
,
event
):
def
do_unknownpartcode
(
self
,
partcode
,
window
,
event
):
(
what
,
message
,
when
,
where
,
modifiers
)
=
event
(
what
,
message
,
when
,
where
,
modifiers
)
=
event
if
DEBUG
:
print
"Mouse down at global:"
,
where
if
DEBUG
:
print
"Mouse down at global:"
,
where
if
DEBUG
:
print
"
\
t
Unknown part code:"
,
partcode
if
DEBUG
:
print
"
\
t
Unknown part code:"
,
partcode
if
DEBUG
:
print
"
\
t
Event:"
,
self
.
printevent
(
event
)
if
DEBUG
:
print
"
\
t
Event:"
,
self
.
printevent
(
event
)
if
hasattr
(
MacOS
,
'HandleEvent'
):
if
hasattr
(
MacOS
,
'HandleEvent'
):
MacOS
.
HandleEvent
(
event
)
MacOS
.
HandleEvent
(
event
)
def
do_unknownwindow
(
self
,
partcode
,
window
,
event
):
def
do_unknownwindow
(
self
,
partcode
,
window
,
event
):
if
DEBUG
:
print
'Unknown window:'
,
window
if
DEBUG
:
print
'Unknown window:'
,
window
if
hasattr
(
MacOS
,
'HandleEvent'
):
if
hasattr
(
MacOS
,
'HandleEvent'
):
MacOS
.
HandleEvent
(
event
)
MacOS
.
HandleEvent
(
event
)
def
do_keyDown
(
self
,
event
):
def
do_keyDown
(
self
,
event
):
self
.
do_key
(
event
)
self
.
do_key
(
event
)
def
do_autoKey
(
self
,
event
):
def
do_autoKey
(
self
,
event
):
if
not
event
[
-
1
]
&
cmdKey
:
if
not
event
[
-
1
]
&
cmdKey
:
self
.
do_key
(
event
)
self
.
do_key
(
event
)
def
do_key
(
self
,
event
):
def
do_key
(
self
,
event
):
(
what
,
message
,
when
,
where
,
modifiers
)
=
event
(
what
,
message
,
when
,
where
,
modifiers
)
=
event
c
=
chr
(
message
&
charCodeMask
)
c
=
chr
(
message
&
charCodeMask
)
if
self
.
menubar
:
if
self
.
menubar
:
result
=
MenuEvent
(
event
)
result
=
MenuEvent
(
event
)
id
=
(
result
>>
16
)
&
0xffff
# Hi word
id
=
(
result
>>
16
)
&
0xffff
# Hi word
item
=
result
&
0xffff
# Lo word
item
=
result
&
0xffff
# Lo word
if
id
:
if
id
:
self
.
do_rawmenu
(
id
,
item
,
None
,
event
)
self
.
do_rawmenu
(
id
,
item
,
None
,
event
)
return
return
# Otherwise we fall-through
# Otherwise we fall-through
if
modifiers
&
cmdKey
:
if
modifiers
&
cmdKey
:
if
c
==
'.'
:
if
c
==
'.'
:
raise
self
raise
self
else
:
else
:
if
not
self
.
menubar
:
if
not
self
.
menubar
:
if
hasattr
(
MacOS
,
'HandleEvent'
):
if
hasattr
(
MacOS
,
'HandleEvent'
):
MacOS
.
HandleEvent
(
event
)
MacOS
.
HandleEvent
(
event
)
return
return
else
:
else
:
# See whether the front window wants it
# See whether the front window wants it
w
=
MyFrontWindow
()
w
=
MyFrontWindow
()
if
w
and
self
.
_windows
.
has_key
(
w
):
if
w
and
self
.
_windows
.
has_key
(
w
):
window
=
self
.
_windows
[
w
]
window
=
self
.
_windows
[
w
]
try
:
try
:
do_char
=
window
.
do_char
do_char
=
window
.
do_char
except
AttributeError
:
except
AttributeError
:
do_char
=
self
.
do_char
do_char
=
self
.
do_char
do_char
(
c
,
event
)
do_char
(
c
,
event
)
# else it wasn't for us, sigh...
# else it wasn't for us, sigh...
def
do_char
(
self
,
c
,
event
):
def
do_char
(
self
,
c
,
event
):
if
DEBUG
:
print
"Character"
,
`c`
if
DEBUG
:
print
"Character"
,
`c`
def
do_updateEvt
(
self
,
event
):
def
do_updateEvt
(
self
,
event
):
(
what
,
message
,
when
,
where
,
modifiers
)
=
event
(
what
,
message
,
when
,
where
,
modifiers
)
=
event
wid
=
WhichWindow
(
message
)
wid
=
WhichWindow
(
message
)
if
wid
and
self
.
_windows
.
has_key
(
wid
):
if
wid
and
self
.
_windows
.
has_key
(
wid
):
window
=
self
.
_windows
[
wid
]
window
=
self
.
_windows
[
wid
]
window
.
do_rawupdate
(
wid
,
event
)
window
.
do_rawupdate
(
wid
,
event
)
else
:
else
:
if
hasattr
(
MacOS
,
'HandleEvent'
):
if
hasattr
(
MacOS
,
'HandleEvent'
):
MacOS
.
HandleEvent
(
event
)
MacOS
.
HandleEvent
(
event
)
def
do_activateEvt
(
self
,
event
):
def
do_activateEvt
(
self
,
event
):
(
what
,
message
,
when
,
where
,
modifiers
)
=
event
(
what
,
message
,
when
,
where
,
modifiers
)
=
event
wid
=
WhichWindow
(
message
)
wid
=
WhichWindow
(
message
)
if
wid
and
self
.
_windows
.
has_key
(
wid
):
if
wid
and
self
.
_windows
.
has_key
(
wid
):
window
=
self
.
_windows
[
wid
]
window
=
self
.
_windows
[
wid
]
window
.
do_activate
(
modifiers
&
1
,
event
)
window
.
do_activate
(
modifiers
&
1
,
event
)
else
:
else
:
if
hasattr
(
MacOS
,
'HandleEvent'
):
if
hasattr
(
MacOS
,
'HandleEvent'
):
MacOS
.
HandleEvent
(
event
)
MacOS
.
HandleEvent
(
event
)
def
do_osEvt
(
self
,
event
):
def
do_osEvt
(
self
,
event
):
(
what
,
message
,
when
,
where
,
modifiers
)
=
event
(
what
,
message
,
when
,
where
,
modifiers
)
=
event
which
=
(
message
>>
24
)
&
0xff
which
=
(
message
>>
24
)
&
0xff
if
which
==
1
:
# suspend/resume
if
which
==
1
:
# suspend/resume
self
.
do_suspendresume
(
event
)
self
.
do_suspendresume
(
event
)
else
:
else
:
if
DEBUG
:
if
DEBUG
:
print
'unknown osEvt:'
,
print
'unknown osEvt:'
,
self
.
printevent
(
event
)
self
.
printevent
(
event
)
def
do_suspendresume
(
self
,
event
):
def
do_suspendresume
(
self
,
event
):
(
what
,
message
,
when
,
where
,
modifiers
)
=
event
(
what
,
message
,
when
,
where
,
modifiers
)
=
event
wid
=
MyFrontWindow
()
wid
=
MyFrontWindow
()
if
wid
and
self
.
_windows
.
has_key
(
wid
):
if
wid
and
self
.
_windows
.
has_key
(
wid
):
window
=
self
.
_windows
[
wid
]
window
=
self
.
_windows
[
wid
]
window
.
do_activate
(
message
&
1
,
event
)
window
.
do_activate
(
message
&
1
,
event
)
def
do_kHighLevelEvent
(
self
,
event
):
def
do_kHighLevelEvent
(
self
,
event
):
(
what
,
message
,
when
,
where
,
modifiers
)
=
event
(
what
,
message
,
when
,
where
,
modifiers
)
=
event
if
DEBUG
:
if
DEBUG
:
print
"High Level Event:"
,
print
"High Level Event:"
,
self
.
printevent
(
event
)
self
.
printevent
(
event
)
try
:
try
:
AEProcessAppleEvent
(
event
)
AEProcessAppleEvent
(
event
)
except
:
except
:
pass
pass
#print "AEProcessAppleEvent error:"
#print "AEProcessAppleEvent error:"
#traceback.print_exc()
#traceback.print_exc()
def
do_unknownevent
(
self
,
event
):
def
do_unknownevent
(
self
,
event
):
if
DEBUG
:
if
DEBUG
:
print
"Unhandled event:"
,
print
"Unhandled event:"
,
self
.
printevent
(
event
)
self
.
printevent
(
event
)
def
printevent
(
self
,
event
):
def
printevent
(
self
,
event
):
(
what
,
message
,
when
,
where
,
modifiers
)
=
event
(
what
,
message
,
when
,
where
,
modifiers
)
=
event
nicewhat
=
`what`
nicewhat
=
`what`
if
eventname
.
has_key
(
what
):
if
eventname
.
has_key
(
what
):
nicewhat
=
eventname
[
what
]
nicewhat
=
eventname
[
what
]
print
nicewhat
,
print
nicewhat
,
if
what
==
kHighLevelEvent
:
if
what
==
kHighLevelEvent
:
h
,
v
=
where
h
,
v
=
where
print
`ostypecode(message)`
,
hex
(
when
),
`ostypecode(h | (v<<16))`
,
print
`ostypecode(message)`
,
hex
(
when
),
`ostypecode(h | (v<<16))`
,
else
:
else
:
print
hex
(
message
),
hex
(
when
),
where
,
print
hex
(
message
),
hex
(
when
),
where
,
print
hex
(
modifiers
)
print
hex
(
modifiers
)
class
MenuBar
:
class
MenuBar
:
"""Represent a set of menus in a menu bar.
"""Represent a set of menus in a menu bar.
Interface:
Interface:
- (constructor)
- (constructor)
- (destructor)
- (destructor)
- addmenu
- addmenu
- addpopup (normally used internally)
- addpopup (normally used internally)
- dispatch (called from Application)
- dispatch (called from Application)
"""
"""
nextid
=
1
# Necessarily a class variable
nextid
=
1
# Necessarily a class variable
def
getnextid
(
self
):
def
getnextid
(
self
):
id
=
MenuBar
.
nextid
id
=
MenuBar
.
nextid
MenuBar
.
nextid
=
id
+
1
MenuBar
.
nextid
=
id
+
1
return
id
return
id
def
__init__
(
self
,
parent
=
None
):
def
__init__
(
self
,
parent
=
None
):
self
.
parent
=
parent
self
.
parent
=
parent
ClearMenuBar
()
ClearMenuBar
()
self
.
bar
=
GetMenuBar
()
self
.
bar
=
GetMenuBar
()
self
.
menus
=
{}
self
.
menus
=
{}
# XXX necessary?
# XXX necessary?
def
close
(
self
):
def
close
(
self
):
self
.
parent
=
None
self
.
parent
=
None
self
.
bar
=
None
self
.
bar
=
None
self
.
menus
=
None
self
.
menus
=
None
def
addmenu
(
self
,
title
,
after
=
0
,
id
=
None
):
def
addmenu
(
self
,
title
,
after
=
0
,
id
=
None
):
if
id
==
None
:
if
id
==
None
:
id
=
self
.
getnextid
()
id
=
self
.
getnextid
()
if
DEBUG
:
print
'Newmenu'
,
title
,
id
# XXXX
if
DEBUG
:
print
'Newmenu'
,
title
,
id
# XXXX
m
=
NewMenu
(
id
,
title
)
m
=
NewMenu
(
id
,
title
)
m
.
InsertMenu
(
after
)
m
.
InsertMenu
(
after
)
if
after
>=
0
:
if
after
>=
0
:
if
self
.
parent
:
if
self
.
parent
:
self
.
parent
.
needmenubarredraw
=
1
self
.
parent
.
needmenubarredraw
=
1
else
:
else
:
DrawMenuBar
()
DrawMenuBar
()
return
id
,
m
return
id
,
m
def
delmenu
(
self
,
id
):
def
delmenu
(
self
,
id
):
if
DEBUG
:
print
'Delmenu'
,
id
# XXXX
if
DEBUG
:
print
'Delmenu'
,
id
# XXXX
DeleteMenu
(
id
)
DeleteMenu
(
id
)
def
addpopup
(
self
,
title
=
''
):
def
addpopup
(
self
,
title
=
''
):
return
self
.
addmenu
(
title
,
-
1
)
return
self
.
addmenu
(
title
,
-
1
)
# Useless:
# Useless:
#
def install(self):
#
def install(self):
#
if not self.bar: return
#
if not self.bar: return
#
SetMenuBar(self.bar)
#
SetMenuBar(self.bar)
#
if self.parent:
#
if self.parent:
#
self.parent.needmenubarredraw = 1
#
self.parent.needmenubarredraw = 1
#
else:
#
else:
#
DrawMenuBar()
#
DrawMenuBar()
def
fixmenudimstate
(
self
):
def
fixmenudimstate
(
self
):
for
m
in
self
.
menus
.
keys
():
for
m
in
self
.
menus
.
keys
():
menu
=
self
.
menus
[
m
]
menu
=
self
.
menus
[
m
]
if
menu
.
__class__
==
FrameWork
.
AppleMenu
:
if
menu
.
__class__
==
FrameWork
.
AppleMenu
:
continue
continue
for
i
in
range
(
len
(
menu
.
items
)):
for
i
in
range
(
len
(
menu
.
items
)):
label
,
shortcut
,
callback
,
kind
=
menu
.
items
[
i
]
label
,
shortcut
,
callback
,
kind
=
menu
.
items
[
i
]
if
type
(
callback
)
==
types
.
StringType
:
if
type
(
callback
)
==
types
.
StringType
:
wid
=
MyFrontWindow
()
wid
=
MyFrontWindow
()
if
wid
and
self
.
parent
.
_windows
.
has_key
(
wid
):
if
wid
and
self
.
parent
.
_windows
.
has_key
(
wid
):
window
=
self
.
parent
.
_windows
[
wid
]
window
=
self
.
parent
.
_windows
[
wid
]
if
hasattr
(
window
,
"domenu_"
+
callback
):
if
hasattr
(
window
,
"domenu_"
+
callback
):
menu
.
menu
.
EnableMenuItem
(
i
+
1
)
menu
.
menu
.
EnableMenuItem
(
i
+
1
)
elif
hasattr
(
self
.
parent
,
"domenu_"
+
callback
):
elif
hasattr
(
self
.
parent
,
"domenu_"
+
callback
):
menu
.
menu
.
EnableMenuItem
(
i
+
1
)
menu
.
menu
.
EnableMenuItem
(
i
+
1
)
else
:
else
:
menu
.
menu
.
DisableMenuItem
(
i
+
1
)
menu
.
menu
.
DisableMenuItem
(
i
+
1
)
elif
hasattr
(
self
.
parent
,
"domenu_"
+
callback
):
elif
hasattr
(
self
.
parent
,
"domenu_"
+
callback
):
menu
.
menu
.
EnableMenuItem
(
i
+
1
)
menu
.
menu
.
EnableMenuItem
(
i
+
1
)
else
:
else
:
menu
.
menu
.
DisableMenuItem
(
i
+
1
)
menu
.
menu
.
DisableMenuItem
(
i
+
1
)
elif
callback
:
elif
callback
:
pass
pass
def
dispatch
(
self
,
id
,
item
,
window
,
event
):
def
dispatch
(
self
,
id
,
item
,
window
,
event
):
if
self
.
menus
.
has_key
(
id
):
if
self
.
menus
.
has_key
(
id
):
self
.
menus
[
id
].
dispatch
(
id
,
item
,
window
,
event
)
self
.
menus
[
id
].
dispatch
(
id
,
item
,
window
,
event
)
else
:
else
:
if
DEBUG
:
print
"MenuBar.dispatch(%d, %d, %s, %s)"
%
\
if
DEBUG
:
print
"MenuBar.dispatch(%d, %d, %s, %s)"
%
\
(
id
,
item
,
window
,
event
)
(
id
,
item
,
window
,
event
)
# XXX Need a way to get menus as resources and bind them to callbacks
# XXX Need a way to get menus as resources and bind them to callbacks
class
Menu
:
class
Menu
:
"One menu."
"One menu."
def
__init__
(
self
,
bar
,
title
,
after
=
0
,
id
=
None
):
def
__init__
(
self
,
bar
,
title
,
after
=
0
,
id
=
None
):
self
.
bar
=
bar
self
.
bar
=
bar
self
.
id
,
self
.
menu
=
self
.
bar
.
addmenu
(
title
,
after
,
id
)
self
.
id
,
self
.
menu
=
self
.
bar
.
addmenu
(
title
,
after
,
id
)
bar
.
menus
[
self
.
id
]
=
self
bar
.
menus
[
self
.
id
]
=
self
self
.
items
=
[]
self
.
items
=
[]
self
.
_parent
=
None
self
.
_parent
=
None
def
delete
(
self
):
def
delete
(
self
):
self
.
bar
.
delmenu
(
self
.
id
)
self
.
bar
.
delmenu
(
self
.
id
)
del
self
.
bar
.
menus
[
self
.
id
]
del
self
.
bar
.
menus
[
self
.
id
]
self
.
menu
.
DisposeMenu
()
self
.
menu
.
DisposeMenu
()
del
self
.
bar
del
self
.
bar
del
self
.
items
del
self
.
items
del
self
.
menu
del
self
.
menu
del
self
.
id
del
self
.
id
del
self
.
_parent
del
self
.
_parent
def
additem
(
self
,
label
,
shortcut
=
None
,
callback
=
None
,
kind
=
None
):
def
additem
(
self
,
label
,
shortcut
=
None
,
callback
=
None
,
kind
=
None
):
self
.
menu
.
AppendMenu
(
'x'
)
# add a dummy string
self
.
menu
.
AppendMenu
(
'x'
)
# add a dummy string
self
.
items
.
append
((
label
,
shortcut
,
callback
,
kind
))
self
.
items
.
append
((
label
,
shortcut
,
callback
,
kind
))
item
=
len
(
self
.
items
)
item
=
len
(
self
.
items
)
if
isinstance
(
label
,
unicode
):
if
isinstance
(
label
,
unicode
):
self
.
menu
.
SetMenuItemTextWithCFString
(
item
,
label
)
self
.
menu
.
SetMenuItemTextWithCFString
(
item
,
label
)
else
:
else
:
self
.
menu
.
SetMenuItemText
(
item
,
label
)
self
.
menu
.
SetMenuItemText
(
item
,
label
)
if
shortcut
and
type
(
shortcut
)
==
type
(()):
if
shortcut
and
type
(
shortcut
)
==
type
(()):
modifiers
,
char
=
shortcut
[:
2
]
modifiers
,
char
=
shortcut
[:
2
]
self
.
menu
.
SetItemCmd
(
item
,
ord
(
char
))
self
.
menu
.
SetItemCmd
(
item
,
ord
(
char
))
self
.
menu
.
SetMenuItemModifiers
(
item
,
modifiers
)
self
.
menu
.
SetMenuItemModifiers
(
item
,
modifiers
)
if
len
(
shortcut
)
>
2
:
if
len
(
shortcut
)
>
2
:
self
.
menu
.
SetMenuItemKeyGlyph
(
item
,
shortcut
[
2
])
self
.
menu
.
SetMenuItemKeyGlyph
(
item
,
shortcut
[
2
])
elif
shortcut
:
elif
shortcut
:
self
.
menu
.
SetItemCmd
(
item
,
ord
(
shortcut
))
self
.
menu
.
SetItemCmd
(
item
,
ord
(
shortcut
))
return
item
return
item
def
delitem
(
self
,
item
):
def
delitem
(
self
,
item
):
if
item
!=
len
(
self
.
items
):
if
item
!=
len
(
self
.
items
):
raise
'Can only delete last item of a menu'
raise
'Can only delete last item of a menu'
self
.
menu
.
DeleteMenuItem
(
item
)
self
.
menu
.
DeleteMenuItem
(
item
)
del
self
.
items
[
item
-
1
]
del
self
.
items
[
item
-
1
]
def
addcheck
(
self
,
label
,
shortcut
=
None
,
callback
=
None
):
def
addcheck
(
self
,
label
,
shortcut
=
None
,
callback
=
None
):
return
self
.
additem
(
label
,
shortcut
,
callback
,
'check'
)
return
self
.
additem
(
label
,
shortcut
,
callback
,
'check'
)
def
addradio
(
self
,
label
,
shortcut
=
None
,
callback
=
None
):
def
addradio
(
self
,
label
,
shortcut
=
None
,
callback
=
None
):
return
self
.
additem
(
label
,
shortcut
,
callback
,
'radio'
)
return
self
.
additem
(
label
,
shortcut
,
callback
,
'radio'
)
def
addseparator
(
self
):
def
addseparator
(
self
):
self
.
menu
.
AppendMenu
(
'(-'
)
self
.
menu
.
AppendMenu
(
'(-'
)
self
.
items
.
append
((
''
,
None
,
None
,
'separator'
))
self
.
items
.
append
((
''
,
None
,
None
,
'separator'
))
def
addsubmenu
(
self
,
label
,
title
=
''
):
def
addsubmenu
(
self
,
label
,
title
=
''
):
sub
=
Menu
(
self
.
bar
,
title
,
-
1
)
sub
=
Menu
(
self
.
bar
,
title
,
-
1
)
item
=
self
.
additem
(
label
,
'
\
x1B
'
,
None
,
'submenu'
)
item
=
self
.
additem
(
label
,
'
\
x1B
'
,
None
,
'submenu'
)
self
.
menu
.
SetItemMark
(
item
,
sub
.
id
)
self
.
menu
.
SetItemMark
(
item
,
sub
.
id
)
sub
.
_parent
=
self
sub
.
_parent
=
self
sub
.
_parent_item
=
item
sub
.
_parent_item
=
item
return
sub
return
sub
def
dispatch
(
self
,
id
,
item
,
window
,
event
):
def
dispatch
(
self
,
id
,
item
,
window
,
event
):
title
,
shortcut
,
callback
,
mtype
=
self
.
items
[
item
-
1
]
title
,
shortcut
,
callback
,
mtype
=
self
.
items
[
item
-
1
]
if
callback
:
if
callback
:
if
not
self
.
bar
.
parent
or
type
(
callback
)
<>
types
.
StringType
:
if
not
self
.
bar
.
parent
or
type
(
callback
)
<>
types
.
StringType
:
menuhandler
=
callback
menuhandler
=
callback
else
:
else
:
# callback is string
# callback is string
wid
=
MyFrontWindow
()
wid
=
MyFrontWindow
()
if
wid
and
self
.
bar
.
parent
.
_windows
.
has_key
(
wid
):
if
wid
and
self
.
bar
.
parent
.
_windows
.
has_key
(
wid
):
window
=
self
.
bar
.
parent
.
_windows
[
wid
]
window
=
self
.
bar
.
parent
.
_windows
[
wid
]
if
hasattr
(
window
,
"domenu_"
+
callback
):
if
hasattr
(
window
,
"domenu_"
+
callback
):
menuhandler
=
getattr
(
window
,
"domenu_"
+
callback
)
menuhandler
=
getattr
(
window
,
"domenu_"
+
callback
)
elif
hasattr
(
self
.
bar
.
parent
,
"domenu_"
+
callback
):
elif
hasattr
(
self
.
bar
.
parent
,
"domenu_"
+
callback
):
menuhandler
=
getattr
(
self
.
bar
.
parent
,
"domenu_"
+
callback
)
menuhandler
=
getattr
(
self
.
bar
.
parent
,
"domenu_"
+
callback
)
else
:
else
:
# nothing we can do. we shouldn't have come this far
# nothing we can do. we shouldn't have come this far
# since the menu item should have been disabled...
# since the menu item should have been disabled...
return
return
elif
hasattr
(
self
.
bar
.
parent
,
"domenu_"
+
callback
):
elif
hasattr
(
self
.
bar
.
parent
,
"domenu_"
+
callback
):
menuhandler
=
getattr
(
self
.
bar
.
parent
,
"domenu_"
+
callback
)
menuhandler
=
getattr
(
self
.
bar
.
parent
,
"domenu_"
+
callback
)
else
:
else
:
# nothing we can do. we shouldn't have come this far
# nothing we can do. we shouldn't have come this far
# since the menu item should have been disabled...
# since the menu item should have been disabled...
return
return
menuhandler
(
id
,
item
,
window
,
event
)
menuhandler
(
id
,
item
,
window
,
event
)
def
enable
(
self
,
onoff
):
def
enable
(
self
,
onoff
):
if
onoff
:
if
onoff
:
self
.
menu
.
EnableMenuItem
(
0
)
self
.
menu
.
EnableMenuItem
(
0
)
if
self
.
_parent
:
if
self
.
_parent
:
self
.
_parent
.
menu
.
EnableMenuItem
(
self
.
_parent_item
)
self
.
_parent
.
menu
.
EnableMenuItem
(
self
.
_parent_item
)
else
:
else
:
self
.
menu
.
DisableMenuItem
(
0
)
self
.
menu
.
DisableMenuItem
(
0
)
if
self
.
_parent
:
if
self
.
_parent
:
self
.
_parent
.
menu
.
DisableMenuItem
(
self
.
_parent_item
)
self
.
_parent
.
menu
.
DisableMenuItem
(
self
.
_parent_item
)
if
self
.
bar
and
self
.
bar
.
parent
:
if
self
.
bar
and
self
.
bar
.
parent
:
self
.
bar
.
parent
.
needmenubarredraw
=
1
self
.
bar
.
parent
.
needmenubarredraw
=
1
class
PopupMenu
(
Menu
):
class
PopupMenu
(
Menu
):
def
__init__
(
self
,
bar
):
def
__init__
(
self
,
bar
):
Menu
.
__init__
(
self
,
bar
,
'(popup)'
,
-
1
)
Menu
.
__init__
(
self
,
bar
,
'(popup)'
,
-
1
)
def
popup
(
self
,
x
,
y
,
event
,
default
=
1
,
window
=
None
):
def
popup
(
self
,
x
,
y
,
event
,
default
=
1
,
window
=
None
):
# NOTE that x and y are global coordinates, and they should probably
# NOTE that x and y are global coordinates, and they should probably
# be topleft of the button the user clicked (not mouse-coordinates),
# be topleft of the button the user clicked (not mouse-coordinates),
# so the popup nicely overlaps.
# so the popup nicely overlaps.
reply
=
self
.
menu
.
PopUpMenuSelect
(
x
,
y
,
default
)
reply
=
self
.
menu
.
PopUpMenuSelect
(
x
,
y
,
default
)
if
not
reply
:
if
not
reply
:
return
return
id
=
(
reply
>>
16
)
&
0xffff
id
=
(
reply
>>
16
)
&
0xffff
item
=
reply
&
0xffff
item
=
reply
&
0xffff
if
not
window
:
if
not
window
:
wid
=
MyFrontWindow
()
wid
=
MyFrontWindow
()
try
:
try
:
window
=
self
.
bar
.
parent
.
_windows
[
wid
]
window
=
self
.
bar
.
parent
.
_windows
[
wid
]
except
:
except
:
pass
# If we can't find the window we pass None
pass
# If we can't find the window we pass None
self
.
dispatch
(
id
,
item
,
window
,
event
)
self
.
dispatch
(
id
,
item
,
window
,
event
)
class
MenuItem
:
class
MenuItem
:
def
__init__
(
self
,
menu
,
title
,
shortcut
=
None
,
callback
=
None
,
kind
=
None
):
def
__init__
(
self
,
menu
,
title
,
shortcut
=
None
,
callback
=
None
,
kind
=
None
):
self
.
item
=
menu
.
additem
(
title
,
shortcut
,
callback
)
self
.
item
=
menu
.
additem
(
title
,
shortcut
,
callback
)
self
.
menu
=
menu
self
.
menu
=
menu
def
delete
(
self
):
def
delete
(
self
):
self
.
menu
.
delitem
(
self
.
item
)
self
.
menu
.
delitem
(
self
.
item
)
del
self
.
menu
del
self
.
menu
del
self
.
item
del
self
.
item
def
check
(
self
,
onoff
):
def
check
(
self
,
onoff
):
self
.
menu
.
menu
.
CheckMenuItem
(
self
.
item
,
onoff
)
self
.
menu
.
menu
.
CheckMenuItem
(
self
.
item
,
onoff
)
def
enable
(
self
,
onoff
):
def
enable
(
self
,
onoff
):
if
onoff
:
if
onoff
:
self
.
menu
.
menu
.
EnableMenuItem
(
self
.
item
)
self
.
menu
.
menu
.
EnableMenuItem
(
self
.
item
)
else
:
else
:
self
.
menu
.
menu
.
DisableMenuItem
(
self
.
item
)
self
.
menu
.
menu
.
DisableMenuItem
(
self
.
item
)
def
settext
(
self
,
text
):
def
settext
(
self
,
text
):
self
.
menu
.
menu
.
SetMenuItemText
(
self
.
item
,
text
)
self
.
menu
.
menu
.
SetMenuItemText
(
self
.
item
,
text
)
def
setstyle
(
self
,
style
):
def
setstyle
(
self
,
style
):
self
.
menu
.
menu
.
SetItemStyle
(
self
.
item
,
style
)
self
.
menu
.
menu
.
SetItemStyle
(
self
.
item
,
style
)
def
seticon
(
self
,
icon
):
def
seticon
(
self
,
icon
):
self
.
menu
.
menu
.
SetItemIcon
(
self
.
item
,
icon
)
self
.
menu
.
menu
.
SetItemIcon
(
self
.
item
,
icon
)
def
setcmd
(
self
,
cmd
):
def
setcmd
(
self
,
cmd
):
self
.
menu
.
menu
.
SetItemCmd
(
self
.
item
,
cmd
)
self
.
menu
.
menu
.
SetItemCmd
(
self
.
item
,
cmd
)
def
setmark
(
self
,
cmd
):
def
setmark
(
self
,
cmd
):
self
.
menu
.
menu
.
SetItemMark
(
self
.
item
,
cmd
)
self
.
menu
.
menu
.
SetItemMark
(
self
.
item
,
cmd
)
class
RadioItem
(
MenuItem
):
class
RadioItem
(
MenuItem
):
def
__init__
(
self
,
menu
,
title
,
shortcut
=
None
,
callback
=
None
):
def
__init__
(
self
,
menu
,
title
,
shortcut
=
None
,
callback
=
None
):
MenuItem
.
__init__
(
self
,
menu
,
title
,
shortcut
,
callback
,
'radio'
)
MenuItem
.
__init__
(
self
,
menu
,
title
,
shortcut
,
callback
,
'radio'
)
class
CheckItem
(
MenuItem
):
class
CheckItem
(
MenuItem
):
def
__init__
(
self
,
menu
,
title
,
shortcut
=
None
,
callback
=
None
):
def
__init__
(
self
,
menu
,
title
,
shortcut
=
None
,
callback
=
None
):
MenuItem
.
__init__
(
self
,
menu
,
title
,
shortcut
,
callback
,
'check'
)
MenuItem
.
__init__
(
self
,
menu
,
title
,
shortcut
,
callback
,
'check'
)
def
Separator
(
menu
):
def
Separator
(
menu
):
menu
.
addseparator
()
menu
.
addseparator
()
def
SubMenu
(
menu
,
label
,
title
=
''
):
def
SubMenu
(
menu
,
label
,
title
=
''
):
return
menu
.
addsubmenu
(
label
,
title
)
return
menu
.
addsubmenu
(
label
,
title
)
class
AppleMenu
(
Menu
):
class
AppleMenu
(
Menu
):
def
__init__
(
self
,
bar
,
abouttext
=
"About me..."
,
aboutcallback
=
None
):
def
__init__
(
self
,
bar
,
abouttext
=
"About me..."
,
aboutcallback
=
None
):
Menu
.
__init__
(
self
,
bar
,
"
\
024
"
,
id
=
SIOUX_APPLEMENU_ID
)
Menu
.
__init__
(
self
,
bar
,
"
\
024
"
,
id
=
SIOUX_APPLEMENU_ID
)
if
MacOS
.
runtimemodel
==
'ppc'
:
if
MacOS
.
runtimemodel
==
'ppc'
:
self
.
additem
(
abouttext
,
None
,
aboutcallback
)
self
.
additem
(
abouttext
,
None
,
aboutcallback
)
self
.
addseparator
()
self
.
addseparator
()
self
.
menu
.
AppendResMenu
(
'DRVR'
)
self
.
menu
.
AppendResMenu
(
'DRVR'
)
else
:
else
:
# Additem()'s tricks do not work for "apple" menu under Carbon
# Additem()'s tricks do not work for "apple" menu under Carbon
self
.
menu
.
InsertMenuItem
(
abouttext
,
0
)
self
.
menu
.
InsertMenuItem
(
abouttext
,
0
)
self
.
items
.
append
((
abouttext
,
None
,
aboutcallback
,
None
))
self
.
items
.
append
((
abouttext
,
None
,
aboutcallback
,
None
))
def
dispatch
(
self
,
id
,
item
,
window
,
event
):
def
dispatch
(
self
,
id
,
item
,
window
,
event
):
if
item
==
1
:
if
item
==
1
:
Menu
.
dispatch
(
self
,
id
,
item
,
window
,
event
)
Menu
.
dispatch
(
self
,
id
,
item
,
window
,
event
)
elif
MacOS
.
runtimemodel
==
'ppc'
:
elif
MacOS
.
runtimemodel
==
'ppc'
:
name
=
self
.
menu
.
GetMenuItemText
(
item
)
name
=
self
.
menu
.
GetMenuItemText
(
item
)
OpenDeskAcc
(
name
)
OpenDeskAcc
(
name
)
class
HelpMenu
(
Menu
):
class
HelpMenu
(
Menu
):
def
__init__
(
self
,
bar
):
def
__init__
(
self
,
bar
):
# Note we don't call Menu.__init__, we do the necessary things by hand
# Note we don't call Menu.__init__, we do the necessary things by hand
self
.
bar
=
bar
self
.
bar
=
bar
self
.
menu
,
index
=
HMGetHelpMenu
()
self
.
menu
,
index
=
HMGetHelpMenu
()
self
.
id
=
self
.
menu
.
GetMenuID
()
self
.
id
=
self
.
menu
.
GetMenuID
()
bar
.
menus
[
self
.
id
]
=
self
bar
.
menus
[
self
.
id
]
=
self
# The next line caters for the entries the system already handles for us
# The next line caters for the entries the system already handles for us
self
.
items
=
[
None
]
*
(
index
-
1
)
self
.
items
=
[
None
]
*
(
index
-
1
)
self
.
_parent
=
None
self
.
_parent
=
None
class
Window
:
class
Window
:
"""A single window belonging to an application"""
"""A single window belonging to an application"""
def
__init__
(
self
,
parent
):
def
__init__
(
self
,
parent
):
self
.
wid
=
None
self
.
wid
=
None
self
.
parent
=
parent
self
.
parent
=
parent
def
open
(
self
,
bounds
=
(
40
,
40
,
400
,
400
),
resid
=
None
):
def
open
(
self
,
bounds
=
(
40
,
40
,
400
,
400
),
resid
=
None
):
if
resid
<>
None
:
if
resid
<>
None
:
self
.
wid
=
GetNewWindow
(
resid
,
-
1
)
self
.
wid
=
GetNewWindow
(
resid
,
-
1
)
else
:
else
:
self
.
wid
=
NewWindow
(
bounds
,
self
.
__class__
.
__name__
,
1
,
self
.
wid
=
NewWindow
(
bounds
,
self
.
__class__
.
__name__
,
1
,
8
,
-
1
,
1
,
0
)
# changed to proc id 8 to include zoom box. jvr
8
,
-
1
,
1
,
0
)
# changed to proc id 8 to include zoom box. jvr
self
.
do_postopen
()
self
.
do_postopen
()
def
do_postopen
(
self
):
def
do_postopen
(
self
):
"""Tell our parent we exist"""
"""Tell our parent we exist"""
self
.
parent
.
appendwindow
(
self
.
wid
,
self
)
self
.
parent
.
appendwindow
(
self
.
wid
,
self
)
def
close
(
self
):
def
close
(
self
):
self
.
do_postclose
()
self
.
do_postclose
()
def
do_postclose
(
self
):
def
do_postclose
(
self
):
self
.
parent
.
removewindow
(
self
.
wid
)
self
.
parent
.
removewindow
(
self
.
wid
)
self
.
parent
=
None
self
.
parent
=
None
self
.
wid
=
None
self
.
wid
=
None
def
SetPort
(
self
):
def
SetPort
(
self
):
# Convinience method
# Convinience method
SetPort
(
self
.
wid
)
SetPort
(
self
.
wid
)
def
GetWindow
(
self
):
def
GetWindow
(
self
):
return
self
.
wid
return
self
.
wid
def
do_inDrag
(
self
,
partcode
,
window
,
event
):
def
do_inDrag
(
self
,
partcode
,
window
,
event
):
where
=
event
[
3
]
where
=
event
[
3
]
window
.
DragWindow
(
where
,
self
.
draglimit
)
window
.
DragWindow
(
where
,
self
.
draglimit
)
draglimit
=
screenbounds
draglimit
=
screenbounds
def
do_inGoAway
(
self
,
partcode
,
window
,
event
):
def
do_inGoAway
(
self
,
partcode
,
window
,
event
):
where
=
event
[
3
]
where
=
event
[
3
]
if
window
.
TrackGoAway
(
where
):
if
window
.
TrackGoAway
(
where
):
self
.
close
()
self
.
close
()
def
do_inZoom
(
self
,
partcode
,
window
,
event
):
def
do_inZoom
(
self
,
partcode
,
window
,
event
):
(
what
,
message
,
when
,
where
,
modifiers
)
=
event
(
what
,
message
,
when
,
where
,
modifiers
)
=
event
if
window
.
TrackBox
(
where
,
partcode
):
if
window
.
TrackBox
(
where
,
partcode
):
window
.
ZoomWindow
(
partcode
,
1
)
window
.
ZoomWindow
(
partcode
,
1
)
rect
=
window
.
GetWindowUserState
()
# so that zoom really works... jvr
rect
=
window
.
GetWindowUserState
()
# so that zoom really works... jvr
self
.
do_postresize
(
rect
[
2
]
-
rect
[
0
],
rect
[
3
]
-
rect
[
1
],
window
)
# jvr
self
.
do_postresize
(
rect
[
2
]
-
rect
[
0
],
rect
[
3
]
-
rect
[
1
],
window
)
# jvr
def
do_inZoomIn
(
self
,
partcode
,
window
,
event
):
def
do_inZoomIn
(
self
,
partcode
,
window
,
event
):
SetPort
(
window
)
# !!!
SetPort
(
window
)
# !!!
self
.
do_inZoom
(
partcode
,
window
,
event
)
self
.
do_inZoom
(
partcode
,
window
,
event
)
def
do_inZoomOut
(
self
,
partcode
,
window
,
event
):
def
do_inZoomOut
(
self
,
partcode
,
window
,
event
):
SetPort
(
window
)
# !!!
SetPort
(
window
)
# !!!
self
.
do_inZoom
(
partcode
,
window
,
event
)
self
.
do_inZoom
(
partcode
,
window
,
event
)
def
do_inGrow
(
self
,
partcode
,
window
,
event
):
def
do_inGrow
(
self
,
partcode
,
window
,
event
):
(
what
,
message
,
when
,
where
,
modifiers
)
=
event
(
what
,
message
,
when
,
where
,
modifiers
)
=
event
result
=
window
.
GrowWindow
(
where
,
self
.
growlimit
)
result
=
window
.
GrowWindow
(
where
,
self
.
growlimit
)
if
result
:
if
result
:
height
=
(
result
>>
16
)
&
0xffff
# Hi word
height
=
(
result
>>
16
)
&
0xffff
# Hi word
width
=
result
&
0xffff
# Lo word
width
=
result
&
0xffff
# Lo word
self
.
do_resize
(
width
,
height
,
window
)
self
.
do_resize
(
width
,
height
,
window
)
growlimit
=
(
50
,
50
,
screenbounds
[
2
]
-
screenbounds
[
0
],
screenbounds
[
3
]
-
screenbounds
[
1
])
# jvr
growlimit
=
(
50
,
50
,
screenbounds
[
2
]
-
screenbounds
[
0
],
screenbounds
[
3
]
-
screenbounds
[
1
])
# jvr
def
do_resize
(
self
,
width
,
height
,
window
):
def
do_resize
(
self
,
width
,
height
,
window
):
l
,
t
,
r
,
b
=
self
.
wid
.
GetWindowPort
().
GetPortBounds
()
# jvr, forGrowIcon
l
,
t
,
r
,
b
=
self
.
wid
.
GetWindowPort
().
GetPortBounds
()
# jvr, forGrowIcon
self
.
SetPort
()
# jvr
self
.
SetPort
()
# jvr
self
.
wid
.
InvalWindowRect
((
r
-
SCROLLBARWIDTH
+
1
,
b
-
SCROLLBARWIDTH
+
1
,
r
,
b
))
# jvr
self
.
wid
.
InvalWindowRect
((
r
-
SCROLLBARWIDTH
+
1
,
b
-
SCROLLBARWIDTH
+
1
,
r
,
b
))
# jvr
window
.
SizeWindow
(
width
,
height
,
1
)
# changed updateFlag to true jvr
window
.
SizeWindow
(
width
,
height
,
1
)
# changed updateFlag to true jvr
self
.
do_postresize
(
width
,
height
,
window
)
self
.
do_postresize
(
width
,
height
,
window
)
def
do_postresize
(
self
,
width
,
height
,
window
):
def
do_postresize
(
self
,
width
,
height
,
window
):
SetPort
(
window
)
SetPort
(
window
)
self
.
wid
.
InvalWindowRect
(
window
.
GetWindowPort
().
GetPortBounds
())
self
.
wid
.
InvalWindowRect
(
window
.
GetWindowPort
().
GetPortBounds
())
def
do_inContent
(
self
,
partcode
,
window
,
event
):
def
do_inContent
(
self
,
partcode
,
window
,
event
):
#
#
# If we're not frontmost, select ourselves and wait for
# If we're not frontmost, select ourselves and wait for
# the activate event.
# the activate event.
#
#
if
MyFrontWindow
()
<>
window
:
if
MyFrontWindow
()
<>
window
:
window
.
SelectWindow
()
window
.
SelectWindow
()
return
return
# We are. Handle the event.
# We are. Handle the event.
(
what
,
message
,
when
,
where
,
modifiers
)
=
event
(
what
,
message
,
when
,
where
,
modifiers
)
=
event
SetPort
(
window
)
SetPort
(
window
)
local
=
GlobalToLocal
(
where
)
local
=
GlobalToLocal
(
where
)
self
.
do_contentclick
(
local
,
modifiers
,
event
)
self
.
do_contentclick
(
local
,
modifiers
,
event
)
def
do_contentclick
(
self
,
local
,
modifiers
,
event
):
def
do_contentclick
(
self
,
local
,
modifiers
,
event
):
if
DEBUG
:
if
DEBUG
:
print
'Click in contents at %s, modifiers %s'
%
(
local
,
modifiers
)
print
'Click in contents at %s, modifiers %s'
%
(
local
,
modifiers
)
def
do_rawupdate
(
self
,
window
,
event
):
def
do_rawupdate
(
self
,
window
,
event
):
if
DEBUG
:
print
"raw update for"
,
window
if
DEBUG
:
print
"raw update for"
,
window
SetPort
(
window
)
SetPort
(
window
)
window
.
BeginUpdate
()
window
.
BeginUpdate
()
self
.
do_update
(
window
,
event
)
self
.
do_update
(
window
,
event
)
window
.
EndUpdate
()
window
.
EndUpdate
()
def
do_update
(
self
,
window
,
event
):
def
do_update
(
self
,
window
,
event
):
if
DEBUG
:
if
DEBUG
:
import
time
import
time
for
i
in
range
(
8
):
for
i
in
range
(
8
):
time
.
sleep
(
0.1
)
time
.
sleep
(
0.1
)
InvertRgn
(
window
.
GetWindowPort
().
visRgn
)
InvertRgn
(
window
.
GetWindowPort
().
visRgn
)
FillRgn
(
window
.
GetWindowPort
().
visRgn
,
GetQDGlobalsGray
())
FillRgn
(
window
.
GetWindowPort
().
visRgn
,
GetQDGlobalsGray
())
else
:
else
:
EraseRgn
(
window
.
GetWindowPort
().
visRgn
)
EraseRgn
(
window
.
GetWindowPort
().
visRgn
)
def
do_activate
(
self
,
activate
,
event
):
def
do_activate
(
self
,
activate
,
event
):
if
DEBUG
:
print
'Activate %d for %s'
%
(
activate
,
self
.
wid
)
if
DEBUG
:
print
'Activate %d for %s'
%
(
activate
,
self
.
wid
)
class
ControlsWindow
(
Window
):
class
ControlsWindow
(
Window
):
def
do_rawupdate
(
self
,
window
,
event
):
def
do_rawupdate
(
self
,
window
,
event
):
if
DEBUG
:
print
"raw update for"
,
window
if
DEBUG
:
print
"raw update for"
,
window
SetPort
(
window
)
SetPort
(
window
)
window
.
BeginUpdate
()
window
.
BeginUpdate
()
self
.
do_update
(
window
,
event
)
self
.
do_update
(
window
,
event
)
#DrawControls(window)
# jvr
#DrawControls(window)
# jvr
UpdateControls
(
window
,
window
.
GetWindowPort
().
visRgn
)
# jvr
UpdateControls
(
window
,
window
.
GetWindowPort
().
visRgn
)
# jvr
window
.
DrawGrowIcon
()
window
.
DrawGrowIcon
()
window
.
EndUpdate
()
window
.
EndUpdate
()
def
do_controlhit
(
self
,
window
,
control
,
pcode
,
event
):
def
do_controlhit
(
self
,
window
,
control
,
pcode
,
event
):
if
DEBUG
:
print
"control hit in"
,
window
,
"on"
,
control
,
"; pcode ="
,
pcode
if
DEBUG
:
print
"control hit in"
,
window
,
"on"
,
control
,
"; pcode ="
,
pcode
def
do_inContent
(
self
,
partcode
,
window
,
event
):
def
do_inContent
(
self
,
partcode
,
window
,
event
):
if
MyFrontWindow
()
<>
window
:
if
MyFrontWindow
()
<>
window
:
window
.
SelectWindow
()
window
.
SelectWindow
()
return
return
(
what
,
message
,
when
,
where
,
modifiers
)
=
event
(
what
,
message
,
when
,
where
,
modifiers
)
=
event
SetPort
(
window
)
# XXXX Needed?
SetPort
(
window
)
# XXXX Needed?
local
=
GlobalToLocal
(
where
)
local
=
GlobalToLocal
(
where
)
pcode
,
control
=
FindControl
(
local
,
window
)
pcode
,
control
=
FindControl
(
local
,
window
)
if
pcode
and
control
:
if
pcode
and
control
:
self
.
do_rawcontrolhit
(
window
,
control
,
pcode
,
local
,
event
)
self
.
do_rawcontrolhit
(
window
,
control
,
pcode
,
local
,
event
)
else
:
else
:
if
DEBUG
:
print
"FindControl(%s, %s) -> (%s, %s)"
%
\
if
DEBUG
:
print
"FindControl(%s, %s) -> (%s, %s)"
%
\
(
local
,
window
,
pcode
,
control
)
(
local
,
window
,
pcode
,
control
)
self
.
do_contentclick
(
local
,
modifiers
,
event
)
self
.
do_contentclick
(
local
,
modifiers
,
event
)
def
do_rawcontrolhit
(
self
,
window
,
control
,
pcode
,
local
,
event
):
def
do_rawcontrolhit
(
self
,
window
,
control
,
pcode
,
local
,
event
):
pcode
=
control
.
TrackControl
(
local
)
pcode
=
control
.
TrackControl
(
local
)
if
pcode
:
if
pcode
:
self
.
do_controlhit
(
window
,
control
,
pcode
,
event
)
self
.
do_controlhit
(
window
,
control
,
pcode
,
event
)
class
ScrolledWindow
(
ControlsWindow
):
class
ScrolledWindow
(
ControlsWindow
):
def
__init__
(
self
,
parent
):
def
__init__
(
self
,
parent
):
self
.
barx
=
self
.
bary
=
None
self
.
barx
=
self
.
bary
=
None
self
.
barx_enabled
=
self
.
bary_enabled
=
1
self
.
barx_enabled
=
self
.
bary_enabled
=
1
self
.
activated
=
1
self
.
activated
=
1
ControlsWindow
.
__init__
(
self
,
parent
)
ControlsWindow
.
__init__
(
self
,
parent
)
def
scrollbars
(
self
,
wantx
=
1
,
wanty
=
1
):
def
scrollbars
(
self
,
wantx
=
1
,
wanty
=
1
):
SetPort
(
self
.
wid
)
SetPort
(
self
.
wid
)
self
.
barx
=
self
.
bary
=
None
self
.
barx
=
self
.
bary
=
None
self
.
barx_enabled
=
self
.
bary_enabled
=
1
self
.
barx_enabled
=
self
.
bary_enabled
=
1
x0
,
y0
,
x1
,
y1
=
self
.
wid
.
GetWindowPort
().
GetPortBounds
()
x0
,
y0
,
x1
,
y1
=
self
.
wid
.
GetWindowPort
().
GetPortBounds
()
vx
,
vy
=
self
.
getscrollbarvalues
()
vx
,
vy
=
self
.
getscrollbarvalues
()
if
vx
==
None
:
self
.
barx_enabled
,
vx
=
0
,
0
if
vx
==
None
:
self
.
barx_enabled
,
vx
=
0
,
0
if
vy
==
None
:
self
.
bary_enabled
,
vy
=
0
,
0
if
vy
==
None
:
self
.
bary_enabled
,
vy
=
0
,
0
if
wantx
:
if
wantx
:
rect
=
x0
-
1
,
y1
-
(
SCROLLBARWIDTH
-
1
),
x1
-
(
SCROLLBARWIDTH
-
2
),
y1
+
1
rect
=
x0
-
1
,
y1
-
(
SCROLLBARWIDTH
-
1
),
x1
-
(
SCROLLBARWIDTH
-
2
),
y1
+
1
self
.
barx
=
NewControl
(
self
.
wid
,
rect
,
""
,
1
,
vx
,
0
,
32767
,
16
,
0
)
self
.
barx
=
NewControl
(
self
.
wid
,
rect
,
""
,
1
,
vx
,
0
,
32767
,
16
,
0
)
if
not
self
.
barx_enabled
:
self
.
barx
.
HiliteControl
(
255
)
if
not
self
.
barx_enabled
:
self
.
barx
.
HiliteControl
(
255
)
##
self.wid.InvalWindowRect(rect)
##
self.wid.InvalWindowRect(rect)
if
wanty
:
if
wanty
:
rect
=
x1
-
(
SCROLLBARWIDTH
-
1
),
y0
-
1
,
x1
+
1
,
y1
-
(
SCROLLBARWIDTH
-
2
)
rect
=
x1
-
(
SCROLLBARWIDTH
-
1
),
y0
-
1
,
x1
+
1
,
y1
-
(
SCROLLBARWIDTH
-
2
)
self
.
bary
=
NewControl
(
self
.
wid
,
rect
,
""
,
1
,
vy
,
0
,
32767
,
16
,
0
)
self
.
bary
=
NewControl
(
self
.
wid
,
rect
,
""
,
1
,
vy
,
0
,
32767
,
16
,
0
)
if
not
self
.
bary_enabled
:
self
.
bary
.
HiliteControl
(
255
)
if
not
self
.
bary_enabled
:
self
.
bary
.
HiliteControl
(
255
)
##
self.wid.InvalWindowRect(rect)
##
self.wid.InvalWindowRect(rect)
def
do_postclose
(
self
):
def
do_postclose
(
self
):
self
.
barx
=
self
.
bary
=
None
self
.
barx
=
self
.
bary
=
None
ControlsWindow
.
do_postclose
(
self
)
ControlsWindow
.
do_postclose
(
self
)
def
do_activate
(
self
,
onoff
,
event
):
def
do_activate
(
self
,
onoff
,
event
):
self
.
activated
=
onoff
self
.
activated
=
onoff
if
onoff
:
if
onoff
:
if
self
.
barx
and
self
.
barx_enabled
:
if
self
.
barx
and
self
.
barx_enabled
:
self
.
barx
.
ShowControl
()
# jvr
self
.
barx
.
ShowControl
()
# jvr
if
self
.
bary
and
self
.
bary_enabled
:
if
self
.
bary
and
self
.
bary_enabled
:
self
.
bary
.
ShowControl
()
# jvr
self
.
bary
.
ShowControl
()
# jvr
else
:
else
:
if
self
.
barx
:
if
self
.
barx
:
self
.
barx
.
HideControl
()
# jvr; An inactive window should have *hidden*
self
.
barx
.
HideControl
()
# jvr; An inactive window should have *hidden*
# scrollbars, not just dimmed (no matter what
# scrollbars, not just dimmed (no matter what
# BBEdit does... look at the Finder)
# BBEdit does... look at the Finder)
if
self
.
bary
:
if
self
.
bary
:
self
.
bary
.
HideControl
()
# jvr
self
.
bary
.
HideControl
()
# jvr
self
.
wid
.
DrawGrowIcon
()
# jvr
self
.
wid
.
DrawGrowIcon
()
# jvr
def
do_postresize
(
self
,
width
,
height
,
window
):
def
do_postresize
(
self
,
width
,
height
,
window
):
l
,
t
,
r
,
b
=
self
.
wid
.
GetWindowPort
().
GetPortBounds
()
l
,
t
,
r
,
b
=
self
.
wid
.
GetWindowPort
().
GetPortBounds
()
self
.
SetPort
()
self
.
SetPort
()
if
self
.
barx
:
if
self
.
barx
:
self
.
barx
.
HideControl
()
# jvr
self
.
barx
.
HideControl
()
# jvr
self
.
barx
.
MoveControl
(
l
-
1
,
b
-
(
SCROLLBARWIDTH
-
1
))
self
.
barx
.
MoveControl
(
l
-
1
,
b
-
(
SCROLLBARWIDTH
-
1
))
self
.
barx
.
SizeControl
((
r
-
l
)
-
(
SCROLLBARWIDTH
-
3
),
SCROLLBARWIDTH
)
# jvr
self
.
barx
.
SizeControl
((
r
-
l
)
-
(
SCROLLBARWIDTH
-
3
),
SCROLLBARWIDTH
)
# jvr
if
self
.
bary
:
if
self
.
bary
:
self
.
bary
.
HideControl
()
# jvr
self
.
bary
.
HideControl
()
# jvr
self
.
bary
.
MoveControl
(
r
-
(
SCROLLBARWIDTH
-
1
),
t
-
1
)
self
.
bary
.
MoveControl
(
r
-
(
SCROLLBARWIDTH
-
1
),
t
-
1
)
self
.
bary
.
SizeControl
(
SCROLLBARWIDTH
,
(
b
-
t
)
-
(
SCROLLBARWIDTH
-
3
))
# jvr
self
.
bary
.
SizeControl
(
SCROLLBARWIDTH
,
(
b
-
t
)
-
(
SCROLLBARWIDTH
-
3
))
# jvr
if
self
.
barx
:
if
self
.
barx
:
self
.
barx
.
ShowControl
()
# jvr
self
.
barx
.
ShowControl
()
# jvr
self
.
wid
.
ValidWindowRect
((
l
,
b
-
SCROLLBARWIDTH
+
1
,
r
-
SCROLLBARWIDTH
+
2
,
b
))
# jvr
self
.
wid
.
ValidWindowRect
((
l
,
b
-
SCROLLBARWIDTH
+
1
,
r
-
SCROLLBARWIDTH
+
2
,
b
))
# jvr
if
self
.
bary
:
if
self
.
bary
:
self
.
bary
.
ShowControl
()
# jvr
self
.
bary
.
ShowControl
()
# jvr
self
.
wid
.
ValidWindowRect
((
r
-
SCROLLBARWIDTH
+
1
,
t
,
r
,
b
-
SCROLLBARWIDTH
+
2
))
# jvr
self
.
wid
.
ValidWindowRect
((
r
-
SCROLLBARWIDTH
+
1
,
t
,
r
,
b
-
SCROLLBARWIDTH
+
2
))
# jvr
self
.
wid
.
InvalWindowRect
((
r
-
SCROLLBARWIDTH
+
1
,
b
-
SCROLLBARWIDTH
+
1
,
r
,
b
))
# jvr, growicon
self
.
wid
.
InvalWindowRect
((
r
-
SCROLLBARWIDTH
+
1
,
b
-
SCROLLBARWIDTH
+
1
,
r
,
b
))
# jvr, growicon
def
do_rawcontrolhit
(
self
,
window
,
control
,
pcode
,
local
,
event
):
def
do_rawcontrolhit
(
self
,
window
,
control
,
pcode
,
local
,
event
):
if
control
==
self
.
barx
:
if
control
==
self
.
barx
:
which
=
'x'
which
=
'x'
elif
control
==
self
.
bary
:
elif
control
==
self
.
bary
:
which
=
'y'
which
=
'y'
else
:
else
:
return
0
return
0
if
pcode
in
(
inUpButton
,
inDownButton
,
inPageUp
,
inPageDown
):
if
pcode
in
(
inUpButton
,
inDownButton
,
inPageUp
,
inPageDown
):
# We do the work for the buttons and grey area in the tracker
# We do the work for the buttons and grey area in the tracker
dummy
=
control
.
TrackControl
(
local
,
self
.
do_controltrack
)
dummy
=
control
.
TrackControl
(
local
,
self
.
do_controltrack
)
else
:
else
:
# but the thumb is handled here
# but the thumb is handled here
pcode
=
control
.
TrackControl
(
local
)
pcode
=
control
.
TrackControl
(
local
)
if
pcode
==
inThumb
:
if
pcode
==
inThumb
:
value
=
control
.
GetControlValue
()
value
=
control
.
GetControlValue
()
print
'setbars'
,
which
,
value
#DBG
print
'setbars'
,
which
,
value
#DBG
self
.
scrollbar_callback
(
which
,
'set'
,
value
)
self
.
scrollbar_callback
(
which
,
'set'
,
value
)
self
.
updatescrollbars
()
self
.
updatescrollbars
()
else
:
else
:
print
'funny part'
,
pcode
#DBG
print
'funny part'
,
pcode
#DBG
return
1
return
1
def
do_controltrack
(
self
,
control
,
pcode
):
def
do_controltrack
(
self
,
control
,
pcode
):
if
control
==
self
.
barx
:
if
control
==
self
.
barx
:
which
=
'x'
which
=
'x'
elif
control
==
self
.
bary
:
elif
control
==
self
.
bary
:
which
=
'y'
which
=
'y'
else
:
else
:
return
return
if
pcode
==
inUpButton
:
if
pcode
==
inUpButton
:
what
=
'-'
what
=
'-'
elif
pcode
==
inDownButton
:
elif
pcode
==
inDownButton
:
what
=
'+'
what
=
'+'
elif
pcode
==
inPageUp
:
elif
pcode
==
inPageUp
:
what
=
'--'
what
=
'--'
elif
pcode
==
inPageDown
:
elif
pcode
==
inPageDown
:
what
=
'++'
what
=
'++'
else
:
else
:
return
return
self
.
scrollbar_callback
(
which
,
what
,
None
)
self
.
scrollbar_callback
(
which
,
what
,
None
)
self
.
updatescrollbars
()
self
.
updatescrollbars
()
def
updatescrollbars
(
self
):
def
updatescrollbars
(
self
):
SetPort
(
self
.
wid
)
SetPort
(
self
.
wid
)
vx
,
vy
=
self
.
getscrollbarvalues
()
vx
,
vy
=
self
.
getscrollbarvalues
()
if
self
.
barx
:
if
self
.
barx
:
if
vx
==
None
:
if
vx
==
None
:
self
.
barx
.
HiliteControl
(
255
)
self
.
barx
.
HiliteControl
(
255
)
self
.
barx_enabled
=
0
self
.
barx_enabled
=
0
else
:
else
:
if
not
self
.
barx_enabled
:
if
not
self
.
barx_enabled
:
self
.
barx_enabled
=
1
self
.
barx_enabled
=
1
if
self
.
activated
:
if
self
.
activated
:
self
.
barx
.
HiliteControl
(
0
)
self
.
barx
.
HiliteControl
(
0
)
self
.
barx
.
SetControlValue
(
vx
)
self
.
barx
.
SetControlValue
(
vx
)
if
self
.
bary
:
if
self
.
bary
:
if
vy
==
None
:
if
vy
==
None
:
self
.
bary
.
HiliteControl
(
255
)
self
.
bary
.
HiliteControl
(
255
)
self
.
bary_enabled
=
0
self
.
bary_enabled
=
0
else
:
else
:
if
not
self
.
bary_enabled
:
if
not
self
.
bary_enabled
:
self
.
bary_enabled
=
1
self
.
bary_enabled
=
1
if
self
.
activated
:
if
self
.
activated
:
self
.
bary
.
HiliteControl
(
0
)
self
.
bary
.
HiliteControl
(
0
)
self
.
bary
.
SetControlValue
(
vy
)
self
.
bary
.
SetControlValue
(
vy
)
# Auxiliary function: convert standard text/image/etc coordinate
# Auxiliary function: convert standard text/image/etc coordinate
# to something palatable as getscrollbarvalues() return
# to something palatable as getscrollbarvalues() return
def
scalebarvalue
(
self
,
absmin
,
absmax
,
curmin
,
curmax
):
def
scalebarvalue
(
self
,
absmin
,
absmax
,
curmin
,
curmax
):
if
curmin
<=
absmin
and
curmax
>=
absmax
:
if
curmin
<=
absmin
and
curmax
>=
absmax
:
return
None
return
None
if
curmin
<=
absmin
:
if
curmin
<=
absmin
:
return
0
return
0
if
curmax
>=
absmax
:
if
curmax
>=
absmax
:
return
32767
return
32767
perc
=
float
(
curmin
-
absmin
)
/
float
(
absmax
-
absmin
)
perc
=
float
(
curmin
-
absmin
)
/
float
(
absmax
-
absmin
)
return
int
(
perc
*
32767
)
return
int
(
perc
*
32767
)
# To be overridden:
# To be overridden:
def
getscrollbarvalues
(
self
):
def
getscrollbarvalues
(
self
):
return
0
,
0
return
0
,
0
def
scrollbar_callback
(
self
,
which
,
what
,
value
):
def
scrollbar_callback
(
self
,
which
,
what
,
value
):
print
'scroll'
,
which
,
what
,
value
print
'scroll'
,
which
,
what
,
value
class
DialogWindow
(
Window
):
class
DialogWindow
(
Window
):
"""A modeless dialog window"""
"""A modeless dialog window"""
def
open
(
self
,
resid
):
def
open
(
self
,
resid
):
self
.
dlg
=
GetNewDialog
(
resid
,
-
1
)
self
.
dlg
=
GetNewDialog
(
resid
,
-
1
)
self
.
wid
=
self
.
dlg
.
GetDialogWindow
()
self
.
wid
=
self
.
dlg
.
GetDialogWindow
()
self
.
do_postopen
()
self
.
do_postopen
()
def
close
(
self
):
def
close
(
self
):
self
.
do_postclose
()
self
.
do_postclose
()
def
do_postclose
(
self
):
def
do_postclose
(
self
):
self
.
dlg
=
None
self
.
dlg
=
None
Window
.
do_postclose
(
self
)
Window
.
do_postclose
(
self
)
def
do_itemhit
(
self
,
item
,
event
):
def
do_itemhit
(
self
,
item
,
event
):
print
'Dialog %s, item %d hit'
%
(
self
.
dlg
,
item
)
print
'Dialog %s, item %d hit'
%
(
self
.
dlg
,
item
)
def
do_rawupdate
(
self
,
window
,
event
):
def
do_rawupdate
(
self
,
window
,
event
):
pass
pass
def
ostypecode
(
x
):
def
ostypecode
(
x
):
"Convert a long int to the 4-character code it really is"
"Convert a long int to the 4-character code it really is"
s
=
''
s
=
''
for
i
in
range
(
4
):
for
i
in
range
(
4
):
x
,
c
=
divmod
(
x
,
256
)
x
,
c
=
divmod
(
x
,
256
)
s
=
chr
(
c
)
+
s
s
=
chr
(
c
)
+
s
return
s
return
s
class
TestApp
(
Application
):
class
TestApp
(
Application
):
"This class is used by the test() function"
"This class is used by the test() function"
def
makeusermenus
(
self
):
def
makeusermenus
(
self
):
self
.
filemenu
=
m
=
Menu
(
self
.
menubar
,
"File"
)
self
.
filemenu
=
m
=
Menu
(
self
.
menubar
,
"File"
)
self
.
saveitem
=
MenuItem
(
m
,
"Save"
,
"S"
,
self
.
save
)
self
.
saveitem
=
MenuItem
(
m
,
"Save"
,
"S"
,
self
.
save
)
Separator
(
m
)
Separator
(
m
)
self
.
optionsmenu
=
mm
=
SubMenu
(
m
,
"Options"
)
self
.
optionsmenu
=
mm
=
SubMenu
(
m
,
"Options"
)
self
.
opt1
=
CheckItem
(
mm
,
"Arguments"
,
"A"
)
self
.
opt1
=
CheckItem
(
mm
,
"Arguments"
,
"A"
)
self
.
opt2
=
CheckItem
(
mm
,
"Being hit on the head lessons"
,
(
kMenuOptionModifier
,
"A"
))
self
.
opt2
=
CheckItem
(
mm
,
"Being hit on the head lessons"
,
(
kMenuOptionModifier
,
"A"
))
self
.
opt3
=
CheckItem
(
mm
,
"Complaints"
,
(
kMenuOptionModifier
|
kMenuNoCommandModifier
,
"A"
))
self
.
opt3
=
CheckItem
(
mm
,
"Complaints"
,
(
kMenuOptionModifier
|
kMenuNoCommandModifier
,
"A"
))
Separator
(
m
)
Separator
(
m
)
self
.
itemeh
=
MenuItem
(
m
,
"Enable Help"
,
None
,
self
.
enablehelp
)
self
.
itemeh
=
MenuItem
(
m
,
"Enable Help"
,
None
,
self
.
enablehelp
)
self
.
itemdbg
=
MenuItem
(
m
,
"Debug"
,
None
,
self
.
debug
)
self
.
itemdbg
=
MenuItem
(
m
,
"Debug"
,
None
,
self
.
debug
)
Separator
(
m
)
Separator
(
m
)
self
.
quititem
=
MenuItem
(
m
,
"Quit"
,
"Q"
,
self
.
quit
)
self
.
quititem
=
MenuItem
(
m
,
"Quit"
,
"Q"
,
self
.
quit
)
def
save
(
self
,
*
args
):
def
save
(
self
,
*
args
):
print
"Save"
print
"Save"
def
quit
(
self
,
*
args
):
def
quit
(
self
,
*
args
):
raise
self
raise
self
def
enablehelp
(
self
,
*
args
):
def
enablehelp
(
self
,
*
args
):
hm
=
self
.
gethelpmenu
()
hm
=
self
.
gethelpmenu
()
self
.
nohelpitem
=
MenuItem
(
hm
,
"There isn't any"
,
None
,
self
.
nohelp
)
self
.
nohelpitem
=
MenuItem
(
hm
,
"There isn't any"
,
None
,
self
.
nohelp
)
def
nohelp
(
self
,
*
args
):
def
nohelp
(
self
,
*
args
):
print
"I told you there isn't any!"
print
"I told you there isn't any!"
def
debug
(
self
,
*
args
):
def
debug
(
self
,
*
args
):
import
pdb
import
pdb
pdb
.
set_trace
()
pdb
.
set_trace
()
def
test
():
def
test
():
"Test program"
"Test program"
app
=
TestApp
()
app
=
TestApp
()
app
.
mainloop
()
app
.
mainloop
()
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
test
()
test
()
Lib/plat-mac/MiniAEFrame.py
View file @
ff41c48a
"""MiniAEFrame - A minimal AppleEvent Application framework.
"""MiniAEFrame - A minimal AppleEvent Application framework.
There are two classes:
There are two classes:
AEServer -- a mixin class offering nice AE handling.
AEServer -- a mixin class offering nice AE handling.
MiniApplication -- a very minimal alternative to FrameWork.py,
MiniApplication -- a very minimal alternative to FrameWork.py,
only suitable for the simplest of AppleEvent servers.
only suitable for the simplest of AppleEvent servers.
"""
"""
import
sys
import
sys
...
@@ -21,179 +21,179 @@ from Carbon import Qd
...
@@ -21,179 +21,179 @@ from Carbon import Qd
import
aetools
import
aetools
import
EasyDialogs
import
EasyDialogs
kHighLevelEvent
=
23
# Not defined anywhere for Python yet?
kHighLevelEvent
=
23
# Not defined anywhere for Python yet?
class
MiniApplication
:
class
MiniApplication
:
"""A minimal FrameWork.Application-like class"""
"""A minimal FrameWork.Application-like class"""
def
__init__
(
self
):
def
__init__
(
self
):
self
.
quitting
=
0
self
.
quitting
=
0
# Initialize menu
# Initialize menu
self
.
appleid
=
1
self
.
appleid
=
1
self
.
quitid
=
2
self
.
quitid
=
2
Menu
.
ClearMenuBar
()
Menu
.
ClearMenuBar
()
self
.
applemenu
=
applemenu
=
Menu
.
NewMenu
(
self
.
appleid
,
"
\
024
"
)
self
.
applemenu
=
applemenu
=
Menu
.
NewMenu
(
self
.
appleid
,
"
\
024
"
)
applemenu
.
AppendMenu
(
"%s;(-"
%
self
.
getaboutmenutext
())
applemenu
.
AppendMenu
(
"%s;(-"
%
self
.
getaboutmenutext
())
if
MacOS
.
runtimemodel
==
'ppc'
:
if
MacOS
.
runtimemodel
==
'ppc'
:
applemenu
.
AppendResMenu
(
'DRVR'
)
applemenu
.
AppendResMenu
(
'DRVR'
)
applemenu
.
InsertMenu
(
0
)
applemenu
.
InsertMenu
(
0
)
self
.
quitmenu
=
Menu
.
NewMenu
(
self
.
quitid
,
"File"
)
self
.
quitmenu
=
Menu
.
NewMenu
(
self
.
quitid
,
"File"
)
self
.
quitmenu
.
AppendMenu
(
"Quit"
)
self
.
quitmenu
.
AppendMenu
(
"Quit"
)
self
.
quitmenu
.
SetItemCmd
(
1
,
ord
(
"Q"
))
self
.
quitmenu
.
SetItemCmd
(
1
,
ord
(
"Q"
))
self
.
quitmenu
.
InsertMenu
(
0
)
self
.
quitmenu
.
InsertMenu
(
0
)
Menu
.
DrawMenuBar
()
Menu
.
DrawMenuBar
()
def
__del__
(
self
):
def
__del__
(
self
):
self
.
close
()
self
.
close
()
def
close
(
self
):
def
close
(
self
):
pass
pass
def
mainloop
(
self
,
mask
=
everyEvent
,
timeout
=
60
*
60
):
def
mainloop
(
self
,
mask
=
everyEvent
,
timeout
=
60
*
60
):
while
not
self
.
quitting
:
while
not
self
.
quitting
:
self
.
dooneevent
(
mask
,
timeout
)
self
.
dooneevent
(
mask
,
timeout
)
def
_quit
(
self
):
def
_quit
(
self
):
self
.
quitting
=
1
self
.
quitting
=
1
def
dooneevent
(
self
,
mask
=
everyEvent
,
timeout
=
60
*
60
):
def
dooneevent
(
self
,
mask
=
everyEvent
,
timeout
=
60
*
60
):
got
,
event
=
Evt
.
WaitNextEvent
(
mask
,
timeout
)
got
,
event
=
Evt
.
WaitNextEvent
(
mask
,
timeout
)
if
got
:
if
got
:
self
.
lowlevelhandler
(
event
)
self
.
lowlevelhandler
(
event
)
def
lowlevelhandler
(
self
,
event
):
def
lowlevelhandler
(
self
,
event
):
what
,
message
,
when
,
where
,
modifiers
=
event
what
,
message
,
when
,
where
,
modifiers
=
event
h
,
v
=
where
h
,
v
=
where
if
what
==
kHighLevelEvent
:
if
what
==
kHighLevelEvent
:
msg
=
"High Level Event: %s %s"
%
\
msg
=
"High Level Event: %s %s"
%
\
(
`code(message)`
,
`code(h | (v<<16))`
)
(
`code(message)`
,
`code(h | (v<<16))`
)
try
:
try
:
AE
.
AEProcessAppleEvent
(
event
)
AE
.
AEProcessAppleEvent
(
event
)
except
AE
.
Error
,
err
:
except
AE
.
Error
,
err
:
print
'AE error: '
,
err
print
'AE error: '
,
err
print
'in'
,
msg
print
'in'
,
msg
traceback
.
print_exc
()
traceback
.
print_exc
()
return
return
elif
what
==
keyDown
:
elif
what
==
keyDown
:
c
=
chr
(
message
&
charCodeMask
)
c
=
chr
(
message
&
charCodeMask
)
if
modifiers
&
cmdKey
:
if
modifiers
&
cmdKey
:
if
c
==
'.'
:
if
c
==
'.'
:
raise
KeyboardInterrupt
,
"Command-period"
raise
KeyboardInterrupt
,
"Command-period"
if
c
==
'q'
:
if
c
==
'q'
:
if
hasattr
(
MacOS
,
'OutputSeen'
):
if
hasattr
(
MacOS
,
'OutputSeen'
):
MacOS
.
OutputSeen
()
MacOS
.
OutputSeen
()
self
.
quitting
=
1
self
.
quitting
=
1
return
return
elif
what
==
mouseDown
:
elif
what
==
mouseDown
:
partcode
,
window
=
Win
.
FindWindow
(
where
)
partcode
,
window
=
Win
.
FindWindow
(
where
)
if
partcode
==
inMenuBar
:
if
partcode
==
inMenuBar
:
result
=
Menu
.
MenuSelect
(
where
)
result
=
Menu
.
MenuSelect
(
where
)
id
=
(
result
>>
16
)
&
0xffff
# Hi word
id
=
(
result
>>
16
)
&
0xffff
# Hi word
item
=
result
&
0xffff
# Lo word
item
=
result
&
0xffff
# Lo word
if
id
==
self
.
appleid
:
if
id
==
self
.
appleid
:
if
item
==
1
:
if
item
==
1
:
EasyDialogs
.
Message
(
self
.
getabouttext
())
EasyDialogs
.
Message
(
self
.
getabouttext
())
elif
item
>
1
and
hasattr
(
Menu
,
'OpenDeskAcc'
):
elif
item
>
1
and
hasattr
(
Menu
,
'OpenDeskAcc'
):
name
=
self
.
applemenu
.
GetMenuItemText
(
item
)
name
=
self
.
applemenu
.
GetMenuItemText
(
item
)
Menu
.
OpenDeskAcc
(
name
)
Menu
.
OpenDeskAcc
(
name
)
elif
id
==
self
.
quitid
and
item
==
1
:
elif
id
==
self
.
quitid
and
item
==
1
:
if
hasattr
(
MacOS
,
'OutputSeen'
):
if
hasattr
(
MacOS
,
'OutputSeen'
):
MacOS
.
OutputSeen
()
MacOS
.
OutputSeen
()
self
.
quitting
=
1
self
.
quitting
=
1
Menu
.
HiliteMenu
(
0
)
Menu
.
HiliteMenu
(
0
)
return
return
# Anything not handled is passed to Python/SIOUX
# Anything not handled is passed to Python/SIOUX
if
hasattr
(
MacOS
,
'HandleEvent'
):
if
hasattr
(
MacOS
,
'HandleEvent'
):
MacOS
.
HandleEvent
(
event
)
MacOS
.
HandleEvent
(
event
)
else
:
else
:
print
"Unhandled event:"
,
event
print
"Unhandled event:"
,
event
def
getabouttext
(
self
):
def
getabouttext
(
self
):
return
self
.
__class__
.
__name__
return
self
.
__class__
.
__name__
def
getaboutmenutext
(
self
):
def
getaboutmenutext
(
self
):
return
"About %s
\
311
"
%
self
.
__class__
.
__name__
return
"About %s
\
311
"
%
self
.
__class__
.
__name__
class
AEServer
:
class
AEServer
:
def
__init__
(
self
):
def
__init__
(
self
):
self
.
ae_handlers
=
{}
self
.
ae_handlers
=
{}
def
installaehandler
(
self
,
classe
,
type
,
callback
):
def
installaehandler
(
self
,
classe
,
type
,
callback
):
AE
.
AEInstallEventHandler
(
classe
,
type
,
self
.
callback_wrapper
)
AE
.
AEInstallEventHandler
(
classe
,
type
,
self
.
callback_wrapper
)
self
.
ae_handlers
[(
classe
,
type
)]
=
callback
self
.
ae_handlers
[(
classe
,
type
)]
=
callback
def
close
(
self
):
def
close
(
self
):
for
classe
,
type
in
self
.
ae_handlers
.
keys
():
for
classe
,
type
in
self
.
ae_handlers
.
keys
():
AE
.
AERemoveEventHandler
(
classe
,
type
)
AE
.
AERemoveEventHandler
(
classe
,
type
)
def
callback_wrapper
(
self
,
_request
,
_reply
):
def
callback_wrapper
(
self
,
_request
,
_reply
):
_parameters
,
_attributes
=
aetools
.
unpackevent
(
_request
)
_parameters
,
_attributes
=
aetools
.
unpackevent
(
_request
)
_class
=
_attributes
[
'evcl'
].
type
_class
=
_attributes
[
'evcl'
].
type
_type
=
_attributes
[
'evid'
].
type
_type
=
_attributes
[
'evid'
].
type
if
self
.
ae_handlers
.
has_key
((
_class
,
_type
)):
if
self
.
ae_handlers
.
has_key
((
_class
,
_type
)):
_function
=
self
.
ae_handlers
[(
_class
,
_type
)]
_function
=
self
.
ae_handlers
[(
_class
,
_type
)]
elif
self
.
ae_handlers
.
has_key
((
_class
,
'****'
)):
elif
self
.
ae_handlers
.
has_key
((
_class
,
'****'
)):
_function
=
self
.
ae_handlers
[(
_class
,
'****'
)]
_function
=
self
.
ae_handlers
[(
_class
,
'****'
)]
elif
self
.
ae_handlers
.
has_key
((
'****'
,
'****'
)):
elif
self
.
ae_handlers
.
has_key
((
'****'
,
'****'
)):
_function
=
self
.
ae_handlers
[(
'****'
,
'****'
)]
_function
=
self
.
ae_handlers
[(
'****'
,
'****'
)]
else
:
else
:
raise
'Cannot happen: AE callback without handler'
,
(
_class
,
_type
)
raise
'Cannot happen: AE callback without handler'
,
(
_class
,
_type
)
# XXXX Do key-to-name mapping here
# XXXX Do key-to-name mapping here
_parameters
[
'_attributes'
]
=
_attributes
_parameters
[
'_attributes'
]
=
_attributes
_parameters
[
'_class'
]
=
_class
_parameters
[
'_class'
]
=
_class
_parameters
[
'_type'
]
=
_type
_parameters
[
'_type'
]
=
_type
if
_parameters
.
has_key
(
'----'
):
if
_parameters
.
has_key
(
'----'
):
_object
=
_parameters
[
'----'
]
_object
=
_parameters
[
'----'
]
del
_parameters
[
'----'
]
del
_parameters
[
'----'
]
# The try/except that used to be here can mask programmer errors.
# The try/except that used to be here can mask programmer errors.
# Let the program crash, the programmer can always add a **args
# Let the program crash, the programmer can always add a **args
# to the formal parameter list.
# to the formal parameter list.
rv
=
apply
(
_function
,
(
_object
,),
_parameters
)
rv
=
_function
(
_object
,
**
_parameters
)
else
:
else
:
#Same try/except comment as above
#Same try/except comment as above
rv
=
apply
(
_function
,
(),
_parameters
)
rv
=
_function
(
**
_parameters
)
if
rv
==
None
:
if
rv
==
None
:
aetools
.
packevent
(
_reply
,
{})
aetools
.
packevent
(
_reply
,
{})
else
:
else
:
aetools
.
packevent
(
_reply
,
{
'----'
:
rv
})
aetools
.
packevent
(
_reply
,
{
'----'
:
rv
})
def
code
(
x
):
def
code
(
x
):
"Convert a long int to the 4-character code it really is"
"Convert a long int to the 4-character code it really is"
s
=
''
s
=
''
for
i
in
range
(
4
):
for
i
in
range
(
4
):
x
,
c
=
divmod
(
x
,
256
)
x
,
c
=
divmod
(
x
,
256
)
s
=
chr
(
c
)
+
s
s
=
chr
(
c
)
+
s
return
s
return
s
class
_Test
(
AEServer
,
MiniApplication
):
class
_Test
(
AEServer
,
MiniApplication
):
"""Mini test application, handles required events"""
"""Mini test application, handles required events"""
def
__init__
(
self
):
def
__init__
(
self
):
MiniApplication
.
__init__
(
self
)
MiniApplication
.
__init__
(
self
)
AEServer
.
__init__
(
self
)
AEServer
.
__init__
(
self
)
self
.
installaehandler
(
'aevt'
,
'oapp'
,
self
.
open_app
)
self
.
installaehandler
(
'aevt'
,
'oapp'
,
self
.
open_app
)
self
.
installaehandler
(
'aevt'
,
'quit'
,
self
.
quit
)
self
.
installaehandler
(
'aevt'
,
'quit'
,
self
.
quit
)
self
.
installaehandler
(
'****'
,
'****'
,
self
.
other
)
self
.
installaehandler
(
'****'
,
'****'
,
self
.
other
)
self
.
mainloop
()
self
.
mainloop
()
def
quit
(
self
,
**
args
):
def
quit
(
self
,
**
args
):
self
.
_quit
()
self
.
_quit
()
def
open_app
(
self
,
**
args
):
def
open_app
(
self
,
**
args
):
pass
pass
def
other
(
self
,
_object
=
None
,
_class
=
None
,
_type
=
None
,
**
args
):
def
other
(
self
,
_object
=
None
,
_class
=
None
,
_type
=
None
,
**
args
):
print
'AppleEvent'
,
(
_class
,
_type
),
'for'
,
_object
,
'Other args:'
,
args
print
'AppleEvent'
,
(
_class
,
_type
),
'for'
,
_object
,
'Other args:'
,
args
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
_Test
()
_Test
()
Lib/plat-mac/argvemulator.py
View file @
ff41c48a
...
@@ -11,104 +11,104 @@ from Carbon.Events import *
...
@@ -11,104 +11,104 @@ from Carbon.Events import *
import
aetools
import
aetools
class
ArgvCollector
:
class
ArgvCollector
:
"""A minimal FrameWork.Application-like class"""
"""A minimal FrameWork.Application-like class"""
def
__init__
(
self
):
def
__init__
(
self
):
self
.
quitting
=
0
self
.
quitting
=
0
self
.
ae_handlers
=
{}
self
.
ae_handlers
=
{}
# Remove the funny -psn_xxx_xxx argument
# Remove the funny -psn_xxx_xxx argument
if
len
(
sys
.
argv
)
>
1
and
sys
.
argv
[
1
][:
4
]
==
'-psn'
:
if
len
(
sys
.
argv
)
>
1
and
sys
.
argv
[
1
][:
4
]
==
'-psn'
:
del
sys
.
argv
[
1
]
del
sys
.
argv
[
1
]
self
.
installaehandler
(
'aevt'
,
'oapp'
,
self
.
open_app
)
self
.
installaehandler
(
'aevt'
,
'oapp'
,
self
.
open_app
)
self
.
installaehandler
(
'aevt'
,
'odoc'
,
self
.
open_file
)
self
.
installaehandler
(
'aevt'
,
'odoc'
,
self
.
open_file
)
def
installaehandler
(
self
,
classe
,
type
,
callback
):
def
installaehandler
(
self
,
classe
,
type
,
callback
):
AE
.
AEInstallEventHandler
(
classe
,
type
,
self
.
callback_wrapper
)
AE
.
AEInstallEventHandler
(
classe
,
type
,
self
.
callback_wrapper
)
self
.
ae_handlers
[(
classe
,
type
)]
=
callback
self
.
ae_handlers
[(
classe
,
type
)]
=
callback
def
close
(
self
):
def
close
(
self
):
for
classe
,
type
in
self
.
ae_handlers
.
keys
():
for
classe
,
type
in
self
.
ae_handlers
.
keys
():
AE
.
AERemoveEventHandler
(
classe
,
type
)
AE
.
AERemoveEventHandler
(
classe
,
type
)
def
mainloop
(
self
,
mask
=
highLevelEventMask
,
timeout
=
1
*
60
):
def
mainloop
(
self
,
mask
=
highLevelEventMask
,
timeout
=
1
*
60
):
stoptime
=
Evt
.
TickCount
()
+
timeout
stoptime
=
Evt
.
TickCount
()
+
timeout
while
not
self
.
quitting
and
Evt
.
TickCount
()
<
stoptime
:
while
not
self
.
quitting
and
Evt
.
TickCount
()
<
stoptime
:
self
.
dooneevent
(
mask
,
timeout
)
self
.
dooneevent
(
mask
,
timeout
)
self
.
close
()
self
.
close
()
def
_quit
(
self
):
def
_quit
(
self
):
self
.
quitting
=
1
self
.
quitting
=
1
def
dooneevent
(
self
,
mask
=
highLevelEventMask
,
timeout
=
1
*
60
):
def
dooneevent
(
self
,
mask
=
highLevelEventMask
,
timeout
=
1
*
60
):
got
,
event
=
Evt
.
WaitNextEvent
(
mask
,
timeout
)
got
,
event
=
Evt
.
WaitNextEvent
(
mask
,
timeout
)
if
got
:
if
got
:
self
.
lowlevelhandler
(
event
)
self
.
lowlevelhandler
(
event
)
def
lowlevelhandler
(
self
,
event
):
def
lowlevelhandler
(
self
,
event
):
what
,
message
,
when
,
where
,
modifiers
=
event
what
,
message
,
when
,
where
,
modifiers
=
event
h
,
v
=
where
h
,
v
=
where
if
what
==
kHighLevelEvent
:
if
what
==
kHighLevelEvent
:
try
:
try
:
AE
.
AEProcessAppleEvent
(
event
)
AE
.
AEProcessAppleEvent
(
event
)
except
AE
.
Error
,
err
:
except
AE
.
Error
,
err
:
msg
=
"High Level Event: %s %s"
%
\
msg
=
"High Level Event: %s %s"
%
\
(
`hex(message)`
,
`hex(h | (v<<16))`
)
(
`hex(message)`
,
`hex(h | (v<<16))`
)
print
'AE error: '
,
err
print
'AE error: '
,
err
print
'in'
,
msg
print
'in'
,
msg
traceback
.
print_exc
()
traceback
.
print_exc
()
return
return
else
:
else
:
print
"Unhandled event:"
,
event
print
"Unhandled event:"
,
event
def
callback_wrapper
(
self
,
_request
,
_reply
):
def
callback_wrapper
(
self
,
_request
,
_reply
):
_parameters
,
_attributes
=
aetools
.
unpackevent
(
_request
)
_parameters
,
_attributes
=
aetools
.
unpackevent
(
_request
)
_class
=
_attributes
[
'evcl'
].
type
_class
=
_attributes
[
'evcl'
].
type
_type
=
_attributes
[
'evid'
].
type
_type
=
_attributes
[
'evid'
].
type
if
self
.
ae_handlers
.
has_key
((
_class
,
_type
)):
if
self
.
ae_handlers
.
has_key
((
_class
,
_type
)):
_function
=
self
.
ae_handlers
[(
_class
,
_type
)]
_function
=
self
.
ae_handlers
[(
_class
,
_type
)]
elif
self
.
ae_handlers
.
has_key
((
_class
,
'****'
)):
elif
self
.
ae_handlers
.
has_key
((
_class
,
'****'
)):
_function
=
self
.
ae_handlers
[(
_class
,
'****'
)]
_function
=
self
.
ae_handlers
[(
_class
,
'****'
)]
elif
self
.
ae_handlers
.
has_key
((
'****'
,
'****'
)):
elif
self
.
ae_handlers
.
has_key
((
'****'
,
'****'
)):
_function
=
self
.
ae_handlers
[(
'****'
,
'****'
)]
_function
=
self
.
ae_handlers
[(
'****'
,
'****'
)]
else
:
else
:
raise
'Cannot happen: AE callback without handler'
,
(
_class
,
_type
)
raise
'Cannot happen: AE callback without handler'
,
(
_class
,
_type
)
# XXXX Do key-to-name mapping here
# XXXX Do key-to-name mapping here
_parameters
[
'_attributes'
]
=
_attributes
_parameters
[
'_attributes'
]
=
_attributes
_parameters
[
'_class'
]
=
_class
_parameters
[
'_class'
]
=
_class
_parameters
[
'_type'
]
=
_type
_parameters
[
'_type'
]
=
_type
if
_parameters
.
has_key
(
'----'
):
if
_parameters
.
has_key
(
'----'
):
_object
=
_parameters
[
'----'
]
_object
=
_parameters
[
'----'
]
del
_parameters
[
'----'
]
del
_parameters
[
'----'
]
# The try/except that used to be here can mask programmer errors.
# The try/except that used to be here can mask programmer errors.
# Let the program crash, the programmer can always add a **args
# Let the program crash, the programmer can always add a **args
# to the formal parameter list.
# to the formal parameter list.
rv
=
apply
(
_function
,
(
_object
,),
_parameters
)
rv
=
_function
(
_object
,
**
_parameters
)
else
:
else
:
#Same try/except comment as above
#Same try/except comment as above
rv
=
apply
(
_function
,
(),
_parameters
)
rv
=
_function
(
**
_parameters
)
if
rv
==
None
:
if
rv
==
None
:
aetools
.
packevent
(
_reply
,
{})
aetools
.
packevent
(
_reply
,
{})
else
:
else
:
aetools
.
packevent
(
_reply
,
{
'----'
:
rv
})
aetools
.
packevent
(
_reply
,
{
'----'
:
rv
})
def
open_app
(
self
,
**
args
):
def
open_app
(
self
,
**
args
):
self
.
_quit
()
self
.
_quit
()
def
open_file
(
self
,
_object
=
None
,
**
args
):
def
open_file
(
self
,
_object
=
None
,
**
args
):
for
alias
in
_object
:
for
alias
in
_object
:
fsr
=
alias
.
FSResolveAlias
(
None
)[
0
]
fsr
=
alias
.
FSResolveAlias
(
None
)[
0
]
pathname
=
fsr
.
as_pathname
()
pathname
=
fsr
.
as_pathname
()
sys
.
argv
.
append
(
pathname
)
sys
.
argv
.
append
(
pathname
)
self
.
_quit
()
self
.
_quit
()
def
other
(
self
,
_object
=
None
,
_class
=
None
,
_type
=
None
,
**
args
):
def
other
(
self
,
_object
=
None
,
_class
=
None
,
_type
=
None
,
**
args
):
print
'Ignore AppleEvent'
,
(
_class
,
_type
),
'for'
,
_object
,
'Other args:'
,
args
print
'Ignore AppleEvent'
,
(
_class
,
_type
),
'for'
,
_object
,
'Other args:'
,
args
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
ArgvCollector
().
mainloop
()
ArgvCollector
().
mainloop
()
print
"sys.argv="
,
sys
.
argv
print
"sys.argv="
,
sys
.
argv
Lib/plat-mac/icopen.py
View file @
ff41c48a
...
@@ -29,7 +29,7 @@ INSTALLATION
...
@@ -29,7 +29,7 @@ INSTALLATION
Put this file in your Python path, and create a file named {Python}:sitecustomize.py
Put this file in your Python path, and create a file named {Python}:sitecustomize.py
that contains:
that contains:
import icopen
import icopen
(If {Python}:sitecustomizer.py already exists, just add the 'import' line to it.)
(If {Python}:sitecustomizer.py already exists, just add the 'import' line to it.)
...
@@ -42,18 +42,18 @@ import __builtin__
...
@@ -42,18 +42,18 @@ import __builtin__
_builtin_open
=
globals
().
get
(
'_builtin_open'
,
__builtin__
.
open
)
_builtin_open
=
globals
().
get
(
'_builtin_open'
,
__builtin__
.
open
)
def
_open_with_typer
(
*
args
):
def
_open_with_typer
(
*
args
):
file
=
apply
(
_builtin_open
,
args
)
file
=
_builtin_open
(
*
args
)
filename
=
args
[
0
]
filename
=
args
[
0
]
mode
=
'r'
mode
=
'r'
if
args
[
1
:]:
if
args
[
1
:]:
mode
=
args
[
1
]
mode
=
args
[
1
]
if
mode
[
0
]
==
'w'
:
if
mode
[
0
]
==
'w'
:
from
ic
import
error
,
settypecreator
from
ic
import
error
,
settypecreator
try
:
try
:
settypecreator
(
filename
)
settypecreator
(
filename
)
except
error
:
except
error
:
pass
pass
return
file
return
file
__builtin__
.
open
=
_open_with_typer
__builtin__
.
open
=
_open_with_typer
...
@@ -63,4 +63,4 @@ _open_with_typer('test.py', 'w')
...
@@ -63,4 +63,4 @@ _open_with_typer('test.py', 'w')
_open_with_typer('test.txt', 'w')
_open_with_typer('test.txt', 'w')
_open_with_typer('test.html', 'w')
_open_with_typer('test.html', 'w')
_open_with_typer('test.foo', 'w')
_open_with_typer('test.foo', 'w')
"""
"""
\ No newline at end of file
Lib/test/reperf.py
View file @
ff41c48a
...
@@ -12,7 +12,7 @@ def timefunc(n, func, *args, **kw):
...
@@ -12,7 +12,7 @@ def timefunc(n, func, *args, **kw):
t0
=
time
.
clock
()
t0
=
time
.
clock
()
try
:
try
:
for
i
in
range
(
n
):
for
i
in
range
(
n
):
result
=
apply
(
func
,
args
,
kw
)
result
=
func
(
*
args
,
**
kw
)
return
result
return
result
finally
:
finally
:
t1
=
time
.
clock
()
t1
=
time
.
clock
()
...
...
Lib/test/test_curses.py
View file @
ff41c48a
...
@@ -26,7 +26,7 @@ def window_funcs(stdscr):
...
@@ -26,7 +26,7 @@ def window_funcs(stdscr):
for
meth
in
[
stdscr
.
addch
,
stdscr
.
addstr
]:
for
meth
in
[
stdscr
.
addch
,
stdscr
.
addstr
]:
for
args
in
[(
'a'
),
(
'a'
,
curses
.
A_BOLD
),
for
args
in
[(
'a'
),
(
'a'
,
curses
.
A_BOLD
),
(
4
,
4
,
'a'
),
(
5
,
5
,
'a'
,
curses
.
A_BOLD
)]:
(
4
,
4
,
'a'
),
(
5
,
5
,
'a'
,
curses
.
A_BOLD
)]:
apply
(
meth
,
args
)
meth
(
*
args
)
for
meth
in
[
stdscr
.
box
,
stdscr
.
clear
,
stdscr
.
clrtobot
,
for
meth
in
[
stdscr
.
box
,
stdscr
.
clear
,
stdscr
.
clrtobot
,
stdscr
.
clrtoeol
,
stdscr
.
cursyncup
,
stdscr
.
delch
,
stdscr
.
clrtoeol
,
stdscr
.
cursyncup
,
stdscr
.
delch
,
...
...
Lib/xml/dom/minidom.py
View file @
ff41c48a
...
@@ -1902,7 +1902,7 @@ def _get_StringIO():
...
@@ -1902,7 +1902,7 @@ def _get_StringIO():
return
StringIO
()
return
StringIO
()
def
_do_pulldom_parse
(
func
,
args
,
kwargs
):
def
_do_pulldom_parse
(
func
,
args
,
kwargs
):
events
=
apply
(
func
,
args
,
kwargs
)
events
=
func
(
*
args
,
**
kwargs
)
toktype
,
rootNode
=
events
.
getEvent
()
toktype
,
rootNode
=
events
.
getEvent
()
events
.
expandNode
(
rootNode
)
events
.
expandNode
(
rootNode
)
events
.
clear
()
events
.
clear
()
...
@@ -1915,7 +1915,7 @@ def parse(file, parser=None, bufsize=None):
...
@@ -1915,7 +1915,7 @@ def parse(file, parser=None, bufsize=None):
return
expatbuilder
.
parse
(
file
)
return
expatbuilder
.
parse
(
file
)
else
:
else
:
from
xml.dom
import
pulldom
from
xml.dom
import
pulldom
return
_do_pulldom_parse
(
pulldom
.
parse
,
(
file
,),
return
_do_pulldom_parse
(
pulldom
.
parse
,
(
file
,),
{
'parser'
:
parser
,
'bufsize'
:
bufsize
})
{
'parser'
:
parser
,
'bufsize'
:
bufsize
})
def
parseString
(
string
,
parser
=
None
):
def
parseString
(
string
,
parser
=
None
):
...
...
Python/bltinmodule.c
View file @
ff41c48a
...
@@ -112,7 +112,10 @@ PyDoc_STRVAR(apply_doc,
...
@@ -112,7 +112,10 @@ PyDoc_STRVAR(apply_doc,
\n
\
\n
\
Call a callable object with positional arguments taken from the tuple args,
\n
\
Call a callable object with positional arguments taken from the tuple args,
\n
\
and keyword arguments taken from the optional dictionary kwargs.
\n
\
and keyword arguments taken from the optional dictionary kwargs.
\n
\
Note that classes are callable, as are instances with a __call__() method."
);
Note that classes are callable, as are instances with a __call__() method.
\n
\
\n
\
Deprecated since release 2.3. Instead, use the extended call syntax:
\n
\
function(*args, **keywords)."
);
static
PyObject
*
static
PyObject
*
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment