Kaydet (Commit) 4522cc9b authored tarafından cvs2svn's avatar cvs2svn

This commit was manufactured by cvs2svn to create branch

'release21-maint'.
üst 35905ec9
# A minimal text editor using MLTE. Based on wed.py.
#
# To be done:
# - Functionality: find, etc.
from Menu import DrawMenuBar
from FrameWork import *
import Win
import Ctl
import Qd
import Res
import Scrap
import os
import macfs
import MacTextEditor
import Mlte
UNDOLABELS = [ # Indexed by MLTECanUndo() value
"Typing", "Cut", "Paste", "Clear", "Font Change", "Color Change", "Size Change",
"Style Change", "Align Left", "Align Center", "Align Right", "Drop", "Move"]
class MlteWindow(Window):
def open(self, path, name, data):
self.path = path
self.name = name
r = windowbounds(400, 400)
w = Win.NewWindow(r, name, 1, 0, -1, 1, 0x55555555)
self.wid = w
flags = MacTextEditor.kTXNDrawGrowIconMask|MacTextEditor.kTXNWantHScrollBarMask| \
MacTextEditor.kTXNWantVScrollBarMask
self.ted, self.frameid = Mlte.TXNNewObject(None, w, None, flags, MacTextEditor.kTXNTextEditStyleFrameType,
MacTextEditor.kTXNTextFile, MacTextEditor.kTXNMacOSEncoding)
self.ted.TXNSetData(MacTextEditor.kTXNTextData, data, 0, 0x7fffffff)
self.changed = 0
self.do_postopen()
self.do_activate(1, None)
def do_idle(self, event):
self.ted.TXNIdle()
self.ted.TXNAdjustCursor(None)
def do_activate(self, onoff, evt):
if onoff:
## self.ted.TXNActivate(self.frameid, 0)
self.ted.TXNFocus(1)
self.parent.active = self
else:
self.ted.TXNFocus(0)
self.parent.active = None
self.parent.updatemenubar()
def do_update(self, wid, event):
self.ted.TXNDraw(None)
def do_postresize(self, width, height, window):
self.ted.TXNResizeFrame(width, height, self.frameid)
def do_contentclick(self, local, modifiers, evt):
self.ted.TXNClick(evt)
self.parent.updatemenubar()
def do_char(self, ch, event):
self.ted.TXNKeyDown(event)
self.parent.updatemenubar()
def close(self):
if self.changed:
save = EasyDialogs.AskYesNoCancel('Save window "%s" before closing?'%self.name, 1)
if save > 0:
self.menu_save()
elif save < 0:
return
if self.parent.active == self:
self.parent.active = None
self.ted.TXNDeleteObject()
del self.ted
## del self.tedtexthandle
self.do_postclose()
def menu_save(self):
if not self.path:
self.menu_save_as()
return # Will call us recursively
dhandle = self.ted.TXNGetData(0, 0x7fffffff)
data = dhandle.data
fp = open(self.path, 'wb') # NOTE: wb, because data has CR for end-of-line
fp.write(data)
if data[-1] <> '\r': fp.write('\r')
fp.close()
self.changed = 0
def menu_save_as(self):
fss, ok = macfs.StandardPutFile('Save as:')
if not ok: return
self.path = fss.as_pathname()
self.name = os.path.split(self.path)[-1]
self.wid.SetWTitle(self.name)
self.menu_save()
def menu_cut(self):
## self.ted.WESelView()
self.ted.TXNCut()
### Mlte.ConvertToPublicScrap()
## Scrap.ZeroScrap()
## self.ted.WECut()
## self.updatescrollbars()
self.parent.updatemenubar()
self.changed = 1
def menu_copy(self):
## Scrap.ZeroScrap()
self.ted.TXNCopy()
### Mlte.ConvertToPublicScrap()
## self.updatescrollbars()
self.parent.updatemenubar()
def menu_paste(self):
### Mlte.ConvertFromPublicScrap()
self.ted.TXNPaste()
## self.updatescrollbars()
self.parent.updatemenubar()
self.changed = 1
def menu_clear(self):
## self.ted.WESelView()
self.ted.TXNClear()
## self.updatescrollbars()
self.parent.updatemenubar()
self.changed = 1
def menu_undo(self):
self.ted.TXNUndo()
## self.updatescrollbars()
self.parent.updatemenubar()
def menu_redo(self):
self.ted.TXNRedo()
## self.updatescrollbars()
self.parent.updatemenubar()
def have_selection(self):
start, stop = self.ted.TXNGetSelection()
return start < stop
def can_paste(self):
return Mlte.TXNIsScrapPastable()
def can_undo(self):
can, which = self.ted.TXNCanUndo()
if not can:
return None
if which >= len(UNDOLABELS):
# Unspecified undo
return "Undo"
which = UNDOLABELS[which]
return "Undo "+which
def can_redo(self):
can, which = self.ted.TXNCanRedo()
if not can:
return None
if which >= len(UNDOLABELS):
# Unspecified undo
return "Redo"
which = UNDOLABELS[which]
return "Redo "+which
class Mlted(Application):
def __init__(self):
Application.__init__(self)
self.num = 0
self.active = None
self.updatemenubar()
def makeusermenus(self):
self.filemenu = m = Menu(self.menubar, "File")
self.newitem = MenuItem(m, "New window", "N", self.open)
self.openitem = MenuItem(m, "Open...", "O", self.openfile)
self.closeitem = MenuItem(m, "Close", "W", self.closewin)
m.addseparator()
self.saveitem = MenuItem(m, "Save", "S", self.save)
self.saveasitem = MenuItem(m, "Save as...", "", self.saveas)
m.addseparator()
self.quititem = MenuItem(m, "Quit", "Q", self.quit)
self.editmenu = m = Menu(self.menubar, "Edit")
self.undoitem = MenuItem(m, "Undo", "Z", self.undo)
self.redoitem = MenuItem(m, "Redo", None, self.redo)
m.addseparator()
self.cutitem = MenuItem(m, "Cut", "X", self.cut)
self.copyitem = MenuItem(m, "Copy", "C", self.copy)
self.pasteitem = MenuItem(m, "Paste", "V", self.paste)
self.clearitem = MenuItem(m, "Clear", "", self.clear)
# Groups of items enabled together:
self.windowgroup = [self.closeitem, self.saveitem, self.saveasitem, self.editmenu]
self.focusgroup = [self.cutitem, self.copyitem, self.clearitem]
self.windowgroup_on = -1
self.focusgroup_on = -1
self.pastegroup_on = -1
self.undo_label = "never"
self.redo_label = "never"
def updatemenubar(self):
changed = 0
on = (self.active <> None)
if on <> self.windowgroup_on:
for m in self.windowgroup:
m.enable(on)
self.windowgroup_on = on
changed = 1
if on:
# only if we have an edit menu
on = self.active.have_selection()
if on <> self.focusgroup_on:
for m in self.focusgroup:
m.enable(on)
self.focusgroup_on = on
changed = 1
on = self.active.can_paste()
if on <> self.pastegroup_on:
self.pasteitem.enable(on)
self.pastegroup_on = on
changed = 1
on = self.active.can_undo()
if on <> self.undo_label:
if on:
self.undoitem.enable(1)
self.undoitem.settext(on)
self.undo_label = on
else:
self.undoitem.settext("Nothing to undo")
self.undoitem.enable(0)
changed = 1
on = self.active.can_redo()
if on <> self.redo_label:
if on:
self.redoitem.enable(1)
self.redoitem.settext(on)
self.redo_label = on
else:
self.redoitem.settext("Nothing to redo")
self.redoitem.enable(0)
changed = 1
if changed:
DrawMenuBar()
#
# Apple menu
#
def do_about(self, id, item, window, event):
EasyDialogs.Message("A simple single-font text editor based on MacTextEditor")
#
# File menu
#
def open(self, *args):
self._open(0)
def openfile(self, *args):
self._open(1)
def _open(self, askfile):
if askfile:
fss, ok = macfs.StandardGetFile('TEXT')
if not ok:
return
path = fss.as_pathname()
name = os.path.split(path)[-1]
try:
fp = open(path, 'rb') # NOTE binary, we need cr as end-of-line
data = fp.read()
fp.close()
except IOError, arg:
EasyDialogs.Message("IOERROR: "+`arg`)
return
else:
path = None
name = "Untitled %d"%self.num
data = ''
w = MlteWindow(self)
w.open(path, name, data)
self.num = self.num + 1
def closewin(self, *args):
if self.active:
self.active.close()
else:
EasyDialogs.Message("No active window?")
def save(self, *args):
if self.active:
self.active.menu_save()
else:
EasyDialogs.Message("No active window?")
def saveas(self, *args):
if self.active:
self.active.menu_save_as()
else:
EasyDialogs.Message("No active window?")
def quit(self, *args):
for w in self._windows.values():
w.close()
if self._windows:
return
self._quit()
#
# Edit menu
#
def undo(self, *args):
if self.active:
self.active.menu_undo()
else:
EasyDialogs.Message("No active window?")
def redo(self, *args):
if self.active:
self.active.menu_redo()
else:
EasyDialogs.Message("No active window?")
def cut(self, *args):
if self.active:
self.active.menu_cut()
else:
EasyDialogs.Message("No active window?")
def copy(self, *args):
if self.active:
self.active.menu_copy()
else:
EasyDialogs.Message("No active window?")
def paste(self, *args):
if self.active:
self.active.menu_paste()
else:
EasyDialogs.Message("No active window?")
def clear(self, *args):
if self.active:
self.active.menu_clear()
else:
EasyDialogs.Message("No active window?")
#
# Other stuff
#
def idle(self, event):
if self.active:
self.active.do_idle(event)
def main():
Mlte.TXNInitTextension(0)
try:
App = Mlted()
App.mainloop()
finally:
Mlte.TXNTerminateTextension()
if __name__ == '__main__':
main()
# Generated from 'MacTextEditor.h'
def FOUR_CHAR_CODE(x): return x
false = 0
true = 1
kTXNClearThisControl = 0xFFFFFFFF
kTXNClearTheseFontFeatures = 0x80000000
kTXNDontCareTypeSize = 0xFFFFFFFF
kTXNDecrementTypeSize = 0x80000000
kTXNUseCurrentSelection = 0xFFFFFFFF
kTXNStartOffset = 0
kTXNEndOffset = 0x7FFFFFFF
MovieFileType = FOUR_CHAR_CODE('moov')
kTXNWillDefaultToATSUIBit = 0
kTXNWillDefaultToATSUIMask = 1L << kTXNWillDefaultToATSUIBit
kTXNWantMoviesBit = 0
kTXNWantSoundBit = 1
kTXNWantGraphicsBit = 2
kTXNAlwaysUseQuickDrawTextBit = 3
kTXNUseTemporaryMemoryBit = 4
kTXNWantMoviesMask = 1L << kTXNWantMoviesBit
kTXNWantSoundMask = 1L << kTXNWantSoundBit
kTXNWantGraphicsMask = 1L << kTXNWantGraphicsBit
kTXNAlwaysUseQuickDrawTextMask = 1L << kTXNAlwaysUseQuickDrawTextBit
kTXNUseTemporaryMemoryMask = 1L << kTXNUseTemporaryMemoryBit
kTXNDrawGrowIconBit = 0
kTXNShowWindowBit = 1
kTXNWantHScrollBarBit = 2
kTXNWantVScrollBarBit = 3
kTXNNoTSMEverBit = 4
kTXNReadOnlyBit = 5
kTXNNoKeyboardSyncBit = 6
kTXNNoSelectionBit = 7
kTXNSaveStylesAsSTYLResourceBit = 8
kOutputTextInUnicodeEncodingBit = 9
kTXNDoNotInstallDragProcsBit = 10
kTXNAlwaysWrapAtViewEdgeBit = 11
kTXNDrawGrowIconMask = 1L << kTXNDrawGrowIconBit
kTXNShowWindowMask = 1L << kTXNShowWindowBit
kTXNWantHScrollBarMask = 1L << kTXNWantHScrollBarBit
kTXNWantVScrollBarMask = 1L << kTXNWantVScrollBarBit
kTXNNoTSMEverMask = 1L << kTXNNoTSMEverBit
kTXNReadOnlyMask = 1L << kTXNReadOnlyBit
kTXNNoKeyboardSyncMask = 1L << kTXNNoKeyboardSyncBit
kTXNNoSelectionMask = 1L << kTXNNoSelectionBit
kTXNSaveStylesAsSTYLResourceMask = 1L << kTXNSaveStylesAsSTYLResourceBit
kOutputTextInUnicodeEncodingMask = 1L << kOutputTextInUnicodeEncodingBit
kTXNDoNotInstallDragProcsMask = 1L << kTXNDoNotInstallDragProcsBit
kTXNAlwaysWrapAtViewEdgeMask = 1L << kTXNAlwaysWrapAtViewEdgeBit
kTXNFontContinuousBit = 0
kTXNSizeContinuousBit = 1
kTXNStyleContinuousBit = 2
kTXNColorContinuousBit = 3
kTXNFontContinuousMask = 1L << kTXNFontContinuousBit
kTXNSizeContinuousMask = 1L << kTXNSizeContinuousBit
kTXNStyleContinuousMask = 1L << kTXNStyleContinuousBit
kTXNColorContinuousMask = 1L << kTXNColorContinuousBit
kTXNIgnoreCaseBit = 0
kTXNEntireWordBit = 1
kTXNUseEncodingWordRulesBit = 31
kTXNIgnoreCaseMask = 1L << kTXNIgnoreCaseBit
kTXNEntireWordMask = 1L << kTXNEntireWordBit
kTXNUseEncodingWordRulesMask = 1L << kTXNUseEncodingWordRulesBit
kTXNTextensionFile = FOUR_CHAR_CODE('txtn')
kTXNTextFile = FOUR_CHAR_CODE('TEXT')
kTXNPictureFile = FOUR_CHAR_CODE('PICT')
kTXNMovieFile = MovieFileType
kTXNSoundFile = FOUR_CHAR_CODE('sfil')
kTXNAIFFFile = FOUR_CHAR_CODE('AIFF')
kTXNTextEditStyleFrameType = 1
kTXNPageFrameType = 2
kTXNMultipleFrameType = 3
kTXNTextData = FOUR_CHAR_CODE('TEXT')
kTXNPictureData = FOUR_CHAR_CODE('PICT')
kTXNMovieData = FOUR_CHAR_CODE('moov')
kTXNSoundData = FOUR_CHAR_CODE('snd ')
kTXNUnicodeTextData = FOUR_CHAR_CODE('utxt')
kTXNLineDirectionTag = FOUR_CHAR_CODE('lndr')
kTXNJustificationTag = FOUR_CHAR_CODE('just')
kTXNIOPrivilegesTag = FOUR_CHAR_CODE('iopv')
kTXNSelectionStateTag = FOUR_CHAR_CODE('slst')
kTXNInlineStateTag = FOUR_CHAR_CODE('inst')
kTXNWordWrapStateTag = FOUR_CHAR_CODE('wwrs')
kTXNKeyboardSyncStateTag = FOUR_CHAR_CODE('kbsy')
kTXNAutoIndentStateTag = FOUR_CHAR_CODE('auin')
kTXNTabSettingsTag = FOUR_CHAR_CODE('tabs')
kTXNRefConTag = FOUR_CHAR_CODE('rfcn')
kTXNMarginsTag = FOUR_CHAR_CODE('marg')
kTXNNoUserIOTag = FOUR_CHAR_CODE('nuio')
kTXNTypingAction = 0
kTXNCutAction = 1
kTXNPasteAction = 2
kTXNClearAction = 3
kTXNChangeFontAction = 4
kTXNChangeFontColorAction = 5
kTXNChangeFontSizeAction = 6
kTXNChangeStyleAction = 7
kTXNAlignLeftAction = 8
kTXNAlignCenterAction = 9
kTXNAlignRightAction = 10
kTXNDropAction = 11
kTXNMoveAction = 12
kTXNFontFeatureAction = 13
kTXNFontVariationAction = 14
kTXNUndoLastAction = 1024
# kTXNClearThisControl = (long)0xFFFFFFFF
# kTXNClearTheseFontFeatures = (long)0x80000000
kTXNReadWrite = false
kTXNReadOnly = true
kTXNSelectionOn = true
kTXNSelectionOff = false
kTXNUseInline = false
kTXNUseBottomline = true
kTXNAutoWrap = false
kTXNNoAutoWrap = true
kTXNSyncKeyboard = false
kTXNNoSyncKeyboard = true
kTXNAutoIndentOff = false
kTXNAutoIndentOn = true
kTXNRightTab = -1
kTXNLeftTab = 0
kTXNCenterTab = 1
kTXNLeftToRight = 0
kTXNRightToLeft = 1
kTXNFlushDefault = 0
kTXNFlushLeft = 1
kTXNFlushRight = 2
kTXNCenter = 4
kTXNFullJust = 8
kTXNForceFullJust = 16
kScrollBarsAlwaysActive = true
kScrollBarsSyncWithFocus = false
# kTXNDontCareTypeSize = (long)0xFFFFFFFF
kTXNDontCareTypeStyle = 0xFF
kTXNIncrementTypeSize = 0x00000001
# kTXNDecrementTypeSize = (long)0x80000000
# kTXNUseCurrentSelection = 0xFFFFFFFFUL
# kTXNStartOffset = 0UL
# kTXNEndOffset = 0x7FFFFFFFUL
kTXNSingleStylePerTextDocumentResType = FOUR_CHAR_CODE('MPSR')
kTXNMultipleStylesPerTextDocumentResType = FOUR_CHAR_CODE('styl')
kTXNShowStart = false
kTXNShowEnd = true
kTXNQDFontNameAttribute = FOUR_CHAR_CODE('fntn')
kTXNQDFontFamilyIDAttribute = FOUR_CHAR_CODE('font')
kTXNQDFontSizeAttribute = FOUR_CHAR_CODE('size')
kTXNQDFontStyleAttribute = FOUR_CHAR_CODE('face')
kTXNQDFontColorAttribute = FOUR_CHAR_CODE('klor')
kTXNTextEncodingAttribute = FOUR_CHAR_CODE('encd')
kTXNATSUIFontFeaturesAttribute = FOUR_CHAR_CODE('atfe')
kTXNATSUIFontVariationsAttribute = FOUR_CHAR_CODE('atva')
# kTXNQDFontNameAttributeSize = sizeof(Str255)
# kTXNQDFontFamilyIDAttributeSize = sizeof(SInt16)
# kTXNQDFontSizeAttributeSize = sizeof(SInt16)
# kTXNQDFontStyleAttributeSize = sizeof(Style)
# kTXNQDFontColorAttributeSize = sizeof(RGBColor)
# kTXNTextEncodingAttributeSize = sizeof(TextEncoding)
kTXNSystemDefaultEncoding = 0
kTXNMacOSEncoding = 1
kTXNUnicodeEncoding = 2
kTXNBackgroundTypeRGB = 1
# status = TXNInitTextension( &defaults
# justification = LMTESysJust
This source diff could not be displayed because it is too large. You can view the blob instead.
# Scan an Apple header file, generating a Python file of generator calls.
import sys
import os
BGENDIR=os.path.join(sys.prefix, ':Tools:bgen:bgen')
sys.path.append(BGENDIR)
from scantools import Scanner_OSX
from bgenlocations import TOOLBOXDIR
LONG = "CoreFoundation"
SHORT = "cf"
OBJECTS = ("CFTypeRef",
"CFArrayRef", "CFMutableArrayRef",
"CFDataRef", "CFMutableDataRef",
"CFDictionaryRef", "CFMutableDictionaryRef",
"CFStringRef", "CFMutableStringRef",
"CFURLRef",
)
# ADD object typenames here
def main():
input = [
"CFBase.h",
"CFArray.h",
## "CFBag.h",
## "CFBundle.h",
## "CFCharacterSet.h",
"CFData.h",
## "CFDate.h",
"CFDictionary.h",
## "CFNumber.h",
## "CFPlugIn.h",
## "CFPreferences.h",
## "CFPropertyList.h",
## "CFSet.h",
"CFString.h",
## "CFStringEncodingExt.h",
## "CFTimeZone.h",
"CFURL.h",
]
output = SHORT + "gen.py"
defsoutput = TOOLBOXDIR + LONG + ".py"
scanner = MyScanner(input, output, defsoutput)
scanner.scan()
scanner.gentypetest(SHORT+"typetest.py")
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_OSX):
def destination(self, type, name, arglist):
classname = "Function"
listname = "functions"
if arglist:
t, n, m = arglist[0]
if t in OBJECTS and m == "InMode":
classname = "Method"
listname = t + "_methods"
# Special case for the silly first AllocatorRef argument
if t == 'CFAllocatorRef' and m == 'InMode' and len(arglist) > 1:
t, n, m = arglist[1]
if t in OBJECTS and m == "InMode":
classname = "MethodSkipArg1"
listname = t + "_methods"
return classname, listname
def writeinitialdefs(self):
self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
def makeblacklistnames(self):
return [
# Memory allocator functions
"CFAllocatorGetDefault",
"CFAllocatorSetDefault",
"CFAllocatorAllocate",
"CFAllocatorReallocate",
"CFAllocatorDeallocate",
"CFGetAllocator",
# Array functions we skip for now.
"CFArrayGetValueAtIndex",
# Data pointer functions. Skip for now.
"CFDataGetBytePtr",
"CFDataGetMutableBytePtr",
"CFDataGetBytes", # XXXX Should support this one
# String functions
"CFStringGetPascalString", # Use the C-string methods.
"CFStringGetPascalStringPtr", # TBD automatically
"CFStringGetCStringPtr",
"CFStringGetCharactersPtr",
"CFStringGetCString",
"CFStringGetCharacters",
"CFURLCreateStringWithFileSystemPath", # Gone in later releases
]
def makegreylist(self):
return []
def makeblacklisttypes(self):
return [
"CFComparatorFunction", # Callback function pointer
"CFAllocatorContext", # Not interested in providing our own allocator
"void_ptr_ptr", # Tricky. This is the initializer for arrays...
"void_ptr", # Ditto for various array lookup methods
"CFArrayApplierFunction", # Callback function pointer
"CFDictionaryApplierFunction", # Callback function pointer
"UniChar_ptr", # XXXX To be done
"const_UniChar_ptr", # XXXX To be done
"UniChar", # XXXX To be done
"va_list", # For printf-to-a-cfstring. Use Python.
"const_CFStringEncoding_ptr", # To be done, I guess
]
def makerepairinstructions(self):
return [
# Buffers in CF seem to be passed as UInt8 * normally.
([("UInt8_ptr", "*", "InMode"), ("CFIndex", "*", "InMode")],
[("UcharInBuffer", "*", "*")]),
# Some functions return a const char *. Don't worry, we won't modify it.
([("const_char_ptr", "*", "ReturnMode")],
[("return_stringptr", "*", "*")]),
# base URLs are optional (pass None for NULL)
([("CFURLRef", "baseURL", "InMode")],
[("OptionalCFURLRef", "*", "*")]),
]
if __name__ == "__main__":
main()
This diff is collapsed.
This diff is collapsed.
# Scan an Apple header file, generating a Python file of generator calls.
import sys
import os
BGENDIR=os.path.join(sys.prefix, ':Tools:bgen:bgen')
sys.path.append(BGENDIR)
from scantools import Scanner_OSX
from bgenlocations import TOOLBOXDIR
LONG = "MacTextEditor"
SHORT = "mlte"
OBJECTS = ("TXNObject", "TXNFontMenuObject")
# ADD object typenames here
def main():
input = "MacTextEditor.h"
output = SHORT + "gen.py"
defsoutput = TOOLBOXDIR + LONG + ".py"
scanner = MyScanner(input, output, defsoutput)
scanner.scan()
scanner.gentypetest(SHORT+"typetest.py")
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_OSX):
def destination(self, type, name, arglist):
classname = "Function"
listname = "functions"
if arglist:
t, n, m = arglist[0]
if t in OBJECTS and m == "InMode":
classname = "Method"
listname = t + "_methods"
return classname, listname
def writeinitialdefs(self):
self.defsfile.write("""
def FOUR_CHAR_CODE(x): return x
false = 0
true = 1
kTXNClearThisControl = 0xFFFFFFFF
kTXNClearTheseFontFeatures = 0x80000000
kTXNDontCareTypeSize = 0xFFFFFFFF
kTXNDecrementTypeSize = 0x80000000
kTXNUseCurrentSelection = 0xFFFFFFFF
kTXNStartOffset = 0
kTXNEndOffset = 0x7FFFFFFF
MovieFileType = FOUR_CHAR_CODE('moov')
""")
def makeblacklistnames(self):
return [
"TXNGetFontDefaults", # Arg is too difficult
"TXNSetFontDefaults", # Arg is too difficult
"TXNInitTextension", # done manually
# Constants with funny definitions
"kTXNClearThisControl",
"kTXNClearTheseFontFeatures",
"kTXNDontCareTypeSize",
"kTXNDecrementTypeSize",
"kTXNUseCurrentSelection",
"kTXNStartOffset",
"kTXNEndOffset",
"kTXNQDFontNameAttributeSize",
"kTXNQDFontFamilyIDAttributeSize",
"kTXNQDFontSizeAttributeSize",
"kTXNQDFontStyleAttributeSize",
"kTXNQDFontColorAttributeSize",
"kTXNTextEncodingAttributeSize",
"status",
"justification",
]
def makegreylist(self):
return []
def makeblacklisttypes(self):
return [
"TXNTab", # TBD
"TXNMargins", # TBD
"TXNControlData", #TBD
"TXNATSUIFeatures", #TBD
"TXNATSUIVariations", #TBD
"TXNAttributeData", #TBD
"TXNTypeAttributes", #TBD
"TXNMatchTextRecord", #TBD
"TXNBackground", #TBD
"UniChar", #TBD
"TXNFindUPP",
]
def makerepairinstructions(self):
return [
# TXNNewObject has a lot of optional parameters
([("FSSpec_ptr", "iFileSpec", "InMode")],
[("OptFSSpecPtr", "*", "*")]),
([("Rect", "iFrame", "OutMode")],
[("OptRectPtr", "*", "InMode")]),
# In UH 332 some of the "const" are missing for input parameters passed
# by reference. We fix that up here.
([("EventRecord", "iEvent", "OutMode")],
[("EventRecord_ptr", "*", "InMode")]),
([("FSSpec", "iFileSpecification", "OutMode")],
[("FSSpec_ptr", "*", "InMode")]),
([("TXNMacOSPreferredFontDescription", "iFontDefaults", "OutMode")],
[("TXNMacOSPreferredFontDescription_ptr", "*", "InMode")]),
# In buffers are passed as void *
([("void", "*", "OutMode"), ("ByteCount", "*", "InMode")],
[("MlteInBuffer", "*", "InMode")]),
# The AdjustCursor region handle is optional
([("RgnHandle", "ioCursorRgn", "InMode")],
[("OptRgnHandle", "*", "*")]),
# The GWorld for TXNDraw is optional
([('GWorldPtr', 'iDrawPort', 'InMode')],
[('OptGWorldPtr', '*', '*')]),
]
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).
#error missing SetActionFilter
import string
# Declarations that change for each manager
MODNAME = 'Mlte' # The name of the module
# The following is *usually* unchanged but may still require tuning
MODPREFIX = MODNAME # The prefix for module-wide routines
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
includestuff = includestuff + """
#ifdef WITHOUT_FRAMEWORKS
#include <MacTextEditor.h>
#else
#include <xxxx.h>
#endif
/* For now we declare them forward here. They'll go to mactoolbox later */
staticforward PyObject *TXNObj_New(TXNObject);
staticforward int TXNObj_Convert(PyObject *, TXNObject *);
staticforward PyObject *TXNFontMenuObj_New(TXNFontMenuObject);
staticforward int TXNFontMenuObj_Convert(PyObject *, TXNFontMenuObject *);
// ADD declarations
#ifdef NOTYET_USE_TOOLBOX_OBJECT_GLUE
//extern PyObject *_CFTypeRefObj_New(CFTypeRef);
//extern int _CFTypeRefObj_Convert(PyObject *, CFTypeRef *);
//#define CFTypeRefObj_New _CFTypeRefObj_New
//#define CFTypeRefObj_Convert _CFTypeRefObj_Convert
#endif
/*
** Parse an optional fsspec
*/
static int
OptFSSpecPtr_Convert(PyObject *v, FSSpec **p_itself)
{
static FSSpec fss;
if (v == Py_None)
{
*p_itself = NULL;
return 1;
}
*p_itself = &fss;
return PyMac_GetFSSpec(v, *p_itself);
}
/*
** Parse an optional rect
*/
static int
OptRectPtr_Convert(PyObject *v, Rect **p_itself)
{
static Rect r;
if (v == Py_None)
{
*p_itself = NULL;
return 1;
}
*p_itself = &r;
return PyMac_GetRect(v, *p_itself);
}
/*
** Parse an optional GWorld
*/
static int
OptGWorldObj_Convert(PyObject *v, GWorldPtr *p_itself)
{
if (v == Py_None)
{
*p_itself = NULL;
return 1;
}
return GWorldObj_Convert(v, p_itself);
}
"""
initstuff = initstuff + """
// PyMac_INIT_TOOLBOX_OBJECT_NEW(xxxx);
"""
TXNObject = OpaqueByValueType("TXNObject", "TXNObj")
TXNFontMenuObject = OpaqueByValueType("TXNFontMenuObject", "TXNFontMenuObj")
TXNFrameID = Type("TXNFrameID", "l")
TXNVersionValue = Type("TXNVersionValue", "l")
TXNFeatureBits = Type("TXNFeatureBits", "l")
TXNInitOptions = Type("TXNInitOptions", "l")
TXNFrameOptions = Type("TXNFrameOptions", "l")
TXNContinuousFlags = Type("TXNContinuousFlags", "l")
TXNMatchOptions = Type("TXNMatchOptions", "l")
TXNFileType = OSTypeType("TXNFileType")
TXNFrameType = Type("TXNFrameType", "l")
TXNDataType = OSTypeType("TXNDataType")
TXNControlTag = OSTypeType("TXNControlTag")
TXNActionKey = Type("TXNActionKey", "l")
TXNTabType = Type("TXNTabType", "b")
TXNScrollBarState = Type("TXNScrollBarState", "l")
TXNOffset = Type("TXNOffset", "l")
TXNObjectRefcon = FakeType("(TXNObjectRefcon)0") # XXXX For now...
TXNErrors = OSErrType("TXNErrors", "l")
TXNTypeRunAttributes = OSTypeType("TXNTypeRunAttributes")
TXNTypeRunAttributeSizes = Type("TXNTypeRunAttributeSizes", "l")
TXNPermanentTextEncodingType = Type("TXNPermanentTextEncodingType", "l")
TXTNTag = OSTypeType("TXTNTag")
TXNBackgroundType = Type("TXNBackgroundType", "l")
DragReference = OpaqueByValueType("DragReference", "DragObj")
DragTrackingMessage = Type("DragTrackingMessage", "h")
RgnHandle = OpaqueByValueType("RgnHandle", "ResObj")
OptRgnHandle = OpaqueByValueType("RgnHandle", "OptResObj")
GWorldPtr = OpaqueByValueType("GWorldPtr", "GWorldObj")
OptGWorldPtr = OpaqueByValueType("GWorldPtr", "OptGWorldObj")
MlteInBuffer = VarInputBufferType('void *', 'ByteCount', 'l')
OptFSSpecPtr = OpaqueByValueType("FSSpec *", "OptFSSpecPtr")
OptRectPtr = OpaqueByValueType("Rect *", "OptRectPtr")
# ADD object type here
execfile("mltetypetest.py")
# Our (opaque) objects
class TXNObjDefinition(GlobalObjectDefinition):
def outputCheckNewArg(self):
Output("if (itself == NULL) return PyMac_Error(resNotFound);")
class TXNFontMenuObjDefinition(GlobalObjectDefinition):
def outputCheckNewArg(self):
Output("if (itself == NULL) return PyMac_Error(resNotFound);")
# ADD object class here
# From here on it's basically all boiler plate...
# Create the generator groups and link them
module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
TXNObject_object = TXNObjDefinition("TXNObject", "TXNObj", "TXNObject")
TXNFontMenuObject_object = TXNFontMenuObjDefinition("TXNFontMenuObject", "TXNFontMenuObj", "TXNFontMenuObject")
# ADD object here
module.addobject(TXNObject_object)
module.addobject(TXNFontMenuObject_object)
# ADD addobject call here
# Create the generator classes used to populate the lists
Function = OSErrWeakLinkFunctionGenerator
Method = OSErrWeakLinkMethodGenerator
# Create and populate the lists
functions = []
TXNObject_methods = []
TXNFontMenuObject_methods = []
# ADD _methods initializer here
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 TXNObject_methods: TXNObject_object.add(f)
for f in TXNFontMenuObject_methods: TXNFontMenuObject_object.add(f)
# ADD Manual generators here
inittextension_body = """
OSStatus _err;
TXNMacOSPreferredFontDescription * iDefaultFonts = NULL;
ItemCount iCountDefaultFonts = 0;
TXNInitOptions iUsageFlags;
PyMac_PRECHECK(TXNInitTextension);
if (!PyArg_ParseTuple(_args, "l", &iUsageFlags))
return NULL;
_err = TXNInitTextension(iDefaultFonts,
iCountDefaultFonts,
iUsageFlags);
if (_err != noErr) return PyMac_Error(_err);
Py_INCREF(Py_None);
_res = Py_None;
return _res;
"""
f = ManualGenerator("TXNInitTextension", inittextension_body);
f.docstring = lambda: "(TXNInitOptions) -> None"
module.add(f)
# generate output (open the output file as late as possible)
SetOutputFileName(OUTPUTFILE)
module.generate()
This diff is collapsed.
This diff is collapsed.
import mkcwproject
import sys
import os
import string
PROJECTDIR = os.path.join(sys.prefix, ":Mac:Build")
MODULEDIRS = [ # Relative to projectdirs
"::Modules:%s",
"::Modules",
":::Modules",
]
# Global variable to control forced rebuild (otherwise the project is only rebuilt
# when it is changed)
FORCEREBUILD=0
def relpath(base, path):
"""Turn abs path into path relative to another. Only works for 2 abs paths
both pointing to folders"""
if not os.path.isabs(base) or not os.path.isabs(path):
raise 'Absolute paths only'
if base[-1] == ':':
base = base[:-1]
basefields = string.split(base, os.sep)
pathfields = string.split(path, os.sep)
commonfields = len(os.path.commonprefix((basefields, pathfields)))
basefields = basefields[commonfields:]
pathfields = pathfields[commonfields:]
pathfields = ['']*(len(basefields)+1) + pathfields
rv = string.join(pathfields, os.sep)
return rv
def genpluginproject(architecture, module,
project=None, projectdir=None,
sources=[], sourcedirs=[],
libraries=[], extradirs=[],
extraexportsymbols=[]):
if architecture == "all":
# For the time being we generate two project files. Not as nice as
# a single multitarget project, but easier to implement for now.
genpluginproject("ppc", module, project, projectdir, sources, sourcedirs,
libraries, extradirs, extraexportsymbols)
genpluginproject("carbon", module, project, projectdir, sources, sourcedirs,
libraries, extradirs, extraexportsymbols)
return
templatename = "template-%s" % architecture
targetname = "%s.%s" % (module, architecture)
dllname = "%s.%s.slb" % (module, architecture)
if not project:
if architecture != "ppc":
project = "%s.%s.mcp"%(module, architecture)
else:
project = "%s.mcp"%module
if not projectdir:
projectdir = PROJECTDIR
if not sources:
sources = [module + 'module.c']
if not sourcedirs:
for moduledir in MODULEDIRS:
if '%' in moduledir:
moduledir = moduledir % module
fn = os.path.join(projectdir, os.path.join(moduledir, sources[0]))
if os.path.exists(fn):
moduledir, sourcefile = os.path.split(fn)
sourcedirs = [relpath(projectdir, moduledir)]
sources[0] = sourcefile
break
else:
print "Warning: %s: sourcefile not found: %s"%(module, sources[0])
sourcedirs = []
if architecture == "carbon":
prefixname = "mwerks_carbonplugin_config.h"
else:
prefixname = "mwerks_plugin_config.h"
dict = {
"sysprefix" : relpath(projectdir, sys.prefix),
"sources" : sources,
"extrasearchdirs" : sourcedirs + extradirs,
"libraries": libraries,
"mac_outputdir" : "::Plugins",
"extraexportsymbols" : extraexportsymbols,
"mac_targetname" : targetname,
"mac_dllname" : dllname,
"prefixname" : prefixname,
}
mkcwproject.mkproject(os.path.join(projectdir, project), module, dict,
force=FORCEREBUILD, templatename=templatename)
def genallprojects(force=0):
global FORCEREBUILD
FORCEREBUILD = force
# Standard Python modules
genpluginproject("all", "pyexpat",
sources=["pyexpat.c"],
libraries=["libexpat.ppc.lib"],
extradirs=["::::expat:*"])
genpluginproject("all", "zlib",
libraries=["zlib.ppc.Lib"],
extradirs=["::::imglibs:zlib:mac", "::::imglibs:zlib"])
genpluginproject("all", "gdbm",
libraries=["gdbm.ppc.gusi.lib"],
extradirs=["::::gdbm:mac", "::::gdbm"])
genpluginproject("all", "_weakref", sources=["_weakref.c"])
genpluginproject("all", "_symtable", sources=["symtablemodule.c"])
genpluginproject("all", "_testcapi")
# bgen-generated Toolbox modules
genpluginproject("ppc", "App", libraries=["AppearanceLib"])
genpluginproject("carbon", "App")
## genpluginproject("ppc", "Cm",
## libraries=["QuickTimeLib"],
## extraexportsymbols=[
## "CmpObj_New",
## "CmpObj_Convert",
## "CmpInstObj_New",
## "CmpInstObj_Convert",
## ])
## genpluginproject("carbon", "Cm",
## extraexportsymbols=[
## "CmpObj_New",
## "CmpObj_Convert",
## "CmpInstObj_New",
## "CmpInstObj_Convert",
## ])
genpluginproject("ppc", "Cm", libraries=["QuickTimeLib"])
genpluginproject("carbon", "Cm")
genpluginproject("all", "Fm")
genpluginproject("ppc", "Help")
genpluginproject("ppc", "Icn", libraries=["IconServicesLib"])
genpluginproject("carbon", "Icn")
genpluginproject("all", "List")
## genpluginproject("ppc", "Qt", libraries=["QuickTimeLib", "Cm.ppc.slb", "Qdoffs.ppc.slb"],
## extradirs=["::Plugins"])
genpluginproject("ppc", "Qt", libraries=["QuickTimeLib"])
## genpluginproject("carbon", "Qt", libraries=["Cm.carbon.slb", "Qdoffs.carbon.slb"],
## extradirs=["::Plugins"])
genpluginproject("carbon", "Qt")
## genpluginproject("all", "Qdoffs",
## extraexportsymbols=["GWorldObj_New", "GWorldObj_Convert"])
genpluginproject("all", "Qdoffs")
genpluginproject("all", "Scrap")
genpluginproject("ppc", "Snd", libraries=["SoundLib"])
genpluginproject("carbon", "Snd")
genpluginproject("all", "Sndihooks", sources=[":snd:Sndihooks.c"])
genpluginproject("ppc", "TE", libraries=["DragLib"])
genpluginproject("carbon", "TE")
genpluginproject("ppc", "Mlte", libraries=["Textension"])
genpluginproject("carbon", "Mlte")
# Carbon Only?
genpluginproject("carbon", "CF")
# Other Mac modules
genpluginproject("all", "calldll", sources=["calldll.c"])
genpluginproject("all", "ColorPicker")
genpluginproject("ppc", "Printing")
genpluginproject("ppc", "waste",
sources=[
"wastemodule.c",
'WEAccessors.c', 'WEBirthDeath.c', 'WEDebug.c',
'WEDrawing.c', 'WEFontTables.c', 'WEHighLevelEditing.c',
'WEICGlue.c', 'WEInlineInput.c', 'WELineLayout.c', 'WELongCoords.c',
'WELowLevelEditing.c', 'WEMouse.c', 'WEObjects.c', 'WEScraps.c',
'WESelecting.c', 'WESelectors.c', 'WEUserSelectors.c', 'WEUtilities.c',
'WEObjectHandlers.c',
'WETabs.c',
'WETabHooks.c'],
libraries=['DragLib'],
extradirs=[
'::::Waste 1.3 Distribution:*',
'::::ICProgKit1.4:APIs']
)
# This is a hack, combining parts of Waste 2.0 with parts of 1.3
genpluginproject("carbon", "waste",
sources=[
"wastemodule.c",
"WEObjectHandlers.c",
"WETabs.c", "WETabHooks.c"],
libraries=["WASTE.Carbon.lib"],
extradirs=[
'{Compiler}:MacOS Support:(Third Party Support):Waste 2.0 Distribution:C_C++ Headers',
'{Compiler}:MacOS Support:(Third Party Support):Waste 2.0 Distribution:Static Libraries',
'::::Waste 1.3 Distribution:Extras:Sample Object Handlers',
'::::Waste 1.3 Distribution:Extras:Waste Tabs 1.3.2']
)
genpluginproject("ppc", "ctb")
genpluginproject("ppc", "icglue", sources=["icgluemodule.c"],
libraries=["ICGlueCFM-PPC.lib"],
extradirs=["::::ICProgKit1.4:APIs"])
genpluginproject("carbon", "icglue", sources=["icgluemodule.c"],
extradirs=["::::ICProgKit1.4:APIs"])
genpluginproject("ppc", "macspeech", libraries=["SpeechLib"])
if __name__ == '__main__':
genallprojects()
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