Kaydet (Commit) a4b1d003 authored tarafından Jack Jansen's avatar Jack Jansen

Interface to the Mac List Manager.

üst f33a69f2
# Test List module.
# Draw a window with all the files in the current folder.
# double-clicking will change folder.
#
# This test expects Win, Evt and FrameWork (and anything used by those)
# to work.
from FrameWork import *
import Win
import Qd
import List
import os
class TestList(Application):
def __init__(self):
os.chdir('Moes:')
self.makemenubar()
self.makewindow()
def makewindow(self):
r = (40, 40, 400, 300)
w = Win.NewWindow(r, "List test", 1, 0, -1, 1, 0x55555555)
r2 = (0, 0, 345, 245)
self.list = List.LNew(r2, (0, 0, 1, 1), (0,0), 0, w, 0, 1, 1, 1)
self.filllist()
w.DrawGrowIcon()
self.win = w
def makeusermenus(self):
self.filemenu = m = Menu(self.menubar, "File")
self.quititem = MenuItem(m, "Quit", "Q", self.quit)
def quit(self, *args):
raise self
def do_about(self, id, item, window, event):
EasyDialogs.Message("""Test the List Manager interface.
Double-click on a folder to change directory""")
def do_activateEvt(self, *args):
self.list.LActivate(1) # XXXX Wrong...
def do_update(self, *args):
print 'LUPDATE'
self.list.LUpdate()
def do_inContent(self, partcode, window, event):
(what, message, when, where, modifiers) = event
Qd.SetPort(window)
local = Qd.GlobalToLocal(where)
print 'CLICK', where, '->', local
dclick = self.list.LClick(local, modifiers)
if dclick:
h, v = self.list.LLastClick()
file = self.list.LGetCell(1000, (h, v))
os.chdir(file)
self.filllist()
def filllist(self):
"""Fill the list with the contents of the current directory"""
l = self.list
l.LSetDrawingMode(0)
l.LDelRow(0, 0)
contents = os.listdir(':')
print contents
l.LAddRow(len(contents), 0)
for i in range(len(contents)):
l.LSetCell(contents[i], (0, i))
l.LSetDrawingMode(1)
l.LUpdate()
def main():
App = TestList()
App.mainloop()
if __name__ == '__main__':
main()
# Generated from 'Sap:CodeWarrior6:Metrowerks C/C++:Headers:Universal Headers 2.0.1f:Lists.h'
lDoVAutoscroll = 2
lDoHAutoscroll = 1
lOnlyOne = -128
lExtendDrag = 64
lNoDisjoint = 32
lNoExtend = 16
lNoRect = 8
lUseSense = 4
lNoNilHilite = 2
lInitMsg = 0
lDrawMsg = 1
lHiliteMsg = 2
lCloseMsg = 3
This diff is collapsed.
# Generated from 'Sap:CodeWarrior6:Metrowerks C/C++:Headers:Universal Headers 2.0.1f:Lists.h'
f = Function(ListRef, 'LNew',
(Rect_ptr, 'rView', InMode),
(Rect_ptr, 'dataBounds', InMode),
(Point, 'cSize', InMode),
(short, 'theProc', InMode),
(WindowRef, 'theWindow', InMode),
(Boolean, 'drawIt', InMode),
(Boolean, 'hasGrow', InMode),
(Boolean, 'scrollHoriz', InMode),
(Boolean, 'scrollVert', InMode),
)
functions.append(f)
f = Method(short, 'LAddColumn',
(short, 'count', InMode),
(short, 'colNum', InMode),
(ListRef, 'lHandle', InMode),
)
methods.append(f)
f = Method(short, 'LAddRow',
(short, 'count', InMode),
(short, 'rowNum', InMode),
(ListRef, 'lHandle', InMode),
)
methods.append(f)
f = Method(void, 'LDelColumn',
(short, 'count', InMode),
(short, 'colNum', InMode),
(ListRef, 'lHandle', InMode),
)
methods.append(f)
f = Method(void, 'LDelRow',
(short, 'count', InMode),
(short, 'rowNum', InMode),
(ListRef, 'lHandle', InMode),
)
methods.append(f)
f = Method(Boolean, 'LGetSelect',
(Boolean, 'next', InMode),
(Cell, 'theCell', InOutMode),
(ListRef, 'lHandle', InMode),
)
methods.append(f)
f = Method(Cell, 'LLastClick',
(ListRef, 'lHandle', InMode),
)
methods.append(f)
f = Method(Boolean, 'LNextCell',
(Boolean, 'hNext', InMode),
(Boolean, 'vNext', InMode),
(Cell, 'theCell', InOutMode),
(ListRef, 'lHandle', InMode),
)
methods.append(f)
f = Method(void, 'LSize',
(short, 'listWidth', InMode),
(short, 'listHeight', InMode),
(ListRef, 'lHandle', InMode),
)
methods.append(f)
f = Method(void, 'LSetDrawingMode',
(Boolean, 'drawIt', InMode),
(ListRef, 'lHandle', InMode),
)
methods.append(f)
f = Method(void, 'LScroll',
(short, 'dCols', InMode),
(short, 'dRows', InMode),
(ListRef, 'lHandle', InMode),
)
methods.append(f)
f = Method(void, 'LAutoScroll',
(ListRef, 'lHandle', InMode),
)
methods.append(f)
f = Method(void, 'LUpdate',
(RgnHandle, 'theRgn', InMode),
(ListRef, 'lHandle', InMode),
)
methods.append(f)
f = Method(void, 'LActivate',
(Boolean, 'act', InMode),
(ListRef, 'lHandle', InMode),
)
methods.append(f)
f = Method(void, 'LCellSize',
(Point, 'cSize', InMode),
(ListRef, 'lHandle', InMode),
)
methods.append(f)
f = Method(Boolean, 'LClick',
(Point, 'pt', InMode),
(short, 'modifiers', InMode),
(ListRef, 'lHandle', InMode),
)
methods.append(f)
f = Method(void, 'LAddToCell',
(InBufferShortsize, 'dataPtr', InMode),
(Cell, 'theCell', InMode),
(ListRef, 'lHandle', InMode),
)
methods.append(f)
f = Method(void, 'LClrCell',
(Cell, 'theCell', InMode),
(ListRef, 'lHandle', InMode),
)
methods.append(f)
f = Method(void, 'LGetCell',
(VarOutBufferShortsize, 'dataPtr', InOutMode),
(Cell, 'theCell', InMode),
(ListRef, 'lHandle', InMode),
)
methods.append(f)
f = Method(void, 'LRect',
(Rect, 'cellRect', OutMode),
(Cell, 'theCell', InMode),
(ListRef, 'lHandle', InMode),
)
methods.append(f)
f = Method(void, 'LSetCell',
(InBufferShortsize, 'dataPtr', InMode),
(Cell, 'theCell', InMode),
(ListRef, 'lHandle', InMode),
)
methods.append(f)
f = Method(void, 'LSetSelect',
(Boolean, 'setIt', InMode),
(Cell, 'theCell', InMode),
(ListRef, 'lHandle', InMode),
)
methods.append(f)
f = Method(void, 'LDraw',
(Cell, 'theCell', InMode),
(ListRef, 'lHandle', InMode),
)
methods.append(f)
# Scan an Apple header file, generating a Python file of generator calls.
import addpack
addpack.addpack(':tools:bgen:bgen')
from scantools import Scanner
LONG = "Lists"
SHORT = "list"
OBJECT = "ListRef"
def main():
input = LONG + ".h"
output = SHORT + "gen.py"
defsoutput = LONG + ".py"
scanner = MyScanner(input, output, defsoutput)
scanner.scan()
scanner.close()
print "=== Done scanning and generating, now importing the generated code... ==="
exec "import " + SHORT + "support"
print "=== Done. It's up to you to compile it now! ==="
class MyScanner(Scanner):
def destination(self, type, name, arglist):
classname = "Function"
listname = "functions"
if arglist:
t, n, m = arglist[-1]
# This is non-functional today
if t == OBJECT and m == "InMode":
classname = "Method"
listname = "methods"
return classname, listname
def makeblacklistnames(self):
return [
"LDispose", # Done by removing the object
"LSearch", # We don't want to handle procs just yet
"LGetCellDataLocation", # What does this do??
]
def makeblacklisttypes(self):
return [
]
def makerepairinstructions(self):
return [
([('ListBounds_ptr', '*', 'InMode')],
[('Rect_ptr', '*', 'InMode')]),
([("Cell", "theCell", "OutMode")],
[("Cell", "theCell", "InOutMode")]),
([("void_ptr", "*", "InMode"), ("short", "*", "InMode")],
[("InBufferShortsize", "*", "*")]),
([("void", "*", "OutMode"), ("short", "*", "OutMode")],
[("VarOutBufferShortsize", "*", "InOutMode")]),
# ([("void", "wStorage", "OutMode")],
# [("NullStorage", "*", "InMode")]),
#
# # GetKeys
# ([('KeyMap', 'theKeys', 'InMode')],
# [('*', '*', 'OutMode')]),
#
# # GetTicker
# ([('unsigned long', '*', '*')],
# [('unsigned_long', '*', '*')]),
]
if __name__ == "__main__":
main()
# This script generates a Python interface for an Apple Macintosh Manager.
# It uses the "bgen" package to generate C code.
# The function specifications are generated by scanning the mamager's header file,
# using the "scantools" package (customized for this particular manager).
import string
# Declarations that change for each manager
MACHEADERFILE = 'Lists.h' # The Apple header file
MODNAME = 'List' # The name of the module
OBJECTNAME = 'List' # The basic name of the objects used here
KIND = 'Handle' # Usually 'Ptr' or 'Handle'
# The following is *usually* unchanged but may still require tuning
MODPREFIX = MODNAME # The prefix for module-wide routines
OBJECTTYPE = "ListRef" # The C type used to represent them
OBJECTPREFIX = MODPREFIX + 'Obj' # The prefix for object methods
INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner
OUTPUTFILE = MODNAME + "module.c" # The file generated by this program
from macsupport import *
# Create the type objects
ListRef = OpaqueByValueType("ListRef", "ListObj")
Cell = Point
VarOutBufferShortsize = VarHeapOutputBufferType('char', 'short', 's') # (buf, &len)
InBufferShortsize = VarInputBufferType('char', 'short', 's') # (buf, len)
# For LUpdate, we alsways update the complete visible region.
RgnHandle = FakeType("(*_self->ob_itself)->port->visRgn")
includestuff = includestuff + """
#include <%s>""" % MACHEADERFILE + """
"""
class ListMethodGenerator(MethodGenerator):
"""Similar to MethodGenerator, but has self as last argument"""
def parseArgumentList(self, args):
args, a0 = args[:-1], args[-1]
t0, n0, m0 = a0
if m0 != InMode:
raise ValueError, "method's 'self' must be 'InMode'"
self.itself = Variable(t0, "_self->ob_itself", SelfMode)
FunctionGenerator.parseArgumentList(self, args)
self.argumentList.append(self.itself)
class MyObjectDefinition(GlobalObjectDefinition):
def outputCheckNewArg(self):
Output("""if (itself == NULL) {
PyErr_SetString(List_Error,"Cannot create null List");
return NULL;
}""")
def outputFreeIt(self, itselfname):
Output("LDispose(%s);", itselfname)
# From here on it's basically all boiler plate...
# Create the generator groups and link them
module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE)
module.addobject(object)
# Create the generator classes used to populate the lists
Function = FunctionGenerator
Method = ListMethodGenerator
# Create and populate the lists
functions = []
methods = []
execfile(INPUTFILE)
# add the populated lists to the generator groups
# (in a different wordl the scan program would generate this)
for f in functions: module.add(f)
for f in methods: object.add(f)
# generate output (open the output file as late as possible)
SetOutputFileName(OUTPUTFILE)
module.generate()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment