[pywin32-checkins] /hgroot/pywin32/pywin32: Add IShellItem2
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: <pyw...@li...> - 2012-07-15 16:15:49
|
changeset 60947f18882f in /hgroot/pywin32/pywin32 details: http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/hgroot/pywin32/pywin32?cmd=changeset;node=60947f18882f summary: Add IShellItem2 diffstat: com/win32comext/shell/shellcon.py | 11 + com/win32comext/shell/src/PyIShellFolder2.cpp | 75 +- com/win32comext/shell/src/PyIShellFolder2.h | 2 +- com/win32comext/shell/src/PyIShellItem2.cpp | 592 ++++++++++++++++++++++++++ com/win32comext/shell/src/PyIShellItem2.h | 124 +++++ com/win32comext/shell/src/shell.cpp | 67 +- setup.py | 1 + 7 files changed, 802 insertions(+), 70 deletions(-) diffs (truncated from 1130 to 300 lines): diff -r 043fe61ee7c0 -r 60947f18882f com/win32comext/shell/shellcon.py --- a/com/win32comext/shell/shellcon.py Mon Jul 09 17:34:43 2012 +1000 +++ b/com/win32comext/shell/shellcon.py Sun Jul 15 10:45:20 2012 -0400 @@ -1233,3 +1233,14 @@ ["GetDefaultSearchGUID", "EnumSearches", "GetDefaultColumn", "GetDefaultColumnState", "GetDetailsEx", "GetDetailsOf", "MapColumnToSCID"] + +## enum GETPROPERTYSTOREFLAGS, used with IShellItem2 methods +GPS_DEFAULT = 0 +GPS_HANDLERPROPERTIESONLY = 0x1 +GPS_READWRITE = 0x2 +GPS_TEMPORARY = 0x4 +GPS_FASTPROPERTIESONLY = 0x8 +GPS_OPENSLOWITEM = 0x10 +GPS_DELAYCREATION = 0x20 +GPS_BESTEFFORT = 0x40 +GPS_MASK_VALID = 0x7f diff -r 043fe61ee7c0 -r 60947f18882f com/win32comext/shell/src/PyIShellFolder2.cpp --- a/com/win32comext/shell/src/PyIShellFolder2.cpp Mon Jul 09 17:34:43 2012 +1000 +++ b/com/win32comext/shell/src/PyIShellFolder2.cpp Sun Jul 15 10:45:20 2012 -0400 @@ -25,7 +25,7 @@ return (IShellFolder2 *)PyIShellFolder::GetI(self); } -// @pymethod |PyIShellFolder2|GetDefaultSearchGUID|Description of GetDefaultSearchGUID. +// @pymethod <o PyIID>|PyIShellFolder2|GetDefaultSearchGUID|Retrieves the default search for the folder PyObject *PyIShellFolder2::GetDefaultSearchGUID(PyObject *self, PyObject *args) { IShellFolder2 *pISF2 = GetI(self); @@ -45,7 +45,8 @@ return PyWinObject_FromIID(guid); } -// @pymethod |PyIShellFolder2|EnumSearches|Description of EnumSearches. +// @pymethod <o PyIEnumExtraSearch>|PyIShellFolder2|EnumSearches|Returns an interface that lists searches defined for the folder +// @comm IEnumExtraSearch is not yet wrapped by Pywin32 PyObject *PyIShellFolder2::EnumSearches(PyObject *self, PyObject *args) { IShellFolder2 *pISF2 = GetI(self); @@ -64,7 +65,7 @@ return PyCom_PyObjectFromIUnknown(penum, IID_IEnumExtraSearch, FALSE); } -// @pymethod |PyIShellFolder2|GetDefaultColumn|Description of GetDefaultColumn. +// @pymethod (int, int)|PyIShellFolder2|GetDefaultColumn|Returns the columns used for sorting and display PyObject *PyIShellFolder2::GetDefaultColumn(PyObject *self, PyObject *args) { IShellFolder2 *pISF2 = GetI(self); @@ -84,15 +85,16 @@ return Py_BuildValue("ii", sort, display); } -// @pymethod |PyIShellFolder2|GetDefaultColumnState|Description of GetDefaultColumnState. +// @pymethod int|PyIShellFolder2|GetDefaultColumnState|Returns flags indicating the default behaviour of the column +// @rdesc Returns a combination of shellcon.SHCOLSTATE_* flags PyObject *PyIShellFolder2::GetDefaultColumnState(PyObject *self, PyObject *args) { IShellFolder2 *pISF2 = GetI(self); if ( pISF2 == NULL ) return NULL; - // @pyparm int|iColumn||Description for iColumn + // @pyparm int|iColumn||Zero-based index of the column UINT iColumn; - if ( !PyArg_ParseTuple(args, "i:GetDefaultColumnState", &iColumn) ) + if ( !PyArg_ParseTuple(args, "k:GetDefaultColumnState", &iColumn) ) return NULL; SHCOLSTATEF flags; HRESULT hr; @@ -104,24 +106,22 @@ return PyLong_FromUnsignedLong(flags); } -// @pymethod |PyIShellFolder2|GetDetailsEx|Description of GetDetailsEx. +// @pymethod object|PyIShellFolder2|GetDetailsEx|Returns the details of an item by Column ID +// @rdesc The type of returned object is determined by the variant type of the requested column PyObject *PyIShellFolder2::GetDetailsEx(PyObject *self, PyObject *args) { IShellFolder2 *pISF2 = GetI(self); if ( pISF2 == NULL ) return NULL; - // @pyparm <o PyIDL>|pidl||Description for pidl + // @pyparm <o PyIDL>|pidl||Relative id list of an item in the folder + // @pyparm <o SHCOLUMNID>|pscid||The Column id/property key of a column in the folder's Details view SHCOLUMNID scid; - PyObject *obpscid; - // @pyparm <o SHCOLUMNID>|pscid||Description for pscid PyObject *obpidl; LPITEMIDLIST pidl; - if ( !PyArg_ParseTuple(args, "OO:GetDetailsEx", &obpidl, &obpscid) ) + if (!PyArg_ParseTuple(args, "OO&:GetDetailsEx", &obpidl, PyObject_AsSHCOLUMNID, &scid)) return NULL; - BOOL bPythonIsHappy = TRUE; - if (bPythonIsHappy && !PyObject_AsPIDL(obpidl, &pidl)) bPythonIsHappy = FALSE; - if (bPythonIsHappy && !PyObject_AsSHCOLUMNID(obpscid, &scid )) bPythonIsHappy = FALSE; - if (!bPythonIsHappy) return NULL; + if (!PyObject_AsPIDL(obpidl, &pidl)) + return NULL; HRESULT hr; VARIANT var; PY_INTERFACE_PRECALL; @@ -136,23 +136,23 @@ return obRet; } -// @pymethod |PyIShellFolder2|GetDetailsOf|Description of GetDetailsOf. +// @pymethod (int, int, str)|PyIShellFolder2|GetDetailsOf|Returns the value or title of a column in the folder's Details view. +// @rdesc Returns a tuple representing a SHELLDETAILS struct, containing the formst (LVCFMT_*), column width in characters, +// and string representation of the requested value PyObject *PyIShellFolder2::GetDetailsOf(PyObject *self, PyObject *args) { IShellFolder2 *pISF2 = GetI(self); if ( pISF2 == NULL ) return NULL; - // @pyparm <o PyIDL>|pidl||Description for pidl - // @pyparm int|iColumn||Description for iColumn + // @pyparm <o PyIDL>|pidl||The relative idl of an item in the folder. Use None to retrieve column title. + // @pyparm int|iColumn||Zero based index of column SHELLDETAILS sd; - // @pyparm <o PySHELLDETAILS>|psd||Description for psd PyObject *obpidl; LPITEMIDLIST pidl; UINT iColumn; - if ( !PyArg_ParseTuple(args, "Oi:GetDetailsOf", &obpidl, &iColumn) ) + if (!PyArg_ParseTuple(args, "Oi:GetDetailsOf", &obpidl, &iColumn)) return NULL; - BOOL bPythonIsHappy = TRUE; - if (!PyObject_AsPIDL(obpidl, &pidl)) + if (!PyObject_AsPIDL(obpidl, &pidl, TRUE)) return NULL; HRESULT hr; PY_INTERFACE_PRECALL; @@ -161,16 +161,18 @@ PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pISF2, IID_IShellFolder2 ); - return Py_BuildValue("((iiN))", sd.fmt, sd.cxChar, PyObject_FromSTRRET(&sd.str, pidl, TRUE)); + return Py_BuildValue("(iiN)", sd.fmt, sd.cxChar, PyObject_FromSTRRET(&sd.str, pidl, TRUE)); } -// @pymethod |PyIShellFolder2|MapColumnToSCID|Description of MapColumnToSCID. +// @pymethod <o SHCOLUMNID>|PyIShellFolder2|MapColumnToSCID|Returns the unique identifier (FMTID, pid) of a column +// @rdesc On XP and earlier, this is the Column Id as provided by <o PyIColumnProvider>. +// For Vista and later, this is the Property Key used with the property system interfaces. PyObject *PyIShellFolder2::MapColumnToSCID(PyObject *self, PyObject *args) { IShellFolder2 *pISF2 = GetI(self); if ( pISF2 == NULL ) return NULL; - // @pyparm int|iColumn||Description for iColumn + // @pyparm int|Column||The zero-based index of the column as presented by the folder's Details view SHCOLUMNID scid; UINT iColumn; if ( !PyArg_ParseTuple(args, "i:MapColumnToSCID", &iColumn) ) @@ -184,24 +186,27 @@ return PyObject_FromSHCOLUMNID(&scid); } -// @object PyIShellFolder2|Description of the interface +// @object PyIShellFolder2|Represents an explorer folder, giving access to details of items in the folder. +// Inherits all methods of <o PyIShellFolder>. static struct PyMethodDef PyIShellFolder2_methods[] = { - { "GetDefaultSearchGUID", PyIShellFolder2::GetDefaultSearchGUID, 1 }, // @pymeth GetDefaultSearchGUID|Description of GetDefaultSearchGUID - { "EnumSearches", PyIShellFolder2::EnumSearches, 1 }, // @pymeth EnumSearches|Description of EnumSearches - { "GetDefaultColumn", PyIShellFolder2::GetDefaultColumn, 1 }, // @pymeth GetDefaultColumn|Description of GetDefaultColumn - { "GetDefaultColumnState", PyIShellFolder2::GetDefaultColumnState, 1 }, // @pymeth GetDefaultColumnState|Description of GetDefaultColumnState - { "GetDetailsEx", PyIShellFolder2::GetDetailsEx, 1 }, // @pymeth GetDetailsEx|Description of GetDetailsEx - { "GetDetailsOf", PyIShellFolder2::GetDetailsOf, 1 }, // @pymeth GetDetailsOf|Description of GetDetailsOf - { "MapColumnToSCID", PyIShellFolder2::MapColumnToSCID, 1 }, // @pymeth MapColumnToSCID|Description of MapColumnToSCID + { "GetDefaultSearchGUID", PyIShellFolder2::GetDefaultSearchGUID, 1 }, // @pymeth GetDefaultSearchGUID|Retrieves the default search for the folder + { "EnumSearches", PyIShellFolder2::EnumSearches, 1 }, // @pymeth EnumSearches|Returns an interface that lists searches defined for the folder + { "GetDefaultColumn", PyIShellFolder2::GetDefaultColumn, 1 }, // @pymeth GetDefaultColumn|Returns the columns used for sorting and display + { "GetDefaultColumnState", PyIShellFolder2::GetDefaultColumnState, 1 }, // @pymeth GetDefaultColumnState|Returns flags indicating the default behaviour of the column + { "GetDetailsEx", PyIShellFolder2::GetDetailsEx, 1 }, // @pymeth GetDetailsEx|Returns the details of an item by Column ID + { "GetDetailsOf", PyIShellFolder2::GetDetailsOf, 1 }, // @pymeth GetDetailsOf|Returns the value or title of a column in the folder's Details view. + { "MapColumnToSCID", PyIShellFolder2::MapColumnToSCID, 1 }, // @pymeth MapColumnToSCID|Returns the unique identifier (FMTID, pid) of a column { NULL } }; -PyComTypeObject PyIShellFolder2::type("PyIShellFolder2", +// @pymeth __iter__|Enumerates all objects in this folder. +PyComEnumProviderTypeObject PyIShellFolder2::type("PyIShellFolder2", &PyIShellFolder::type, sizeof(PyIShellFolder2), PyIShellFolder2_methods, - GET_PYCOM_CTOR(PyIShellFolder2)); + GET_PYCOM_CTOR(PyIShellFolder2), + "EnumObjects"); // --------------------------------------------------- // // Gateway Implementation diff -r 043fe61ee7c0 -r 60947f18882f com/win32comext/shell/src/PyIShellFolder2.h --- a/com/win32comext/shell/src/PyIShellFolder2.h Mon Jul 09 17:34:43 2012 +1000 +++ b/com/win32comext/shell/src/PyIShellFolder2.h Sun Jul 15 10:45:20 2012 -0400 @@ -9,7 +9,7 @@ public: MAKE_PYCOM_CTOR(PyIShellFolder2); static IShellFolder2 *GetI(PyObject *self); - static PyComTypeObject type; + static PyComEnumProviderTypeObject type; // The Python methods static PyObject *GetDefaultSearchGUID(PyObject *self, PyObject *args); diff -r 043fe61ee7c0 -r 60947f18882f com/win32comext/shell/src/PyIShellItem2.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/com/win32comext/shell/src/PyIShellItem2.cpp Sun Jul 15 10:45:20 2012 -0400 @@ -0,0 +1,592 @@ +// This file implements the IShellItem2 Interface and Gateway for Python. +// Generated by makegw.py + +#include "shell_pch.h" +#include "PyIShellItem.h" +#include "PyIShellItem2.h" + +// @doc - This file contains autoduck documentation +// --------------------------------------------------- +// +// Interface Implementation + +PyIShellItem2::PyIShellItem2(IUnknown *pdisp): + PyIShellItem(pdisp) +{ + ob_type = &type; +} + +PyIShellItem2::~PyIShellItem2() +{ +} + +/* static */ IShellItem2 *PyIShellItem2::GetI(PyObject *self) +{ + return (IShellItem2 *)PyIShellItem::GetI(self); +} + +// @pymethod <o PyIPropertyStore>|PyIShellItem2|GetPropertyStore|Returns a collection of the item's properties +PyObject *PyIShellItem2::GetPropertyStore(PyObject *self, PyObject *args) +{ + IShellItem2 *pISI2 = GetI(self); + if ( pISI2 == NULL ) + return NULL; + + void *ret; + GETPROPERTYSTOREFLAGS flags; + IID riid = IID_IPropertyStore; + // @pyparm int|Flags|GPS_DEFAULT|Combination of GETPROPERTYSTOREFLAGS values (shellcon.GPS_*) + // @pyparm <o PyIID>|riid|IID_IPropertyStore|The interface to return + if ( !PyArg_ParseTuple(args, "|kO&:GetPropertyStore", &flags, PyWinObject_AsIID, &riid)) + return NULL; + + HRESULT hr; + PY_INTERFACE_PRECALL; + hr = pISI2->GetPropertyStore( flags, riid, &ret); + PY_INTERFACE_POSTCALL; + + if ( FAILED(hr) ) + return PyCom_BuildPyException(hr, pISI2, IID_IShellItem2 ); + return PyCom_PyObjectFromIUnknown((IUnknown *)ret, riid); +} + +// @pymethod <o PyIPropertyStore>|PyIShellItem2|GetPropertyStoreWithCreateObject|Returns the property store for the item, with alternate handler instantiation +// @comm Primarily used to create a handler in a separate process with reduced privileges +PyObject *PyIShellItem2::GetPropertyStoreWithCreateObject(PyObject *self, PyObject *args) +{ + IShellItem2 *pISI2 = GetI(self); + if ( pISI2 == NULL ) + return NULL; + + void *ret; + GETPROPERTYSTOREFLAGS flags; + IUnknown *punkCreateObject; + PyObject *obCreateObject; + IID riid = IID_IPropertyStore; + // @pyparm int|Flags||Combination of GETPROPERTYSTOREFLAGS values (shellcon.GPS_*) + // @pyparm <o PyIUnknown>|CreateObject||An interface that implements ICreateObject, used to create the property handler + // @pyparm <o PyIID>|riid|IID_IPropertyStore|The interface to be created + if ( !PyArg_ParseTuple(args, "kO|O&:GetPropertyStoreWithCreateObject", &flags, + &obCreateObject, PyWinObject_AsIID, &riid)) + return NULL; + if (!PyCom_InterfaceFromPyObject(obCreateObject, IID_IUnknown, (void **)&punkCreateObject)) + return NULL; + + HRESULT hr; + PY_INTERFACE_PRECALL; + hr = pISI2->GetPropertyStoreWithCreateObject( flags, punkCreateObject, riid, &ret); + PY_INTERFACE_POSTCALL; + + if ( FAILED(hr) ) + return PyCom_BuildPyException(hr, pISI2, IID_IShellItem2 ); + return PyCom_PyObjectFromIUnknown((IUnknown *)ret, riid); +} + +/* +// @pymethod <o PyIPropertyStore>|PyIShellItem2|GetPropertyStoreForKeys|Creates a property store containing just the specified properties of the item +PyObject *PyIShellItem2::GetPropertyStoreForKeys(PyObject *self, PyObject *args) +{ + IShellItem2 *pISI2 = GetI(self); + if ( pISI2 == NULL ) + return NULL; + |