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
31559238
Commit
31559238
authored
Feb 05, 1995
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more support for different kinds of objects
parent
b19a645b
Changes
2
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
550 additions
and
177 deletions
+550
-177
Mac/Lib/test/echo.py
Mac/Lib/test/echo.py
+119
-0
Mac/Lib/toolbox/aetools.py
Mac/Lib/toolbox/aetools.py
+431
-177
No files found.
Mac/Lib/test/echo.py
0 → 100644
View file @
31559238
"""'echo' -- an AppleEvent handler which handles all events the same.
It replies to each event by echoing the parameter back to the client.
This is a good way to find out how the Script Editor formats AppleEvents,
especially to figure out all the different forms an object specifier
can have (without having to rely on Apple's implementation).
"""
import
AE
from
AppleEvents
import
*
import
Evt
from
Events
import
*
import
aetools
import
sys
import
MacOS
import
traceback
kHighLevelEvent
=
23
# Not defined anywhere for Python yet?
def
main
():
echo
=
EchoServer
()
MacOS
.
EnableAppswitch
(
0
)
# Disable Python's own "event handling"
try
:
echo
.
mainloop
()
finally
:
MacOS
.
EnableAppswitch
(
1
)
# Let Python have a go at events
echo
.
close
()
class
EchoServer
:
suites
=
[
'aevt'
,
'core'
]
def
__init__
(
self
):
self
.
active
=
0
for
suite
in
self
.
suites
:
AE
.
AEInstallEventHandler
(
suite
,
typeWildCard
,
self
.
aehandler
)
self
.
active
=
1
def
__del__
(
self
):
self
.
close
()
def
close
(
self
):
if
self
.
active
:
self
.
active
=
0
for
suite
in
self
.
suites
:
AE
.
AERemoveEventHandler
(
suite
,
typeWildCard
)
def
mainloop
(
self
,
mask
=
everyEvent
,
timeout
=
60
*
60
):
while
1
:
got
,
event
=
Evt
.
WaitNextEvent
(
mask
,
timeout
)
if
got
:
self
.
lowlevelhandler
(
event
)
def
lowlevelhandler
(
self
,
event
):
what
,
message
,
when
,
(
h
,
v
),
modifiers
=
event
if
what
==
kHighLevelEvent
:
print
"High Level Event:"
,
`code(message)`
,
`code(h | (v<<16))`
try
:
AE
.
AEProcessAppleEvent
(
event
)
except
AE
.
Error
,
msg
:
print
"AEProcessAppleEvent error:"
traceback
.
print_exc
()
elif
what
==
keyDown
:
c
=
chr
(
message
&
charCodeMask
)
if
c
==
'.'
and
modifiers
&
cmdKey
:
raise
KeyboardInterrupt
,
"Command-period"
MacOS
.
HandleEvent
(
event
)
elif
what
<>
autoKey
:
print
"Event:"
,
(
eventname
(
what
),
message
,
when
,
(
h
,
v
),
modifiers
)
MacOS
.
HandleEvent
(
event
)
def
aehandler
(
self
,
request
,
reply
):
print
"Apple Event"
,
parameters
,
attributes
=
aetools
.
unpackevent
(
request
)
print
"class ="
,
`attributes['evcl'].type`
,
print
"id ="
,
`attributes['evid'].type`
print
"Parameters:"
keys
=
parameters
.
keys
()
keys
.
sort
()
for
key
in
keys
:
print
"%s: %.150s"
%
(
`key`
,
`parameters[key]`
)
print
" :"
,
str
(
parameters
[
key
])
print
"Attributes:"
keys
=
attributes
.
keys
()
keys
.
sort
()
for
key
in
keys
:
print
"%s: %.150s"
%
(
`key`
,
`attributes[key]`
)
aetools
.
packevent
(
reply
,
parameters
)
_eventnames
=
{
keyDown
:
'keyDown'
,
autoKey
:
'autoKey'
,
mouseDown
:
'mouseDown'
,
mouseUp
:
'mouseUp'
,
updateEvt
:
'updateEvt'
,
diskEvt
:
'diskEvt'
,
activateEvt
:
'activateEvt'
,
osEvt
:
'osEvt'
,
}
def
eventname
(
what
):
if
_eventnames
.
has_key
(
what
):
return
_eventnames
[
what
]
else
:
return
`what`
def
code
(
x
):
"Convert a long int to the 4-character code it really is"
s
=
''
for
i
in
range
(
4
):
x
,
c
=
divmod
(
x
,
256
)
s
=
chr
(
c
)
+
s
return
s
if
__name__
==
'__main__'
:
main
()
else
:
main
()
Mac/Lib/toolbox/aetools.py
View file @
31559238
This diff is collapsed.
Click to expand it.
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