the usual
This commit is contained in:
parent
fc8a01fc5a
commit
227a4232e6
|
@ -11,6 +11,8 @@ addpack.addpack('Demo')
|
|||
addpack.addpack('bgen')
|
||||
addpack.addpack('ae')
|
||||
addpack.addpack('evt')
|
||||
#addpack.addpack('menu')
|
||||
addpack.addpack('win')
|
||||
|
||||
import sys
|
||||
sys.stdout = sys.stderr
|
||||
|
@ -20,18 +22,25 @@ import AE
|
|||
from AppleEvents import *
|
||||
import Evt
|
||||
from Events import *
|
||||
import Menu
|
||||
import Dlg
|
||||
import Win
|
||||
from Windows import *
|
||||
import Qd
|
||||
|
||||
import aetools
|
||||
import EasyDialogs
|
||||
|
||||
kHighLevelEvent = 23 # Not defined anywhere for Python yet?
|
||||
|
||||
|
||||
def main():
|
||||
echo = EchoServer()
|
||||
MacOS.EnableAppswitch(0) # Disable Python's own "event handling"
|
||||
yield = MacOS.EnableAppswitch(-1) # Disable Python's own "event handling"
|
||||
try:
|
||||
echo.mainloop()
|
||||
echo.mainloop(everyEvent, 0)
|
||||
finally:
|
||||
MacOS.EnableAppswitch(1) # Let Python have a go at events
|
||||
MacOS.EnableAppswitch(yield) # Let Python have a go at events
|
||||
echo.close()
|
||||
|
||||
|
||||
|
@ -44,6 +53,13 @@ class EchoServer:
|
|||
for suite in self.suites:
|
||||
AE.AEInstallEventHandler(suite, typeWildCard, self.aehandler)
|
||||
self.active = 1
|
||||
self.appleid = 1
|
||||
Menu.ClearMenuBar()
|
||||
self.applemenu = applemenu = Menu.NewMenu(self.appleid, "\024")
|
||||
applemenu.AppendMenu("All about echo...;(-")
|
||||
applemenu.AddResMenu('DRVR')
|
||||
applemenu.InsertMenu(0)
|
||||
Menu.DrawMenuBar()
|
||||
|
||||
def __del__(self):
|
||||
self.close()
|
||||
|
@ -64,22 +80,38 @@ class EchoServer:
|
|||
self.lowlevelhandler(event)
|
||||
|
||||
def lowlevelhandler(self, event):
|
||||
what, message, when, (h, v), modifiers = event
|
||||
what, message, when, where, modifiers = event
|
||||
h, v = where
|
||||
if what == kHighLevelEvent:
|
||||
print "High Level Event:", `code(message)`, `code(h | (v<<16))`
|
||||
msg = "High Level Event: %s %s" % \
|
||||
(`code(message)`, `code(h | (v<<16))`)
|
||||
try:
|
||||
AE.AEProcessAppleEvent(event)
|
||||
except AE.Error, msg:
|
||||
print "AEProcessAppleEvent error:"
|
||||
except AE.Error, err:
|
||||
EasyDialogs.Message(msg + "\015AEProcessAppleEvent error: %s" % str(err))
|
||||
traceback.print_exc()
|
||||
else:
|
||||
EasyDialogs.Message(msg + "\015OK!")
|
||||
elif what == keyDown:
|
||||
c = chr(message & charCodeMask)
|
||||
if c == '.' and modifiers & cmdKey:
|
||||
raise KeyboardInterrupt, "Command-period"
|
||||
MacOS.HandleEvent(event)
|
||||
elif what == mouseDown:
|
||||
partcode, window = Win.FindWindow(where)
|
||||
if partcode == inMenuBar:
|
||||
result = Menu.MenuSelect(where)
|
||||
id = (result>>16) & 0xffff # Hi word
|
||||
item = result & 0xffff # Lo word
|
||||
if id == self.appleid:
|
||||
if item == 1:
|
||||
EasyDialogs.Message("Echo -- echo AppleEvents")
|
||||
elif item > 1:
|
||||
name = self.applemenu.GetItem(item)
|
||||
Qd.OpenDeskAcc(name)
|
||||
elif what <> autoKey:
|
||||
print "Event:", (eventname(what), message, when, (h, v), modifiers)
|
||||
MacOS.HandleEvent(event)
|
||||
## MacOS.HandleEvent(event)
|
||||
|
||||
def aehandler(self, request, reply):
|
||||
print "Apple Event",
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
# Generated from 'D:Development:THINK C:Mac #includes:Apple #includes:AppleEvents.h'
|
||||
|
||||
typeBoolean = 'bool'
|
||||
typeChar = 'TEXT'
|
||||
typeSMInt = 'shor'
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
# Generated from 'D:Development:THINK C:Mac #includes:Apple #includes:Controls.h'
|
||||
|
||||
pushButProc = 0
|
||||
checkBoxProc = 1
|
||||
radioButProc = 2
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
# Generated from 'D:Development:THINK C:Mac #includes:Apple #includes:Dialogs.h'
|
||||
|
||||
ctrlItem = 4
|
||||
btnCtrl = 0
|
||||
chkCtrl = 1
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
# Generated from 'D:Development:THINK C:Mac #includes:Apple #includes:Events.h'
|
||||
|
||||
nullEvent = 0
|
||||
mouseDown = 1
|
||||
mouseUp = 2
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
# Generated from 'D:Development:THINK C:Mac #includes:Apple #includes:Resources.h'
|
||||
|
||||
resSysHeap = 64
|
||||
resPurgeable = 32
|
||||
resLocked = 16
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
# Generated from 'D:Development:THINK C:Mac #includes:Apple #includes:Sound.h'
|
||||
|
||||
swMode = -1
|
||||
ftMode = 1
|
||||
ffMode = 0
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
# Generated from 'D:Development:THINK C:Mac #includes:Apple #includes:Windows.h'
|
||||
|
||||
documentProc = 0
|
||||
dBoxProc = 1
|
||||
plainDBox = 2
|
||||
|
|
|
@ -312,3 +312,4 @@ f = AEFunction(OSErr, 'AEManagerInfo',
|
|||
(long, 'result', OutMode),
|
||||
)
|
||||
functions.append(f)
|
||||
|
||||
|
|
|
@ -170,3 +170,4 @@ f = Method(short, 'GetCVariant',
|
|||
(ControlHandle, 'theControl', InMode),
|
||||
)
|
||||
methods.append(f)
|
||||
|
||||
|
|
|
@ -42,6 +42,3 @@ f = Function(void, 'GetKeys',
|
|||
)
|
||||
functions.append(f)
|
||||
|
||||
f = Function(long, 'TickCount',
|
||||
)
|
||||
functions.append(f)
|
||||
|
|
|
@ -50,7 +50,7 @@ typedef struct MenuObject {
|
|||
} MenuObject;
|
||||
|
||||
PyObject *MenuObj_New(itself)
|
||||
const MenuHandle itself;
|
||||
MenuHandle itself;
|
||||
{
|
||||
MenuObject *it;
|
||||
it = PyObject_NEW(MenuObject, &Menu_Type);
|
||||
|
|
|
@ -240,3 +240,4 @@ f = Function(void, 'DelMCEntries',
|
|||
(short, 'menuItem', InMode),
|
||||
)
|
||||
functions.append(f)
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ typedef struct ResourceObject {
|
|||
} ResourceObject;
|
||||
|
||||
PyObject *ResObj_New(itself)
|
||||
const Handle itself;
|
||||
Handle itself;
|
||||
{
|
||||
ResourceObject *it;
|
||||
if (itself == NULL) return PyMac_Error(resNotFound);
|
||||
|
|
|
@ -269,3 +269,4 @@ f = ResMethod(void, 'SetResourceSize',
|
|||
(long, 'newSize', InMode),
|
||||
)
|
||||
resmethods.append(f)
|
||||
|
||||
|
|
|
@ -38,6 +38,9 @@ class ResourcesScanner(Scanner):
|
|||
return [
|
||||
"ReadPartialResource",
|
||||
"WritePartialResource",
|
||||
## "RmveResource", # RemoveResource
|
||||
## "SizeResource", # GetResourceSizeOnDisk
|
||||
## "MaxSizeRsrc", # GetMaxResourceSize
|
||||
]
|
||||
|
||||
def makerepairinstructions(self):
|
||||
|
|
|
@ -129,3 +129,4 @@ f = SndFunction(void, 'Exp1to6',
|
|||
(unsigned_long, 'whichChannel', InMode),
|
||||
)
|
||||
functions.append(f)
|
||||
|
||||
|
|
|
@ -53,21 +53,22 @@ class FixedInputOutputBufferType(InputOnlyType):
|
|||
|
||||
def declareSize(self, name):
|
||||
Output("%s %s__len__;", self.sizetype, name)
|
||||
Output("int %s__in_len__;", name)
|
||||
|
||||
def getargsFormat(self):
|
||||
# XXX This only works if the size is int-sized!!!
|
||||
return "s#"
|
||||
|
||||
def getargsArgs(self, name):
|
||||
return "&%s__in__, &%s__len__" % (name, name)
|
||||
return "&%s__in__, &%s__in_len__" % (name, name)
|
||||
|
||||
def getargsCheck(self, name):
|
||||
Output("if (%s__len__ != %s)", name, self.size)
|
||||
Output("if (%s__in_len__ != %s)", name, self.size)
|
||||
OutLbrace()
|
||||
Output('PyErr_SetString(PyExc_TypeError, "buffer length should be %s");',
|
||||
self.size)
|
||||
Output("goto %s__error__;", name)
|
||||
OutRbrace()
|
||||
Output("%s__len__ = %s__in_len__;", name, name)
|
||||
|
||||
def passOutput(self, name):
|
||||
return "%s__in__, %s__out__" % (name, name)
|
||||
|
@ -76,7 +77,7 @@ class FixedInputOutputBufferType(InputOnlyType):
|
|||
return "s#"
|
||||
|
||||
def mkvalueArgs(self, name):
|
||||
return "%s__out__, %s" % (name, self.size)
|
||||
return "%s__out__, (int)%s" % (name, self.size)
|
||||
|
||||
def cleanup(self, name):
|
||||
DedentLevel()
|
||||
|
@ -138,7 +139,7 @@ class VarInputBufferType(FixedInputBufferType):
|
|||
FixedInputBufferType.__init__(self, "0", datatype, sizetype, sizeformat)
|
||||
|
||||
def getargsCheck(self, name):
|
||||
pass
|
||||
Output("%s__len__ = %s__in_len__;", name, name)
|
||||
|
||||
def passInput(self, name):
|
||||
return "%s__in__, %s__len__" % (name, name)
|
||||
|
@ -161,11 +162,14 @@ class StructInputOutputBufferType(FixedInputOutputBufferType):
|
|||
def declareInputBuffer(self, name):
|
||||
Output("%s *%s__in__;", self.type, name)
|
||||
|
||||
def declareSize(self, name):
|
||||
Output("int %s__in_len__;", name)
|
||||
|
||||
def declareOutputBuffer(self, name):
|
||||
Output("%s %s__out__;", self.type, name)
|
||||
|
||||
def getargsArgs(self, name):
|
||||
return "(char **)&%s__in__, &%s__len__" % (name, name)
|
||||
return "(char **)&%s__in__, &%s__in_len__" % (name, name)
|
||||
|
||||
def passInput(self, name):
|
||||
return "%s__in__" % name
|
||||
|
@ -174,7 +178,7 @@ class StructInputOutputBufferType(FixedInputOutputBufferType):
|
|||
return "%s__in__, &%s__out__" % (name, name)
|
||||
|
||||
def mkvalueArgs(self, name):
|
||||
return "(char *)&%s__out__, %s" % (name, self.size)
|
||||
return "(char *)&%s__out__, (int)%s" % (name, self.size)
|
||||
|
||||
|
||||
class StructCombinedInputOutputBufferType(StructInputOutputBufferType):
|
||||
|
@ -211,6 +215,9 @@ class StructOutputBufferType(OutputOnlyBufferMixIn, StructInputOutputBufferType)
|
|||
|
||||
Instantiate with the struct type as parameter.
|
||||
"""
|
||||
|
||||
def declareSize(self, name):
|
||||
pass
|
||||
|
||||
def passOutput(self, name):
|
||||
return "&%s__out__" % name
|
||||
|
@ -222,6 +229,9 @@ class ArrayOutputBufferType(OutputOnlyBufferMixIn, StructInputOutputBufferType):
|
|||
|
||||
Instantiate with the struct type as parameter.
|
||||
"""
|
||||
|
||||
def declareSize(self, name):
|
||||
pass
|
||||
|
||||
def passOutput(self, name):
|
||||
return "%s__out__" % name
|
||||
|
|
|
@ -20,17 +20,19 @@ class HeapInputOutputBufferType(FixedInputOutputBufferType):
|
|||
Output("%s *%s__out__;", self.datatype, name)
|
||||
|
||||
def getargsCheck(self, name):
|
||||
Output("if ((%s__out__ = malloc(%s__len__)) == NULL)", name, name)
|
||||
Output("if ((%s__out__ = malloc(%s__in_len__)) == NULL)", name, name)
|
||||
OutLbrace()
|
||||
Output('PyErr_NoMemory();')
|
||||
Output("goto %s__error__;", name)
|
||||
OutRbrace()
|
||||
Output("%s__len__ = %s__in_len__;", name, name)
|
||||
|
||||
def passOutput(self, name):
|
||||
return "%s__in__, %s__out__, %s__len__" % (name, name, name)
|
||||
return "%s__in__, %s__out__, (%s)%s__len__" % \
|
||||
(name, name, self.sizetype, name)
|
||||
|
||||
def mkvalueArgs(self, name):
|
||||
return "%s__out__, %s__len__" % (name, name)
|
||||
return "%s__out__, (int)%s__len__" % (name, name)
|
||||
|
||||
def cleanup(self, name):
|
||||
Output("free(%s__out__);", name)
|
||||
|
@ -75,10 +77,10 @@ class HeapOutputBufferType(OutputOnlyMixIn, HeapInputOutputBufferType):
|
|||
pass
|
||||
|
||||
def getargsFormat(self):
|
||||
return self.sizeformat
|
||||
return "i"
|
||||
|
||||
def getargsArgs(self, name):
|
||||
return "&%s__len__" % name
|
||||
return "&%s__in_len__" % name
|
||||
|
||||
def passOutput(self, name):
|
||||
return "%s__out__, %s__len__" % (name, name)
|
||||
|
|
|
@ -29,7 +29,7 @@ class VarStackOutputBufferType(StackOutputBufferType):
|
|||
return "%s__out__, &%s__len__" % (name, name)
|
||||
|
||||
def mkvalueArgs(self, name):
|
||||
return "%s__out__, %s__len__" % (name, name)
|
||||
return "%s__out__, (int)%s__len__" % (name, name)
|
||||
|
||||
|
||||
class VarVarStackOutputBufferType(VarStackOutputBufferType):
|
||||
|
@ -56,4 +56,4 @@ class ReturnVarStackOutputBufferType(VarStackOutputBufferType):
|
|||
return "%s__out__, %s__len__" % (name, name)
|
||||
|
||||
def mkvalueArgs(self, name):
|
||||
return "%s__out__, _rv" % name
|
||||
return "%s__out__, (int)_rv" % name
|
||||
|
|
Loading…
Reference in New Issue