From Karl.Bellve@umassmed.edu Mon May 7 18:34:48 2001 From: Karl.Bellve@umassmed.edu (Karl Bellve) Date: Mon, 07 May 2001 13:34:48 -0400 Subject: [python-win32] Exiting an embedded script? Message-ID: <3AF6DCB8.8CBFA2AC@umassmed.edu> I am trying to exit an embedded script before the end of the script. If I use sys.exit(), the parent application also exits. How can I prematurely end the python script without ending the parent application. I am using PyRun_SimpleFile() I then check the return of that function but if the python script calls sys.exit(), my program exits before it can do anything about the error. Any ideas? --Karl From jh@magnus.dk Tue May 8 15:43:57 2001 From: jh@magnus.dk (Jesper Hertel) Date: Tue, 8 May 2001 16:43:57 +0200 Subject: [python-win32] Exiting an embedded script? Message-ID: Hello Karl, I am not sure that I completely understand the question, but how about putting the code in a function and then use raise to quit the function when needed? This doesn't work as you said: ... code 1 ... if condition: sys.exit() ... code 2 ... My suggestion is to change it to: def main(): ... code 1 ... if condition: raise "exit" ... code 2 ... try: main() except "exit": # Allow the exit. pass I haven't tried it under your circumstances; it is just an idea. Best regards, Jesper Hertel System Developer Forlaget Magnus A/S Denmark jh@magnus.dk -----Original Message----- From: Karl Bellve [mailto:Karl.Bellve@umassmed.edu] Sent: Monday, May 07, 2001 7:35 PM To: python-win32 Subject: [python-win32] Exiting an embedded script? I am trying to exit an embedded script before the end of the script. If I use sys.exit(), the parent application also exits. How can I prematurely end the python script without ending the parent application. I am using PyRun_SimpleFile() I then check the return of that function but if the python script calls sys.exit(), my program exits before it can do anything about the error. Any ideas? --Karl _______________________________________________ Python-win32 mailing list Python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32 From pavlos@gaaros.com Tue May 8 19:21:36 2001 From: pavlos@gaaros.com (pavlos@gaaros.com) Date: Tue, 08 May 2001 18:21:36 GMT Subject: [python-win32] Posting Events Message-ID: <20010508182136.28669.qmail@mail.yifansoft.com> WinComs I am trying to post an event from a python COM server to a VB client. I do not know whether it is possible or not. Checked the python win32 book and there are no references on events. Anyone has any references to direct me to? Thanks Pavlos From itamarst@yahoo.com Thu May 10 16:53:01 2001 From: itamarst@yahoo.com (Itamar S.-T.) Date: Thu, 10 May 2001 08:53:01 -0700 (PDT) Subject: [python-win32] Getting security info about a file Message-ID: <20010510155301.44906.qmail@web13005.mail.yahoo.com> Hi, lets say I want to get the security information on a file. So I do: >>> o = win32security.GetFileSecurity(r"c:\mingc.pyd", win32security.OWNER_SECURITY_INFORMATION) >>> o So what do I do with 'o' now in order to get the owner? I tried: >>> s = win32security.SID(o) >>> win32security.LookupAccountSid(None, s) Traceback (innermost last): File "", line 1, in ? api_error: (1332, 'LookupAccountSid', 'No mapping between account names and security IDs was done.') What am I doing wrong? ===== Itamar Shtull-Trauring, itamar(at)shtull-trauring.org __________________________________________________ Do You Yahoo!? Yahoo! Auctions - buy the things you want at great prices http://auctions.yahoo.com/ From Karl.Bellve@umassmed.edu Thu May 10 16:57:13 2001 From: Karl.Bellve@umassmed.edu (Karl Bellve) Date: Thu, 10 May 2001 11:57:13 -0400 Subject: [python-win32] Exiting an embedded script? References: Message-ID: <3AFABA59.5FB85E22@umassmed.edu> Thanks for answering! I was hoping there was a simple solution in C/C++ to prevent the script from closing the application on a sys.exit() call and not on the python side. Jesper Hertel wrote: > > Hello Karl, > > I am not sure that I completely understand the question, but how about > putting the code in a function and then use raise to quit the function when > needed? > > This doesn't work as you said: > -- Cheers, Karl Bellve, Ph.D. ICQ # 13956200 Biomedical Imaging Group TLCA# 7938 University of Massachusetts Email: Karl.Bellve@umassmed.edu Phone: (508) 856-6514 Fax: (508) 856-1840 PGP Public key: finger kdb@molmed.umassmed.edu From ldeller@xplantechnology.com Wed May 23 08:42:30 2001 From: ldeller@xplantechnology.com (Luke Deller) Date: Wed, 23 May 2001 17:42:30 +1000 Subject: [python-win32] win32clipboard & bitmaps Message-ID: Hi, I'm having trouble with the win32clipboard module in win32all-138. I do the following after copying a bitmap image into the clipboard: $ python Python 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information. >>> import win32clipboard >>> win32clipboard.OpenClipboard(0) >>> print win32clipboard.IsClipboardFormatAvailable(win32clipboard.CF_BITMAP) 1 >>> str = win32clipboard.GetClipboardData(win32clipboard.CF_BITMAP) Traceback (most recent call last): File "", line 1, in ? pywintypes.api_error: (6, 'GetClipboardData:GlobalLock', 'The handle is invalid. ') Any ideas why I get this exception? Is this a bug in win32clipboard? The clipboard contents will paste correctly into another application (eg Microsoft Word using "Paste Special" to paste as a regular bitmap) Thanks! Luke. From ldeller@xplantechnology.com Wed May 23 13:52:23 2001 From: ldeller@xplantechnology.com (Luke Deller) Date: Wed, 23 May 2001 22:52:23 +1000 Subject: [python-win32] win32clipboard & bitmaps In-Reply-To: Message-ID: This is a multi-part message in MIME format. ------=_NextPart_000_000C_01C0E3DB.08206E60 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Hi again, I downloaded the PyWin32 code from cvs and found the problem in win32clipboard. It assumes that the handle returned from GetClipboardData was an HGLOBAL. This is not true for some clipboard formats such as bitmaps and metafiles. I have patched win32clipboardmodule.cpp to handle CF_ENHMETAFILE and CF_METAFILE correctly, and to generate an "unimplemented" error message for CF_BITMAP and CF_DIB. (my patch is attached to this email). Regards, Luke Deller. -----Original Message----- From: python-win32-admin@python.org [mailto:python-win32-admin@python.org]On Behalf Of Luke Deller Sent: Wednesday, 23 May 2001 5:43 PM To: python-win32@python.org Subject: [python-win32] win32clipboard & bitmaps Hi, I'm having trouble with the win32clipboard module in win32all-138. I do the following after copying a bitmap image into the clipboard: $ python Python 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information. >>> import win32clipboard >>> win32clipboard.OpenClipboard(0) >>> print win32clipboard.IsClipboardFormatAvailable(win32clipboard.CF_BITMAP) 1 >>> str = win32clipboard.GetClipboardData(win32clipboard.CF_BITMAP) Traceback (most recent call last): File "", line 1, in ? pywintypes.api_error: (6, 'GetClipboardData:GlobalLock', 'The handle is invalid. ') Any ideas why I get this exception? Is this a bug in win32clipboard? The clipboard contents will paste correctly into another application (eg Microsoft Word using "Paste Special" to paste as a regular bitmap) Thanks! Luke. _______________________________________________ Python-win32 mailing list Python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32 ------=_NextPart_000_000C_01C0E3DB.08206E60 Content-Type: application/octet-stream; name="win32clipboard.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="win32clipboard.patch" Index: win32/src/win32clipboardmodule.cpp =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /home/cvsroot/PyWin32/win32/src/win32clipboardmodule.cpp,v retrieving revision 1.8 diff -u -r1.8 win32clipboardmodule.cpp --- win32clipboardmodule.cpp 2001/05/08 23:46:28 1.8 +++ win32clipboardmodule.cpp 2001/05/23 12:55:15 @@ -290,33 +290,81 @@ =20 if (!handle) { return ReturnAPIError("GetClipboardData"); - } + } =20 =20 - HGLOBAL cData; - cData =3D GlobalLock(handle); - if (!cData) { - GlobalUnlock(handle); - return ReturnAPIError("GetClipboardData:GlobalLock"); - } - DWORD size =3D GlobalSize(cData); - if (!size) { - GlobalUnlock(handle); - return ReturnAPIError("GetClipboardData:GlobalSize"); + void * cData; + DWORD size; + switch (format) { + case CF_ENHMETAFILE: + size =3D GetEnhMetaFileBits((HENHMETAFILE)handle, 0, NULL); + if (!size) + return ReturnAPIError("GetClipboardData:GetEnhMetafileBits(NULL)"); + // allocate a temporary buffer for enhanced metafile + cData =3D malloc(size); + if (cData =3D=3D NULL) + return ReturnAPIError("GetClipboardData:malloc"); + // copy enhanced metafile into the temporary buffer + if (0 =3D=3D GetEnhMetaFileBits((HENHMETAFILE)handle, size, = (LPBYTE)cData)) { + free(cData); + return ReturnAPIError("GetClipboardData:GetEnhMetafileBits"); + } + break; + case CF_METAFILEPICT: + size =3D GetMetaFileBitsEx((HMETAFILE)handle, 0, NULL); + if (!size) + return ReturnAPIError("GetClipboardData:GetMetafileBitsEx(NULL)"); + // allocate a temporary buffer for metafile + cData =3D malloc(size); + if (cData =3D=3D NULL) + return ReturnAPIError("GetClipboardData:malloc"); + // copy metafile into the temporary buffer + if (0 =3D=3D GetMetaFileBitsEx((HMETAFILE)handle, size, cData)) { + free(cData); + return ReturnAPIError("GetClipboardData:GetMetafileBitsEx"); + } + break; + case CF_BITMAP: + return ReturnAPIError("GetClipboardData(CF_BITMAP) = unimplemented"); + break; + case CF_DIB: + return ReturnAPIError("GetClipboardData(CF_DIB) unimplemented"); + break; + default: + cData =3D GlobalLock(handle); + if (!cData) { + GlobalUnlock(handle); + return ReturnAPIError("GetClipboardData:GlobalLock"); + } + size =3D GlobalSize(cData); + if (!size) { + GlobalUnlock(handle); + return ReturnAPIError("GetClipboardData:GlobalSize"); + } + break; } switch (format) { case CF_UNICODETEXT: ret =3D PyWinObject_FromWCHAR((wchar_t *)cData, (size / = sizeof(wchar_t))-1); + GlobalUnlock(handle); break; // For the text formats, strip the null! case CF_TEXT: case CF_OEMTEXT: ret =3D PyString_FromStringAndSize((char *)cData, size-1); + GlobalUnlock(handle); + break; + case CF_ENHMETAFILE: + case CF_METAFILEPICT: + case CF_BITMAP: + case CF_DIB: + ret =3D PyString_FromStringAndSize((char *)cData, size); + free(cData); break; default: ret =3D PyString_FromStringAndSize((char *)cData, size); + GlobalUnlock(handle); break; } - GlobalUnlock(handle); return ret; =20 // @comm An application can enumerate the available formats in = advance by ------=_NextPart_000_000C_01C0E3DB.08206E60-- From MarkH@ActiveState.com Wed May 23 14:33:22 2001 From: MarkH@ActiveState.com (Mark Hammond) Date: Wed, 23 May 2001 23:33:22 +1000 Subject: [python-win32] win32clipboard & bitmaps In-Reply-To: Message-ID: > I have patched win32clipboardmodule.cpp to handle CF_ENHMETAFILE and > CF_METAFILE correctly, and to generate an "unimplemented" error > message for > CF_BITMAP and CF_DIB. (my patch is attached to this email). Excellent! Thanks! I have checked that in (with very minor changes - whitespace and the not implemented exception is NotImplementedError rather than win32api.error) Mark.