# - update events # # It also detects clicks in controls and tracks the control. from Evt import * from Win import * from Dlg import * from Ctl import * from Menu import * from Qd import * from Res import * import AE from addpack import addpack addpack('Demo') addpack('bgen') addpack('evt') addpack('win') addpack('ctl') from Events import * from Windows import * from Controls import * import MacOS MacOS.EnableAppswitch(0) # Stop Python from ever getting events itself everywhere = (-32000, -32000, 32000, 32000) # NB using 0x7fff doesn't work -- apparently a little slop must be present
# fullbuild creates everything that needs to be created before a # distribution can be made, and puts it all in the right place. # # It expects the projects to be in the places where Jack likes them: # in directories named like 'build.macppc.shared'. That is fixable, # however. # # NOTE: You should proably make a copy of python with which to execute this # script, rebuilding running programs does not work... import os import sys import macfs import addpack addpack.addpack('Tools') addpack.addpack('bgen') addpack.addpack('AE') import aetools from Metrowerks_Shell_Suite import Metrowerks_Shell_Suite from Required_Suite import Required_Suite addpack.addpack('Mac') addpack.addpack('scripts') import mkapplet class MwShell(aetools.TalkTo, Metrowerks_Shell_Suite, Required_Suite): pass def buildmwproject(top, creator, projects):
import cmp import getopt import os import string import sys import addpack # Set the directory to look for the freeze-private modules dir = os.path.dirname(sys.argv[0]) if dir: pack = dir else: pack = PACK addpack.addpack(pack) # Import the freeze-private modules import checkextensions import findmodules import makeconfig import makefreeze import makemakefile import parsesetup # Main program def main(): # overridable context
# # Turn a pyc file into a resource file containing it in 'PYC ' resource form import addpack addpack.addpack('Tools') addpack.addpack('bgen') addpack.addpack('res') from Res import * import Res from Resources import * import os import macfs import sys READ = 1 WRITE = 2 smAllScripts = -3 error = 'mkpycresourcefile.error' def Pstring(str): if len(str) > 255: raise ValueError, 'String too large' return chr(len(str))+str def createoutput(dst): """Create output file. Return handle and first id to use.""" FSpCreateResFile(dst, 'PYTH', 'rsrc', smAllScripts) output = FSpOpenResFile(dst, WRITE) UseResFile(output)
import cmp import getopt import os import string import sys import addpack # Set the directory to look for the freeze-private modules dir = os.path.dirname(sys.argv[0]) if dir: pack = dir else: pack = PACK addpack.addpack(pack) # Import the freeze-private modules import checkextensions import findmodules import makeconfig import makefreeze import makemakefile import parsesetup # Main program def main():
#! /usr/local/bin/python # Tk man page browser -- currently only shows the Tcl/Tk man pages import sys import os import string import regex from Tkinter import * import addpack addpack.addpack('/ufs/guido/src/python/Demo/guido/tkinter') from ManPage import ManPage MANNDIR = '/usr/local/man/mann' MAN3DIR = '/usr/local/man/man3' def listmanpages(mandir): files = os.listdir(mandir) names = [] for file in files: if file[-2:-1] == '.' and (file[-1] in 'ln123456789'): names.append(file[:-2]) names.sort() return names class SelectionBox: def __init__(self, master=None): self.choices = []
# Progress dialog from addpack import addpack addpack('Demo') addpack('bgen') addpack('dlg') addpack('evt') from Dlg import GetNewDialog, ModalDialog, SetIText count = 0 def filter(d, e): r = 1 print "Filter(%s, %s) -> %s" % ( ` d `, ` e `, ` r `) return r def main(): d = GetNewDialog(256, -1) tp, h, rect = d.GetDItem(2) SetIText(h, "Progress...") for i in range(100): if i % 10 == 0: str = "Progress...%d" % i SetIText(h, str) ModalDialog(filter) for j in range(100): pass
# Progress dialog from addpack import addpack addpack('Demo') addpack('bgen') addpack('dlg') addpack('evt') from Dlg import GetNewDialog, ModalDialog, SetIText count = 0 def filter(d, e): r = 1 print "Filter(%s, %s) -> %s" % (`d`, `e`, `r`) return r def main(): d = GetNewDialog(256, -1) tp, h, rect = d.GetDItem(2) SetIText(h, "Progress...") for i in range(100): if i%10 == 0: str = "Progress...%d" % i SetIText(h, str) ModalDialog(filter) for j in range(100): pass if __name__ == '__main__': main()
"A sort of application framework for the Mac" import MacOS import traceback from addpack import addpack addpack('Demo') addpack('bgen') addpack('ae') #addpack('ctl') addpack('dlg') addpack('evt') addpack('menu') #addpack('qd') #addpack('res') #addpack('snd') addpack('win') from AE import * from AppleEvents import * #from Ctl import * #from Controls import * from Dlg import * from Dialogs import * from Evt import * from Events import * from Menu import * from Menus import * #from Qd import * #from QuickDraw import *
"""Edit the Python Preferences file.""" import addpack addpack.addpack('Tools') addpack.addpack('bgen') addpack.addpack('evt') from Dlg import * from Events import * from Res import * import string import struct import macfs import MacOS import os import sys import Res # For Res.Error # resource IDs in our own resources (dialogs, etc) MESSAGE_ID = 256 DIALOG_ID = 512 TEXT_ITEM = 1 OK_ITEM = 2 CANCEL_ITEM = 3 REVERT_ITEM = 4 DIR_ITEM = 5 # Resource IDs in the preferences file PATH_STRINGS_ID = 128 DIRECTORY_ID = 128
"""'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 addpack addpack.addpack('Demo') addpack.addpack('bgen') addpack.addpack('ae') addpack.addpack('evt') #addpack.addpack('menu') addpack.addpack('win') import sys sys.stdout = sys.stderr import traceback import MacOS import AE from AppleEvents import * import Evt from Events import * import Menu import Dlg import Win from Windows import * import Qd import aetools
# # Turn a pyc file into a resource file containing it in 'PYC ' resource form import addpack addpack.addpack('Tools') addpack.addpack('bgen') addpack.addpack('res') from Res import * import Res from Resources import * import os import macfs import sys READ = 1 WRITE = 2 smAllScripts = -3 error = 'mkpycresourcefile.error' def Pstring(str): if len(str) > 255: raise ValueError, 'String too large' return chr(len(str)) + str def createoutput(dst): """Create output file. Return handle and first id to use.""" FSpCreateResFile(dst, 'PYTH', 'rsrc', smAllScripts) output = FSpOpenResFile(dst, WRITE)
# - key events (including key repeat) # - update events # # It also detects clicks in controls and tracks the control. from Evt import * from Win import * from Dlg import * from Ctl import * from Menu import * from Qd import * from Res import * import AE from addpack import addpack addpack('Demo') addpack('bgen') addpack('evt') addpack('win') addpack('ctl') from Events import * from Windows import * from Controls import * import MacOS MacOS.EnableAppswitch(0) # Stop Python from ever getting events itself everywhere = (-32000, -32000, 32000, 32000) # NB using 0x7fff doesn't work -- apparently a little slop must be present
# fullbuild creates everything that needs to be created before a # distribution can be made, and puts it all in the right place. # # It expects the projects to be in the places where Jack likes them: # in directories named like 'build.macppc.shared'. That is fixable, # however. # # NOTE: You should proably make a copy of python with which to execute this # script, rebuilding running programs does not work... import os import sys import macfs import addpack addpack.addpack('Tools') addpack.addpack('bgen') addpack.addpack('AE') import aetools from Metrowerks_Shell_Suite import Metrowerks_Shell_Suite from Required_Suite import Required_Suite addpack.addpack('Mac') addpack.addpack('scripts') import mkapplet class MwShell(aetools.TalkTo, Metrowerks_Shell_Suite, Required_Suite): pass
"A sort of application framework for the Mac" DEBUG=0 import MacOS import traceback from addpack import addpack addpack('Tools') addpack('bgen') addpack('ae') addpack('ctl') addpack('dlg') addpack('evt') addpack('menu') addpack('qd') #addpack('res') #addpack('snd') addpack('win') from AE import * from AppleEvents import * from Ctl import * from Controls import * from Dlg import * from Dialogs import * from Evt import * from Events import * from Menu import * from Menus import * from Qd import *
# Jack Jansen, CWI, August 1995. # # To do: # - Also do project files (.µ and .¹), after using AppleEvents to the # various builders to clean the projects # - Don't hexbin (and clean) if there exists a .hqx file that is newer. # import os import binhex import sys import macostools import macfs import addpack addpack.addpack('Tools') addpack.addpack('bgen') addpack.addpack('AE') import aetools from Metrowerks_Shell_Suite import Metrowerks_Shell_Suite from Required_Suite import Required_Suite class MwShell(aetools.TalkTo, Metrowerks_Shell_Suite, Required_Suite): pass # Top-level directory TOP = '' # Where to put CW projects, relative to TOP
# Scan an Apple header file, generating a Python file of generator calls. import addpack addpack.addpack('D:python:Tools:bgen:bgen') from scantools import Scanner def main(): input = "QuickDraw.h" output = "qdgen.py" defsoutput = "QuickDraw.py" scanner = MyScanner(input, output, defsoutput) scanner.scan() scanner.close() print "=== Done scanning and generating, now importing the generated code... ===" import qdsupport 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[0] if t in ("WindowPtr", "WindowPeek") and m == "InMode": classname = "Method" listname = "methods" return classname, listname def makeblacklistnames(self):
# 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 import addpack addpack.addpack('D:python:Tools:bgen:bgen') # Declarations that change for each manager MACHEADERFILE = 'Menus.h' # The Apple header file MODNAME = 'Menu' # The name of the module OBJECTNAME = 'Menu' # The basic name of the objects used here # The following is *usually* unchanged but may still require tuning MODPREFIX = MODNAME # The prefix for module-wide routines OBJECTTYPE = OBJECTNAME + 'Handle' # 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 EXTRAFILE = string.lower(MODPREFIX) + 'edit.py' # A similar file but hand-made OUTPUTFILE = MODNAME + "module.c" # The file generated by this program from macsupport import * # Create the type objects MenuHandle = OpaqueByValueType(OBJECTTYPE, OBJECTPREFIX) includestuff = includestuff + """
# Jack Jansen, CWI, August 1995. # # To do: # - Also do project files (.µ and .¹), after using AppleEvents to the # various builders to clean the projects # - Don't hexbin (and clean) if there exists a .hqx file that is newer. # import os import binhex import sys import macostools import macfs import addpack addpack.addpack('Tools') addpack.addpack('bgen') addpack.addpack('AE') import aetools from Metrowerks_Shell_Suite import Metrowerks_Shell_Suite from Required_Suite import Required_Suite class MwShell(aetools.TalkTo, Metrowerks_Shell_Suite, Required_Suite): pass # Top-level directory TOP='' # Where to put CW projects, relative to TOP CWDIR=':Mac:mwerks:projects'