mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
Got angry and added support for pretty much the whole file and folder
manager. This should allow us the get rid of most of the FSSpecs, only navigation services remains to be done.
This commit is contained in:
parent
a191befb2d
commit
e2ba87396c
11 changed files with 2761 additions and 0 deletions
347
Mac/Modules/folder/_Foldermodule.c
Normal file
347
Mac/Modules/folder/_Foldermodule.c
Normal file
|
@ -0,0 +1,347 @@
|
|||
|
||||
/* ========================= Module _Folder ========================= */
|
||||
|
||||
#include "Python.h"
|
||||
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "pywintoolbox.h"
|
||||
#else
|
||||
#include "macglue.h"
|
||||
#include "pymactoolbox.h"
|
||||
#endif
|
||||
|
||||
/* Macro to test whether a weak-loaded CFM function exists */
|
||||
#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
|
||||
PyErr_SetString(PyExc_NotImplementedError, \
|
||||
"Not available in this shared library/OS version"); \
|
||||
return NULL; \
|
||||
}} while(0)
|
||||
|
||||
|
||||
#ifdef WITHOUT_FRAMEWORKS
|
||||
#include <Folders.h>
|
||||
#else
|
||||
#include <Carbon/Carbon.h>
|
||||
#endif
|
||||
|
||||
|
||||
static PyObject *Folder_Error;
|
||||
|
||||
static PyObject *Folder_FindFolder(PyObject *_self, PyObject *_args)
|
||||
{
|
||||
PyObject *_res = NULL;
|
||||
OSErr _err;
|
||||
short vRefNum;
|
||||
OSType folderType;
|
||||
Boolean createFolder;
|
||||
short foundVRefNum;
|
||||
long foundDirID;
|
||||
if (!PyArg_ParseTuple(_args, "hO&b",
|
||||
&vRefNum,
|
||||
PyMac_GetOSType, &folderType,
|
||||
&createFolder))
|
||||
return NULL;
|
||||
_err = FindFolder(vRefNum,
|
||||
folderType,
|
||||
createFolder,
|
||||
&foundVRefNum,
|
||||
&foundDirID);
|
||||
if (_err != noErr) return PyMac_Error(_err);
|
||||
_res = Py_BuildValue("hl",
|
||||
foundVRefNum,
|
||||
foundDirID);
|
||||
return _res;
|
||||
}
|
||||
|
||||
static PyObject *Folder_ReleaseFolder(PyObject *_self, PyObject *_args)
|
||||
{
|
||||
PyObject *_res = NULL;
|
||||
OSErr _err;
|
||||
short vRefNum;
|
||||
OSType folderType;
|
||||
if (!PyArg_ParseTuple(_args, "hO&",
|
||||
&vRefNum,
|
||||
PyMac_GetOSType, &folderType))
|
||||
return NULL;
|
||||
_err = ReleaseFolder(vRefNum,
|
||||
folderType);
|
||||
if (_err != noErr) return PyMac_Error(_err);
|
||||
Py_INCREF(Py_None);
|
||||
_res = Py_None;
|
||||
return _res;
|
||||
}
|
||||
|
||||
static PyObject *Folder_FSFindFolder(PyObject *_self, PyObject *_args)
|
||||
{
|
||||
PyObject *_res = NULL;
|
||||
OSErr _err;
|
||||
short vRefNum;
|
||||
OSType folderType;
|
||||
Boolean createFolder;
|
||||
FSRef foundRef;
|
||||
if (!PyArg_ParseTuple(_args, "hO&b",
|
||||
&vRefNum,
|
||||
PyMac_GetOSType, &folderType,
|
||||
&createFolder))
|
||||
return NULL;
|
||||
_err = FSFindFolder(vRefNum,
|
||||
folderType,
|
||||
createFolder,
|
||||
&foundRef);
|
||||
if (_err != noErr) return PyMac_Error(_err);
|
||||
_res = Py_BuildValue("O&",
|
||||
PyMac_BuildFSRef, &foundRef);
|
||||
return _res;
|
||||
}
|
||||
|
||||
static PyObject *Folder_AddFolderDescriptor(PyObject *_self, PyObject *_args)
|
||||
{
|
||||
PyObject *_res = NULL;
|
||||
OSErr _err;
|
||||
FolderType foldType;
|
||||
FolderDescFlags flags;
|
||||
FolderClass foldClass;
|
||||
FolderLocation foldLocation;
|
||||
OSType badgeSignature;
|
||||
OSType badgeType;
|
||||
Str255 name;
|
||||
Boolean replaceFlag;
|
||||
if (!PyArg_ParseTuple(_args, "O&lO&O&O&O&O&b",
|
||||
PyMac_GetOSType, &foldType,
|
||||
&flags,
|
||||
PyMac_GetOSType, &foldClass,
|
||||
PyMac_GetOSType, &foldLocation,
|
||||
PyMac_GetOSType, &badgeSignature,
|
||||
PyMac_GetOSType, &badgeType,
|
||||
PyMac_GetStr255, name,
|
||||
&replaceFlag))
|
||||
return NULL;
|
||||
_err = AddFolderDescriptor(foldType,
|
||||
flags,
|
||||
foldClass,
|
||||
foldLocation,
|
||||
badgeSignature,
|
||||
badgeType,
|
||||
name,
|
||||
replaceFlag);
|
||||
if (_err != noErr) return PyMac_Error(_err);
|
||||
Py_INCREF(Py_None);
|
||||
_res = Py_None;
|
||||
return _res;
|
||||
}
|
||||
|
||||
static PyObject *Folder_GetFolderTypes(PyObject *_self, PyObject *_args)
|
||||
{
|
||||
PyObject *_res = NULL;
|
||||
OSErr _err;
|
||||
UInt32 requestedTypeCount;
|
||||
UInt32 totalTypeCount;
|
||||
FolderType theTypes;
|
||||
if (!PyArg_ParseTuple(_args, "l",
|
||||
&requestedTypeCount))
|
||||
return NULL;
|
||||
_err = GetFolderTypes(requestedTypeCount,
|
||||
&totalTypeCount,
|
||||
&theTypes);
|
||||
if (_err != noErr) return PyMac_Error(_err);
|
||||
_res = Py_BuildValue("lO&",
|
||||
totalTypeCount,
|
||||
PyMac_BuildOSType, theTypes);
|
||||
return _res;
|
||||
}
|
||||
|
||||
static PyObject *Folder_RemoveFolderDescriptor(PyObject *_self, PyObject *_args)
|
||||
{
|
||||
PyObject *_res = NULL;
|
||||
OSErr _err;
|
||||
FolderType foldType;
|
||||
if (!PyArg_ParseTuple(_args, "O&",
|
||||
PyMac_GetOSType, &foldType))
|
||||
return NULL;
|
||||
_err = RemoveFolderDescriptor(foldType);
|
||||
if (_err != noErr) return PyMac_Error(_err);
|
||||
Py_INCREF(Py_None);
|
||||
_res = Py_None;
|
||||
return _res;
|
||||
}
|
||||
|
||||
static PyObject *Folder_GetFolderName(PyObject *_self, PyObject *_args)
|
||||
{
|
||||
PyObject *_res = NULL;
|
||||
OSErr _err;
|
||||
short vRefNum;
|
||||
OSType foldType;
|
||||
short foundVRefNum;
|
||||
Str255 name;
|
||||
if (!PyArg_ParseTuple(_args, "hO&O&",
|
||||
&vRefNum,
|
||||
PyMac_GetOSType, &foldType,
|
||||
PyMac_GetStr255, name))
|
||||
return NULL;
|
||||
_err = GetFolderName(vRefNum,
|
||||
foldType,
|
||||
&foundVRefNum,
|
||||
name);
|
||||
if (_err != noErr) return PyMac_Error(_err);
|
||||
_res = Py_BuildValue("h",
|
||||
foundVRefNum);
|
||||
return _res;
|
||||
}
|
||||
|
||||
static PyObject *Folder_AddFolderRouting(PyObject *_self, PyObject *_args)
|
||||
{
|
||||
PyObject *_res = NULL;
|
||||
OSErr _err;
|
||||
OSType fileType;
|
||||
FolderType routeFromFolder;
|
||||
FolderType routeToFolder;
|
||||
RoutingFlags flags;
|
||||
Boolean replaceFlag;
|
||||
if (!PyArg_ParseTuple(_args, "O&O&O&lb",
|
||||
PyMac_GetOSType, &fileType,
|
||||
PyMac_GetOSType, &routeFromFolder,
|
||||
PyMac_GetOSType, &routeToFolder,
|
||||
&flags,
|
||||
&replaceFlag))
|
||||
return NULL;
|
||||
_err = AddFolderRouting(fileType,
|
||||
routeFromFolder,
|
||||
routeToFolder,
|
||||
flags,
|
||||
replaceFlag);
|
||||
if (_err != noErr) return PyMac_Error(_err);
|
||||
Py_INCREF(Py_None);
|
||||
_res = Py_None;
|
||||
return _res;
|
||||
}
|
||||
|
||||
static PyObject *Folder_RemoveFolderRouting(PyObject *_self, PyObject *_args)
|
||||
{
|
||||
PyObject *_res = NULL;
|
||||
OSErr _err;
|
||||
OSType fileType;
|
||||
FolderType routeFromFolder;
|
||||
if (!PyArg_ParseTuple(_args, "O&O&",
|
||||
PyMac_GetOSType, &fileType,
|
||||
PyMac_GetOSType, &routeFromFolder))
|
||||
return NULL;
|
||||
_err = RemoveFolderRouting(fileType,
|
||||
routeFromFolder);
|
||||
if (_err != noErr) return PyMac_Error(_err);
|
||||
Py_INCREF(Py_None);
|
||||
_res = Py_None;
|
||||
return _res;
|
||||
}
|
||||
|
||||
static PyObject *Folder_FindFolderRouting(PyObject *_self, PyObject *_args)
|
||||
{
|
||||
PyObject *_res = NULL;
|
||||
OSErr _err;
|
||||
OSType fileType;
|
||||
FolderType routeFromFolder;
|
||||
FolderType routeToFolder;
|
||||
RoutingFlags flags;
|
||||
if (!PyArg_ParseTuple(_args, "O&O&",
|
||||
PyMac_GetOSType, &fileType,
|
||||
PyMac_GetOSType, &routeFromFolder))
|
||||
return NULL;
|
||||
_err = FindFolderRouting(fileType,
|
||||
routeFromFolder,
|
||||
&routeToFolder,
|
||||
&flags);
|
||||
if (_err != noErr) return PyMac_Error(_err);
|
||||
_res = Py_BuildValue("O&l",
|
||||
PyMac_BuildOSType, routeToFolder,
|
||||
flags);
|
||||
return _res;
|
||||
}
|
||||
|
||||
static PyObject *Folder_InvalidateFolderDescriptorCache(PyObject *_self, PyObject *_args)
|
||||
{
|
||||
PyObject *_res = NULL;
|
||||
OSErr _err;
|
||||
short vRefNum;
|
||||
long dirID;
|
||||
if (!PyArg_ParseTuple(_args, "hl",
|
||||
&vRefNum,
|
||||
&dirID))
|
||||
return NULL;
|
||||
_err = InvalidateFolderDescriptorCache(vRefNum,
|
||||
dirID);
|
||||
if (_err != noErr) return PyMac_Error(_err);
|
||||
Py_INCREF(Py_None);
|
||||
_res = Py_None;
|
||||
return _res;
|
||||
}
|
||||
|
||||
static PyObject *Folder_IdentifyFolder(PyObject *_self, PyObject *_args)
|
||||
{
|
||||
PyObject *_res = NULL;
|
||||
OSErr _err;
|
||||
short vRefNum;
|
||||
long dirID;
|
||||
FolderType foldType;
|
||||
if (!PyArg_ParseTuple(_args, "hl",
|
||||
&vRefNum,
|
||||
&dirID))
|
||||
return NULL;
|
||||
_err = IdentifyFolder(vRefNum,
|
||||
dirID,
|
||||
&foldType);
|
||||
if (_err != noErr) return PyMac_Error(_err);
|
||||
_res = Py_BuildValue("O&",
|
||||
PyMac_BuildOSType, foldType);
|
||||
return _res;
|
||||
}
|
||||
|
||||
static PyMethodDef Folder_methods[] = {
|
||||
{"FindFolder", (PyCFunction)Folder_FindFolder, 1,
|
||||
PyDoc_STR("(short vRefNum, OSType folderType, Boolean createFolder) -> (short foundVRefNum, long foundDirID)")},
|
||||
{"ReleaseFolder", (PyCFunction)Folder_ReleaseFolder, 1,
|
||||
PyDoc_STR("(short vRefNum, OSType folderType) -> None")},
|
||||
{"FSFindFolder", (PyCFunction)Folder_FSFindFolder, 1,
|
||||
PyDoc_STR("(short vRefNum, OSType folderType, Boolean createFolder) -> (FSRef foundRef)")},
|
||||
{"AddFolderDescriptor", (PyCFunction)Folder_AddFolderDescriptor, 1,
|
||||
PyDoc_STR("(FolderType foldType, FolderDescFlags flags, FolderClass foldClass, FolderLocation foldLocation, OSType badgeSignature, OSType badgeType, Str255 name, Boolean replaceFlag) -> None")},
|
||||
{"GetFolderTypes", (PyCFunction)Folder_GetFolderTypes, 1,
|
||||
PyDoc_STR("(UInt32 requestedTypeCount) -> (UInt32 totalTypeCount, FolderType theTypes)")},
|
||||
{"RemoveFolderDescriptor", (PyCFunction)Folder_RemoveFolderDescriptor, 1,
|
||||
PyDoc_STR("(FolderType foldType) -> None")},
|
||||
{"GetFolderName", (PyCFunction)Folder_GetFolderName, 1,
|
||||
PyDoc_STR("(short vRefNum, OSType foldType, Str255 name) -> (short foundVRefNum)")},
|
||||
{"AddFolderRouting", (PyCFunction)Folder_AddFolderRouting, 1,
|
||||
PyDoc_STR("(OSType fileType, FolderType routeFromFolder, FolderType routeToFolder, RoutingFlags flags, Boolean replaceFlag) -> None")},
|
||||
{"RemoveFolderRouting", (PyCFunction)Folder_RemoveFolderRouting, 1,
|
||||
PyDoc_STR("(OSType fileType, FolderType routeFromFolder) -> None")},
|
||||
{"FindFolderRouting", (PyCFunction)Folder_FindFolderRouting, 1,
|
||||
PyDoc_STR("(OSType fileType, FolderType routeFromFolder) -> (FolderType routeToFolder, RoutingFlags flags)")},
|
||||
{"InvalidateFolderDescriptorCache", (PyCFunction)Folder_InvalidateFolderDescriptorCache, 1,
|
||||
PyDoc_STR("(short vRefNum, long dirID) -> None")},
|
||||
{"IdentifyFolder", (PyCFunction)Folder_IdentifyFolder, 1,
|
||||
PyDoc_STR("(short vRefNum, long dirID) -> (FolderType foldType)")},
|
||||
{NULL, NULL, 0}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
void init_Folder(void)
|
||||
{
|
||||
PyObject *m;
|
||||
PyObject *d;
|
||||
|
||||
|
||||
|
||||
|
||||
m = Py_InitModule("_Folder", Folder_methods);
|
||||
d = PyModule_GetDict(m);
|
||||
Folder_Error = PyMac_GetOSErrException();
|
||||
if (Folder_Error == NULL ||
|
||||
PyDict_SetItemString(d, "Error", Folder_Error) != 0)
|
||||
return;
|
||||
}
|
||||
|
||||
/* ======================= End module _Folder ======================= */
|
||||
|
68
Mac/Modules/folder/folderscan.py
Normal file
68
Mac/Modules/folder/folderscan.py
Normal file
|
@ -0,0 +1,68 @@
|
|||
# Scan an Apple header file, generating a Python file of generator calls.
|
||||
|
||||
import sys
|
||||
import os
|
||||
from bgenlocations import TOOLBOXDIR, BGENDIR
|
||||
sys.path.append(BGENDIR)
|
||||
from scantools import Scanner_OSX
|
||||
|
||||
LONG = "Folders"
|
||||
SHORT = "folder"
|
||||
OBJECT = "NOTUSED"
|
||||
|
||||
def main():
|
||||
input = LONG + ".h"
|
||||
output = SHORT + "gen.py"
|
||||
defsoutput = TOOLBOXDIR + LONG + ".py"
|
||||
scanner = MyScanner(input, output, defsoutput)
|
||||
scanner.scan()
|
||||
scanner.close()
|
||||
scanner.gentypetest(SHORT+"typetest.py")
|
||||
print "=== Testing definitions output code ==="
|
||||
execfile(defsoutput, {}, {})
|
||||
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]
|
||||
# This is non-functional today
|
||||
if t == OBJECT and m == "InMode":
|
||||
classname = "Method"
|
||||
listname = "methods"
|
||||
return classname, listname
|
||||
|
||||
def makeblacklistnames(self):
|
||||
return [
|
||||
"FindFolderExtended", # Has funny void* argument
|
||||
"FSFindFolderExtended", # ditto
|
||||
"FolderManagerRegisterCallNotificationProcs", # ditto
|
||||
|
||||
"FindFolderEx", # Non-MacOS routine
|
||||
]
|
||||
|
||||
def makeblacklisttypes(self):
|
||||
return [
|
||||
"FolderManagerNotificationProcPtr",
|
||||
"FolderManagerNotificationUPP",
|
||||
"FolderRouting", # To be done, not difficult
|
||||
"FolderDesc", # To be done, not difficult
|
||||
|
||||
]
|
||||
|
||||
def makerepairinstructions(self):
|
||||
return [
|
||||
]
|
||||
|
||||
def writeinitialdefs(self):
|
||||
self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
|
||||
self.defsfile.write("true = True\n")
|
||||
self.defsfile.write("false = False\n")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
61
Mac/Modules/folder/foldersupport.py
Normal file
61
Mac/Modules/folder/foldersupport.py
Normal file
|
@ -0,0 +1,61 @@
|
|||
# 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 = 'Folders.h' # The Apple header file
|
||||
MODNAME = '_Folder' # The name of the module
|
||||
|
||||
# The following is *usually* unchanged but may still require tuning
|
||||
MODPREFIX = 'Folder' # 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
|
||||
ConstStrFileNameParam = ConstStr255Param
|
||||
StrFileName = Str255
|
||||
FolderClass = OSTypeType("FolderClass")
|
||||
# FolderDesc
|
||||
FolderDescFlags = Type("FolderDescFlags", "l")
|
||||
FolderLocation = OSTypeType("FolderLocation")
|
||||
# FolderRouting
|
||||
FolderType = OSTypeType("FolderType")
|
||||
RoutingFlags = Type("RoutingFlags", "l")
|
||||
|
||||
|
||||
includestuff = includestuff + """
|
||||
#ifdef WITHOUT_FRAMEWORKS
|
||||
#include <Folders.h>
|
||||
#else
|
||||
#include <Carbon/Carbon.h>
|
||||
#endif
|
||||
|
||||
"""
|
||||
|
||||
execfile(string.lower(MODPREFIX) + 'typetest.py')
|
||||
|
||||
# From here on it's basically all boiler plate...
|
||||
|
||||
# Create the generator groups and link them
|
||||
module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
|
||||
|
||||
# Create the generator classes used to populate the lists
|
||||
Function = OSErrFunctionGenerator
|
||||
|
||||
# Create and populate the lists
|
||||
functions = []
|
||||
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)
|
||||
|
||||
# generate output (open the output file as late as possible)
|
||||
SetOutputFileName(OUTPUTFILE)
|
||||
module.generate()
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue