pywin32-checkins Mailing List for Python for Windows Extensions (Page 94)
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
You can subscribe to this list here.
2003 |
Jan
|
Feb
|
Mar
|
Apr
(2) |
May
(1) |
Jun
(6) |
Jul
(50) |
Aug
(11) |
Sep
(24) |
Oct
(184) |
Nov
(118) |
Dec
(22) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2004 |
Jan
(31) |
Feb
(25) |
Mar
(34) |
Apr
(105) |
May
(49) |
Jun
(38) |
Jul
(39) |
Aug
(7) |
Sep
(98) |
Oct
(79) |
Nov
(20) |
Dec
(17) |
2005 |
Jan
(66) |
Feb
(32) |
Mar
(43) |
Apr
(30) |
May
(58) |
Jun
(30) |
Jul
(16) |
Aug
(4) |
Sep
(21) |
Oct
(42) |
Nov
(11) |
Dec
(14) |
2006 |
Jan
(42) |
Feb
(30) |
Mar
(22) |
Apr
(1) |
May
(9) |
Jun
(15) |
Jul
(20) |
Aug
(9) |
Sep
(8) |
Oct
(1) |
Nov
(9) |
Dec
(43) |
2007 |
Jan
(52) |
Feb
(45) |
Mar
(20) |
Apr
(12) |
May
(59) |
Jun
(39) |
Jul
(35) |
Aug
(31) |
Sep
(17) |
Oct
(20) |
Nov
(4) |
Dec
(4) |
2008 |
Jan
(28) |
Feb
(111) |
Mar
(4) |
Apr
(27) |
May
(40) |
Jun
(27) |
Jul
(32) |
Aug
(94) |
Sep
(87) |
Oct
(153) |
Nov
(336) |
Dec
(331) |
2009 |
Jan
(298) |
Feb
(127) |
Mar
(20) |
Apr
(8) |
May
|
Jun
(10) |
Jul
(6) |
Aug
|
Sep
(2) |
Oct
(2) |
Nov
|
Dec
(1) |
2010 |
Jan
(7) |
Feb
(1) |
Mar
|
Apr
|
May
(15) |
Jun
(4) |
Jul
(3) |
Aug
(28) |
Sep
(1) |
Oct
(19) |
Nov
(16) |
Dec
(6) |
2011 |
Jan
(2) |
Feb
(18) |
Mar
(17) |
Apr
(12) |
May
(5) |
Jun
(11) |
Jul
(7) |
Aug
(2) |
Sep
(2) |
Oct
(4) |
Nov
(4) |
Dec
|
2012 |
Jan
(6) |
Feb
(2) |
Mar
|
Apr
(8) |
May
(4) |
Jun
(3) |
Jul
(13) |
Aug
(27) |
Sep
(8) |
Oct
(9) |
Nov
(3) |
Dec
(2) |
2013 |
Jan
|
Feb
(1) |
Mar
(5) |
Apr
(10) |
May
|
Jun
(2) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
(9) |
2014 |
Jan
(2) |
Feb
(4) |
Mar
(4) |
Apr
(1) |
May
(4) |
Jun
(2) |
Jul
|
Aug
|
Sep
|
Oct
(2) |
Nov
|
Dec
(1) |
2015 |
Jan
(1) |
Feb
|
Mar
|
Apr
(6) |
May
(2) |
Jun
|
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
|
Dec
|
2016 |
Jan
(3) |
Feb
(2) |
Mar
|
Apr
(3) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2017 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(1) |
Oct
|
Nov
|
Dec
|
From: Roger U. <ru...@us...> - 2007-02-24 00:29:08
|
Update of /cvsroot/pywin32/pywin32/win32/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23533/win32/src Modified Files: win32process.i Log Message: Use PyWinLong_AsVoidPtr in place of PyLong_AsVoidPtr Index: win32process.i =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/win32process.i,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** win32process.i 25 Jan 2007 21:42:17 -0000 1.26 --- win32process.i 24 Feb 2007 00:29:07 -0000 1.27 *************** *** 430,438 **** if (!PyWinObject_AsHANDLE(obhprocess, &hprocess, FALSE)) return NULL; ! Func=(LPTHREAD_START_ROUTINE)PyLong_AsVoidPtr(obFunc); ! if (Func==NULL && PyErr_Occurred()) return NULL; ! Parameter=PyLong_AsVoidPtr(obParameter); ! if (Parameter==NULL && PyErr_Occurred()) return NULL; SECURITY_ATTRIBUTES *pSA; --- 430,436 ---- if (!PyWinObject_AsHANDLE(obhprocess, &hprocess, FALSE)) return NULL; ! if (!PyWinLong_AsVoidPtr(obFunc, (void **)&Func)) return NULL; ! if (!PyWinLong_AsVoidPtr(obParameter, &Parameter)) return NULL; SECURITY_ATTRIBUTES *pSA; |
From: Roger U. <ru...@us...> - 2007-02-24 00:21:04
|
Update of /cvsroot/pywin32/pywin32/win32/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20630/win32/src Modified Files: win32service.i Log Message: Use PyWinLong_AsVoidPtr in locking functions Index: win32service.i =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/win32service.i,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** win32service.i 14 Jan 2007 16:37:37 -0000 1.10 --- win32service.i 24 Feb 2007 00:21:03 -0000 1.11 *************** *** 746,750 **** goto cleanup; } ! int len = _tcslen(pStr); _tcsncpy(p, pStr, len); p += len; --- 746,750 ---- goto cleanup; } ! size_t len = _tcslen(pStr); _tcsncpy(p, pStr, len); p += len; *************** *** 1105,1113 **** } %typemap(python,out) SC_LOCK{ ! $target = PyLong_FromVoidPtr($source); } %typemap(python,in) SC_LOCK{ ! $target=PyLong_AsVoidPtr($source); ! if ($target==NULL && PyErr_Occurred()) return NULL; } --- 1105,1112 ---- } %typemap(python,out) SC_LOCK{ ! $target = PyWinLong_FromVoidPtr($source); } %typemap(python,in) SC_LOCK{ ! if (!PyWinLong_AsVoidPtr($source, &$target)) return NULL; } |
From: Roger U. <ru...@us...> - 2007-02-22 20:45:13
|
Update of /cvsroot/pywin32/pywin32/win32/Demos In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28725/win32/Demos Modified Files: win32gui_demo.py Log Message: Use class name in CreateWindow Index: win32gui_demo.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/Demos/win32gui_demo.py,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** win32gui_demo.py 5 Jan 2007 20:36:41 -0000 1.5 --- win32gui_demo.py 22 Feb 2007 20:45:08 -0000 1.6 *************** *** 68,72 **** wc.lpfnWndProc=wndproc_1 class_atom=win32gui.RegisterClass(wc) ! hwnd = win32gui.CreateWindow(class_atom,'Spin the Lobster!', win32con.WS_CAPTION|win32con.WS_VISIBLE, 100,100,900,900, 0, 0, 0, None) --- 68,73 ---- wc.lpfnWndProc=wndproc_1 class_atom=win32gui.RegisterClass(wc) ! hwnd = win32gui.CreateWindow(wc.lpszClassName, ! 'Spin the Lobster!', win32con.WS_CAPTION|win32con.WS_VISIBLE, 100,100,900,900, 0, 0, 0, None) *************** *** 76,80 **** time.sleep(0.01) win32gui.DestroyWindow(hwnd) ! win32gui.UnregisterClass(class_atom,None) def TestGradientFill(): --- 77,81 ---- time.sleep(0.01) win32gui.DestroyWindow(hwnd) ! win32gui.UnregisterClass(wc.lpszClassName, None) def TestGradientFill(): |
From: Roger U. <ru...@us...> - 2007-02-22 20:40:59
|
Update of /cvsroot/pywin32/pywin32/win32/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26522/win32/src Modified Files: win32gui.i Log Message: Use standard functions for converting WPARAM, LPARAM, and resource ids. More 64-bit compat issues Allow window class name to be used as well as class atom in CreateWindow Index: win32gui.i =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/win32gui.i,v retrieving revision 1.101 retrieving revision 1.102 diff -C2 -d -r1.101 -r1.102 *** win32gui.i 16 Jan 2007 19:04:21 -0000 1.101 --- win32gui.i 22 Feb 2007 20:40:54 -0000 1.102 *************** *** 211,217 **** %init %{ PyEval_InitThreads(); /* Start the interpreter's thread-awareness */ ! PyDict_SetItemString(d, "dllhandle", PyLong_FromVoidPtr(g_dllhandle)); PyDict_SetItemString(d, "error", PyWinExc_ApiError); // hack borrowed from win32security since version of SWIG we use doesn't do keyword arguments #ifdef WINXPGUI --- 211,227 ---- %init %{ PyEval_InitThreads(); /* Start the interpreter's thread-awareness */ [...1006 lines suppressed...] - if (!PyWinObject_AsWCHAR(obTemplateName, (WCHAR **)&pofn->lpTemplateName)) - goto done; - ret=PyWinObject_AsHANDLE(obOwner, (PHANDLE)&pofn->hwndOwner, TRUE) && PyWinObject_AsHANDLE(obhInstance, (PHANDLE)&pofn->hInstance, TRUE) && --- 6124,6127 ---- *************** *** 6174,6178 **** PyWinObject_AsWCHAR(obInitialDir, (WCHAR **)&pofn->lpstrInitialDir, TRUE) && PyWinObject_AsWCHAR(obTitle, (WCHAR **)&pofn->lpstrTitle, TRUE) && ! PyWinObject_AsWCHAR(obDefExt, (WCHAR **)&pofn->lpstrDefExt, TRUE); done: --- 6129,6134 ---- PyWinObject_AsWCHAR(obInitialDir, (WCHAR **)&pofn->lpstrInitialDir, TRUE) && PyWinObject_AsWCHAR(obTitle, (WCHAR **)&pofn->lpstrTitle, TRUE) && ! PyWinObject_AsWCHAR(obDefExt, (WCHAR **)&pofn->lpstrDefExt, TRUE) && ! ((obTemplateName==Py_None)||PyWinObject_AsResourceIdW(obTemplateName, (WCHAR **)&pofn->lpTemplateName)); done: |
From: Roger U. <ru...@us...> - 2007-02-22 18:51:51
|
Update of /cvsroot/pywin32/pywin32/win32/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12727/win32/src Modified Files: win32file.i Log Message: Use PyWinLong_FromVoidPtr for backup context pointers Pass file handles to CopyProgressRoutine as plain int handles to avoid Detach operations Index: win32file.i =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/win32file.i,v retrieving revision 1.72 retrieving revision 1.73 diff -C2 -d -r1.72 -r1.73 *** win32file.i 8 Feb 2007 07:19:57 -0000 1.72 --- win32file.i 22 Feb 2007 18:51:39 -0000 1.73 *************** *** 3574,3579 **** if (!PyWinObject_AsHANDLE(obh, &h, FALSE)) return NULL; ! ctxt=PyLong_AsVoidPtr(obctxt); ! if ((ctxt==NULL) && PyErr_Occurred()) return NULL; if (obbuf==Py_None){ --- 3574,3578 ---- if (!PyWinObject_AsHANDLE(obh, &h, FALSE)) return NULL; ! if (!PyWinLong_AsVoidPtr(obctxt, &ctxt)) return NULL; if (obbuf==Py_None){ *************** *** 3599,3603 **** return NULL; } ! return Py_BuildValue("lNN", bytes_read, obbufout, PyLong_FromVoidPtr(ctxt)); } --- 3598,3602 ---- return NULL; } ! return Py_BuildValue("lNN", bytes_read, obbufout, PyWinLong_FromVoidPtr(ctxt)); } *************** *** 3622,3627 **** if (!PyWinObject_AsHANDLE(obh, &h, FALSE)) return NULL; ! ctxt=PyLong_AsVoidPtr(obctxt); ! if ((ctxt==NULL) && PyErr_Occurred()) return NULL; if (!PyWinObject_AsULARGE_INTEGER(obbytes_to_seek, &bytes_to_seek)) --- 3621,3625 ---- if (!PyWinObject_AsHANDLE(obh, &h, FALSE)) return NULL; ! if (!PyWinLong_AsVoidPtr(obctxt, &ctxt)) return NULL; if (!PyWinObject_AsULARGE_INTEGER(obbytes_to_seek, &bytes_to_seek)) *************** *** 3665,3670 **** if (!PyWinObject_AsHANDLE(obh, &h, FALSE)) return NULL; ! ctxt=PyLong_AsVoidPtr(obctxt); ! if ((ctxt==NULL) && PyErr_Occurred()) return NULL; if (PyObject_AsReadBuffer(obbuf, (const void **)&buf, &buflen)==-1) --- 3663,3667 ---- if (!PyWinObject_AsHANDLE(obh, &h, FALSE)) return NULL; ! if (!PyWinLong_AsVoidPtr(obctxt, &ctxt)) return NULL; if (PyObject_AsReadBuffer(obbuf, (const void **)&buf, &buflen)==-1) *************** *** 3677,3681 **** return NULL; } ! return Py_BuildValue("lN", bytes_written, PyLong_FromVoidPtr(ctxt)); } --- 3674,3678 ---- return NULL; } ! return Py_BuildValue("lN", bytes_written, PyWinLong_FromVoidPtr(ctxt)); } *************** *** 3728,3743 **** LPVOID lpData) { ! PyObject *args=NULL, *hsrc=NULL, *hdst=NULL, *ret=NULL; DWORD retcode; CEnterLeavePython _celp; PyObject **callback_objects=(PyObject **)lpData; - hsrc=PyWinObject_FromHANDLE(hSourceFile); - hdst=PyWinObject_FromHANDLE(hDestinationFile); // Py_BuildValue should catch PyHANDLEs NULL ! args=Py_BuildValue("LLLLkkOOO", TotalFileSize, TotalBytesTransferred, StreamSize, StreamBytesTransferred, dwStreamNumber, dwCallbackReason, ! hsrc, hdst, callback_objects[1]); if (args==NULL) // Some serious error, cancel operation. retcode=PROGRESS_CANCEL; --- 3725,3740 ---- LPVOID lpData) { ! PyObject *args=NULL, *ret=NULL; DWORD retcode; CEnterLeavePython _celp; PyObject **callback_objects=(PyObject **)lpData; // Py_BuildValue should catch PyHANDLEs NULL ! args=Py_BuildValue("LLLLkkNNO", TotalFileSize, TotalBytesTransferred, StreamSize, StreamBytesTransferred, dwStreamNumber, dwCallbackReason, ! PyWinLong_FromHANDLE(hSourceFile), ! PyWinLong_FromHANDLE(hDestinationFile), ! callback_objects[1]); if (args==NULL) // Some serious error, cancel operation. retcode=PROGRESS_CANCEL; *************** *** 3748,3752 **** else{ retcode=PyInt_AsLong(ret); ! if (PyErr_Occurred()) retcode=PROGRESS_CANCEL; } --- 3745,3749 ---- else{ retcode=PyInt_AsLong(ret); ! if ((retcode==(DWORD)-1) && PyErr_Occurred()) retcode=PROGRESS_CANCEL; } *************** *** 3755,3769 **** Py_XDECREF(args); Py_XDECREF(ret); - // Detach PyHANDLEs so they don't prematurely close file handles when destroyed - if (hsrc!=NULL){ - ret=PyObject_CallMethod(hsrc,"Detach",NULL); - Py_DECREF(hsrc); - Py_XDECREF(ret); - } - if (hdst!=NULL){ - ret=PyObject_CallMethod(hdst,"Detach",NULL); - Py_DECREF(hdst); - Py_XDECREF(ret); - } return retcode; } --- 3752,3755 ---- |
From: Mark H. <mha...@us...> - 2007-02-22 00:20:54
|
Update of /cvsroot/pywin32/pywin32/win32/Lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14178 Modified Files: win32timezone.py Log Message: Another patch from Jason supporting dynamic time zones in Vista Index: win32timezone.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/Lib/win32timezone.py,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** win32timezone.py 17 Feb 2007 04:43:36 -0000 1.6 --- win32timezone.py 22 Feb 2007 00:20:52 -0000 1.7 *************** *** 13,17 **** Written by Jason R. Coombs (ja...@ja...). ! Copyright © 2003-2006. All Rights Reserved. --- 13,17 ---- Written by Jason R. Coombs (ja...@ja...). ! Copyright © 2003-2007. All Rights Reserved. *************** *** 92,96 **** http://support.microsoft.com/gp/cp_dst) ! As a result, the following test will fail in Windows Vista and machines with the patch. #>>> nov2 = datetime.datetime( 2003, 11, 2, tzinfo = tzi ) #>>> nov2.utctimetuple() --- 92,98 ---- http://support.microsoft.com/gp/cp_dst) ! As a result, the following test will fail in machines with the patch ! except for Vista and its succssors, which have dynamic time ! zone support. #>>> nov2 = datetime.datetime( 2003, 11, 2, tzinfo = tzi ) #>>> nov2.utctimetuple() *************** *** 103,111 **** (2007, 11, 2, 6, 0, 0, 4, 306, 0) - Eventually, I would like to correct the problem for the Vista platform by using - Vista Dynamic Time Zones (which is really just a term for historic & future time - zone accomodation). For now, however, note that time zones not in the current year - could be calculated incorrectly. - There is a function you can call to get some capabilities of the time zone data. --- 105,108 ---- *************** *** 115,122 **** >>> caps.has_key( 'MissingTZPatch' ) True ! ! Currently, this library doesn't support dynamic TZs, even if the platform does. ! >>> caps['DynamicTZSupport'] ! False """ from __future__ import generators --- 112,117 ---- >>> caps.has_key( 'MissingTZPatch' ) True ! >>> caps.has_key( 'DynamicTZSupport' ) ! True """ from __future__ import generators *************** *** 127,131 **** __date__ = '$Date$'[10:-2] ! import os, _winreg, struct, datetime, win32api, re, sys class TimeZoneInfo( datetime.tzinfo ): --- 122,192 ---- __date__ = '$Date$'[10:-2] ! import os, _winreg, struct, datetime, win32api, re, sys, operator ! ! import logging ! log = logging.getLogger( __file__ ) ! ! class WinTZI( object ): ! format = '3l8h8h' ! ! def __init__( self, key, name = None ): ! if( not name and len( key ) == struct.calcsize( self.format ) ): ! self.__init_from_bytes__( key ) ! else: ! self.__init_from_reg_key__( key, name ) ! ! def __init_from_reg_key__( self, key, name = None ): ! if not name: ! key, name = os.path.split( key ) ! value, type = _winreg.QueryValueEx( key, name ) ! self.__init_from_bytes__( value ) ! ! def __init_from_bytes__( self, bytes ): ! components = struct.unpack( self.format, bytes ) ! makeMinuteTimeDelta = lambda x: datetime.timedelta( minutes = x ) ! self.bias, self.standardBiasOffset, self.daylightBiasOffset = \ ! map( makeMinuteTimeDelta, components[:3] ) ! # daylightEnd and daylightStart are 8-tuples representing a Win32 SYSTEMTIME structure ! self.daylightEnd, self.daylightStart = components[3:11], components[11:19] ! ! def LocateStartDay( self, year ): ! return self._LocateDay( year, self.daylightStart ) ! ! def LocateEndDay( self, year ): ! return self._LocateDay( year, self.daylightEnd ) ! ! def _LocateDay( self, year, win32SystemTime ): ! """ ! Takes a SYSTEMTIME structure as retrieved from a TIME_ZONE_INFORMATION ! structure and interprets it based on the given year to identify the actual day. ! ! This method is necessary because the SYSTEMTIME structure refers to a day by its ! day of the week or week of the month (e.g. 4th saturday in April). ! ! Refer to the Windows Platform SDK for more information on the SYSTEMTIME ! and TIME_ZONE_INFORMATION structures. ! """ ! month = win32SystemTime[ 1 ] ! # MS stores Sunday as 0, Python datetime stores Monday as zero ! targetWeekday = ( win32SystemTime[ 2 ] + 6 ) % 7 ! # win32SystemTime[3] is the week of the month, so the following ! # is the first day of that week ! day = ( win32SystemTime[ 3 ] - 1 ) * 7 + 1 ! hour, min, sec, msec = win32SystemTime[4:] ! result = datetime.datetime( year, month, day, hour, min, sec, msec ) ! # now the result is the correct week, but not necessarily the correct day of the week ! daysToGo = targetWeekday - result.weekday() ! result += datetime.timedelta( daysToGo ) ! # if we selected a day in the month following the target month, ! # move back a week or two. ! # This is necessary because Microsoft defines the fifth week in a month ! # to be the last week in a month and adding the time delta might have ! # pushed the result into the next month. ! while result.month == month + 1: ! result -= datetime.timedelta( weeks = 1 ) ! return result ! ! def __cmp__( self, other ): ! return cmp( self.__dict__, other.__dict__ ) class TimeZoneInfo( datetime.tzinfo ): *************** *** 171,183 **** self.standardName = _winreg.QueryValueEx( key, "Std" )[0] self.daylightName = _winreg.QueryValueEx( key, "Dlt" )[0] ! # TZI contains a structure of time zone information and is similar to ! # TIME_ZONE_INFORMATION described in the Windows Platform SDK ! winTZI, type = _winreg.QueryValueEx( key, "TZI" ) ! winTZI = struct.unpack( '3l8h8h', winTZI ) ! makeMinuteTimeDelta = lambda x: datetime.timedelta( minutes = x ) ! self.bias, self.standardBiasOffset, self.daylightBiasOffset = \ ! map( makeMinuteTimeDelta, winTZI[:3] ) ! # daylightEnd and daylightStart are 8-tuples representing a Win32 SYSTEMTIME structure ! self.daylightEnd, self.daylightStart = winTZI[3:11], winTZI[11:19] self._LoadDynamicInfoFromKey( key ) --- 232,236 ---- self.standardName = _winreg.QueryValueEx( key, "Std" )[0] self.daylightName = _winreg.QueryValueEx( key, "Dlt" )[0] ! self.staticInfo = WinTZI( key, "TZI" ) self._LoadDynamicInfoFromKey( key ) *************** *** 187,193 **** except WindowsError: return ! self.dynamicInfo = _RegKeyDict( dkey ) ! del self.dynamicInfo['FirstEntry'] ! del self.dynamicInfo['LastEntry'] def __repr__( self ): --- 240,251 ---- except WindowsError: return ! info = _RegKeyDict( dkey ) ! del info['FirstEntry'] ! del info['LastEntry'] ! years = map( int, info.keys() ) ! values = map( WinTZI, info.values() ) ! # create a range mapping that searches by descending year and matches ! # if the target year is greater or equal. ! self.dynamicInfo = RangeMap( zip( years, values ), descending, operator.ge ) def __repr__( self ): *************** *** 202,223 **** def tzname( self, dt ): ! if self.dst( dt ) == self.daylightBiasOffset: result = self.daylightName ! elif self.dst( dt ) == self.standardBiasOffset: result = self.standardName return result ! def _getStandardBias( self ): ! return self.bias + self.standardBiasOffset ! standardBias = property( _getStandardBias ) ! def _getDaylightBias( self ): ! return self.bias + self.daylightBiasOffset ! daylightBias = property( _getDaylightBias ) def utcoffset( self, dt ): "Calculates the utcoffset according to the datetime.tzinfo spec" if dt is None: return ! return -( self.bias + self.dst( dt ) ) def dst( self, dt ): --- 260,291 ---- def tzname( self, dt ): ! winInfo = self.getWinInfo( dt ) ! if self.dst( dt ) == winInfo.daylightBiasOffset: result = self.daylightName ! elif self.dst( dt ) == winInfo.standardBiasOffset: result = self.standardName return result + + def getWinInfo( self, targetYear ): + if not hasattr( self, 'dynamicInfo' ) or not self.dynamicInfo: + return self.staticInfo + # Find the greatest year entry in self.dynamicInfo which is for + # a year greater than or equal to our targetYear. If not found, + # default to the earliest year. + return self.dynamicInfo.get( targetYear, self.dynamicInfo[ RangeItemLast() ] ) ! def _getStandardBias( self, dt ): ! winInfo = self.getWinInfo( dt.year ) ! return winInfo.bias + winInfo.standardBiasOffset ! def _getDaylightBias( self, dt ): ! winInfo = self.getWinInfo( dt.year ) ! return winInfo.bias + winInfo.daylightBiasOffset def utcoffset( self, dt ): "Calculates the utcoffset according to the datetime.tzinfo spec" if dt is None: return ! winInfo = self.getWinInfo( dt.year ) ! return -( winInfo.bias + self.dst( dt ) ) def dst( self, dt ): *************** *** 225,230 **** if dt is None: return assert dt.tzinfo is self - result = self.standardBiasOffset try: dstStart = self.GetDSTStartTime( dt.year ) --- 293,305 ---- if dt is None: return assert dt.tzinfo is self + winInfo = self.getWinInfo( dt.year ) + if not self.fixedStandardTime and self._inDaylightSavings( dt ): + result = winInfo.daylightBiasOffset + else: + result = winInfo.standardBiasOffset + return result + + def _inDaylightSavings( self, dt ): try: dstStart = self.GetDSTStartTime( dt.year ) *************** *** 237,289 **** # typically ends before it begins in a given year. inDaylightSavings = not ( dstEnd < dt.replace( tzinfo=None ) <= dstStart ) - - if inDaylightSavings and not self.fixedStandardTime: - result = self.daylightBiasOffset except ValueError: # there was an error parsing the time zone, which is normal when a # start and end time are not specified. ! pass ! return result def GetDSTStartTime( self, year ): "Given a year, determines the time when daylight savings time starts" ! return self._LocateDay( year, self.daylightStart ) def GetDSTEndTime( self, year ): "Given a year, determines the time when daylight savings ends." ! return self._LocateDay( year, self.daylightEnd ) - def _LocateDay( self, year, win32SystemTime ): - """ - Takes a SYSTEMTIME structure as retrieved from a TIME_ZONE_INFORMATION - structure and interprets it based on the given year to identify the actual day. - - This method is necessary because the SYSTEMTIME structure refers to a day by its - day of the week or week of the month (e.g. 4th saturday in April). - - Refer to the Windows Platform SDK for more information on the SYSTEMTIME - and TIME_ZONE_INFORMATION structures. - """ - month = win32SystemTime[ 1 ] - # MS stores Sunday as 0, Python datetime stores Monday as zero - targetWeekday = ( win32SystemTime[ 2 ] + 6 ) % 7 - # win32SystemTime[3] is the week of the month, so the following - # is the first day of that week - day = ( win32SystemTime[ 3 ] - 1 ) * 7 + 1 - hour, min, sec, msec = win32SystemTime[4:] - result = datetime.datetime( year, month, day, hour, min, sec, msec ) - # now the result is the correct week, but not necessarily the correct day of the week - daysToGo = targetWeekday - result.weekday() - result += datetime.timedelta( daysToGo ) - # if we selected a day in the month following the target month, - # move back a week or two. - # This is necessary because Microsoft defines the fifth week in a month - # to be the last week in a month and adding the time delta might have - # pushed the result into the next month. - while result.month == month + 1: - result -= datetime.timedelta( weeks = 1 ) - return result - def __cmp__( self, other ): return cmp( self.__dict__, other.__dict__ ) --- 312,330 ---- # typically ends before it begins in a given year. inDaylightSavings = not ( dstEnd < dt.replace( tzinfo=None ) <= dstStart ) except ValueError: # there was an error parsing the time zone, which is normal when a # start and end time are not specified. ! inDaylightSavings = False ! return inDaylightSavings def GetDSTStartTime( self, year ): "Given a year, determines the time when daylight savings time starts" ! return self.getWinInfo( year ).LocateStartDay( year ) def GetDSTEndTime( self, year ): "Given a year, determines the time when daylight savings ends." ! return self.getWinInfo( year ).LocateEndDay( year ) def __cmp__( self, other ): return cmp( self.__dict__, other.__dict__ ) *************** *** 416,417 **** --- 457,542 ---- result = None return result + + # the following code implements a RangeMap and its support classes + + ascending = cmp + def descending( a, b ): + return -ascending( a, b ) + + class RangeMap( dict ): + """A dictionary-like object that uses the keys as bounds for a range. + Inclusion of the value for that range is determined by the + keyMatchComparator, which defaults to greater-than-or-equal. + A value is returned for a key if it is the first key that matches in + the sorted list of keys. By default, keys are sorted in ascending + order, but can be sorted in any other order using the keySortComparator. + + Let's create a map that maps 1-3 -> 'a', 4-6 -> 'b' + >>> r = RangeMap( { 3: 'a', 6: 'b' } ) # boy, that was easy + >>> r[1], r[2], r[3], r[4], r[5], r[6] + ('a', 'a', 'a', 'b', 'b', 'b') + + But you'll notice that the way rangemap is defined, it must be open-ended on one side. + >>> r[0] + 'a' + >>> r[-1] + 'a' + + One can close the open-end of the RangeMap by using RangeValueUndefined + >>> r = RangeMap( { 0: RangeValueUndefined(), 3: 'a', 6: 'b' } ) + >>> r[0] + Traceback (most recent call last): + ... + KeyError: 0 + + One can get the first or last elements in the range by using RangeItem + >>> last_item = RangeItem( -1 ) + >>> r[last_item] + 'b' + + >>> r[RangeItemLast()] + 'b' + + >>> r.bounds() + (0, 6) + + """ + def __init__( self, source, keySortComparator = ascending, keyMatchComparator = operator.le ): + dict.__init__( self, source ) + self.sort = keySortComparator + self.match = keyMatchComparator + + def __getitem__( self, item ): + sortedKeys = self.keys() + sortedKeys.sort( self.sort ) + if isinstance( item, RangeItem ): + result = self.__getitem__( sortedKeys[ item ] ) + else: + key = self._find_first_match_( sortedKeys, item ) + result = dict.__getitem__( self, key ) + if isinstance( result, RangeValueUndefined ): raise KeyError, key + return result + + def _find_first_match_( self, keys, item ): + is_match = lambda k: self.match( item, k ) + # use of ifilter here would be more efficent + matches = filter( is_match, keys ) + if matches: + return matches[0] + raise KeyError( item ) + + def bounds( self ): + sortedKeys = self.keys() + sortedKeys.sort( self.sort ) + return sortedKeys[ RangeItemFirst() ], sortedKeys[ RangeItemLast() ] + + class RangeValueUndefined( object ): pass + class RangeItem( int ): + def __new__( cls, value ): + return int.__new__( cls, value ) + class RangeItemFirst( RangeItem ): + def __new__( cls ): + return RangeItem.__new__( cls, 0 ) + class RangeItemLast( RangeItem ): + def __new__( cls ): + return RangeItem.__new__( cls, -1 ) |
From: Roger U. <ru...@us...> - 2007-02-20 10:31:17
|
Update of /cvsroot/pywin32/pywin32/win32/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25264/win32/src Modified Files: win32apimodule.cpp Log Message: Use PyWinObject_AsPARAM for WPARAM/LPARAM Index: win32apimodule.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/win32apimodule.cpp,v retrieving revision 1.71 retrieving revision 1.72 diff -C2 -d -r1.71 -r1.72 *** win32apimodule.cpp 17 Feb 2007 17:26:18 -0000 1.71 --- win32apimodule.cpp 20 Feb 2007 10:31:15 -0000 1.72 *************** *** 2440,2455 **** { HWND hwnd; ! PyObject *obhwnd; UINT message; WPARAM wParam=0; LPARAM lParam=0; ! if (!PyArg_ParseTuple(args, "Oi|ii:PostMessage", &obhwnd, // @pyparm <o PyHANDLE>|hwnd||The hWnd of the window to receive the message. &message, // @pyparm int|idMessage||The ID of the message to post. ! &wParam, // @pyparm int|wParam||The wParam for the message ! &lParam)) // @pyparm int|lParam||The lParam for the message return NULL; if (!PyWinObject_AsHANDLE(obhwnd, (HANDLE *)&hwnd, FALSE)) return NULL; // @pyseeapi PostMessage PyW32_BEGIN_ALLOW_THREADS --- 2440,2459 ---- { HWND hwnd; ! PyObject *obhwnd, *obwParam=Py_None, *oblParam=Py_None; UINT message; WPARAM wParam=0; LPARAM lParam=0; ! if (!PyArg_ParseTuple(args, "OI|OO:PostMessage", &obhwnd, // @pyparm <o PyHANDLE>|hwnd||The hWnd of the window to receive the message. &message, // @pyparm int|idMessage||The ID of the message to post. ! &obwParam, // @pyparm int|wParam|None|The wParam for the message ! &oblParam)) // @pyparm int|lParam|None|The lParam for the message return NULL; if (!PyWinObject_AsHANDLE(obhwnd, (HANDLE *)&hwnd, FALSE)) return NULL; + if (!PyWinObject_AsPARAM(obwParam, &wParam)) + return NULL; + if (!PyWinObject_AsPARAM(oblParam, (WPARAM *)&lParam)) + return NULL; // @pyseeapi PostMessage PyW32_BEGIN_ALLOW_THREADS *************** *** 2469,2478 **** WPARAM wParam=0; LPARAM lParam=0; ! if (!PyArg_ParseTuple(args, "ii|ii:PostThreadMessage", &threadId, // @pyparm int|tid||Identifier of the thread to which the message will be posted. &message, // @pyparm int|idMessage||The ID of the message to post. ! &wParam, // @pyparm int|wParam||The wParam for the message ! &lParam)) // @pyparm int|lParam||The lParam for the message return NULL; // @pyseeapi PostThreadMessage PyW32_BEGIN_ALLOW_THREADS --- 2473,2488 ---- WPARAM wParam=0; LPARAM lParam=0; ! PyObject *obwParam=Py_None, *oblParam=Py_None; ! if (!PyArg_ParseTuple(args, "iI|OO:PostThreadMessage", &threadId, // @pyparm int|tid||Identifier of the thread to which the message will be posted. &message, // @pyparm int|idMessage||The ID of the message to post. ! &obwParam, // @pyparm int/str|wParam|None|The wParam for the message ! &oblParam)) // @pyparm int/str|lParam|None|The lParam for the message ! return NULL; ! if (!PyWinObject_AsPARAM(obwParam, &wParam)) return NULL; + if (!PyWinObject_AsPARAM(oblParam, (WPARAM *)&lParam)) + return NULL; + // @pyseeapi PostThreadMessage PyW32_BEGIN_ALLOW_THREADS *************** *** 3850,3866 **** { HWND hwnd; ! PyObject *obhwnd; ! int message; ! int wParam=0; ! int lParam=0; ! if (!PyArg_ParseTuple(args, "Oi|ii:SendMessage", ! &obhwnd, // @pyparm <o PyHANDLE>|hwnd||The hWnd of the window to receive the message. ! &message, // @pyparm int|idMessage||The ID of the message to send. ! &wParam, // @pyparm int|wParam||The wParam for the message ! &lParam)) // @pyparm int|lParam||The lParam for the message ! return NULL; if (!PyWinObject_AsHANDLE(obhwnd, (HANDLE *)&hwnd, FALSE)) return NULL; LRESULT rc; // @pyseeapi SendMessage --- 3860,3879 ---- { HWND hwnd; ! PyObject *obhwnd, *obwParam=Py_None, *oblParam=Py_None; ! UINT message; ! WPARAM wParam=0; ! LPARAM lParam=0; ! if (!PyArg_ParseTuple(args, "OI|OO:SendMessage", ! &obhwnd, // @pyparm <o PyHANDLE>|hwnd||The hWnd of the window to receive the message. ! &message, // @pyparm int|idMessage||The ID of the message to send. ! &obwParam, // @pyparm int/string|wParam|None|The wParam for the message ! &oblParam)) // @pyparm int/string|lParam|None|The lParam for the message return NULL; if (!PyWinObject_AsHANDLE(obhwnd, (HANDLE *)&hwnd, FALSE)) return NULL; + if (!PyWinObject_AsPARAM(obwParam, &wParam)) + return NULL; + if (!PyWinObject_AsPARAM(oblParam, (WPARAM *)&lParam)) + return NULL; LRESULT rc; // @pyseeapi SendMessage |
From: Roger U. <ru...@us...> - 2007-02-20 10:10:24
|
Update of /cvsroot/pywin32/pywin32/com/win32comext/shell/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17845/com/win32comext/shell/src Modified Files: PyIShellBrowser.cpp Log Message: Use PyWinObject_AsPARAM for WPARAM/LPARAM Index: PyIShellBrowser.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32comext/shell/src/PyIShellBrowser.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** PyIShellBrowser.cpp 27 Jan 2007 20:09:20 -0000 1.7 --- PyIShellBrowser.cpp 20 Feb 2007 10:10:23 -0000 1.8 *************** *** 261,297 **** } - // Little helper stolen from win32gui - // Need to change win32gui also, or move this function into pywintypes - static BOOL make_param(PyObject *ob, WPARAM *pparam) - { - if (ob==NULL || ob==Py_None){ - *pparam=NULL; - return TRUE; - } - #ifdef UNICODE - #define TCHAR_DESC "Unicode" - if (PyUnicode_Check(ob)){ - *pparam = (WPARAM)PyUnicode_AS_UNICODE(ob); - return TRUE; - } - #else - #define TCHAR_DESC "String" - if (PyString_Check(ob)){ - *pparam = (WPARAM)PyString_AS_STRING(ob); - return TRUE; - } - #endif - *pparam=(WPARAM)PyLong_AsVoidPtr(ob); - if ((*pparam!=NULL) || !PyErr_Occurred()) - return TRUE; - - PyErr_Clear(); - PyBufferProcs *pb = ob->ob_type->tp_as_buffer; - if (pb != NULL && pb->bf_getreadbuffer) - return pb->bf_getreadbuffer(ob,0,(VOID **)pparam)!=-1; - PyErr_SetString(PyExc_TypeError, "Must be a" TCHAR_DESC ", int, or buffer object"); - return FALSE; - } - // @pymethod int|PyIShellBrowser|SendControlMsg|Sends a control msg to browser's toolbar or status bar PyObject *PyIShellBrowser::SendControlMsg(PyObject *self, PyObject *args) --- 261,264 ---- *************** *** 311,318 **** WPARAM wParam; LPARAM lParam; ! if (!make_param(obwparam, &wParam)) return NULL; // WPARAM and LPARAM are defined as UINT_PTR and LONG_PTR, so they can't be used interchangeably without a cast ! if (!make_param(oblparam, (WPARAM *)&lParam)) return NULL; --- 278,285 ---- WPARAM wParam; LPARAM lParam; ! if (!PyWinObject_AsPARAM(obwparam, &wParam)) return NULL; // WPARAM and LPARAM are defined as UINT_PTR and LONG_PTR, so they can't be used interchangeably without a cast ! if (!PyWinObject_AsPARAM(oblparam, (WPARAM *)&lParam)) return NULL; |
From: Roger U. <ru...@us...> - 2007-02-20 10:05:40
|
Update of /cvsroot/pywin32/pywin32/win32/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16015/win32/src Modified Files: PyWinTypes.h PyWinTypesmodule.cpp Log Message: Add unified function for converting WPARAM and LPARAM Index: PyWinTypesmodule.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/PyWinTypesmodule.cpp,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** PyWinTypesmodule.cpp 17 Feb 2007 07:30:16 -0000 1.25 --- PyWinTypesmodule.cpp 20 Feb 2007 10:05:39 -0000 1.26 *************** *** 614,617 **** --- 614,651 ---- + // Conversion for WPARAM and LPARAM + /* ??? WPARAM is defined as UINT_PTR, and LPARAM is defined as LONG_PTR. + Make separate functions to avoid cast ??? */ + BOOL PyWinObject_AsPARAM(PyObject *ob, WPARAM *pparam) + { + if (ob==NULL || ob==Py_None){ + *pparam=NULL; + return TRUE; + } + #ifdef UNICODE + #define TCHAR_DESC "Unicode" + if (PyUnicode_Check(ob)){ + *pparam = (WPARAM)PyUnicode_AS_UNICODE(ob); + return TRUE; + } + #else + #define TCHAR_DESC "String" + if (PyString_Check(ob)){ + *pparam = (WPARAM)PyString_AS_STRING(ob); + return TRUE; + } + #endif + if (PyWinLong_AsVoidPtr(ob, (void **)pparam)) + return TRUE; + + PyErr_Clear(); + PyBufferProcs *pb = ob->ob_type->tp_as_buffer; + if (pb != NULL && pb->bf_getreadbuffer) + return pb->bf_getreadbuffer(ob,0,(VOID **)pparam)!=-1; + PyErr_SetString(PyExc_TypeError, "WPARAM must be a " TCHAR_DESC ", int, or buffer object"); + return FALSE; + } + + /* List of functions exported by this module */ // @module pywintypes|A module which supports common Windows types. Index: PyWinTypes.h =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/PyWinTypes.h,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** PyWinTypes.h 17 Feb 2007 07:30:16 -0000 1.33 --- PyWinTypes.h 20 Feb 2007 10:05:39 -0000 1.34 *************** *** 341,344 **** --- 341,347 ---- #endif + // WPARAM and LPARAM conversion + PYWINTYPES_EXPORT BOOL PyWinObject_AsPARAM(PyObject *ob, WPARAM *pparam); + /* ** SECURITY_ATTRIBUTES support |
From: Roger U. <ru...@us...> - 2007-02-19 20:29:19
|
Update of /cvsroot/pywin32/pywin32/com/win32comext/shell/demos/servers In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27330/com/win32comext/shell/demos/servers Modified Files: shell_view.py Log Message: Allow Scintilla view to be displayed Index: shell_view.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32comext/shell/demos/servers/shell_view.py,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** shell_view.py 12 Feb 2007 03:21:56 -0000 1.7 --- shell_view.py 19 Feb 2007 20:29:18 -0000 1.8 *************** *** 191,195 **** extras = shellcon.SFGAO_HASSUBFOLDER | \ shellcon.SFGAO_FOLDER | \ ! shellcon.SFGAO_FILESYSANCESTOR ret_flags &= (dwAttr | extras) return ret_flags --- 191,196 ---- extras = shellcon.SFGAO_HASSUBFOLDER | \ shellcon.SFGAO_FOLDER | \ ! shellcon.SFGAO_FILESYSANCESTOR | \ ! shellcon.SFGAO_BROWSABLE ret_flags &= (dwAttr | extras) return ret_flags *************** *** 220,224 **** return NewEnum(pidls, iid=shell.IID_IEnumIDList, useDispatcher=(debug>0)) ! # As per comments above, even though this manages a file, it is *not* a # ShellFolderFileSystem, as the children are not on the file system. --- 221,233 ---- return NewEnum(pidls, iid=shell.IID_IEnumIDList, useDispatcher=(debug>0)) ! ! def GetDisplayNameOf(self, pidl, flags): ! final_pidl=pidl[-1] ! full_fname=final_pidl.split('\0')[-1] ! return os.path.split(full_fname)[-1] ! ! def GetAttributesOf(self, pidls, attrFlags): ! return shellcon.SFGAO_HASSUBFOLDER|shellcon.SFGAO_FOLDER|shellcon.SFGAO_FILESYSANCESTOR|shellcon.SFGAO_BROWSABLE ! # As per comments above, even though this manages a file, it is *not* a # ShellFolderFileSystem, as the children are not on the file system. *************** *** 334,337 **** --- 343,351 ---- return NewEnum(items, iid=shell.IID_IEnumIDList, useDispatcher=(debug>0)) + def GetDisplayNameOf(self, pidl, flags): + ## return full path for sys.path dirs, since they don't appear under a parent folder + final_pidl=pidl[-1] + display_name=final_pidl.split('\0')[-1] + return display_name # Simple shell view implementations *************** *** 398,401 **** --- 412,416 ---- win32gui.SetWindowLong(self.hwnd, win32con.GWL_WNDPROC, message_map) print "View 's hwnd is", self.hwnd + return self.hwnd def _CreateChildWindow(self, prev): |
From: Roger U. <ru...@us...> - 2007-02-17 17:26:20
|
Update of /cvsroot/pywin32/pywin32/win32/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20065/win32/src Modified Files: win32apimodule.cpp Log Message: Add Get/SetSystemFileCacheSize Use PyWinObject_AsResourceId in resource functions Index: win32apimodule.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/win32apimodule.cpp,v retrieving revision 1.70 retrieving revision 1.71 diff -C2 -d -r1.70 -r1.71 *** win32apimodule.cpp 5 Feb 2007 07:53:08 -0000 1.70 --- win32apimodule.cpp 17 Feb 2007 17:26:18 -0000 1.71 *************** *** 48,51 **** --- 48,55 ---- typedef BOOL (WINAPI *GlobalMemoryStatusExfunc)(LPMEMORYSTATUSEX); static GlobalMemoryStatusExfunc pfnGlobalMemoryStatusEx=NULL; + typedef BOOL (WINAPI *GetSystemFileCacheSizefunc)(PSIZE_T,PSIZE_T,PDWORD); + static GetSystemFileCacheSizefunc pfnGetSystemFileCacheSize = NULL; + typedef BOOL (WINAPI *SetSystemFileCacheSizefunc)(SIZE_T,SIZE_T,DWORD); + static SetSystemFileCacheSizefunc pfnSetSystemFileCacheSize = NULL; // from secur32.dll *************** *** 1132,1146 **** HINSTANCE hInstance; PyObject *obhInstance, *obid; ! LPCTSTR id; if (!PyArg_ParseTuple(args,"OO:LoadCursor", &obhInstance, // @pyparm <o PyHANDLE>|hInstance||Handle to the instance to load the resource from, or None to load a standard system cursor ! &obid)) // @pyparm int|cursorid||The ID of the cursor. Can be a resource id or for system cursors, one of win32con.IDC_* return NULL; if (!PyWinObject_AsHANDLE(obhInstance, (HANDLE *)&hInstance, TRUE)) return NULL; ! /* ??? Cursor id should also accept a string. Need to create a function for this, same logic used several ! places in win32api and win32gui for resource id's. ??? */ ! id=(LPCTSTR)PyLong_AsVoidPtr(obid); ! if (id==NULL && PyErr_Occurred()) return NULL; // @pyseeapi LoadCursor --- 1136,1147 ---- HINSTANCE hInstance; PyObject *obhInstance, *obid; ! LPTSTR id=NULL; if (!PyArg_ParseTuple(args,"OO:LoadCursor", &obhInstance, // @pyparm <o PyHANDLE>|hInstance||Handle to the instance to load the resource from, or None to load a standard system cursor ! &obid)) // @pyparm <o PyResourceId>|cursorid||The ID of the cursor. Can be a resource id or for system cursors, one of win32con.IDC_* return NULL; if (!PyWinObject_AsHANDLE(obhInstance, (HANDLE *)&hInstance, TRUE)) return NULL; ! if (!PyWinObject_AsResourceId(obid, &id)) return NULL; // @pyseeapi LoadCursor *************** *** 1148,1151 **** --- 1149,1153 ---- HCURSOR ret = ::LoadCursor(hInstance, MAKEINTRESOURCE(id)); PyW32_END_ALLOW_THREADS + PyWinObject_FreeResourceId(id); if (ret==NULL) ReturnAPIError("LoadCursor"); return PyWinLong_FromHANDLE(ret); *************** *** 1666,1683 **** { HINSTANCE handle; ! PyObject *obhandle; ! char *fnName; ! // @pyparm <o PyHANDLE>|hModule||Specifies the handle to the module. ! // @pyparm string|functionName||Specifies the name of the procedure. ! if (!PyArg_ParseTuple(args, "Os:GetProcAddress", &obhandle, &fnName)) return (NULL); if (!PyWinObject_AsHANDLE(obhandle, (HANDLE *)&handle, FALSE)) return NULL; ! FARPROC proc = ::GetProcAddress(handle, fnName); if (proc==NULL) return ReturnAPIError("GetProcAddress"); // @pyseeapi GetProcAddress ! return PyLong_FromVoidPtr(proc); } --- 1668,1689 ---- { HINSTANCE handle; ! PyObject *obhandle, *obfnName; ! char *fnName=NULL; ! ! if (!PyArg_ParseTuple(args, "OO:GetProcAddress", ! &obhandle, // @pyparm <o PyHANDLE>|hModule||Specifies the handle to the module. ! &obfnName)) // @pyparm <o PyResourceId>|functionName||Specifies the name of the procedure, or its ordinal value return (NULL); if (!PyWinObject_AsHANDLE(obhandle, (HANDLE *)&handle, FALSE)) return NULL; ! // GetProcAddress is char only ! if (!PyWinObject_AsResourceIdA(obfnName, &fnName)) ! return NULL; FARPROC proc = ::GetProcAddress(handle, fnName); + PyWinObject_FreeResourceId(fnName); if (proc==NULL) return ReturnAPIError("GetProcAddress"); // @pyseeapi GetProcAddress ! return PyWinLong_FromVoidPtr(proc); } *************** *** 1817,1822 **** #endif // MAINWIN info.dwPageSize, ! PyLong_FromVoidPtr(info.lpMinimumApplicationAddress), ! PyLong_FromVoidPtr(info.lpMaximumApplicationAddress), PyLong_FromUnsignedLongLong(info.dwActiveProcessorMask), info.dwNumberOfProcessors, --- 1823,1828 ---- #endif // MAINWIN info.dwPageSize, ! PyWinLong_FromVoidPtr(info.lpMinimumApplicationAddress), ! PyWinLong_FromVoidPtr(info.lpMaximumApplicationAddress), PyLong_FromUnsignedLongLong(info.dwActiveProcessorMask), info.dwNumberOfProcessors, *************** *** 2234,2237 **** --- 2240,2286 ---- } + // @pymethod tuple|win32api|GetSystemFileCacheSize|Returns the amount of memory reserved for file cache + static PyObject * + PyGetSystemFileCacheSize(PyObject *self, PyObject *args) + { + CHECK_PFN(GetSystemFileCacheSize); + SIZE_T minsize,maxsize; + DWORD flags; + if (!(*pfnGetSystemFileCacheSize)(&minsize, &maxsize, &flags)) + return PyWin_SetAPIError("GetSystemFileCacheSize"); + // @rdesc Returns a tuple containing the minimum and maximum cache sizes, and flags (combination of win32con.MM_WORKING_SET_* flags) + return Py_BuildValue("NNN", + PyLong_FromUnsignedLongLong(minsize), + PyLong_FromUnsignedLongLong(maxsize), + PyLong_FromUnsignedLong(flags)); + } + + // @pymethod |win32api|SetSystemFileCacheSize|Sets the amount of memory reserved for file cache + // @comm Requires SE_INCREASE_QUOTA_NAME priv + // @comm Pass -1 for both min and max to flush file cache. + // @comm Accepts keyword args. + static PyObject * + PySetSystemFileCacheSize(PyObject *self, PyObject *args, PyObject *kwargs) + { + CHECK_PFN(SetSystemFileCacheSize); + SIZE_T minsize,maxsize; + DWORD flags=0; + #ifdef _WIN64 + static char *input_fmt="kk|k:SetSystemFileCacheSize"; + #else + static char *input_fmt="KK|k:SetSystemFileCacheSize"; + #endif + static char *keywords[]={"MinimumFileCacheSize","MaximumFileCacheSize","Flags", NULL}; + if (!PyArg_ParseTupleAndKeywords(args, kwargs, input_fmt, keywords, + &minsize, // @pyparm long|MinimumFileCacheSize||Minimum size in bytes. + &maxsize, // @pyparm long|MaximumFileCacheSize||Maximum size in bytes. + &flags)) // @pyparm int|Flags|0|Combination of win32con.MM_WORKING_SET_* flags + return NULL; + if (!(*pfnSetSystemFileCacheSize)(minsize, maxsize, flags)) + return PyWin_SetAPIError("SetSystemFileCacheSize"); + Py_INCREF(Py_None); + return Py_None; + } + // @pymethod int|win32api|GetVersion|Returns the current version of Windows, and information about the environment. static PyObject * *************** *** 3814,3823 **** if (!PyWinObject_AsHANDLE(obhwnd, (HANDLE *)&hwnd, FALSE)) return NULL; ! int rc; // @pyseeapi SendMessage PyW32_BEGIN_ALLOW_THREADS rc = ::SendMessage(hwnd, message, wParam, lParam); PyW32_END_ALLOW_THREADS ! return Py_BuildValue("i",rc); } --- 3863,3872 ---- if (!PyWinObject_AsHANDLE(obhwnd, (HANDLE *)&hwnd, FALSE)) return NULL; ! LRESULT rc; // @pyseeapi SendMessage PyW32_BEGIN_ALLOW_THREADS rc = ::SendMessage(hwnd, message, wParam, lParam); PyW32_END_ALLOW_THREADS ! return PyWinLong_FromVoidPtr((void *)rc); } *************** *** 3920,3927 **** PyW32_END_ALLOW_THREADS // @pyseeapi ShellExecute ! if ((rc) <= (HINSTANCE)32) { return ReturnAPIError("ShellExecute", (int)rc ); } ! return PyLong_FromVoidPtr(rc); // @rdesc The instance handle of the application that was run. (This handle could also be the handle of a dynamic data exchange [DDE] server application.) // If there is an error, the method raises an exception. --- 3969,3976 ---- PyW32_END_ALLOW_THREADS // @pyseeapi ShellExecute ! if (rc <= (HINSTANCE)32) { return ReturnAPIError("ShellExecute", (int)rc ); } ! return PyWinLong_FromVoidPtr(rc); // @rdesc The instance handle of the application that was run. (This handle could also be the handle of a dynamic data exchange [DDE] server application.) // If there is an error, the method raises an exception. *************** *** 3987,3997 **** else if (PyString_Check(dataOb)) data = (ULONG_PTR)PyString_AsString(dataOb); ! else{ ! data = (ULONG_PTR)PyLong_AsVoidPtr(dataOb); ! if (data==NULL && PyErr_Occurred()){ ! PyErr_SetString(PyExc_TypeError, "4th argument must be a None, string or an integer."); return NULL; - } - } PyW32_BEGIN_ALLOW_THREADS --- 4036,4042 ---- else if (PyString_Check(dataOb)) data = (ULONG_PTR)PyString_AsString(dataOb); ! else ! if (!PyWinLong_AsVoidPtr(dataOb, (void **)&data)) return NULL; PyW32_BEGIN_ALLOW_THREADS *************** *** 4138,4142 **** LONG_PTR rc = ::GetWindowLongPtr(hwnd, offset ); PyW32_END_ALLOW_THREADS ! return PyLong_FromVoidPtr((void *)rc); } --- 4183,4187 ---- LONG_PTR rc = ::GetWindowLongPtr(hwnd, offset ); PyW32_END_ALLOW_THREADS ! return PyWinLong_FromVoidPtr((void *)rc); } *************** *** 4157,4167 **** if (!PyWinObject_AsHANDLE(obhwnd, (HANDLE *)&hwnd, FALSE)) return NULL; ! newVal=(LONG_PTR)PyLong_AsVoidPtr(obval); ! if (newVal==NULL && PyErr_Occurred()) return NULL; PyW32_BEGIN_ALLOW_THREADS LONG_PTR rc = ::SetWindowLongPtr(hwnd, offset, newVal ) ; PyW32_END_ALLOW_THREADS ! return PyLong_FromVoidPtr((void *)rc); } // @pymethod int|win32api|SetWindowWord| --- 4202,4211 ---- if (!PyWinObject_AsHANDLE(obhwnd, (HANDLE *)&hwnd, FALSE)) return NULL; ! if (!PyWinLong_AsVoidPtr(obval, (void **)&newVal)) return NULL; PyW32_BEGIN_ALLOW_THREADS LONG_PTR rc = ::SetWindowLongPtr(hwnd, offset, newVal ) ; PyW32_END_ALLOW_THREADS ! return PyWinLong_FromVoidPtr((void *)rc); } // @pymethod int|win32api|SetWindowWord| *************** *** 4203,4213 **** if (!PyWinObject_AsHANDLE(obhwnd, (HANDLE *)&hwnd, FALSE)) return NULL; ! newVal=(LONG_PTR)PyLong_AsVoidPtr(obval); ! if (newVal==NULL && PyErr_Occurred()) return NULL; PyW32_BEGIN_ALLOW_THREADS LONG_PTR rc = ::SetClassLongPtr(hwnd, offset, newVal ); PyW32_END_ALLOW_THREADS ! return PyLong_FromVoidPtr((void *)rc); } --- 4247,4256 ---- if (!PyWinObject_AsHANDLE(obhwnd, (HANDLE *)&hwnd, FALSE)) return NULL; ! if (!PyWinLong_AsVoidPtr(obval, (void **)&newVal)) return NULL; PyW32_BEGIN_ALLOW_THREADS LONG_PTR rc = ::SetClassLongPtr(hwnd, offset, newVal ); PyW32_END_ALLOW_THREADS ! return PyWinLong_FromVoidPtr((void *)rc); } *************** *** 4533,4589 **** PyObject *obType; PyObject *obName; WORD wLanguage = MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL); ! if ( !PyArg_ParseTuple(args, "OOO|i:LoadResource", &obhModule, // @pyparm <o PyHANDLE>|handle||The handle of the module containing the resource. Use None for currrent process executable. ! &obType, // @pyparm object|type||The type of resource to load. ! &obName, // @pyparm object|name||The name of the resource to load. &wLanguage // @pyparm int|language|NEUTRAL|Language to use, defaults to LANG_NEUTRAL. ) ) return NULL; ! if (!PyWinObject_AsHANDLE(obhModule, (HANDLE *)&hModule, TRUE)) ! return NULL; ! ! BOOL bFreeType = FALSE, bFreeName = FALSE; ! LPTSTR lpType; ! if ( PyInt_Check(obType) ) ! lpType = MAKEINTRESOURCE(PyInt_AS_LONG((PyIntObject *)obType)); ! else if (PyWinObject_AsTCHAR(obType, &lpType)) ! bFreeType = TRUE; ! else ! return ReturnError("Bad type for resource type.", "LoadResource"); ! ! LPTSTR lpName; ! if ( PyInt_Check(obName) ) ! lpName = MAKEINTRESOURCE(PyInt_AS_LONG((PyIntObject *)obName)); ! else if (PyWinObject_AsTCHAR(obName, &lpName)) ! bFreeName = TRUE; ! else { ! if (bFreeType) PyWinObject_FreeTCHAR(lpType); ! return ReturnError("Bad type for resource name.", "LoadResource"); ! } ! ! HRSRC hrsrc = FindResourceEx(hModule, lpType, lpName, wLanguage); ! if (bFreeType) PyWinObject_FreeTCHAR(lpType); ! if (bFreeName) PyWinObject_FreeTCHAR(lpName); ! if ( hrsrc == NULL ) ! return ReturnAPIError("LoadResource"); ! ! DWORD size = SizeofResource(hModule, hrsrc); ! if ( size == 0 ) ! return ReturnAPIError("LoadResource"); ! ! HGLOBAL hglob = LoadResource(hModule, hrsrc); ! if ( hglob == NULL ) ! return ReturnAPIError("LoadResource"); ! ! LPVOID p = LockResource(hglob); ! if ( p == NULL ) ! return ReturnAPIError("LoadResource"); ! ! return PyString_FromStringAndSize((char *)p, size); } ! // @pymethod |win32api|BeginUpdateResource|Begins an update cycle for a PE file. static PyObject * PyBeginUpdateResource(PyObject *self, PyObject *args) { --- 4576,4620 ---- PyObject *obType; PyObject *obName; + PyObject *ret=NULL; WORD wLanguage = MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL); + LPTSTR lpType=NULL,lpName=NULL; ! if ( !PyArg_ParseTuple(args, "OOO|H:LoadResource", &obhModule, // @pyparm <o PyHANDLE>|handle||The handle of the module containing the resource. Use None for currrent process executable. ! &obType, // @pyparm <o PyResourceId>|type||The type of resource to load. ! &obName, // @pyparm <o PyResourceId>|name||The name or Id of the resource to load. &wLanguage // @pyparm int|language|NEUTRAL|Language to use, defaults to LANG_NEUTRAL. ) ) return NULL; ! if (PyWinObject_AsHANDLE(obhModule, (HANDLE *)&hModule, TRUE) ! &&PyWinObject_AsResourceId(obType, &lpType) ! &&PyWinObject_AsResourceId(obName, &lpName)){ ! HRSRC hrsrc = FindResourceEx(hModule, lpType, lpName, wLanguage); ! if ( hrsrc == NULL ) ! PyWin_SetAPIError("FindResourceEx"); ! else{ ! DWORD size = SizeofResource(hModule, hrsrc); ! if ( size == 0 ) ! PyWin_SetAPIError("SizeofResource"); ! else{ ! HGLOBAL hglob = LoadResource(hModule, hrsrc); ! if ( hglob == NULL ) ! PyWin_SetAPIError("LoadResource"); ! else{ ! LPVOID p = LockResource(hglob); ! if ( p == NULL ) ! PyWin_SetAPIError("LockResource"); ! else ! ret=PyString_FromStringAndSize((char *)p, size); ! } ! } ! } ! } ! PyWinObject_FreeResourceId(lpType); ! PyWinObject_FreeResourceId(lpName); ! return ret; } ! // @pymethod <o PyHANDLE>|win32api|BeginUpdateResource|Begins an update cycle for a PE file. static PyObject * PyBeginUpdateResource(PyObject *self, PyObject *args) { *************** *** 4611,4622 **** PyObject *obType; PyObject *obName; LPVOID lpData; DWORD cbData; WORD wLanguage = MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL); ! if ( !PyArg_ParseTuple(args, "OOOs#|i:UpdateResource", &obhUpdate, // @pyparm <o PyHANDLE>|handle||The update-file handle. ! &obType, // @pyparm object|type||The type of resource to load. ! &obName, // @pyparm object|name||The name of the resource to load. &lpData, // @pyparm string|data||The data to place into the resource. &cbData, --- 4642,4655 ---- PyObject *obType; PyObject *obName; + PyObject *ret=NULL; LPVOID lpData; DWORD cbData; WORD wLanguage = MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL); + LPWSTR lpType=NULL,lpName=NULL; ! if ( !PyArg_ParseTuple(args, "OOOs#|H:UpdateResource", &obhUpdate, // @pyparm <o PyHANDLE>|handle||The update-file handle. ! &obType, // @pyparm <o PyResourceId>|type||The type of resource to update ! &obName, // @pyparm <o PyResourceId>|name||The id/name of the resource to update &lpData, // @pyparm string|data||The data to place into the resource. &cbData, *************** *** 4625,4657 **** return NULL; ! if (!PyWinObject_AsHANDLE(obhUpdate, (HANDLE *)&hUpdate, FALSE)) ! return NULL; ! BOOL bFreeType = FALSE, bFreeName = FALSE; ! LPWSTR lpType; ! if ( PyInt_Check(obType) ) ! lpType = MAKEINTRESOURCEW(PyInt_AS_LONG((PyIntObject *)obType)); ! else if (PyWinObject_AsWCHAR(obType, &lpType) ) ! bFreeType = TRUE; ! else ! return ReturnError("Bad type for resource type.", "UpdateResource"); ! ! LPWSTR lpName; ! if ( PyInt_Check(obName) ) ! lpName = MAKEINTRESOURCEW(PyInt_AS_LONG((PyIntObject *)obName)); ! else if ( PyWinObject_AsWCHAR(obName, &lpName) ) ! bFreeName = TRUE; ! else { ! if (bFreeType) PyWinObject_FreeBstr(lpType); ! return ReturnError("Bad type for resource name.", "UpdateResource"); ! } ! ! BOOL ok = UpdateResourceW(hUpdate, lpType, lpName, wLanguage, lpData, cbData); ! if (bFreeType) PyWinObject_FreeWCHAR(lpType); ! if (bFreeName) PyWinObject_FreeWCHAR(lpName); ! if ( !ok ) ! return ReturnAPIError("UpdateResource"); ! ! Py_INCREF(Py_None); ! return Py_None; } --- 4658,4674 ---- return NULL; ! if (PyWinObject_AsHANDLE(obhUpdate, (HANDLE *)&hUpdate, FALSE) ! &&PyWinObject_AsResourceIdW(obType, &lpType) ! &&PyWinObject_AsResourceIdW(obName, &lpName)){ ! if (UpdateResourceW(hUpdate, lpType, lpName, wLanguage, lpData, cbData)){ ! Py_INCREF(Py_None); ! ret=Py_None; ! } ! else ! PyWin_SetAPIError("UpdateResource"); ! } ! PyWinObject_FreeResourceId(lpType); ! PyWinObject_FreeResourceId(lpName); ! return ret; } *************** *** 4664,4669 **** if ( !PyArg_ParseTuple(args, "Oi:EndUpdateResource", ! &obhUpdate, // @pyparm <o PyHANDLE>|handle||The update-file handle. ! &fDiscard // @pyparm int|discard||Flag to discard all writes. ) ) return NULL; --- 4681,4686 ---- if ( !PyArg_ParseTuple(args, "Oi:EndUpdateResource", ! &obhUpdate, // @pyparm <o PyHANDLE>|handle||The update-file handle. ! &fDiscard // @pyparm int|discard||Flag to discard all writes. ) ) return NULL; *************** *** 4677,4713 **** } ! BOOL PyWinObject_AsResourceID(PyObject *ob, long *resource_id) ! { ! // resource names and types can be either string pointers or long ints ! if (PyWinObject_AsWCHAR(ob, (WCHAR **)resource_id)) ! return TRUE; ! PyErr_Clear(); ! if (PyInt_Check(ob)){ ! *resource_id=PyInt_AsLong(ob); ! return TRUE; ! } ! PyErr_Clear(); ! PyErr_SetString(PyExc_TypeError, "Resource name/type must be integer or string"); ! return FALSE; ! } ! ! BOOL CALLBACK EnumResProc(HMODULE module, LPCSTR type, LPSTR name, PyObject ! *param) { ! PyObject *pyname; ! if (HIWORD(name) == 0) ! { ! pyname = PyInt_FromLong(reinterpret_cast<long>(name)); ! } ! else if (name[0] == '#') ! { ! pyname = PyInt_FromLong(_ttoi(name + 1)); ! } else ! { ! pyname = PyString_FromString(name); ! } ! PyList_Append(param, pyname); ! Py_DECREF(pyname); return TRUE; } --- 4694,4709 ---- } ! BOOL CALLBACK EnumResProc(HMODULE module, LPCSTR type, LPSTR name, PyObject *ret) { ! PyObject *obname; ! if (IS_INTRESOURCE(name)) ! obname=PyWinLong_FromVoidPtr(name); else ! obname=PyString_FromString(name); ! if ((obname==NULL) || (PyList_Append(ret, obname)==-1)){ ! Py_XDECREF(obname); ! return FALSE; ! } ! Py_DECREF(obname); return TRUE; } *************** *** 4717,4752 **** { HMODULE hmodule; ! PyObject *obhmodule; ! LPCSTR restype; ! char buf[20]; ! // NOTE: MH can't make the string version of the param ! // return anything useful, so I undocumented its use! ! // pyparm <o PyHANDLE>|hmodule||The handle to the module to enumerate. ! // pyparm string|resType||The type of resource to enumerate as a string (eg, 'RT_DIALOG') ! if (!PyArg_ParseTuple(args, "Os:EnumResourceNames", &obhmodule, &restype)) ! { ! PyErr_Clear(); ! int restypeint; ! // @pyparm <o PyHANDLE>|hmodule||The handle to the module to enumerate. ! // @pyparm int|resType||The type of resource to enumerate as an integer (eg, win32con.RT_DIALOG) ! if (!PyArg_ParseTuple(args, "Oi:EnumResourceNames", &obhmodule, &restypeint)) ! { ! return NULL; ! } ! sprintf(buf, "#%d", restypeint); ! restype = buf; ! } if (!PyWinObject_AsHANDLE(obhmodule, (HANDLE *)&hmodule, FALSE)) return NULL; ! // @rdesc The result is a list of string or integers, one for each resource enumerated. ! PyObject *result = PyList_New(0); ! if (result==NULL) return NULL; - EnumResourceNames( - hmodule, - restype, - reinterpret_cast<ENUMRESNAMEPROC>(EnumResProc), - reinterpret_cast<LONG_PTR>(result)); return result; } --- 4713,4756 ---- { HMODULE hmodule; ! PyObject *obhmodule, *obrestype; ! char *restype=NULL; ! // @pyparm <o PyHANDLE>|hmodule||The handle to the module to enumerate. ! // @pyparm <o PyResourceId>|resType||The type of resource to enumerate. (win32con.RT_*). ! // If passed as a string, form is '#' sign followed by decimal number. eg RT_ANICURSOR would be '#21' ! if (!PyArg_ParseTuple(args, "OO:EnumResourceNames", ! &obhmodule, ! &obrestype)) ! return NULL; ! if (!PyWinObject_AsHANDLE(obhmodule, (HANDLE *)&hmodule, FALSE)) return NULL; ! if (!PyWinObject_AsResourceId(obrestype, &restype)) return NULL; + PyObject *result = PyList_New(0); + if (result!=NULL){ + // @rdesc The result is a list of string or integers, one for each resource enumerated. + if (!EnumResourceNames( + hmodule, + restype, + reinterpret_cast<ENUMRESNAMEPROC>(EnumResProc), + reinterpret_cast<LONG_PTR>(result))){ + // don't overwrite any error that may have been set by callback function + if (PyErr_Occurred()){ + Py_DECREF(result); + result=NULL; + } + else{ + DWORD err=GetLastError(); + // These two errors indicate no resource of specified type found in module, just return empty list if so + if ((err!=ERROR_RESOURCE_TYPE_NOT_FOUND) && (err!=NO_ERROR)){ + PyWin_SetAPIError("EnumResourceNames", err); + Py_DECREF(result); + result=NULL; + } + } + } + } + PyWinObject_FreeResourceId(restype); return result; } *************** *** 4756,4765 **** PyObject *obname=NULL; if (IS_INTRESOURCE(typname)) ! obname=PyInt_FromLong((LONG)typname); else obname=PyWinObject_FromWCHAR(typname); ! if (obname==NULL) return FALSE; ! PyList_Append(ret, obname); Py_DECREF(obname); return TRUE; --- 4760,4770 ---- PyObject *obname=NULL; if (IS_INTRESOURCE(typname)) ! obname=PyWinLong_FromVoidPtr(typname); else obname=PyWinObject_FromWCHAR(typname); ! if ((obname==NULL) || (PyList_Append(ret, obname)==-1)){ ! Py_XDECREF(obname); return FALSE; ! } Py_DECREF(obname); return TRUE; *************** *** 4772,4776 **** HMODULE hmodule; ! // @pyparm <o PyHandle>|hmodule||The handle to the module to enumerate. if (!PyArg_ParseTuple(args, "O:EnumResourceTypes", &pyhandle)) return NULL; --- 4777,4781 ---- HMODULE hmodule; ! // @pyparm <o PyHANDLE>|hmodule||The handle to the module to enumerate. if (!PyArg_ParseTuple(args, "O:EnumResourceTypes", &pyhandle)) return NULL; *************** *** 4778,4781 **** --- 4783,4788 ---- return NULL; ret=PyList_New(0); + if (ret==NULL) + return NULL; if(!EnumResourceTypesW(hmodule, reinterpret_cast<ENUMRESTYPEPROCW>(EnumResourceTypesProc), *************** *** 4793,4803 **** resid=wIDLanguage; PyObject *oblangid = PyInt_FromLong(resid); ! PyList_Append(ret, oblangid); Py_DECREF(oblangid); return TRUE; } ! // @pymethod [<o PyUnicode>,...]|win32api|EnumResourceLanguages|List languages for a resource ! PyObject *PyEnumResourceLanguages(PyObject *, PyObject *args) { PyObject *ret=NULL, *pyhandle=NULL; --- 4800,4813 ---- resid=wIDLanguage; PyObject *oblangid = PyInt_FromLong(resid); ! if ((oblangid==NULL)||(PyList_Append(ret, oblangid)==-1)){ ! Py_XDECREF(oblangid); ! return FALSE; ! } Py_DECREF(oblangid); return TRUE; } ! // @pymethod [int,...]|win32api|EnumResourceLanguages|List languages for a resource ! PyObject *PyEnumResourceLanguages(PyObject *self, PyObject *args) { PyObject *ret=NULL, *pyhandle=NULL; *************** *** 4805,4834 **** WCHAR *resname=NULL, *typname=NULL; PyObject *obresname=NULL, *obtypname=NULL; ! // @pyparm <o PyHandle>|hmodule||Handle to the module that contains resource ! // @pyparm string/unicode/int|lpType||Resource type, can be string or integer ! // @pyparm string/unicode/int|lpName||Resource name, can be string or integer ! if (!PyArg_ParseTuple(args, "OOO:EnumResourceLanguages", &pyhandle, &obtypname, &obresname)) ! return NULL; ! if (!PyWinObject_AsHANDLE(pyhandle, (HANDLE *)&hmodule)) return NULL; ! if(!PyWinObject_AsResourceID(obtypname,(long *)&typname)) ! goto done; ! if(!PyWinObject_AsResourceID(obresname,(long *)&resname)) ! goto done; ! ret=PyList_New(0); ! if(!EnumResourceLanguagesW(hmodule, ! typname, ! resname, ! reinterpret_cast<ENUMRESLANGPROCW>(EnumResourceLanguagesProc), ! reinterpret_cast<LONG_PTR>(ret))){ ! Py_DECREF(ret); ! ret=NULL; ! PyWin_SetAPIError("EnumResourceLanguages",GetLastError()); } ! done: ! if ((typname!=NULL)&&(!IS_INTRESOURCE(typname))) ! PyWinObject_FreeWCHAR(typname); ! if ((resname!=NULL)&&(!IS_INTRESOURCE(resname))) ! PyWinObject_FreeWCHAR(resname); return ret; } --- 4815,4842 ---- WCHAR *resname=NULL, *typname=NULL; PyObject *obresname=NULL, *obtypname=NULL; ! ! if (!PyArg_ParseTuple(args, "OOO:EnumResourceLanguages", ! &pyhandle, // @pyparm <o PyHANDLE>|hmodule||Handle to the module that contains resource ! &obtypname, // @pyparm <o PyResourceId>|lpType||Resource type, can be string or integer ! &obresname)) // @pyparm <o PyResourceId>|lpName||Resource name, can be string or integer return NULL; ! ! if (PyWinObject_AsHANDLE(pyhandle, (HANDLE *)&hmodule) ! &&PyWinObject_AsResourceIdW(obtypname,&typname) ! &&PyWinObject_AsResourceIdW(obresname,&resname)){ ! ret=PyList_New(0); ! if (ret!=NULL) ! if(!EnumResourceLanguagesW(hmodule, ! typname, ! resname, ! reinterpret_cast<ENUMRESLANGPROCW>(EnumResourceLanguagesProc), ! reinterpret_cast<LONG_PTR>(ret))){ ! Py_DECREF(ret); ! ret=NULL; ! PyWin_SetAPIError("EnumResourceLanguages",GetLastError()); ! } } ! PyWinObject_FreeResourceId(typname); ! PyWinObject_FreeResourceId(resname); return ret; } *************** *** 5470,5473 **** --- 5478,5483 ---- {"GetSystemDefaultLCID",PyGetSystemDefaultLCID,1}, // @pymeth GetSystemDefaultLCID|Retrieves the system default locale identifier. {"GetSystemDirectory", PyGetSystemDirectory,1}, // @pymeth GetSystemDirectory|Returns the Windows system directory. + {"GetSystemFileCacheSize", PyGetSystemFileCacheSize,METH_NOARGS}, // @pymeth GetSystemFileCacheSize|Returns the amount of memory reserved for file cache + {"SetSystemFileCacheSize", (PyCFunction)PySetSystemFileCacheSize, METH_KEYWORDS|METH_VARARGS}, // @pymeth SetSystemFileCacheSize|Sets the amount of memory reserved for file cache {"GetSystemInfo", PyGetSystemInfo, 1}, // @pymeth GetSystemInfo|Retrieves information about the current system. {"GetSystemMetrics", PyGetSystemMetrics, 1}, // @pymeth GetSystemMetrics|Returns the specified system metrics. *************** *** 5668,5671 **** --- 5678,5683 ---- pfnSetHandleInformation=(SetHandleInformationfunc)GetProcAddress(hmodule,"SetHandleInformation"); pfnGlobalMemoryStatusEx=(GlobalMemoryStatusExfunc)GetProcAddress(hmodule,"GlobalMemoryStatusEx"); + pfnGetSystemFileCacheSize=(GetSystemFileCacheSizefunc)GetProcAddress(hmodule,"GetSystemFileCacheSize"); + pfnSetSystemFileCacheSize=(SetSystemFileCacheSizefunc)GetProcAddress(hmodule,"SetSystemFileCacheSize"); } |
From: Roger U. <ru...@us...> - 2007-02-17 07:37:52
|
Update of /cvsroot/pywin32/pywin32/win32/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25200/win32/src Modified Files: PyHANDLE.cpp Log Message: Use PyWinLong_AsVoidPtr for int handles Index: PyHANDLE.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/PyHANDLE.cpp,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** PyHANDLE.cpp 11 Jan 2007 13:13:48 -0000 1.13 --- PyHANDLE.cpp 17 Feb 2007 07:37:47 -0000 1.14 *************** *** 30,41 **** *pHANDLE = (HANDLE)(*pH); } else{ // Support integer objects for b/w compat. ! // Can't use PyLong_AsVoidPtr here, since it calls PyLong_AsLong. See ! // http://sourceforge.net/tracker/?func=detail&atid=105470&aid=1630863&group_id=5470 ! #ifdef _WIN64 ! *pHANDLE = (HANDLE)PyLong_AsLongLong(ob); ! #else ! *pHANDLE = (HANDLE)PyInt_AsLong(ob); ! #endif ! if ((*pHANDLE==(HANDLE)-1)&&PyErr_Occurred()){ PyErr_SetString(PyExc_TypeError, "The object is not a PyHANDLE object"); return FALSE; --- 30,35 ---- *pHANDLE = (HANDLE)(*pH); } else{ // Support integer objects for b/w compat. ! // treat int handles same a void pointers ! if (!PyWinLong_AsVoidPtr(ob, (void **)pHANDLE)){ PyErr_SetString(PyExc_TypeError, "The object is not a PyHANDLE object"); return FALSE; *************** *** 51,63 **** // For handles that aren't returned as PyHANDLE or a subclass thereof (HDC, HWND, etc). ! // Return as python ints or longs // ??? Maybe make this a macro to avoid extra function call ??? PyObject *PyWinLong_FromHANDLE(HANDLE h) { ! #ifdef _WIN64 ! return PyLong_FromLongLong((long long)h); ! #else ! return PyInt_FromLong((long)h); ! #endif } --- 45,53 ---- // For handles that aren't returned as PyHANDLE or a subclass thereof (HDC, HWND, etc). ! // Treated same as void pointers. // ??? Maybe make this a macro to avoid extra function call ??? PyObject *PyWinLong_FromHANDLE(HANDLE h) { ! return PyWinLong_FromVoidPtr(h); } |
From: Roger U. <ru...@us...> - 2007-02-17 07:30:24
|
Update of /cvsroot/pywin32/pywin32/win32/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22320/win32/src Modified Files: PyWinTypes.h PyWinTypesmodule.cpp Log Message: Add functions to convert void pointers and resource ids Index: PyWinTypesmodule.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/PyWinTypesmodule.cpp,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** PyWinTypesmodule.cpp 4 Feb 2007 22:11:11 -0000 1.24 --- PyWinTypesmodule.cpp 17 Feb 2007 07:30:16 -0000 1.25 *************** *** 285,289 **** } /* strip trailing cr/lf */ ! int end = _tcslen(buf)-1; if (end>1 && (buf[end-1]==_T('\n') || buf[end-1]==_T('\r'))) buf[end-1] = _T('\0'); --- 285,289 ---- } /* strip trailing cr/lf */ ! size_t end = _tcslen(buf)-1; if (end>1 && (buf[end-1]==_T('\n') || buf[end-1]==_T('\r'))) buf[end-1] = _T('\0'); *************** *** 516,519 **** --- 516,617 ---- } + /* + PyLong_AsVoidPtr is unsuitable for use in many places due to the following issues: + + 1. It fails to convert some types. On 32-bit, it calls PyLong_AsLong + which doesn't check if the type has number methods defined (tp_as_number). + This causes it to fail for PyHANDLE's. + However, it doesn't even fail consistently since on 64-bit it uses + PyLong_AsLongLong which does check tp_as_number. + + 2. When it fails to convert an object (even one for which it should succeed!) + it uses PyErr_BadInternalCall which returns a vague and misleading error. + + 3. The documentation says it's only guaranteed to work for objects created using + PyLong_FromVoidPtr. However, there's no way to call this from the + interpreter which means that places which can also accept a plain number + as well as an address have no way to ensure that both will be converted + consistently. Additionally, PyLong_FromVoidPtr just returns a python int or + long so there is actually no way to verify that an object was created using + that function and can be converted back to a usable address. + + From the response to this bug report: + http://sourceforge.net/tracker/?func=detail&atid=105470&aid=1630863&group_id=5470 + apparently if you want any reasonable or consistent behaviour from this function + you're expected to perform the type checking yourself first. + And if you have to do all that, why use the damn function at all ? + Accordingly, here is our own version. + */ + BOOL PyWinLong_AsVoidPtr(PyObject *ob, void **pptr) + { + #ifdef _WIN64 + *pptr=(void *)PyLong_AsLongLong(ob); + #else + *pptr=(void *)PyInt_AsLong(ob); + #endif + if (*pptr==(void *)-1 && PyErr_Occurred()){ + PyErr_Format(PyExc_TypeError,"Unable to convert %s to pointer-sized value", ob->ob_type->tp_name); + return FALSE; + } + return TRUE; + } + + PyObject *PyWinLong_FromVoidPtr(void *ptr) + { + #ifdef _WIN64 + return PyLong_FromLongLong((LONG_PTR)ptr); + #else + return PyInt_FromLong((LONG_PTR)ptr); + #endif + } + + + // @object PyResourceId|Identifies a resource or function in a module. + // This can be a WORD-sized integer value (0-65536), or string/unicode + // depending on whether the *A or *W API function is to be called. + // Class atoms as used with <om win32gui.CreateWindow> are also treated + // as resource ids since they can also be represented by a name or WORD id. + // When passing resource names and types as strings, they are usually formatted + // as a pound sign followed by decimal form of the id. ('#42' for example) + BOOL PyWinObject_AsResourceIdA(PyObject *ob, char **presource_id) + { + // Plain character conversion + if (PyWinObject_AsString(ob, presource_id)) + return TRUE; + PyErr_Clear(); + if (PyWinLong_AsVoidPtr(ob, (void **)presource_id) && IS_INTRESOURCE(*presource_id)) + return TRUE; + *presource_id=NULL; + PyErr_SetString(PyExc_TypeError, "Resource id/name must be string or int in the range 0-65536"); + return FALSE; + } + + BOOL PyWinObject_AsResourceIdW(PyObject *ob, WCHAR **presource_id) + { + // Unicode version of above + if (PyWinObject_AsWCHAR(ob, presource_id)) + return TRUE; + PyErr_Clear(); + if (PyWinLong_AsVoidPtr(ob, (void **)presource_id) && IS_INTRESOURCE(*presource_id)) + return TRUE; + *presource_id=NULL; + PyErr_SetString(PyExc_TypeError, "Resource id/name must be unicode or int in the range 0-65536"); + return FALSE; + } + + // PyWinObject_FreeString is overloaded to accept either char * or WCHAR * + void PyWinObject_FreeResourceId(char *resource_id) + { + if ((resource_id!=NULL) && !IS_INTRESOURCE(resource_id)) + PyWinObject_FreeString(resource_id); + } + + void PyWinObject_FreeResourceId(WCHAR *resource_id) + { + if ((resource_id!=NULL) && !IS_INTRESOURCE(resource_id)) + PyWinObject_FreeString(resource_id); + } + + /* List of functions exported by this module */ // @module pywintypes|A module which supports common Windows types. Index: PyWinTypes.h =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/PyWinTypes.h,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** PyWinTypes.h 11 Jan 2007 13:13:48 -0000 1.32 --- PyWinTypes.h 17 Feb 2007 07:30:16 -0000 1.33 *************** *** 326,329 **** --- 326,344 ---- PYWINTYPES_EXPORT BOOL PyWinObject_AsDWORDArray(PyObject *obdwords, DWORD **pdwords, DWORD *item_cnt, BOOL bNoneOk=TRUE); + // Substitute for Python's inconsistent PyLong_AsVoidPtr + PYWINTYPES_EXPORT BOOL PyWinLong_AsVoidPtr(PyObject *ob, void **pptr); + PYWINTYPES_EXPORT PyObject *PyWinLong_FromVoidPtr(void *ptr); + + // Conversion for resource id/name and class atom + PYWINTYPES_EXPORT BOOL PyWinObject_AsResourceIdA(PyObject *ob, char **presource_id); + PYWINTYPES_EXPORT BOOL PyWinObject_AsResourceIdW(PyObject *ob, WCHAR **presource_id); + PYWINTYPES_EXPORT void PyWinObject_FreeResourceId(char *resource_id); + PYWINTYPES_EXPORT void PyWinObject_FreeResourceId(WCHAR *resource_id); + #ifdef UNICODE + #define PyWinObject_AsResourceId PyWinObject_AsResourceIdW + #else + #define PyWinObject_AsResourceId PyWinObject_AsResourceIdA + #endif + /* ** SECURITY_ATTRIBUTES support |
From: Roger U. <ru...@us...> - 2007-02-17 05:33:12
|
Update of /cvsroot/pywin32/pywin32/win32/Lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10886/win32/Lib Modified Files: winioctlcon.py Log Message: Add TXFS control codes Index: winioctlcon.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/Lib/winioctlcon.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** winioctlcon.py 21 Oct 2005 04:44:39 -0000 1.2 --- winioctlcon.py 17 Feb 2007 05:32:55 -0000 1.3 *************** *** 282,285 **** --- 282,286 ---- USN_REASON_REPARSE_POINT_CHANGE = 0x00100000 USN_REASON_STREAM_CHANGE = 0x00200000 + USN_REASON_TRANSACTED_CHANGE = 0x00400000 USN_REASON_CLOSE = 0x80000000L USN_DELETE_FLAG_DELETE = 0x00000001 *************** *** 296,300 **** VOLUME_IS_DIRTY = 0x00000001 VOLUME_UPGRADE_SCHEDULED = 0x00000002 ! FILE_PREFETCH_TYPE_FOR_CREATE = 0x1 FILESYSTEM_STATISTICS_TYPE_NTFS = 1 FILESYSTEM_STATISTICS_TYPE_FAT = 2 --- 297,308 ---- VOLUME_IS_DIRTY = 0x00000001 VOLUME_UPGRADE_SCHEDULED = 0x00000002 ! VOLUME_SESSION_OPEN = 4 ! ! FILE_PREFETCH_TYPE_FOR_CREATE = 1 ! FILE_PREFETCH_TYPE_FOR_DIRENUM = 2 ! FILE_PREFETCH_TYPE_FOR_CREATE_EX = 3 ! FILE_PREFETCH_TYPE_FOR_DIRENUM_EX = 4 ! FILE_PREFETCH_TYPE_MAX = 4 ! FILESYSTEM_STATISTICS_TYPE_NTFS = 1 FILESYSTEM_STATISTICS_TYPE_FAT = 2 *************** *** 434,437 **** --- 442,451 ---- IOCTL_SERENUM_PORT_DESC = CTL_CODE(FILE_DEVICE_SERENUM,130,METHOD_BUFFERED,FILE_ANY_ACCESS) IOCTL_SERENUM_GET_PORT_NAME = CTL_CODE(FILE_DEVICE_SERENUM,131,METHOD_BUFFERED,FILE_ANY_ACCESS) + + ## ??? can't find where FILE_DEVICE_AVIO is defined ??? + ## IOCTL_AVIO_ALLOCATE_STREAM = CTL_CODE(FILE_DEVICE_AVIO, 1, METHOD_BUFFERED, FILE_SPECIAL_ACCESS) + ## IOCTL_AVIO_FREE_STREAM = CTL_CODE(FILE_DEVICE_AVIO, 2, METHOD_BUFFERED, FILE_SPECIAL_ACCESS) + ## IOCTL_AVIO_MODIFY_STREAM = CTL_CODE(FILE_DEVICE_AVIO, 3, METHOD_BUFFERED, FILE_SPECIAL_ACCESS) + SERIAL_LSRMST_ESCAPE = 0x00 SERIAL_LSRMST_LSR_DATA = 0x01 *************** *** 512,515 **** --- 526,560 ---- FSCTL_READ_FROM_PLEX = CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 71, METHOD_OUT_DIRECT, FILE_READ_DATA) FSCTL_FILE_PREFETCH = CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 72, METHOD_BUFFERED, FILE_SPECIAL_ACCESS) + FSCTL_MAKE_MEDIA_COMPATIBLE = CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 76, METHOD_BUFFERED, FILE_WRITE_DATA) + FSCTL_SET_DEFECT_MANAGEMENT = CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 77, METHOD_BUFFERED, FILE_WRITE_DATA) + FSCTL_QUERY_SPARING_INFO = CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 78, METHOD_BUFFERED, FILE_ANY_ACCESS) + FSCTL_QUERY_ON_DISK_VOLUME_INFO = CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 79, METHOD_BUFFERED, FILE_ANY_ACCESS) + FSCTL_SET_VOLUME_COMPRESSION_STATE = CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 80, METHOD_BUFFERED, FILE_SPECIAL_ACCESS) + FSCTL_TXFS_MODIFY_RM = CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 81, METHOD_BUFFERED, FILE_WRITE_DATA) + FSCTL_TXFS_QUERY_RM_INFORMATION = CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 82, METHOD_BUFFERED, FILE_READ_DATA) + FSCTL_TXFS_ROLLFORWARD_REDO = CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 84, METHOD_BUFFERED, FILE_WRITE_DATA) + FSCTL_TXFS_ROLLFORWARD_UNDO = CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 85, METHOD_BUFFERED, FILE_WRITE_DATA) + FSCTL_TXFS_START_RM = CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 86, METHOD_BUFFERED, FILE_WRITE_DATA) + FSCTL_TXFS_SHUTDOWN_RM = CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 87, METHOD_BUFFERED, FILE_WRITE_DATA) + FSCTL_TXFS_READ_BACKUP_INFORMATION = CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 88, METHOD_BUFFERED, FILE_READ_DATA) + FSCTL_TXFS_WRITE_BACKUP_INFORMATION = CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 89, METHOD_BUFFERED, FILE_WRITE_DATA) + FSCTL_TXFS_CREATE_SECONDARY_RM = CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 90, METHOD_BUFFERED, FILE_WRITE_DATA) + FSCTL_TXFS_GET_METADATA_INFO = CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 91, METHOD_BUFFERED, FILE_READ_DATA) + FSCTL_TXFS_GET_TRANSACTED_VERSION = CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 92, METHOD_BUFFERED, FILE_READ_DATA) + FSCTL_TXFS_CREATE_MINIVERSION = CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 95, METHOD_BUFFERED, FILE_WRITE_DATA) + FSCTL_TXFS_TRANSACTION_ACTIVE = CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 99, METHOD_BUFFERED, FILE_READ_DATA) + FSCTL_SET_ZERO_ON_DEALLOCATION = CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 101, METHOD_BUFFERED, FILE_SPECIAL_ACCESS) + FSCTL_SET_REPAIR = CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 102, METHOD_BUFFERED, FILE_ANY_ACCESS) + FSCTL_GET_REPAIR = CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 103, METHOD_BUFFERED, FILE_ANY_ACCESS) + FSCTL_WAIT_FOR_REPAIR = CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 104, METHOD_BUFFERED, FILE_ANY_ACCESS) + FSCTL_INITIATE_REPAIR = CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 106, METHOD_BUFFERED, FILE_ANY_ACCESS) + FSCTL_CSC_INTERNAL = CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 107, METHOD_NEITHER, FILE_ANY_ACCESS) + FSCTL_SHRINK_VOLUME = CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 108, METHOD_BUFFERED, FILE_SPECIAL_ACCESS) + FSCTL_SET_SHORT_NAME_BEHAVIOR = CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 109, METHOD_BUFFERED, FILE_ANY_ACCESS) + FSCTL_DFSR_SET_GHOST_HANDLE_STATE = CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 110, METHOD_BUFFERED, FILE_ANY_ACCESS) + FSCTL_TXFS_LIST_TRANSACTION_LOCKED_FILES = CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 120, METHOD_BUFFERED, FILE_READ_DATA) + FSCTL_TXFS_LIST_TRANSACTIONS = CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 121, METHOD_BUFFERED, FILE_READ_DATA) + FSCTL_QUERY_PAGEFILE_ENCRYPTION = CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 122, METHOD_BUFFERED, FILE_ANY_ACCESS) + IOCTL_VOLUME_BASE = ord('V') IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS = CTL_CODE(IOCTL_VOLUME_BASE, 0, METHOD_BUFFERED, FILE_ANY_ACCESS) |
From: Mark H. <mha...@us...> - 2007-02-17 04:43:39
|
Update of /cvsroot/pywin32/pywin32/win32/Lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23608 Modified Files: win32timezone.py Log Message: Patch from Jason R. Coombs to handle 2007 timezones and new vista features Index: win32timezone.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/Lib/win32timezone.py,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** win32timezone.py 2 Jan 2006 22:12:38 -0000 1.5 --- win32timezone.py 17 Feb 2007 04:43:36 -0000 1.6 *************** *** 13,18 **** Written by Jason R. Coombs (ja...@ja...). ! Copyright © 2003. ! All Rights Reserved. To use this time zone module with the datetime module, simply pass --- 13,21 ---- Written by Jason R. Coombs (ja...@ja...). ! Copyright © 2003-2006. ! All Rights Reserved. ! ! This module is licenced for use in Mark Hammond's pywin32 ! library under the same terms as the pywin32 library. To use this time zone module with the datetime module, simply pass *************** *** 40,46 **** >>> aug2.utctimetuple() (2003, 8, 2, 6, 0, 0, 5, 214, 0) ! >>> nov2 = datetime.datetime( 2003, 11, 2, tzinfo = tzi ) >>> nov2.utctimetuple() ! (2003, 11, 2, 7, 0, 0, 6, 306, 0) To convert from one timezone to another, just use the astimezone method. --- 43,49 ---- >>> aug2.utctimetuple() (2003, 8, 2, 6, 0, 0, 5, 214, 0) ! >>> nov2 = datetime.datetime( 2003, 11, 25, tzinfo = tzi ) >>> nov2.utctimetuple() ! (2003, 11, 25, 7, 0, 0, 1, 329, 0) To convert from one timezone to another, just use the astimezone method. *************** *** 68,71 **** --- 71,122 ---- >>> tz == pickle.loads( pickle.dumps( tz ) ) True + + >>> aest = win32timezone.TimeZoneInfo( 'AUS Eastern Standard Time' ) + >>> est = win32timezone.TimeZoneInfo( 'E. Australia Standard Time' ) + >>> dt = datetime.datetime( 2006, 11, 11, 1, 0, 0, tzinfo = aest ) + >>> estdt = dt.astimezone( est ) + >>> estdt.strftime( '%Y-%m-%d %H:%M:%S' ) + '2006-11-11 00:00:00' + + >>> dt = datetime.datetime( 2007, 1, 12, 1, 0, 0, tzinfo = aest ) + >>> estdt = dt.astimezone( est ) + >>> estdt.strftime( '%Y-%m-%d %H:%M:%S' ) + '2007-01-12 00:00:00' + + >>> dt = datetime.datetime( 2007, 6, 13, 1, 0, 0, tzinfo = aest ) + >>> estdt = dt.astimezone( est ) + >>> estdt.strftime( '%Y-%m-%d %H:%M:%S' ) + '2007-06-13 01:00:00' + + Microsoft now has a patch for handling time zones in 2007 (see + http://support.microsoft.com/gp/cp_dst) + + As a result, the following test will fail in Windows Vista and machines with the patch. + #>>> nov2 = datetime.datetime( 2003, 11, 2, tzinfo = tzi ) + #>>> nov2.utctimetuple() + (2003, 11, 2, 7, 0, 0, 6, 306, 0) + + Note that is the correct response beginning in 2007 + This test will fail in Windows versions prior to Vista + #>>> nov2 = datetime.datetime( 2007, 11, 2, tzinfo = tzi ) + #>>> nov2.utctimetuple() + (2007, 11, 2, 6, 0, 0, 4, 306, 0) + + Eventually, I would like to correct the problem for the Vista platform by using + Vista Dynamic Time Zones (which is really just a term for historic & future time + zone accomodation). For now, however, note that time zones not in the current year + could be calculated incorrectly. + + There is a function you can call to get some capabilities of the time + zone data. + >>> caps = GetTZCapabilities() + >>> isinstance( caps, dict ) + True + >>> caps.has_key( 'MissingTZPatch' ) + True + + Currently, this library doesn't support dynamic TZs, even if the platform does. + >>> caps['DynamicTZSupport'] + False """ from __future__ import generators *************** *** 73,80 **** __author__ = 'Jason R. Coombs <ja...@ja...>' __version__ = '$Revision$'[11:-2] ! __vssauthor__ = '$Author$'[9:-2] ! __date__ = '$Modtime: 04-04-14 10:52 $'[10:-2] ! import os, _winreg, struct, datetime class TimeZoneInfo( datetime.tzinfo ): --- 124,131 ---- __author__ = 'Jason R. Coombs <ja...@ja...>' __version__ = '$Revision$'[11:-2] ! __sccauthor__ = '$Author$'[9:-2] ! __date__ = '$Date$'[10:-2] ! import os, _winreg, struct, datetime, win32api, re, sys class TimeZoneInfo( datetime.tzinfo ): *************** *** 129,132 **** --- 180,193 ---- # daylightEnd and daylightStart are 8-tuples representing a Win32 SYSTEMTIME structure self.daylightEnd, self.daylightStart = winTZI[3:11], winTZI[11:19] + self._LoadDynamicInfoFromKey( key ) + + def _LoadDynamicInfoFromKey( self, key ): + try: + dkey = _winreg.OpenKeyEx( key, 'Dynamic DST' ) + except WindowsError: + return + self.dynamicInfo = _RegKeyDict( dkey ) + del self.dynamicInfo['FirstEntry'] + del self.dynamicInfo['LastEntry'] def __repr__( self ): *************** *** 169,174 **** dstStart = self.GetDSTStartTime( dt.year ) dstEnd = self.GetDSTEndTime( dt.year ) ! if dstStart <= dt.replace( tzinfo=None ) < dstEnd and not self.fixedStandardTime: result = self.daylightBiasOffset except ValueError: --- 230,242 ---- dstStart = self.GetDSTStartTime( dt.year ) dstEnd = self.GetDSTEndTime( dt.year ) + + if dstStart < dstEnd: + inDaylightSavings = dstStart <= dt.replace( tzinfo=None ) < dstEnd + else: + # in the southern hemisphere, daylight savings time + # typically ends before it begins in a given year. + inDaylightSavings = not ( dstEnd < dt.replace( tzinfo=None ) <= dstStart ) ! if inDaylightSavings and not self.fixedStandardTime: result = self.daylightBiasOffset except ValueError: *************** *** 291,293 **** fixStandardTime = local['StandardName'] == local['DaylightName'] and \ local['StandardBias'] == local['DaylightBias'] ! return TimeZoneInfo( local['StandardName'], fixStandardTime ) --- 359,417 ---- fixStandardTime = local['StandardName'] == local['DaylightName'] and \ local['StandardBias'] == local['DaylightBias'] ! keyName = [ 'StandardName', 'TimeZoneKeyName' ][ sys.getwindowsversion() >= (6,) ] ! standardName = local[ keyName ] ! standardName = __TimeZoneKeyNameWorkaround( standardName ) ! return TimeZoneInfo( standardName, fixStandardTime ) ! ! def __TimeZoneKeyNameWorkaround( name ): ! """It may be a bug in Vista, but in standard Windows Vista install ! (both 32-bit and 64-bit), it appears the TimeZoneKeyName returns a ! string with extraneous characters.""" ! try: ! return name[:name.index('\x00')] ! except ValueError: ! #null character not found ! return name ! ! def GetTZCapabilities(): ! """Run a few known tests to determine the capabilities of the time zone database ! on this machine. ! Note Dynamic Time Zone support is not available on any platform at this time; this ! is a limitation of this library, not the platform.""" ! tzi = TimeZoneInfo( 'Mountain Standard Time' ) ! MissingTZPatch = datetime.datetime( 2007,11,2,tzinfo=tzi ).utctimetuple() != (2007,11,2,6,0,0,4,306,0) ! DynamicTZSupport = not MissingTZPatch and datetime.datetime( 2003,11,2,tzinfo=tzi).utctimetuple() == (2003,11,2,7,0,0,6,306,0) ! del tzi ! return vars() ! ! ! class DLLHandleCache( object ): ! def __init__( self ): ! self.__cache = {} ! ! def __getitem__( self, filename ): ! key = filename.lower() ! return self.__cache.setdefault( key, win32api.LoadLibrary( key ) ) ! ! DLLCache = DLLHandleCache() ! ! def resolveMUITimeZone( spec ): ! """Resolve a multilingual user interface resource for the time zone name ! >>> result = resolveMUITimeZone( '@tzres.dll,-110' ) ! >>> expectedResultType = [type(None),unicode][sys.getwindowsversion() >= (6,)] ! >>> type( result ) is expectedResultType ! True ! ! spec should be of the format @path,-stringID[;comment] ! see http://msdn2.microsoft.com/en-us/library/ms725481.aspx for details ! """ ! pattern = re.compile( '@(?P<dllname>.*),-(?P<index>\d+)(?:;(?P<comment>.*))?' ) ! matcher = pattern.match( spec ) ! assert matcher, 'Could not parse MUI spec' ! ! try: ! handle = DLLCache[ matcher.groupdict()[ 'dllname' ] ] ! result = win32api.LoadString( handle, int( matcher.groupdict()[ 'index' ] ) ) ! except win32api.error, e: ! result = None ! return result |
From: Mark H. <mha...@us...> - 2007-02-15 13:11:08
|
Update of /cvsroot/pywin32/pywin32 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31039 Modified Files: setup.py Log Message: Support for IEmptyVolumeCache, IEmptyVolumeCache2 and IEmptyVolumeCacheCallBack contributed by Sidnei da Silva from Enfold. Index: setup.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/setup.py,v retrieving revision 1.55 retrieving revision 1.56 diff -C2 -d -r1.55 -r1.56 *** setup.py 15 Feb 2007 13:07:48 -0000 1.55 --- setup.py 15 Feb 2007 13:11:02 -0000 1.56 *************** *** 1237,1240 **** --- 1237,1242 ---- %(shell)s/PyIEnumIDList.cpp %(shell)s/PyIExtractIcon.cpp + %(shell)s/PyIEmptyVolumeCache.cpp + %(shell)s/PyIEmptyVolumeCacheCallBack.cpp %(shell)s/PyIInputObject.cpp %(shell)s/PyIPersistFolder.cpp |
From: Mark H. <mha...@us...> - 2007-02-15 13:11:06
|
Update of /cvsroot/pywin32/pywin32/com/win32comext/shell In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31039/com/win32comext/shell Modified Files: shellcon.py Log Message: Support for IEmptyVolumeCache, IEmptyVolumeCache2 and IEmptyVolumeCacheCallBack contributed by Sidnei da Silva from Enfold. Index: shellcon.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32comext/shell/shellcon.py,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** shellcon.py 6 Apr 2006 10:11:31 -0000 1.16 --- shellcon.py 15 Feb 2007 13:11:02 -0000 1.17 *************** *** 1077,1078 **** --- 1077,1087 ---- GADOF_DIRTY = 1 + # From EmptyVC.h + EVCF_HASSETTINGS = 0x0001 + EVCF_ENABLEBYDEFAULT = 0x0002 + EVCF_REMOVEFROMLIST = 0x0004 + EVCF_ENABLEBYDEFAULT_AUTO = 0x0008 + EVCF_DONTSHOWIFZERO = 0x0010 + EVCF_SETTINGSMODE = 0x0020 + EVCF_OUTOFDISKSPACE = 0x0040 + EVCCBF_LASTNOTIFICATION = 0x0001 |
Update of /cvsroot/pywin32/pywin32/com/win32comext/shell/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31039/com/win32comext/shell/src Modified Files: shell.cpp Added Files: PyIEmptyVolumeCache.cpp PyIEmptyVolumeCache.h PyIEmptyVolumeCacheCallBack.cpp PyIEmptyVolumeCacheCallBack.h Log Message: Support for IEmptyVolumeCache, IEmptyVolumeCache2 and IEmptyVolumeCacheCallBack contributed by Sidnei da Silva from Enfold. --- NEW FILE: PyIEmptyVolumeCache.h --- // This file declares the IEmptyVolumeCache Gateway for Python. // --------------------------------------------------- // // Gateway Declaration class PyGEmptyVolumeCache : public PyGatewayBase, public IEmptyVolumeCache { protected: PyGEmptyVolumeCache(PyObject *instance) : PyGatewayBase(instance) { ; } PYGATEWAY_MAKE_SUPPORT2(PyGEmptyVolumeCache, IEmptyVolumeCache, IID_IEmptyVolumeCache, PyGatewayBase) // IEmptyVolumeCache STDMETHOD(Initialize)( HKEY hkRegKey, LPCWSTR pcwszVolume, LPWSTR * ppwszDisplayName, LPWSTR * ppwszDescription, DWORD * pdwFlags); STDMETHOD(GetSpaceUsed)( DWORDLONG * pdwlSpaceUsed, IEmptyVolumeCacheCallBack * picb); STDMETHOD(Purge)( DWORDLONG dwlSpaceToFree, IEmptyVolumeCacheCallBack * picb); STDMETHOD(ShowProperties)( HWND hwnd); STDMETHOD(Deactivate)( DWORD * pdwFlags); }; class PyGEmptyVolumeCache2 : public PyGEmptyVolumeCache, public IEmptyVolumeCache2 { protected: PyGEmptyVolumeCache2(PyObject *instance) : PyGEmptyVolumeCache(instance) { ; } PYGATEWAY_MAKE_SUPPORT2(PyGEmptyVolumeCache2, IEmptyVolumeCache2, IID_IEmptyVolumeCache2, PyGEmptyVolumeCache) // IEmptyVolumeCache STDMETHOD(Initialize)( HKEY hkRegKey, LPCWSTR pcwszVolume, LPWSTR * ppwszDisplayName, LPWSTR * ppwszDescription, DWORD * pdwFlags) { return PyGEmptyVolumeCache::Initialize(hkRegKey, pcwszVolume, ppwszDisplayName, ppwszDescription, pdwFlags); } STDMETHOD(GetSpaceUsed)( DWORDLONG * pdwlSpaceUsed, IEmptyVolumeCacheCallBack * picb) { return PyGEmptyVolumeCache::GetSpaceUsed(pdwlSpaceUsed, picb); } STDMETHOD(Purge)( DWORDLONG dwlSpaceToFree, IEmptyVolumeCacheCallBack * picb) { return PyGEmptyVolumeCache::Purge(dwlSpaceToFree, picb); } STDMETHOD(ShowProperties)( HWND hwnd) { return PyGEmptyVolumeCache::ShowProperties(hwnd); } STDMETHOD(Deactivate)( DWORD * pdwFlags) { return PyGEmptyVolumeCache::Deactivate(pdwFlags); } // IEmptyVolumeCache2 STDMETHOD(InitializeEx)( HKEY hkRegKey, LPCWSTR pcwszVolume, LPCWSTR pcwszKeyName, LPWSTR * ppwszDisplayName, LPWSTR * ppwszDescription, LPWSTR * ppwszBtnText, DWORD * pdwFlags); }; --- NEW FILE: PyIEmptyVolumeCacheCallBack.cpp --- // This file implements the IEmptyVolumeCacheCallBack Interface and Gateway for Python. // Generated by makegw.py #include "shell_pch.h" #include "EmptyVC.h" #include "PyIEmptyVolumeCacheCallBack.h" // @doc - This file contains autoduck documentation // @object PyIEmptyVolumeCacheCallBack|Callback used by <o PyIEmptyVolumeCacheCallBack> // --------------------------------------------------- // // Interface Implementation PyIEmptyVolumeCacheCallBack::PyIEmptyVolumeCacheCallBack(IUnknown *pdisp): PyIUnknown(pdisp) { ob_type = &type; } PyIEmptyVolumeCacheCallBack::~PyIEmptyVolumeCacheCallBack() { } /* static */ IEmptyVolumeCacheCallBack *PyIEmptyVolumeCacheCallBack::GetI(PyObject *self) { return (IEmptyVolumeCacheCallBack *)PyIUnknown::GetI(self); } // @pymethod |PyIEmptyVolumeCacheCallBack|ScanProgress|Description of ScanProgress. PyObject *PyIEmptyVolumeCacheCallBack::ScanProgress(PyObject *self, PyObject *args) { IEmptyVolumeCacheCallBack *pIEVCCB = GetI(self); if ( pIEVCCB == NULL ) return NULL; DWORDLONG dwlSpaceUsed; PyObject *obdwlSpaceUsed; // @pyparm long|dwlSpaceUsed||Description for dwlSpaceUsed // @pyparm int|dwFlags||Description for dwFlags // @pyparm unicode|pcwszStatus||Description for pcwszStatus PyObject *obpcwszStatus; DWORD dwFlags; LPWSTR pcwszStatus; if ( !PyArg_ParseTuple(args, "OkO:ScanProgress", &obdwlSpaceUsed, &dwFlags, &obpcwszStatus) ) return NULL; dwlSpaceUsed = PyLong_AsUnsignedLongLong(obdwlSpaceUsed); if (dwlSpaceUsed == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred()) return NULL; if (!PyWinObject_AsWCHAR(obpcwszStatus, &pcwszStatus)) return NULL; HRESULT hr; PY_INTERFACE_PRECALL; hr = pIEVCCB->ScanProgress( dwlSpaceUsed, dwFlags, pcwszStatus ); SysFreeString(pcwszStatus); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pIEVCCB, IID_IEmptyVolumeCacheCallBack ); Py_INCREF(Py_None); return Py_None; } // @pymethod |PyIEmptyVolumeCacheCallBack|PurgeProgress|Description of PurgeProgress. PyObject *PyIEmptyVolumeCacheCallBack::PurgeProgress(PyObject *self, PyObject *args) { IEmptyVolumeCacheCallBack *pIEVCCB = GetI(self); if ( pIEVCCB == NULL ) return NULL; DWORDLONG dwlSpaceFreed; PyObject *obdwlSpaceFreed; // @pyparm <o PyDWORDLONG>|dwlSpaceFreed||Description for dwlSpaceFreed DWORDLONG dwlSpaceToFree; PyObject *obdwlSpaceToFree; // @pyparm long|spaceFreed|| // @pyparm long|spaceToFree|| // @pyparm long|flags|| // @pyparm unicode|status|| PyObject *obpcwszStatus; DWORD dwFlags; LPWSTR pcwszStatus; if ( !PyArg_ParseTuple(args, "OOlO:PurgeProgress", &obdwlSpaceFreed, &obdwlSpaceToFree, &dwFlags, &obpcwszStatus) ) return NULL; dwlSpaceFreed = PyLong_AsUnsignedLongLong(obdwlSpaceFreed); if (dwlSpaceFreed == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred()) return NULL; dwlSpaceToFree = PyLong_AsUnsignedLongLong(obdwlSpaceToFree); if (dwlSpaceToFree == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred()) return NULL; if (!PyWinObject_AsWCHAR(obpcwszStatus, &pcwszStatus)) return NULL; HRESULT hr; PY_INTERFACE_PRECALL; hr = pIEVCCB->PurgeProgress( dwlSpaceFreed, dwlSpaceToFree, dwFlags, pcwszStatus ); SysFreeString(pcwszStatus); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pIEVCCB, IID_IEmptyVolumeCacheCallBack ); Py_INCREF(Py_None); return Py_None; } // @object PyIEmptyVolumeCacheCallBack|Description of the interface static struct PyMethodDef PyIEmptyVolumeCacheCallBack_methods[] = { { "ScanProgress", PyIEmptyVolumeCacheCallBack::ScanProgress, 1 }, // @pymeth ScanProgress|Description of ScanProgress { "PurgeProgress", PyIEmptyVolumeCacheCallBack::PurgeProgress, 1 }, // @pymeth PurgeProgress|Description of PurgeProgress { NULL } }; PyComTypeObject PyIEmptyVolumeCacheCallBack::type("PyIEmptyVolumeCacheCallBack", &PyIUnknown::type, sizeof(PyIEmptyVolumeCacheCallBack), PyIEmptyVolumeCacheCallBack_methods, GET_PYCOM_CTOR(PyIEmptyVolumeCacheCallBack)); --- NEW FILE: PyIEmptyVolumeCacheCallBack.h --- // This file declares the IEmptyVolumeCacheCallBack Interface for Python. // --------------------------------------------------- // // Interface Declaration class PyIEmptyVolumeCacheCallBack : public PyIUnknown { public: MAKE_PYCOM_CTOR(PyIEmptyVolumeCacheCallBack); static IEmptyVolumeCacheCallBack *GetI(PyObject *self); static PyComTypeObject type; // The Python methods static PyObject *ScanProgress(PyObject *self, PyObject *args); static PyObject *PurgeProgress(PyObject *self, PyObject *args); protected: PyIEmptyVolumeCacheCallBack(IUnknown *pdisp); ~PyIEmptyVolumeCacheCallBack(); }; Index: shell.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32comext/shell/src/shell.cpp,v retrieving revision 1.50 retrieving revision 1.51 diff -C2 -d -r1.50 -r1.51 *** shell.cpp 12 Feb 2007 07:38:57 -0000 1.50 --- shell.cpp 15 Feb 2007 13:11:02 -0000 1.51 *************** *** 14,17 **** --- 14,18 ---- #include "shell_pch.h" + #include "EmptyVC.h" #include "PyIShellLink.h" #include "PyIContextMenu.h" *************** *** 19,22 **** --- 20,25 ---- #include "PyIShellExtInit.h" #include "PyIShellFolder.h" + #include "PyIEmptyVolumeCache.h" + #include "PyIEmptyVolumeCacheCallBack.h" #include "PyIEnumIDList.h" #include "PyICopyHook.h" *************** *** 2318,2324 **** --- 2321,2330 ---- PYCOM_INTERFACE_FULL(ColumnProvider), PYCOM_INTERFACE_FULL(DropTargetHelper), + PYCOM_INTERFACE_CLIENT_ONLY(EmptyVolumeCacheCallBack), PYCOM_INTERFACE_CLIENT_ONLY(QueryAssociations), PYCOM_INTERFACE_SERVER_ONLY(DeskBand), PYCOM_INTERFACE_SERVER_ONLY(DockingWindow), + PYCOM_INTERFACE_SERVER_ONLY(EmptyVolumeCache), + PYCOM_INTERFACE_SERVER_ONLY(EmptyVolumeCache2), // IID_ICopyHook doesn't exist - hack it up { &IID_IShellCopyHook, "IShellCopyHook", "IID_IShellCopyHook", &PyICopyHook::type, GET_PYGATEWAY_CTOR(PyGCopyHook) }, --- NEW FILE: PyIEmptyVolumeCache.cpp --- // This file implements the IEmptyVolumeCache Gateway for Python. #include "shell_pch.h" #include "EmptyVC.h" #include "PyIEmptyVolumeCache.h" // @doc - This file contains autoduck documentation // @object PyIEmptyVolumeCache|Used for cleaning up temporary file ("disk cleanup") // @comm This is a "gateway" object only - you can only implement this // interface - see the shell/demos/server/empty_volume_cache.py. The methods // described here are the methods you must implement - you can't call them. // <nl>Please contribute to these docs! // @pymeth PyIEmptyVolumeCache|Initialize // @pymeth PyIEmptyVolumeCache|GetSpaceUsed // @pymeth PyIEmptyVolumeCache|Purge // @pymeth PyIEmptyVolumeCache|ShowProperties // @pymeth PyIEmptyVolumeCache2|InitializeEx // // --------------------------------------------------- // // Gateway Implementation // @pymethod |PyIEmptyVolumeCache|Initialize| STDMETHODIMP PyGEmptyVolumeCache::Initialize( /* [in] */ HKEY hkRegKey, /* [in] */ LPCWSTR pcwszVolume, /* [out] */ LPWSTR * ppwszDisplayName, /* [out] */ LPWSTR * ppwszDescription, /* [out] */ DWORD * pdwFlags) { PY_GATEWAY_METHOD; HRESULT hr; BOOL bPythonIsHappy = TRUE; ULONG dwFlags; PyObject *result; PyObject *obppwszDisplayName; PyObject *obppwszDescription; PyObject *obpcwszVolume = NULL; PyObject *obhkRegKey = PyWinObject_FromHKEY(hkRegKey); if (obhkRegKey==NULL) goto args_failed; if (!(obpcwszVolume = MakeOLECHARToObj(pcwszVolume))) goto args_failed; hr=InvokeViaPolicy("Initialize", &result, "NNk", obhkRegKey, obpcwszVolume, *pdwFlags); if (FAILED(hr)) return hr; // Process the Python results, and convert back to the real params if (!PyTuple_Check(result)) { PyErr_Format(PyExc_TypeError, "Initialize must return a tuple of (unicode, unicode, long) - got '%s'", result->ob_type->tp_name); bPythonIsHappy = FALSE; } if (bPythonIsHappy && !PyArg_ParseTuple(result, "OOl" , &obppwszDisplayName, &obppwszDescription, &dwFlags)) bPythonIsHappy = FALSE; if (bPythonIsHappy && !PyWinObject_AsWCHAR(obppwszDisplayName, ppwszDisplayName)) bPythonIsHappy = FALSE; if (bPythonIsHappy && !PyWinObject_AsWCHAR(obppwszDescription, ppwszDescription)) bPythonIsHappy = FALSE; if (!bPythonIsHappy) hr = PyCom_SetAndLogCOMErrorFromPyException("Initialize", IID_IEmptyVolumeCache); if (pdwFlags) *pdwFlags = dwFlags; Py_DECREF(result); return hr; args_failed: // only hit on error convering input args, not normal exit. Py_XDECREF(obhkRegKey); Py_XDECREF(obpcwszVolume); return MAKE_PYCOM_GATEWAY_FAILURE_CODE("Initialize"); } // @pymethod |PyIEmptyVolumeCache|GetSpaceUsed| STDMETHODIMP PyGEmptyVolumeCache::GetSpaceUsed( /* [out] */ DWORDLONG * pdwlSpaceUsed, /* [in] */ IEmptyVolumeCacheCallBack * picb) { PY_GATEWAY_METHOD; PyObject *obpicb; obpicb = PyCom_PyObjectFromIUnknown(picb, IID_IEmptyVolumeCacheCallBack, TRUE); if (!obpicb) return MAKE_PYCOM_GATEWAY_FAILURE_CODE("GetSpaceUsed"); PyObject *result; HRESULT hr=InvokeViaPolicy("GetSpaceUsed", &result, "O", obpicb); Py_XDECREF(obpicb); if (FAILED(hr)) return hr; // Process the Python results, and convert back to the real params if (!PyWinObject_AsUPY_LONG_LONG(result, pdwlSpaceUsed)) { PyErr_Format(PyExc_TypeError, "GetSpaceUsed must return a long - got '%s'", result->ob_type->tp_name); hr = PyCom_SetAndLogCOMErrorFromPyException("GetSpaceUsed", IID_IEmptyVolumeCache); } Py_DECREF(result); return hr; } // @pymethod |PyIEmptyVolumeCache|Purge| STDMETHODIMP PyGEmptyVolumeCache::Purge( /* [in] */ DWORDLONG dwlSpaceToFree, /* [in] */ IEmptyVolumeCacheCallBack * picb) { PY_GATEWAY_METHOD; PyObject *obdwlSpaceToFree = PyLong_FromUnsignedLongLong(dwlSpaceToFree); if (obdwlSpaceToFree==NULL) return MAKE_PYCOM_GATEWAY_FAILURE_CODE("Purge"); PyObject *obpicb; obpicb = PyCom_PyObjectFromIUnknown(picb, IID_IEmptyVolumeCacheCallBack, TRUE); if (!obpicb) { Py_DECREF(obdwlSpaceToFree); return MAKE_PYCOM_GATEWAY_FAILURE_CODE("Purge"); } return InvokeViaPolicy("Purge", NULL, "NN", obdwlSpaceToFree, obpicb); } // @pymethod |PyIEmptyVolumeCache|ShowProperties| STDMETHODIMP PyGEmptyVolumeCache::ShowProperties( /* [in] */ HWND hwnd) { PY_GATEWAY_METHOD; return InvokeViaPolicy("ShowProperties", NULL, "N", PyWinLong_FromHANDLE(hwnd)); } // @pymethod |PyIEmptyVolumeCache|Deactivate| STDMETHODIMP PyGEmptyVolumeCache::Deactivate( /* [out] */ DWORD * pdwFlags) { PY_GATEWAY_METHOD; PyObject *result; HRESULT hr=InvokeViaPolicy("Deactivate", &result); if (FAILED(hr)) return hr; // Process the Python results, and convert back to the real params BOOL bPythonIsHappy = TRUE; if (!PyWinObject_AsUPY_LONG_LONG(result, pdwFlags)) { PyErr_Format(PyExc_TypeError, "Deactivate must return a long - got '%s'", result->ob_type->tp_name); hr = PyCom_SetAndLogCOMErrorFromPyException("Deactivate", IID_IEmptyVolumeCache); } Py_DECREF(result); return hr; } // IEmptyVolumeCache2 // @object PyIEmptyVolumeCache2|See also <o PyIEmptyVolumeCache> // @pymeth PyIEmptyVolumeCache|Deactivate // @pymethod |PyIEmptyVolumeCache2|InitializeEx| STDMETHODIMP PyGEmptyVolumeCache2::InitializeEx( /* [in] */ HKEY hkRegKey, /* [in] */ LPCWSTR pcwszVolume, /* [in] */ LPCWSTR pcwszKeyName, /* [out] */ LPWSTR * ppwszDisplayName, /* [out] */ LPWSTR * ppwszDescription, /* [out] */ LPWSTR * ppwszBtnText, /* [out] */ DWORD * pdwFlags) { PY_GATEWAY_METHOD; BOOL bPythonIsHappy = TRUE; ULONG dwFlags; HRESULT hr; PyObject *result; PyObject *obppwszDisplayName; PyObject *obppwszDescription; PyObject *obppwszBtnText; PyObject *obpcwszVolume = NULL; PyObject *obpcwszKeyName = NULL; PyObject *obhkRegKey = PyWinObject_FromHKEY(hkRegKey); if (!obhkRegKey) goto args_failed; if (!(obpcwszVolume = MakeOLECHARToObj(pcwszVolume))) goto args_failed; if (!(obpcwszKeyName = MakeOLECHARToObj(pcwszKeyName))) goto args_failed; hr=InvokeViaPolicy("InitializeEx", &result, "NNNk", obhkRegKey, obpcwszVolume, obpcwszKeyName, *pdwFlags); // NOTE: From here, do *not* exit via args_failed - the args have been cleaned up if (FAILED(hr)) return hr; // Process the Python results, and convert back to the real params if (!PyTuple_Check(result)) { PyErr_Format(PyExc_TypeError, "Initialize must return a tuple of (unicode, unicode, unicode, long) - got '%s'", result->ob_type->tp_name); bPythonIsHappy = FALSE; } if (bPythonIsHappy && !PyArg_ParseTuple(result, "OOOl" , &obppwszDisplayName, &obppwszDescription, &obppwszBtnText, &dwFlags)) bPythonIsHappy = FALSE; if (bPythonIsHappy && !PyWinObject_AsWCHAR(obppwszDisplayName, ppwszDisplayName)) bPythonIsHappy = FALSE; if (bPythonIsHappy && !PyWinObject_AsWCHAR(obppwszDescription, ppwszDescription)) bPythonIsHappy = FALSE; if (bPythonIsHappy && !PyWinObject_AsWCHAR(obppwszBtnText, ppwszBtnText)) bPythonIsHappy = FALSE; if (!bPythonIsHappy) hr = PyCom_SetAndLogCOMErrorFromPyException("InitializeEx", IID_IEmptyVolumeCache); if (pdwFlags) *pdwFlags = dwFlags; Py_DECREF(result); return hr; args_failed: // only hit on error convering input args, not normal exit. Py_XDECREF(obhkRegKey); Py_XDECREF(obpcwszVolume); Py_XDECREF(obpcwszKeyName); return MAKE_PYCOM_GATEWAY_FAILURE_CODE("InitializeEx"); } |
From: Mark H. <mha...@us...> - 2007-02-15 13:11:04
|
Update of /cvsroot/pywin32/pywin32/com/win32comext/shell/demos/servers In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31039/com/win32comext/shell/demos/servers Added Files: empty_volume_cache.py Log Message: Support for IEmptyVolumeCache, IEmptyVolumeCache2 and IEmptyVolumeCacheCallBack contributed by Sidnei da Silva from Enfold. --- NEW FILE: empty_volume_cache.py --- # A sample implementation of IEmptyVolumeCache - see # http://msdn2.microsoft.com/en-us/library/aa969271.aspx for an overview. # # * Execute this script to register the handler # * Start the "disk cleanup" tool - look for "pywin32 compiled files" import sys, os, stat, time import pythoncom from win32com.shell import shell, shellcon from win32com.server.exception import COMException import win32gui import win32con import winerror # Our shell extension. IEmptyVolumeCache_Methods = "Initialize GetSpaceUsed Purge ShowProperties Deactivate".split() IEmptyVolumeCache2_Methods = "InitializeEx".split() ico = os.path.join(sys.prefix, "py.ico") if not os.path.isfile(ico): ico = os.path.join(sys.prefix, "PC", "py.ico") if not os.path.isfile(ico): ico = None print "Can't find python.ico - no icon will be installed" class EmptyVolumeCache: _reg_progid_ = "Python.ShellExtension.EmptyVolumeCache" _reg_desc_ = "Python Sample Shell Extension (disk cleanup)" _reg_clsid_ = "{EADD0777-2968-4c72-A999-2BF5F756259C}" _reg_icon_ = ico _com_interfaces_ = [shell.IID_IEmptyVolumeCache, shell.IID_IEmptyVolumeCache2] _public_methods_ = IEmptyVolumeCache_Methods + IEmptyVolumeCache2_Methods def Initialize(self, hkey, volume, flags): # This should never be called, except on win98. print "Unless we are on 98, Initialize call is unexpected!" raise COMException(hresult=winerror.E_NOTIMPL) def InitializeEx(self, hkey, volume, key_name, flags): # Must return a tuple of: # (display_name, description, button_name, flags) print "InitializeEx called with", hkey, volume, key_name, flags self.volume = volume if flags & shellcon.EVCF_SETTINGSMODE: print "We are being run on a schedule" # In this case, "because there is no opportunity for user # feedback, only those files that are extremely safe to clean up # should be touched. You should ignore the initialization # method's pcwszVolume parameter and clean unneeded files # regardless of what drive they are on." self.volume = None # flag as 'any disk will do' elif flags & shellcon.EVCF_OUTOFDISKSPACE: # In this case, "the handler should be aggressive about deleting # files, even if it results in a performance loss. However, the # handler obviously should not delete files that would cause an # application to fail or the user to lose data." print "We are being run as we are out of disk-space" else: # This case is not documented - we are guessing :) print "We are being run because the user asked" # For the sake of demo etc, we tell the shell to only show us when # there are > 0 bytes available. Our GetSpaceUsed will check the # volume, so will return 0 when we are on a different disk flags = shellcon.EVCF_DONTSHOWIFZERO | shellcon.EVCF_ENABLEBYDEFAULT return ("pywin32 compiled files", "Removes all .pyc and .pyo files in the pywin32 directories", "click me!", flags ) def _GetDirectories(self): root_dir = os.path.abspath(os.path.dirname(os.path.dirname(win32gui.__file__))) if self.volume is not None and \ not root_dir.lower().startswith(self.volume.lower()): return [] return [os.path.join(root_dir, p) for p in ('win32', 'win32com', 'win32comext', 'isapi')] def _WalkCallback(self, arg, directory, files): # callback function for os.path.walk - no need to be member, but its # close to the callers :) callback, total_list = arg for file in files: fqn = os.path.join(directory, file).lower() if file.endswith(".pyc") or file.endswith(".pyo"): # See below - total_list == None means delete files, # otherwise it is a list where the result is stored. Its a # list simply due to the way os.walk works - only [0] is # referenced if total_list is None: print "Deleting file", fqn # Should do callback.PurgeProcess - left as an exercise :) os.remove(fqn) else: total_list[0] += os.stat(fqn)[stat.ST_SIZE] # and callback to the tool if callback: # for the sake of seeing the progress bar do its thing, # we take longer than we need to... # ACK - for some bizarre reason this screws up the XP # cleanup manager - clues welcome!! :) ## print "Looking in", directory, ", but waiting a while..." ## time.sleep(3) # now do it used = total_list[0] callback.ScanProgress(used, 0, "Looking at " + fqn) def GetSpaceUsed(self, callback): total = [0] # See _WalkCallback above try: for d in self._GetDirectories(): os.path.walk(d, self._WalkCallback, (callback, total)) print "After looking in", d, "we have", total[0], "bytes" except pythoncom.error, (hr, msg, exc, arg): # This will be raised by the callback when the user selects 'cancel'. if hr != winerror.E_ABORT: raise # that's the documented error code! print "User cancelled the operation" return total[0] def Purge(self, amt_to_free, callback): print "Purging", amt_to_free, "bytes..." # we ignore amt_to_free - it is generally what we returned for # GetSpaceUsed try: for d in self._GetDirectories(): os.path.walk(d, self._WalkCallback, (callback, None)) except pythoncom.error, (hr, msg, exc, arg): # This will be raised by the callback when the user selects 'cancel'. if hr != winerror.E_ABORT: raise # that's the documented error code! print "User cancelled the operation" def ShowProperties(self, hwnd): raise COMException(hresult=winerror.E_NOTIMPL) def Deactivate(self): print "Deactivate called" return 0 def DllRegisterServer(): # Also need to register specially in: # HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches # See link at top of file. import _winreg kn = r"Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\%s" \ % (EmptyVolumeCache._reg_desc_,) key = _winreg.CreateKey(_winreg.HKEY_LOCAL_MACHINE, kn) _winreg.SetValueEx(key, None, 0, _winreg.REG_SZ, EmptyVolumeCache._reg_clsid_) def DllUnregisterServer(): import _winreg kn = r"Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\%s" \ % (EmptyVolumeCache._reg_desc_,) try: key = _winreg.DeleteKey(_winreg.HKEY_LOCAL_MACHINE, kn) except WindowsError, details: import errno if details.errno != errno.ENOENT: raise print EmptyVolumeCache._reg_desc_, "unregistration complete." if __name__=='__main__': from win32com.server import register register.UseCommandLine(EmptyVolumeCache, finalize_register = DllRegisterServer, finalize_unregister = DllUnregisterServer) |
From: Mark H. <mha...@us...> - 2007-02-15 13:07:53
|
Update of /cvsroot/pywin32/pywin32 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30291 Modified Files: setup.py Log Message: Create a .pch in release builds (but don't attempt to distribute them!) Index: setup.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/setup.py,v retrieving revision 1.54 retrieving revision 1.55 diff -C2 -d -r1.54 -r1.55 *** setup.py 3 Feb 2007 21:11:13 -0000 1.54 --- setup.py 15 Feb 2007 13:07:48 -0000 1.55 *************** *** 688,698 **** ext.extra_compile_args.append("/Fp"+pch_name) - # Put our DLL base address in. - if not self.mingw32: - base = ext.base_address - if not base: - base = dll_base_addresses[ext.name] - ext.extra_link_args.append("/BASE:0x%x" % (base,)) - # some source files are compiled for different extensions # with special defines. So we cannot use a shared --- 688,691 ---- *************** *** 702,705 **** --- 695,722 ---- # 2.3+ - Wrong dir, numbered name self.build_temp = os.path.join(self.build_temp, ext.name) + + if not self.mingw32: + # Put our DLL base address in. + base = ext.base_address + if not base: + base = dll_base_addresses[ext.name] + ext.extra_link_args.append("/BASE:0x%x" % (base,)) + + # like Python, always use debug info, even in release builds + # (note the compiler doesn't include debug info, so you only get + # basic info - but its better than nothing!) + # For now use the temp dir - later we may package them, so should + # maybe move them next to the output file. + # ack - but fails with obscure errors in py23 :( + if sys.version_info > (2,4): + pch_dir = os.path.join(self.build_temp) + if not self.debug: + ext.extra_compile_args.append("/Zi") + ext.extra_compile_args.append("/Fd%s\%s_vc.pdb" % + (pch_dir, ext.name)) + ext.extra_link_args.append("/DEBUG") + ext.extra_link_args.append("/PDB:%s\%s.pdb" % + (pch_dir, ext.name)) + self.swig_cpp = True try: |
From: Mark H. <mha...@us...> - 2007-02-15 13:02:07
|
Update of /cvsroot/pywin32/pywin32/com/win32comext/shell/demos In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27641/demos Added Files: dump_link.py Log Message: An old test file I had hanging around... --- NEW FILE: dump_link.py --- # dump_link.py - dumps information about shell shortcuts # import sys, os from win32com.shell import shell, shellcon import pythoncom import glob from win32com.storagecon import * def DumpLink(fname): shellLink = pythoncom.CoCreateInstance(shell.CLSID_ShellLink, None, pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink) persistFile = shellLink.QueryInterface(pythoncom.IID_IPersistFile) persistFile.Load(fname,STGM_READ) shellLink.Resolve(0, shell.SLR_ANY_MATCH | shell.SLR_NO_UI) fname, findData = shellLink.GetPath(0) print "Filename", fname, ", UNC=", shellLink.GetPath(shell.SLGP_UNCPRIORITY)[0] def FavDumper(nothing, path, names): # called by os.path.walk for name in names: print name, try: DumpLink(name) except pythoncom.com_error: print " - not a link" def DumpFavorites(): favfold = str(shell.SHGetSpecialFolderPath(0, shellcon.CSIDL_FAVORITES)) print "Your favourites are at", favfold os.path.walk(favfold, FavDumper, None) if __name__=='__main__': if len(sys.argv)>1: for fspec in sys.argv[1:]: files = glob.glob(fspec) if files: for file in files: print file DumpLink(file) print else: print "Can not find", fspec else: print "Dumping your favorites folder!" DumpFavorites() |
From: Roger U. <ru...@us...> - 2007-02-12 07:38:59
|
Update of /cvsroot/pywin32/pywin32/com/win32comext/shell/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1828/com/win32comext/shell/src Modified Files: shell.cpp Log Message: Various compatiblility issues Index: shell.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32comext/shell/src/shell.cpp,v retrieving revision 1.49 retrieving revision 1.50 diff -C2 -d -r1.49 -r1.50 *** shell.cpp 22 Sep 2006 05:05:51 -0000 1.49 --- shell.cpp 12 Feb 2007 07:38:57 -0000 1.50 *************** *** 460,464 **** // @tupleitem 0|int|Mask|Combination of shellcon.CMIC_MASK_* constants, can be 0 // @tupleitem 1|<o PyHANDLE>|hwnd|Window that owns the shortcut menu ! // @tupleitem 2|int or str|Vert|Action to be carried out, specified as a string command or integer menu item id // @tupleitem 3|str|Parameters|Extra parameters to be passed to the command line for the action, can be None // @tupleitem 4|str|Directory|Working directory, can be None --- 460,464 ---- // @tupleitem 0|int|Mask|Combination of shellcon.CMIC_MASK_* constants, can be 0 // @tupleitem 1|<o PyHANDLE>|hwnd|Window that owns the shortcut menu ! // @tupleitem 2|int or str|Verb|Action to be carried out, specified as a string command or integer menu item id // @tupleitem 3|str|Parameters|Extra parameters to be passed to the command line for the action, can be None // @tupleitem 4|str|Directory|Working directory, can be None *************** *** 468,478 **** BOOL PyObject_AsCMINVOKECOMMANDINFO(PyObject *ob, CMINVOKECOMMANDINFO *pci) { ! PyObject *obVerb; ZeroMemory(pci, sizeof(CMINVOKECOMMANDINFO)); pci->cbSize=sizeof(CMINVOKECOMMANDINFO); ! if (!PyArg_ParseTuple(ob, "iiOzziii:CMINVOKECOMMANDINFO tuple", &pci->fMask, &pci->hwnd, &obVerb, &pci->lpParameters, &pci->lpDirectory, ! &pci->nShow, &pci->dwHotKey, &pci->hIcon)) return FALSE; if (PyString_Check(obVerb)) { pci->lpVerb = PyString_AsString(obVerb); --- 468,482 ---- BOOL PyObject_AsCMINVOKECOMMANDINFO(PyObject *ob, CMINVOKECOMMANDINFO *pci) { ! PyObject *obVerb, *obhwnd, *obhIcon; ZeroMemory(pci, sizeof(CMINVOKECOMMANDINFO)); pci->cbSize=sizeof(CMINVOKECOMMANDINFO); ! if (!PyArg_ParseTuple(ob, "iOOzziiO:CMINVOKECOMMANDINFO tuple", &pci->fMask, &obhwnd, &obVerb, &pci->lpParameters, &pci->lpDirectory, ! &pci->nShow, &pci->dwHotKey, &obhIcon)) return FALSE; + if (!PyWinObject_AsHANDLE(obhwnd, (HANDLE *)&pci->hwnd, FALSE)) + return NULL; + if (!PyWinObject_AsHANDLE(obhIcon, (HANDLE *)&pci->hIcon, TRUE)) + return NULL; if (PyString_Check(obVerb)) { pci->lpVerb = PyString_AsString(obVerb); *************** *** 516,522 **** return NULL; } ! return Py_BuildValue("iiNNNiii", pci->fMask, pci->hwnd, obVerb, obParams, obDir, ! pci->nShow, pci->dwHotKey, pci->hIcon); } --- 520,526 ---- return NULL; } ! return Py_BuildValue("iNNNNiiN", pci->fMask, PyWinLong_FromHANDLE(pci->hwnd), obVerb, obParams, obDir, ! pci->nShow, pci->dwHotKey, PyWinLong_FromHANDLE(pci->hIcon)); } *************** *** 576,581 **** BOOL PyObject_AsMSG( PyObject *obpmsg, MSG *msg ) { ! return PyArg_ParseTuple(obpmsg, "iiiii(ii)", &msg->hwnd,&msg->message,&msg->wParam,&msg->lParam,&msg->time,&msg->pt.x,&msg->pt.y); } PyObject *PyObject_FromMSG(const MSG *msg) { --- 580,588 ---- BOOL PyObject_AsMSG( PyObject *obpmsg, MSG *msg ) { ! PyObject *obhwnd; ! return PyArg_ParseTuple(obpmsg, "Oiiii(ii)", &obhwnd,&msg->message,&msg->wParam,&msg->lParam,&msg->time,&msg->pt.x,&msg->pt.y) ! && PyWinObject_AsHANDLE(obhwnd, (HANDLE *)&msg->hwnd, FALSE); } + PyObject *PyObject_FromMSG(const MSG *msg) { *************** *** 584,588 **** return Py_None; } ! return Py_BuildValue("iiiii(ii)", msg->hwnd,msg->message,msg->wParam,msg->lParam,msg->time,msg->pt.x,msg->pt.y); } --- 591,595 ---- return Py_None; } ! return Py_BuildValue("Niiii(ii)", PyWinLong_FromHANDLE(msg->hwnd),msg->message,msg->wParam,msg->lParam,msg->time,msg->pt.x,msg->pt.y); } *************** *** 753,757 **** } ! BOOL PyObject_AsOLEMENUGROUPWIDTHS( PyObject *oblpMenuWidths, OLEMENUGROUPWIDTHS *pWidths) { --- 760,764 ---- } ! // @object PyLPOLEMENUGROUPWIDTHS|Tuple containing 6 ints indicating nbr of options in each menu group BOOL PyObject_AsOLEMENUGROUPWIDTHS( PyObject *oblpMenuWidths, OLEMENUGROUPWIDTHS *pWidths) { *************** *** 814,821 **** BOOL PyObject_AsSHFILEOPSTRUCT(PyObject *ob, SHFILEOPSTRUCT *p) { ! PyObject *obFrom, *obTo, *obNameMappings = Py_None, *obProgressTitle = Py_None; memset(p, 0, sizeof(*p)); ! if (!PyArg_ParseTuple(ob, "iiOO|iOO", ! &p->hwnd, // @tupleitem 0|int|hwnd|Handle of window in which to display status messages &p->wFunc, // @tupleitem 1|int|wFunc|One of the shellcon.FO_* values &obFrom, // @tupleitem 2|str/unicode|From|String containing source file name(s) separated by nulls --- 821,828 ---- BOOL PyObject_AsSHFILEOPSTRUCT(PyObject *ob, SHFILEOPSTRUCT *p) { ! PyObject *obFrom, *obTo, *obNameMappings = Py_None, *obProgressTitle = Py_None, *obhwnd; memset(p, 0, sizeof(*p)); ! if (!PyArg_ParseTuple(ob, "OiOO|iOO", ! &obhwnd, // @tupleitem 0|int|hwnd|Handle of window in which to display status messages &p->wFunc, // @tupleitem 1|int|wFunc|One of the shellcon.FO_* values &obFrom, // @tupleitem 2|str/unicode|From|String containing source file name(s) separated by nulls *************** *** 825,829 **** &obProgressTitle)) // @tupleitem 6|string|ProgressTitle|Title for progress dialog (flags must contain FOF_SIMPLEPROGRESS). Default=None return FALSE; ! if (obNameMappings != Py_None) { PyErr_SetString(PyExc_TypeError, "The NameMappings value must be None"); --- 832,837 ---- &obProgressTitle)) // @tupleitem 6|string|ProgressTitle|Title for progress dialog (flags must contain FOF_SIMPLEPROGRESS). Default=None return FALSE; ! if (!PyWinObject_AsHANDLE(obhwnd, (HANDLE *)&p->hwnd, TRUE)) ! return NULL; if (obNameMappings != Py_None) { PyErr_SetString(PyExc_TypeError, "The NameMappings value must be None"); *************** *** 870,874 **** } assert(!PyErr_Occurred()); ! args = Py_BuildValue("lilO", hwnd, uMsg, lParam, pc->data); if (!args) goto done; result = PyEval_CallObject(pc->fn, args); --- 878,882 ---- } assert(!PyErr_Occurred()); ! args = Py_BuildValue("NilO", PyWinLong_FromHANDLE(hwnd), uMsg, lParam, pc->data); if (!args) goto done; result = PyEval_CallObject(pc->fn, args); *************** *** 899,902 **** --- 907,911 ---- memset(&bi, 0, sizeof(BROWSEINFO)); PyObject *rc = NULL; + PyObject *obhwndOwner=Py_None; PyObject *obPIDL = Py_None; PyObject *obTitle = Py_None; *************** *** 910,922 **** #endif ! if(!PyArg_ParseTuple(args, "|lOOlOO:SHBrowseForFolder", ! &bi.hwndOwner, // @pyparm int|hwndOwner|0| ! &obPIDL, // @pyparm <o PyIDL>|pidlRoot|None| ! &obTitle, // @pyparm <o Unicode>/string|title|None| ! &bi.ulFlags, // @pyparm int|flags|0| &obcb, // @pyparm object|callback|None|A callable object to be used as the callback, or None &obcbparam)) // @pyparm object|callback_data|None|An object passed to the callback function return NULL; ! if (obcb != Py_None) { #if (PY_VERSION_HEX >= 0x02030000) // PyGILState only in 2.3+ --- 919,932 ---- #endif ! if(!PyArg_ParseTuple(args, "|OOOlOO:SHBrowseForFolder", ! &obhwndOwner, // @pyparm <o PyHANDLE>|hwndOwner|None|Parent window for the dialog box, can be None ! &obPIDL, // @pyparm <o PyIDL>|pidlRoot|None|PIDL identifying the place to start browsing. Desktop is used if not specified ! &obTitle, // @pyparm <o Unicode>/string|title|None|Title to be displayed with the directory tree ! &bi.ulFlags, // @pyparm int|flags|0|Combination of shellcon.BIF_* flags &obcb, // @pyparm object|callback|None|A callable object to be used as the callback, or None &obcbparam)) // @pyparm object|callback_data|None|An object passed to the callback function return NULL; ! if (!PyWinObject_AsHANDLE(obhwndOwner, (HANDLE *)&bi.hwndOwner, TRUE)) ! return NULL; if (obcb != Py_None) { #if (PY_VERSION_HEX >= 0x02030000) // PyGILState only in 2.3+ *************** *** 1028,1039 **** { HWND hwndOwner; int nFolder; BOOL bCreate = FALSE; ! if(!PyArg_ParseTuple(args, "li|i:SHGetSpecialFolderPath", ! &hwndOwner, // @pyparm int|hwndOwner|| &nFolder, // @pyparm int|nFolder||One of the CSIDL_* constants specifying the path. &bCreate)) // @pyparm int|bCreate|0|Should the path be created. return NULL; ! // @comm This method is only available in shell version 4.71. If the // function is not available, a COM Exception with HRESULT=E_NOTIMPL --- 1038,1051 ---- { HWND hwndOwner; + PyObject *obhwndOwner; int nFolder; BOOL bCreate = FALSE; ! if(!PyArg_ParseTuple(args, "Oi|i:SHGetSpecialFolderPath", ! &obhwndOwner, // @pyparm <o PyHANDLE>|hwndOwner||Parent window, can be None (or 0) &nFolder, // @pyparm int|nFolder||One of the CSIDL_* constants specifying the path. &bCreate)) // @pyparm int|bCreate|0|Should the path be created. return NULL; ! if (!PyWinObject_AsHANDLE(obhwndOwner, (HANDLE *)&hwndOwner, TRUE)) ! return NULL; // @comm This method is only available in shell version 4.71. If the // function is not available, a COM Exception with HRESULT=E_NOTIMPL *************** *** 1056,1065 **** { HWND hwndOwner; int nFolder; ! if(!PyArg_ParseTuple(args, "li|i:SHGetSpecialFolderLocation", ! &hwndOwner, // @pyparm int|hwndOwner|| &nFolder)) // @pyparm int|nFolder||One of the CSIDL_* constants specifying the path. return NULL; ! LPITEMIDLIST pidl; PY_INTERFACE_PRECALL; --- 1068,1079 ---- { HWND hwndOwner; + PyObject *obhwndOwner; int nFolder; ! if(!PyArg_ParseTuple(args, "Oi:SHGetSpecialFolderLocation", ! &obhwndOwner, // @pyparm <o PyHANDLE>|hwndOwner||Parent window, can be None (or 0) &nFolder)) // @pyparm int|nFolder||One of the CSIDL_* constants specifying the path. return NULL; ! if (!PyWinObject_AsHANDLE(obhwndOwner, (HANDLE *)&hwndOwner, TRUE)) ! return NULL; LPITEMIDLIST pidl; PY_INTERFACE_PRECALL; *************** *** 1113,1119 **** info.dwAttributes = info_attrs; PY_INTERFACE_PRECALL; ! DWORD dw = SHGetFileInfo(name, attr, &info, sizeof(info), flags); PY_INTERFACE_POSTCALL; ! ret = Py_BuildValue("iN", dw, PyObject_FromSHFILEINFO(&info)); if (name) PyWinObject_FreeTCHAR(name); if (pidl) PyObject_FreePIDL(pidl); --- 1127,1133 ---- info.dwAttributes = info_attrs; PY_INTERFACE_PRECALL; ! DWORD_PTR dw = SHGetFileInfo(name, attr, &info, sizeof(info), flags); PY_INTERFACE_POSTCALL; ! ret = Py_BuildValue("NN", PyLong_FromUnsignedLongLong(dw), PyObject_FromSHFILEINFO(&info)); if (name) PyWinObject_FreeTCHAR(name); if (pidl) PyObject_FreePIDL(pidl); *************** *** 1125,1139 **** { HWND hwndOwner; int nFolder; long flags; PyObject *obHandle; BOOL bCreate = FALSE; ! if(!PyArg_ParseTuple(args, "liOl:SHGetFolderPath", ! &hwndOwner, // @pyparm int|hwndOwner|| &nFolder, // @pyparm int|nFolder||One of the CSIDL_* constants specifying the path. &obHandle, // @pyparm <o PyHANDLE>|handle||An access token that can be used to represent a particular user, or None &flags)) // @pyparm int|flags||Controls which path is returned. May be SHGFP_TYPE_CURRENT or SHGFP_TYPE_DEFAULT return NULL; ! HANDLE handle; if (!PyWinObject_AsHANDLE(obHandle, &handle, TRUE)) --- 1139,1155 ---- { HWND hwndOwner; + PyObject *obhwndOwner; int nFolder; long flags; PyObject *obHandle; BOOL bCreate = FALSE; ! if(!PyArg_ParseTuple(args, "OiOl:SHGetFolderPath", ! &obhwndOwner, // @pyparm <o PyHANDLE>|hwndOwner||Parent window, can be None (or 0) &nFolder, // @pyparm int|nFolder||One of the CSIDL_* constants specifying the path. &obHandle, // @pyparm <o PyHANDLE>|handle||An access token that can be used to represent a particular user, or None &flags)) // @pyparm int|flags||Controls which path is returned. May be SHGFP_TYPE_CURRENT or SHGFP_TYPE_DEFAULT return NULL; ! if (!PyWinObject_AsHANDLE(obhwndOwner, (HANDLE *)&hwndOwner, TRUE)) ! return NULL; HANDLE handle; if (!PyWinObject_AsHANDLE(obHandle, &handle, TRUE)) *************** *** 1194,1205 **** int nFolder; DWORD flags = 0; ! PyObject *obToken=Py_None; ! if(!PyArg_ParseTuple(args, "li|Ol:SHGetFolderLocation", ! &hwndOwner, // @pyparm int|hwndOwner||Window in which to display any neccessary dialogs &nFolder, // @pyparm int|nFolder||One of the CSIDL_* constants specifying the path. &obToken, // @pyparm <o PyHANDLE>|hToken|None|An access token that can be used to represent a particular user, or None &flags)) // @pyparm int|reserved|0|Must be 0 return NULL; if (!PyWinObject_AsHANDLE(obToken, &hToken, TRUE)) return NULL; --- 1210,1223 ---- int nFolder; DWORD flags = 0; ! PyObject *obToken=Py_None, *obhwndOwner; ! if(!PyArg_ParseTuple(args, "Oi|Ol:SHGetFolderLocation", ! &obhwndOwner, // @pyparm int|hwndOwner||Window in which to display any neccessary dialogs &nFolder, // @pyparm int|nFolder||One of the CSIDL_* constants specifying the path. &obToken, // @pyparm <o PyHANDLE>|hToken|None|An access token that can be used to represent a particular user, or None &flags)) // @pyparm int|reserved|0|Must be 0 return NULL; + if (!PyWinObject_AsHANDLE(obhwndOwner, (HANDLE *)&hwndOwner, TRUE)) + return NULL; if (!PyWinObject_AsHANDLE(obToken, &hToken, TRUE)) return NULL; *************** *** 1241,1252 **** { HWND hwnd; char *path; DWORD flags; ! if(!PyArg_ParseTuple(args, "lzl:SHEmptyRecycleBin", ! &hwnd, // @pyparm int|hwnd|| &path, // @pyparm string|path||A NULL-terminated string that contains the path of the root drive on which the recycle bin is located. This parameter can contain the address of a string formatted with the drive, folder, and subfolder names (c:\windows\system . . .). It can also contain an empty string or NULL. If this value is an empty string or NULL, all recycle bins on all drives will be emptied. &flags)) // @pyparm int|flags||One of the SHERB_* values. return NULL; ! // @comm This method is only available in shell version 4.71. If the function is not available, a COM Exception with HRESULT=E_NOTIMPL will be raised. if (pfnSHEmptyRecycleBin==NULL) --- 1259,1272 ---- { HWND hwnd; + PyObject *obhwnd; char *path; DWORD flags; ! if(!PyArg_ParseTuple(args, "Ozl:SHEmptyRecycleBin", ! &obhwnd, // @pyparm <o PyHANDLE>|hwnd||Handle to parent window, can be None &path, // @pyparm string|path||A NULL-terminated string that contains the path of the root drive on which the recycle bin is located. This parameter can contain the address of a string formatted with the drive, folder, and subfolder names (c:\windows\system . . .). It can also contain an empty string or NULL. If this value is an empty string or NULL, all recycle bins on all drives will be emptied. &flags)) // @pyparm int|flags||One of the SHERB_* values. return NULL; ! if (!PyWinObject_AsHANDLE(obhwnd, (HANDLE *)&hwnd, TRUE)) ! return NULL; // @comm This method is only available in shell version 4.71. If the function is not available, a COM Exception with HRESULT=E_NOTIMPL will be raised. if (pfnSHEmptyRecycleBin==NULL) *************** *** 1481,1488 **** LONG events; UINT msg; ! PyObject *obPIDL; SHChangeNotifyEntry entry; ! if(!PyArg_ParseTuple(args, "iiii(Oi):SHChangeNotifyRegister", ! &hwnd, // @pyparm int|hwnd||Handle to the window that receives the change or notification messages. &sources, // @pyparm int|sources||One or more values that indicate the type of events for which to receive notifications. &events, // @pyparm int|events||Change notification events for which to receive notification. --- 1501,1508 ---- LONG events; UINT msg; ! PyObject *obPIDL, *obhwnd; SHChangeNotifyEntry entry; ! if(!PyArg_ParseTuple(args, "Oiii(Oi):SHChangeNotifyRegister", ! &obhwnd, // @pyparm <o PyHANDLE>|hwnd||Handle to the window that receives the change or notification messages. &sources, // @pyparm int|sources||One or more values that indicate the type of events for which to receive notifications. &events, // @pyparm int|events||Change notification events for which to receive notification. *************** *** 1491,1495 **** &entry.fRecursive)) return NULL; ! if (!PyObject_AsPIDL(obPIDL, (ITEMIDLIST **)&entry.pidl, TRUE)) return NULL; --- 1511,1516 ---- &entry.fRecursive)) return NULL; ! if (!PyWinObject_AsHANDLE(obhwnd, (HANDLE *)&hwnd, FALSE)) ! return NULL; if (!PyObject_AsPIDL(obPIDL, (ITEMIDLIST **)&entry.pidl, TRUE)) return NULL; *************** *** 1527,1540 **** } ! // @pymethod int/string|shell|DragQueryFile| static PyObject *PyDragQueryFile(PyObject *self, PyObject *args) { ! int iglobal; UINT index; ! if(!PyArg_ParseTuple(args, "ii:DragQueryFile", ! &iglobal, // @pyparm int|hglobal||The HGLOBAL object - generally obtained via the 'data_handle' property of a <o PySTGMEDIUM> object. &index)) // @pyparm int|index||The index to retrieve. If -1, the result if an integer representing the valid index values. return NULL; ! HDROP hglobal = (HDROP)iglobal; if (index==0xFFFFFFFF) { return PyInt_FromLong(DragQueryFile(hglobal, index, NULL, 0)); --- 1548,1563 ---- } ! // @pymethod int/string|shell|DragQueryFile|Retrieves the names (or count) of dropped files static PyObject *PyDragQueryFile(PyObject *self, PyObject *args) { ! HDROP hglobal; ! PyObject *obhglobal; UINT index; ! if(!PyArg_ParseTuple(args, "Oi:DragQueryFile", ! &obhglobal, // @pyparm <o PyHANDLE>|hglobal||The HGLOBAL object - generally obtained via the 'data_handle' property of a <o PySTGMEDIUM> object. &index)) // @pyparm int|index||The index to retrieve. If -1, the result if an integer representing the valid index values. return NULL; ! if (!PyWinObject_AsHANDLE(obhglobal, (HANDLE *)&hglobal, FALSE)) ! return NULL; if (index==0xFFFFFFFF) { return PyInt_FromLong(DragQueryFile(hglobal, index, NULL, 0)); *************** *** 1551,1564 **** } ! // @pymethod int/<o PyUnicode>|shell|DragQueryFileW| static PyObject *PyDragQueryFileW(PyObject *self, PyObject *args) { ! int iglobal; UINT index; ! if(!PyArg_ParseTuple(args, "ii:DragQueryFileW", ! &iglobal, // @pyparm int|hglobal||The HGLOBAL object - generally obtained via the 'data_handle' property of a <o PySTGMEDIUM> object. &index)) // @pyparm int|index||The index to retrieve. If -1, the result if an integer representing the valid index values. return NULL; ! HDROP hglobal = (HDROP)iglobal; if (index==0xFFFFFFFF) { return PyInt_FromLong(DragQueryFileW(hglobal, index, NULL, 0)); --- 1574,1589 ---- } ! // @pymethod int/<o PyUnicode>|shell|DragQueryFileW|Retrieves the names (or count) of dropped files static PyObject *PyDragQueryFileW(PyObject *self, PyObject *args) { ! HDROP hglobal; ! PyObject *obhglobal; UINT index; ! if(!PyArg_ParseTuple(args, "Oi:DragQueryFileW", ! &obhglobal, // @pyparm <o PyHANDLE>|hglobal||The HGLOBAL object - generally obtained via the 'data_handle' property of a <o PySTGMEDIUM> object. &index)) // @pyparm int|index||The index to retrieve. If -1, the result if an integer representing the valid index values. return NULL; ! if (!PyWinObject_AsHANDLE(obhglobal, (HANDLE *)&hglobal, FALSE)) ! return NULL; if (index==0xFFFFFFFF) { return PyInt_FromLong(DragQueryFileW(hglobal, index, NULL, 0)); *************** *** 1580,1588 **** static PyObject *PyDragQueryPoint(PyObject *self, PyObject *args) { ! int iglobal; ! if(!PyArg_ParseTuple(args, "i:DragQueryFile", ! &iglobal)) // @pyparm int|hglobal||The HGLOBAL object - generally obtained the 'data_handle' property of a <o PySTGMEDIUM> return NULL; - HDROP hglobal = (HDROP)iglobal; POINT pt; BOOL result = ::DragQueryPoint(hglobal, &pt); --- 1605,1615 ---- static PyObject *PyDragQueryPoint(PyObject *self, PyObject *args) { ! HDROP hglobal; ! PyObject *obhglobal; ! if(!PyArg_ParseTuple(args, "O:DragQueryFile", ! &obhglobal)) // @pyparm <o PyHANDLE>|hglobal||The HGLOBAL object - generally obtained the 'data_handle' property of a <o PySTGMEDIUM> ! return NULL; ! if (!PyWinObject_AsHANDLE(obhglobal, (HANDLE *)&hglobal, FALSE)) return NULL; POINT pt; BOOL result = ::DragQueryPoint(hglobal, &pt); *************** *** 1640,1648 **** static PyObject *PyAddressAsPIDL(PyObject *self, PyObject *args) { ! long lpidl; // @pyparm int|address||The address of the PIDL ! if (!PyArg_ParseTuple(args, "l:AddressAsPIDL", &lpidl)) return NULL; ! return PyObject_FromPIDL((LPCITEMIDLIST)lpidl, FALSE); } --- 1667,1679 ---- static PyObject *PyAddressAsPIDL(PyObject *self, PyObject *args) { ! LPCITEMIDLIST lpidl; ! PyObject *obpidl; // @pyparm int|address||The address of the PIDL ! if (!PyArg_ParseTuple(args, "O:AddressAsPIDL", &obpidl)) return NULL; ! lpidl=(LPCITEMIDLIST)PyLong_AsVoidPtr(obpidl); ! if (lpidl==NULL && PyErr_Occurred()) ! return NULL; ! return PyObject_FromPIDL(lpidl, FALSE); } *************** *** 2047,2060 **** "hIcon", "hMonitor", NULL, }; ! PyObject *obVerb = NULL, *obFile = NULL, *obParams = NULL; PyObject *obDirectory = NULL, *obIDList = NULL, *obClass = NULL; PyObject *obhkeyClass = NULL, *obHotKey = NULL, *obhIcon = NULL; PyObject *obhMonitor = NULL; ! if (!PyArg_ParseTupleAndKeywords(args, kw, "|llOOOOlOOOOOO", kw_items, // @pyparm int|fMask|0|The default mask for the // structure. Other masks may be added based on // what paramaters are supplied. &p->fMask, ! &p->hwnd, // @pyparm int|hwnd|0| &obVerb, // @pyparm string|lpVerb|| &obFile, // @pyparm string|lpFile|| --- 2078,2091 ---- "hIcon", "hMonitor", NULL, }; ! PyObject *obhwnd=Py_None, *obVerb = NULL, *obFile = NULL, *obParams = NULL; PyObject *obDirectory = NULL, *obIDList = NULL, *obClass = NULL; PyObject *obhkeyClass = NULL, *obHotKey = NULL, *obhIcon = NULL; PyObject *obhMonitor = NULL; ! if (!PyArg_ParseTupleAndKeywords(args, kw, "|lOOOOOlOOOOOO", kw_items, // @pyparm int|fMask|0|The default mask for the // structure. Other masks may be added based on // what paramaters are supplied. &p->fMask, ! &obhwnd, // @pyparm <o PyHANDLE>|hwnd|0| &obVerb, // @pyparm string|lpVerb|| &obFile, // @pyparm string|lpFile|| *************** *** 2069,2073 **** &obhMonitor)) // @pyparm <o PyHANDLE>|hMonitor|| goto done; ! if (obVerb && !PyWinObject_AsString(obVerb, (char **)&p->lpVerb)) goto done; --- 2100,2105 ---- &obhMonitor)) // @pyparm <o PyHANDLE>|hMonitor|| goto done; ! if (!PyWinObject_AsHANDLE(obhwnd, (HANDLE *)&p->hwnd, TRUE)) ! goto done; if (obVerb && !PyWinObject_AsString(obVerb, (char **)&p->lpVerb)) goto done; |
From: Mark H. <mha...@us...> - 2007-02-12 03:22:00
|
Update of /cvsroot/pywin32/pywin32/com/win32comext/shell/demos/servers In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3691 Modified Files: shell_view.py Log Message: Upgrade the shell_view sample to include a list-control based view and also get more coverage for the shell.cpp functions and structure handling. Index: shell_view.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32comext/shell/demos/servers/shell_view.py,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** shell_view.py 26 May 2004 09:39:11 -0000 1.6 --- shell_view.py 12 Feb 2007 03:21:56 -0000 1.7 *************** *** 51,55 **** import pyclbr import pythoncom ! import win32gui, win32api, win32con, winerror from win32com.shell import shell, shellcon from win32com.server.util import wrap, NewEnum --- 51,56 ---- import pyclbr import pythoncom ! import win32gui, win32gui_struct, win32api, win32con, winerror ! import commctrl from win32com.shell import shell, shellcon from win32com.server.util import wrap, NewEnum *************** *** 62,65 **** --- 63,70 ---- debug=0 + # markh is toying with an implementation that allows auto reload of a module + # if this attribute exists. + com_auto_reload = True + # Helper function to get a system IShellFolder interface, and the PIDL within # that folder for an existing file/directory. *************** *** 165,169 **** try: inout, ret = folder.GetUIObjectOf(hwndOwner, [child_pidl], iid, ! inout, pythoncom.IID_IUnknown) except pythoncom.com_error, (hr, desc, exc, arg): raise COMException(hresult=hr) --- 170,174 ---- try: inout, ret = folder.GetUIObjectOf(hwndOwner, [child_pidl], iid, ! inout, iid) except pythoncom.com_error, (hr, desc, exc, arg): raise COMException(hresult=hr) *************** *** 321,327 **** # by us - see the notes at the top of the file. #print "Initialize called with pidl", repr(pidl) ! pass def CreateViewObject(self, hwnd, iid): ! raise COMException(hresult=winerror.E_NOTIMPL) def EnumObjects(self, hwndOwner, flags): items = [ ["directory\0" + p] for p in sys.path if os.path.isdir(p)] --- 326,333 ---- # by us - see the notes at the top of the file. #print "Initialize called with pidl", repr(pidl) ! self.pidl = pidl def CreateViewObject(self, hwnd, iid): ! return wrap(FileSystemView(self, hwnd), useDispatcher=debug>0) ! def EnumObjects(self, hwndOwner, flags): items = [ ["directory\0" + p] for p in sys.path if os.path.isdir(p)] *************** *** 329,333 **** useDispatcher=(debug>0)) ! # A Simple shell view implementation # This uses scintilla to display a filename, and optionally jump to a line # number. --- 335,671 ---- useDispatcher=(debug>0)) ! # Simple shell view implementations ! ! # Uses a builtin listview control to display simple lists of directories ! # or filenames. ! class FileSystemView: ! _public_methods_ = IShellView_Methods ! _com_interfaces_ = [pythoncom.IID_IOleWindow, ! shell.IID_IShellView, ! ] ! def __init__(self, folder, hwnd): ! self.hwnd_parent = hwnd # provided by explorer. ! self.hwnd = None # intermediate window for catching command notifications. ! self.hwnd_child = None # our ListView ! self.activate_state = None ! self.hmenu = None ! self.browser = None ! self.folder = folder ! self.children = None ! ! # IOleWindow ! def GetWindow(self): ! return self.hwnd ! ! def ContextSensitiveHelp(self, enter_mode): ! raise COMException(hresult=winerror.E_NOTIMPL) ! ! # IShellView ! def CreateViewWindow(self, prev, settings, browser, rect): ! print "CreateViewWindow", prev, settings, browser, rect ! self.cur_foldersettings = settings ! self.browser = browser ! self._CreateMainWindow(prev, settings, browser, rect) ! self._CreateChildWindow(prev) ! ! def _CreateMainWindow(self, prev, settings, browser, rect): ! # Creates a parent window that hosts the view window. This window ! # gets the control notifications etc sent from the child. ! style = win32con.WS_CHILD | win32con.WS_VISIBLE # ! wclass_name = "EnfoldDesktop_DefView" ! # Register the Window class. ! wc = win32gui.WNDCLASS() ! wc.hInstance = win32gui.dllhandle ! wc.lpszClassName = wclass_name ! wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW ! try: ! win32gui.RegisterClass(wc) ! except win32gui.error, details: ! # Should only happen when this module is reloaded ! if details[0] != winerror.ERROR_CLASS_ALREADY_EXISTS: ! raise ! ! message_map = { ! win32con.WM_DESTROY: self.OnDestroy, ! win32con.WM_COMMAND: self.OnCommand, ! win32con.WM_NOTIFY: self.OnNotify, ! win32con.WM_CONTEXTMENU: self.OnContextMenu, ! } ! ! self.hwnd = win32gui.CreateWindow( wclass_name, "", style, \ ! rect[0], rect[1], rect[2]-rect[0], rect[3]-rect[1], ! self.hwnd_parent, 0, win32gui.dllhandle, None) ! win32gui.SetWindowLong(self.hwnd, win32con.GWL_WNDPROC, message_map) ! print "View 's hwnd is", self.hwnd ! ! def _CreateChildWindow(self, prev): ! # Creates the list view window. ! print "_CreateChildWindow" ! assert self.hwnd_child is None, "already have a window" ! assert self.cur_foldersettings is not None, "no settings" ! style = win32con.WS_CHILD | win32con.WS_VISIBLE | win32con.WS_BORDER | \ ! commctrl.LVS_SHAREIMAGELISTS | commctrl.LVS_EDITLABELS ! ! view_mode, view_flags = self.cur_foldersettings ! if view_mode==shellcon.FVM_ICON: ! style |= commctrl.LVS_ICON | commctrl.LVS_AUTOARRANGE ! elif view_mode==shellcon.FVM_SMALLICON: ! style |= commctrl.LVS_SMALLICON | commctrl.LVS_AUTOARRANGE ! elif view_mode==shellcon.FVM_LIST: ! style |= commctrl.LVS_LIST | commctrl.LVS_AUTOARRANGE ! elif view_mode==shellcon.FVM_DETAILS: ! style |= commctrl.LVS_REPORT | commctrl.LVS_AUTOARRANGE ! else: ! # XP 'thumbnails' etc ! view_mode = shellcon.FVM_DETAILS ! # Default to 'report' ! style |= commctrl.LVS_REPORT | commctrl.LVS_AUTOARRANGE ! ! for f_flag, l_flag in [ ! (shellcon.FWF_SINGLESEL, commctrl.LVS_SINGLESEL), ! (shellcon.FWF_ALIGNLEFT, commctrl.LVS_ALIGNLEFT), ! (shellcon.FWF_SHOWSELALWAYS, commctrl.LVS_SHOWSELALWAYS), ! ]: ! if view_flags & f_flag: ! style |= l_flag ! ! self.hwnd_child = win32gui.CreateWindowEx( ! win32con.WS_EX_CLIENTEDGE, ! "SysListView32", None, style, ! 0, 0, 0, 0, ! self.hwnd, 1000, 0, None) ! ! cr = win32gui.GetClientRect(self.hwnd) ! win32gui.MoveWindow(self.hwnd_child, ! 0, 0, cr[2]-cr[0], cr[3]-cr[1], ! True) ! ! # Setup the columns for the view. ! lvc, extras = win32gui_struct.PackLVCOLUMN(fmt=commctrl.LVCFMT_LEFT, ! subItem=1, ! text='Name', ! cx=300) ! win32gui.SendMessage(self.hwnd_child, commctrl.LVM_INSERTCOLUMN, ! 0, lvc) ! ! lvc, extras = win32gui_struct.PackLVCOLUMN(fmt=commctrl.LVCFMT_RIGHT, ! subItem=1, ! text='Exists', ! cx=50) ! win32gui.SendMessage(self.hwnd_child, commctrl.LVM_INSERTCOLUMN, ! 1, lvc) ! # and fill it with the content ! self.Refresh() ! ! def GetCurrentInfo(self): ! return self.cur_foldersettings ! ! def UIActivate(self, activate_state): ! print "OnActivate" ! ! def _OnActivate(self, activate_state): ! if self.activate_state == activate_state: ! return ! self._OnDeactivate() # restore menu's first, if necessary. ! if activate_state != shellcon.SVUIA_DEACTIVATE: ! assert self.hmenu is None, "Should have destroyed it!" ! self.hmenu = win32gui.CreateMenu() ! widths = 0,0,0,0,0,0 ! # Ask explorer to add its standard items. ! self.browser.InsertMenusSB(self.hmenu, widths) ! # Merge with these standard items ! self._MergeMenus(activate_state) ! self.browser.SetMenuSB(self.hmenu, 0, self.hwnd); ! self.activate_state = activate_state ! ! def _OnDeactivate(self): ! if self.browser is not None and self.hmenu is not None: ! self.browser.SetMenuSB(0, 0, 0) ! self.browser.RemoveMenusSB(self.hmenu) ! win32gui.DestroyMenu(self.hmenu) ! self.hmenu = None ! self.hsubmenus = None ! self.activate_state = shellcon.SVUIA_DEACTIVATE ! ! def _MergeMenus(self, activate_state): ! # Merge the operations we support into the top-level menus. ! # NOTE: This function it *not* called each time the selection changes. ! # SVUIA_ACTIVATE_FOCUS really means "have a selection?" ! have_sel = activate_state == shellcon.SVUIA_ACTIVATE_FOCUS ! # only do "file" menu here, and only 1 item on it! ! mid = shellcon.FCIDM_MENU_FILE ! # Get the hmenu for the menu ! buf, extras = win32gui_struct.EmptyMENUITEMINFO(win32con.MIIM_SUBMENU) ! win32gui.GetMenuItemInfo(self.hmenu, ! mid, ! False, ! buf) ! data = win32gui_struct.UnpackMENUITEMINFO(buf) ! submenu = data[3] ! print "Do someting with the file menu!" ! ! def Refresh(self): ! stateMask = commctrl.LVIS_SELECTED | commctrl.LVIS_DROPHILITED ! state = 0 ! self.children = [] ! # Enumerate and store the child PIDLs ! for cid in self.folder.EnumObjects(self.hwnd, 0): ! print "Have CID" ! self.children.append(cid) ! ! for row_index, data in enumerate(self.children): ! assert len(data)==1, "expecting just a child PIDL" ! typ, path = data[0].split('\0') ! desc = os.path.exists(path) and "Yes" or "No" ! prop_vals = (path, desc) ! # first col ! data, extras = win32gui_struct.PackLVITEM( ! item=row_index, ! subItem=0, ! text=prop_vals[0], ! state=state, ! stateMask=stateMask) ! win32gui.SendMessage(self.hwnd_child, ! commctrl.LVM_INSERTITEM, ! row_index, data) ! # rest of the cols. ! col_index = 1 ! for prop_val in prop_vals[1:]: ! data, extras = win32gui_struct.PackLVITEM( ! item=row_index, ! subItem=col_index, ! text=prop_val) ! ! win32gui.SendMessage(self.hwnd_child, ! commctrl.LVM_SETITEM, ! 0, data) ! col_index += 1 ! ! def SelectItem(self, pidl, flag): ! # For the sake of brevity, we don't implement this yet. ! # You would need to locate the index of the item in the shell-view ! # with that PIDL, then ask the list-view to select it. ! print "Please implement SelectItem for PIDL", pidl ! ! def GetItemObject(self, item_num, iid): ! raise COMException(hresult=winerror.E_NOTIMPL) ! ! def TranslateAccelerator(self, msg): ! return winerror.S_FALSE ! ! def DestroyViewWindow(self): ! win32gui.DestroyWindow(self.hwnd) ! self.hwnd = None ! print "Destroyed view window" ! ! # Message handlers. ! def OnDestroy(self, hwnd, msg, wparam, lparam): ! print "OnDestory" ! ! def OnCommand(self, hwnd, msg, wparam, lparam): ! print "OnCommand" ! ! def OnNotify(self, hwnd, msg, wparam, lparam): ! hwndFrom, idFrom, code = win32gui_struct.UnpackWMNOTIFY(lparam) ! print "OnNotify code=0x%x (0x%x, 0x%x)" % (code, wparam, lparam) ! if code == commctrl.NM_SETFOCUS: ! # Control got focus - Explorer may not know - tell it ! if self.browser is not None: ! self.browser.OnViewWindowActive(None) ! # And do our menu thang ! self._OnActivate(shellcon.SVUIA_ACTIVATE_FOCUS) ! elif code == commctrl.NM_KILLFOCUS: ! self._OnDeactivate() ! elif code == commctrl.NM_DBLCLK: ! # This DblClick implementation leaves a little to be desired :) ! # It demonstrates some useful concepts, such as asking the ! # folder for its context-menu and invoking a command from it. ! # However, as our folder delegates IContextMenu to the shell ! # itself, the end result is that the folder is opened in ! # its "normal" place in Windows explorer rather than inside ! # our shell-extension. ! # Determine the selected items. ! sel = [] ! n = -1 ! while 1: ! n = win32gui.SendMessage(self.hwnd_child, ! commctrl.LVM_GETNEXTITEM, ! n, ! commctrl.LVNI_SELECTED) ! if n==-1: ! break ! sel.append(self.children[n][-1:]) ! print "Selection is", sel ! # Get the IContextMenu for the items. ! inout, cm = self.folder.GetUIObjectOf(self.hwnd_parent, sel, ! shell.IID_IContextMenu, 0) ! hmenu = win32gui.CreateMenu() ! try: ! # As per 'Q179911', we need to determine if the default operation ! # should be 'open' or 'explore' ! flags = shellcon.CMF_DEFAULTONLY ! try: ! self.browser.GetControlWindow(shellcon.FCW_TREE) ! flags |= shellcon.CMF_EXPLORE ! except pythoncom.com_error: ! pass ! id_cmd_first = 1 # TrackPopupMenu makes it hard to use 0 ! cm.QueryContextMenu(hmenu, 0, id_cmd_first, -1, flags) ! # Find the default item in the returned menu. ! cmd = win32gui.GetMenuDefaultItem(hmenu, False, 0) ! if cmd == -1: ! print "Oops: _doDefaultActionFor found no default menu" ! else: ! ci = 0, self.hwnd_parent, cmd-id_cmd_first, None, None, 0, 0, 0 ! cm.InvokeCommand(ci) ! finally: ! win32gui.DestroyMenu(hmenu) ! ! def OnContextMenu(self, hwnd, msg, wparam, lparam): ! # Get the selected items. ! pidls = [] ! n = -1 ! while 1: ! n = win32gui.SendMessage(self.hwnd_child, ! commctrl.LVM_GETNEXTITEM, ! n, ! commctrl.LVNI_SELECTED) ! if n==-1: ! break ! pidls.append(self.children[n][-1:]) ! ! spt = win32api.GetCursorPos() ! if not pidls: ! print "Ignoring background click" ! return ! # Get the IContextMenu for the items. ! inout, cm = self.folder.GetUIObjectOf(self.hwnd_parent, pidls, shell.IID_IContextMenu, 0) ! hmenu = win32gui.CreatePopupMenu() ! sel = None ! # As per 'Q179911', we need to determine if the default operation ! # should be 'open' or 'explore' ! try: ! flags = 0 ! try: ! self.browser.GetControlWindow(shellcon.FCW_TREE) ! flags |= shellcon.CMF_EXPLORE ! except pythoncom.com_error: ! pass ! id_cmd_first = 1 # TrackPopupMenu makes it hard to use 0 ! cm.QueryContextMenu(hmenu, 0, id_cmd_first, -1, flags) ! tpm_flags = win32con.TPM_LEFTALIGN | win32con.TPM_RETURNCMD | \ ! win32con.TPM_RIGHTBUTTON ! sel = win32gui.TrackPopupMenu(hmenu, ! tpm_flags, ! spt[0], spt[1], ! 0, self.hwnd, None) ! print "TrackPopupMenu returned", sel ! finally: ! win32gui.DestroyMenu(hmenu) ! if sel: ! ci = 0, self.hwnd_parent, sel-id_cmd_first, None, None, 0, 0, 0 ! cm.InvokeCommand(ci) ! ! # This uses scintilla to display a filename, and optionally jump to a line # number. |
From: Mark H. <mha...@us...> - 2007-02-11 12:39:12
|
Update of /cvsroot/pywin32/pywin32/com/win32com/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29099/win32com/test Modified Files: testPyComTest.py Log Message: add a property that takes a param to the test suite. Index: testPyComTest.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32com/test/testPyComTest.py,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** testPyComTest.py 7 Feb 2007 23:12:31 -0000 1.26 --- testPyComTest.py 11 Feb 2007 12:39:06 -0000 1.27 *************** *** 138,141 **** --- 138,146 ---- raise error, "got %r" % (o.CurrencyProp,) + # damn - props with params don't work for dynamic objects :( + # o.SetParamProp(0, 1) + # if o.ParamProp(0) != 1: + # raise RuntimeError, o.paramProp(0) + try: import datetime *************** *** 295,298 **** --- 300,307 ---- raise error, "%s got %r" % (val, o.CurrencyProp) + o.SetParamProp(0, 1) + if o.ParamProp(0) != 1: + raise RuntimeError, o.paramProp(0) + # Do the connection point thing... # Create a connection object. |
From: Mark H. <mha...@us...> - 2007-02-11 12:39:08
|
Update of /cvsroot/pywin32/pywin32/com/TestSources/PyCOMTest In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29099/TestSources/PyCOMTest Modified Files: PyCOMImpl.cpp PyCOMImpl.h PyCOMTest.idl Log Message: add a property that takes a param to the test suite. Index: PyCOMTest.idl =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/TestSources/PyCOMTest/PyCOMTest.idl,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** PyCOMTest.idl 7 Feb 2007 23:12:30 -0000 1.14 --- PyCOMTest.idl 11 Feb 2007 12:39:05 -0000 1.15 *************** *** 248,251 **** --- 248,254 ---- [propget] HRESULT CurrencyProp([out, retval] CY* retval); [propput] HRESULT CurrencyProp([in] CY val); + [propget] HRESULT ParamProp([in] int which, [out, retval] int *retval); + [propput] HRESULT ParamProp([in] int which, [in]int val); + // reserved words etc HRESULT None(); HRESULT def(); *************** *** 276,280 **** // Test enum in and byref params. HRESULT TestDerived([in] QsAttribute inval, [out, retval] QsAttribute* retval); - }; // The event interface. --- 279,282 ---- Index: PyCOMImpl.h =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/TestSources/PyCOMTest/PyCOMImpl.h,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** PyCOMImpl.h 7 Feb 2007 23:12:30 -0000 1.13 --- PyCOMImpl.h 11 Feb 2007 12:39:05 -0000 1.14 *************** *** 102,105 **** --- 102,107 ---- STDMETHOD(get_CurrencyProp)(CY *ret); STDMETHOD(put_CurrencyProp)(CY val); + STDMETHOD(get_ParamProp)(int which, int *ret2); + STDMETHOD(put_ParamProp)(int which, int val); STDMETHOD(None)(); *************** *** 124,127 **** --- 126,130 ---- unsigned long m_ulong; CY m_cy; + int m_paramprop1, m_paramprop2; }; Index: PyCOMImpl.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/TestSources/PyCOMTest/PyCOMImpl.cpp,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** PyCOMImpl.cpp 7 Feb 2007 23:12:30 -0000 1.14 --- PyCOMImpl.cpp 11 Feb 2007 12:39:05 -0000 1.15 *************** *** 682,685 **** --- 682,702 ---- } + HRESULT CPyCOMTest::get_ParamProp(int which, int *ret) + { + if (!ret) + return E_POINTER; + *ret = which==0 ? m_paramprop1 : m_paramprop2; + return S_OK; + } + + HRESULT CPyCOMTest::put_ParamProp(int which, int val) + { + if (which==0) + m_paramprop1 = val; + else + m_paramprop2 = val; + return S_OK; + } + HRESULT CPyCOMTest::None() { |