From jan.wedel at ettex.de Wed Dec 11 10:38:15 2013 From: jan.wedel at ettex.de (Wedel, Jan) Date: Wed, 11 Dec 2013 09:38:15 +0000 Subject: [python-win32] Missing memory de/allocation in com server causes APPCRASH? Message-ID: <47EE7F193EDC7E468E74BB0ACFB17929011692C1CA@EX10MBOX1B.hosting.inetserver.de> Hi, I already posted a related question on the comtypes mailing list but unfortunately Thomas Heller told me that he cannot actively provide support anymore. So I'm hoping to get some help here because it might also relate more to ctypes. At first, sorry for the long mail but it's a rather complex issue and I want to provide as much information and context as required. Heres the problem: We wrote a COM server using comtypes which worked well on Win XP. However, on Windows 2008 and Win 7, the same code crashes after calling a specific method that our server provides. By "crashes" I mean the COM client (Tried it with a C++ and python client) receives a COMError: _ctypes.COMError: (-2147417851, 'Ausnahmefehler des Servers.', (None, None, None, 0, None)) The Server does *not* throw any exceptions as far as I can see and keeps on running. I added some printf debugging in comtypes but everything seems fine and ends up calling some win32api functions after message dispatching is done. Every time this happens, in the windows application event log, there is an entry saying "python.exe" was the offending application, "ntdll.dll" was the offending module. I also set up windows debugging modules with shows the following stack trace (just first few lines at the top): ntdll!RtlpLowFragHeapFree+0x31 (FPO: [Non-Fpo]) 01 0021ed04 76f49c46 00390000 00000000 029e76e0 ntdll!RtlFreeHeap+0x101 02 0021ed18 7718afbd 00390000 00000000 029e76e8 kernel32!HeapFree+0x14 03 0021ed2c 7718afd9 7725f6f8 029e76e8 0021ed54 ole32!CRetailMalloc_Free+0x1c (FPO: [Non-Fpo]) 04 0021ed3c 75be6efc 029e76e8 01f685fe 0021edcc ole32!CoTaskMemFree+0x13 Since the problem arises reproducibly when calling one method the has a pointer to an array as input and output, I believe this is some kind of memory issue (which also the stack trace suggests) that was probably just not recognized/caught by WinXP before but now shows up in more recent windows versions. My assumption is, that either I need to actively allocate or deallocate memory for in/out parameters. This is the method signature of the method that our server provides and that crashes: IOPCItemMgt::ValidateItems HRESULT ValidateItems( [in] DWORD dwCount, [in, size_is(dwCount)] OPCITEMDEF * pItemArray, [in] BOOL bBlobUpdate, [out, size_is(,dwCount)] OPCITEMRESULT ** ppValidationResults, [out, size_is(,dwCount)] HRESULT ** ppErrors ); Assume that this is the signature in python comtypes server: def ValidateItems(self, count, p_item_array, update_blob): and this is the ctypes structure which should be returned in " ppValidationResults ": OpcDa.tagOPCITEMRESULT How would I create these structures (especially ppValidationResults), its contents and the pointers so that I would not create any memory issues, null pointers or whatsoever? My implementation creates a few items by calling validation_result = OpcDa.tagOPCITEMRESULT() filling in the contents with e.g. validation_result.hServer = server_item_handle adding it to a list validation_results.append(validation_result) then converting it to a pointer to an array with a helper function: def p_list(items): c_items = (type(items[0])*len(items))(*items) p_items = cast(c_items, POINTER(type(items[0]))) return p_items (...) p_validation_results = p_list(validation_results) doing the same with "errors" and then returning it: return p_validation_results, p_errors Is that correct? Do I have to keep references to the list, the pointer or the item strcuture objects to avoid them beeing garbage collected? Thanks a lot! -------------- next part -------------- An HTML attachment was scrubbed... URL: From jan.wedel at ettex.de Thu Dec 12 14:39:10 2013 From: jan.wedel at ettex.de (Wedel, Jan) Date: Thu, 12 Dec 2013 13:39:10 +0000 Subject: [python-win32] Missing memory de/allocation in com server causes APPCRASH? In-Reply-To: <47EE7F193EDC7E468E74BB0ACFB17929011692C1CA@EX10MBOX1B.hosting.inetserver.de> References: <47EE7F193EDC7E468E74BB0ACFB17929011692C1CA@EX10MBOX1B.hosting.inetserver.de> Message-ID: <47EE7F193EDC7E468E74BB0ACFB17929011692C5FE@EX10MBOX1B.hosting.inetserver.de> Ok, being pretty desperate, I tried a few ways of returning the data until I got it partially working. 1. I returned null pointers: return POINTER(OpcDa.tagOPCITEMRESULT)(), POINTER(HRESULT)() Obviously, it did not return any sensible data, but it did not crash! The client actually receives the null pointer which is better that crashing without any information. 2. Using the above knowledge, I tried to refactor the existing code as follows: - creating the arrays in advance: add_results = (OpcDa.tagOPCITEMRESULT*count)() errors = (HRESULT*count)() - looping over all elements of the array and filling in the data: (...) add_results[index].hServer = server_item_handle (...) Errors[index] = HRESULT(S_OK) - returning a new pointer to the arrays return POINTER(OpcDa.tagOPCITEMRESULT)(add_results), POINTER(HRESULT)(errors) - Do not store the arrays in python's "self" Using this procedure, it does not crash the client and it does return data. Now, I am wondering why I had to do this on Win Server 2008 and on Xp the old code worked. However, this led me to next problem: hServer is of type c_ulong which means 4 bytes and is the first element of the tagOPCITEMRESULT structure. Reproducibly, the first two bytes of the first element of the array gets corrupted *somewhere* in the same way, more specifically it gets overwritten to 0x4A00. The value 0x4A doesn't ring any bells that could reveal the cause for that. All following elements of the array are not corrupted. The question is, how could that happen? What could possible overwrite memory? Do I have to prevent freeing memory used by these arrays somehow before returning them via COM? Thanks, //Jan Von: python-win32 [mailto:python-win32-bounces+jan.wedel=ettex.de at python.org] Im Auftrag von Wedel, Jan Gesendet: Mittwoch, 11. Dezember 2013 10:38 An: python-win32 at python.org Betreff: [python-win32] Missing memory de/allocation in com server causes APPCRASH? Hi, I already posted a related question on the comtypes mailing list but unfortunately Thomas Heller told me that he cannot actively provide support anymore. So I'm hoping to get some help here because it might also relate more to ctypes. At first, sorry for the long mail but it's a rather complex issue and I want to provide as much information and context as required. Heres the problem: We wrote a COM server using comtypes which worked well on Win XP. However, on Windows 2008 and Win 7, the same code crashes after calling a specific method that our server provides. By "crashes" I mean the COM client (Tried it with a C++ and python client) receives a COMError: _ctypes.COMError: (-2147417851, 'Ausnahmefehler des Servers.', (None, None, None, 0, None)) The Server does *not* throw any exceptions as far as I can see and keeps on running. I added some printf debugging in comtypes but everything seems fine and ends up calling some win32api functions after message dispatching is done. Every time this happens, in the windows application event log, there is an entry saying "python.exe" was the offending application, "ntdll.dll" was the offending module. I also set up windows debugging modules with shows the following stack trace (just first few lines at the top): ntdll!RtlpLowFragHeapFree+0x31 (FPO: [Non-Fpo]) 01 0021ed04 76f49c46 00390000 00000000 029e76e0 ntdll!RtlFreeHeap+0x101 02 0021ed18 7718afbd 00390000 00000000 029e76e8 kernel32!HeapFree+0x14 03 0021ed2c 7718afd9 7725f6f8 029e76e8 0021ed54 ole32!CRetailMalloc_Free+0x1c (FPO: [Non-Fpo]) 04 0021ed3c 75be6efc 029e76e8 01f685fe 0021edcc ole32!CoTaskMemFree+0x13 Since the problem arises reproducibly when calling one method the has a pointer to an array as input and output, I believe this is some kind of memory issue (which also the stack trace suggests) that was probably just not recognized/caught by WinXP before but now shows up in more recent windows versions. My assumption is, that either I need to actively allocate or deallocate memory for in/out parameters. This is the method signature of the method that our server provides and that crashes: IOPCItemMgt::ValidateItems HRESULT ValidateItems( [in] DWORD dwCount, [in, size_is(dwCount)] OPCITEMDEF * pItemArray, [in] BOOL bBlobUpdate, [out, size_is(,dwCount)] OPCITEMRESULT ** ppValidationResults, [out, size_is(,dwCount)] HRESULT ** ppErrors ); Assume that this is the signature in python comtypes server: def ValidateItems(self, count, p_item_array, update_blob): and this is the ctypes structure which should be returned in " ppValidationResults ": OpcDa.tagOPCITEMRESULT How would I create these structures (especially ppValidationResults), its contents and the pointers so that I would not create any memory issues, null pointers or whatsoever? My implementation creates a few items by calling validation_result = OpcDa.tagOPCITEMRESULT() filling in the contents with e.g. validation_result.hServer = server_item_handle adding it to a list validation_results.append(validation_result) then converting it to a pointer to an array with a helper function: def p_list(items): c_items = (type(items[0])*len(items))(*items) p_items = cast(c_items, POINTER(type(items[0]))) return p_items (...) p_validation_results = p_list(validation_results) doing the same with "errors" and then returning it: return p_validation_results, p_errors Is that correct? Do I have to keep references to the list, the pointer or the item strcuture objects to avoid them beeing garbage collected? Thanks a lot! -------------- next part -------------- An HTML attachment was scrubbed... URL: From rupole at hotmail.com Fri Dec 13 01:16:31 2013 From: rupole at hotmail.com (Roger Upole) Date: Thu, 12 Dec 2013 19:16:31 -0500 Subject: [python-win32] Missing memory de/allocation in com server causes APPCRASH? References: <47EE7F193EDC7E468E74BB0ACFB17929011692C1CA@EX10MBOX1B.hosting.inetserver.de> <47EE7F193EDC7E468E74BB0ACFB17929011692C5FE@EX10MBOX1B.hosting.inetserver.de> Message-ID: I'm guessing you have a 32/64 bit problem, as most XP installs are 32-bit. I'd take a closer look at hServer, since handles are pointer-sized (4 bytes on 32 bit and 8 bytes on x64). Roger "Wedel, Jan" wrote in message news:47EE7F193EDC7E468E74BB0ACFB17929011692C5FE at EX10MBOX1B.hosting.inetserver.de... Ok, being pretty desperate, I tried a few ways of returning the data until I got it partially working. 1. I returned null pointers: return POINTER(OpcDa.tagOPCITEMRESULT)(), POINTER(HRESULT)() Obviously, it did not return any sensible data, but it did not crash! The client actually receives the null pointer which is better that crashing without any information. 2. Using the above knowledge, I tried to refactor the existing code as follows: - creating the arrays in advance: add_results = (OpcDa.tagOPCITEMRESULT*count)() errors = (HRESULT*count)() - looping over all elements of the array and filling in the data: (...) add_results[index].hServer = server_item_handle (...) Errors[index] = HRESULT(S_OK) - returning a new pointer to the arrays return POINTER(OpcDa.tagOPCITEMRESULT)(add_results), POINTER(HRESULT)(errors) - Do not store the arrays in python's "self" Using this procedure, it does not crash the client and it does return data. Now, I am wondering why I had to do this on Win Server 2008 and on Xp the old code worked. However, this led me to next problem: hServer is of type c_ulong which means 4 bytes and is the first element of the tagOPCITEMRESULT structure. Reproducibly, the first two bytes of the first element of the array gets corrupted *somewhere* in the same way, more specifically it gets overwritten to 0x4A00. The value 0x4A doesn't ring any bells that could reveal the cause for that. All following elements of the array are not corrupted. The question is, how could that happen? What could possible overwrite memory? Do I have to prevent freeing memory used by these arrays somehow before returning them via COM? Thanks, //Jan Von: python-win32 [mailto:python-win32-bounces+jan.wedel=ettex.de at python.org] Im Auftrag von Wedel, Jan Gesendet: Mittwoch, 11. Dezember 2013 10:38 An: python-win32 at python.org Betreff: [python-win32] Missing memory de/allocation in com server causes APPCRASH? Hi, I already posted a related question on the comtypes mailing list but unfortunately Thomas Heller told me that he cannot actively provide support anymore. So I'm hoping to get some help here because it might also relate more to ctypes. At first, sorry for the long mail but it's a rather complex issue and I want to provide as much information and context as required. Heres the problem: We wrote a COM server using comtypes which worked well on Win XP. However, on Windows 2008 and Win 7, the same code crashes after calling a specific method that our server provides. By "crashes" I mean the COM client (Tried it with a C++ and python client) receives a COMError: _ctypes.COMError: (-2147417851, 'Ausnahmefehler des Servers.', (None, None, None, 0, None)) The Server does *not* throw any exceptions as far as I can see and keeps on running. I added some printf debugging in comtypes but everything seems fine and ends up calling some win32api functions after message dispatching is done. Every time this happens, in the windows application event log, there is an entry saying "python.exe" was the offending application, "ntdll.dll" was the offending module. I also set up windows debugging modules with shows the following stack trace (just first few lines at the top): ntdll!RtlpLowFragHeapFree+0x31 (FPO: [Non-Fpo]) 01 0021ed04 76f49c46 00390000 00000000 029e76e0 ntdll!RtlFreeHeap+0x101 02 0021ed18 7718afbd 00390000 00000000 029e76e8 kernel32!HeapFree+0x14 03 0021ed2c 7718afd9 7725f6f8 029e76e8 0021ed54 ole32!CRetailMalloc_Free+0x1c (FPO: [Non-Fpo]) 04 0021ed3c 75be6efc 029e76e8 01f685fe 0021edcc ole32!CoTaskMemFree+0x13 Since the problem arises reproducibly when calling one method the has a pointer to an array as input and output, I believe this is some kind of memory issue (which also the stack trace suggests) that was probably just not recognized/caught by WinXP before but now shows up in more recent windows versions. My assumption is, that either I need to actively allocate or deallocate memory for in/out parameters. This is the method signature of the method that our server provides and that crashes: IOPCItemMgt::ValidateItems HRESULT ValidateItems( [in] DWORD dwCount, [in, size_is(dwCount)] OPCITEMDEF * pItemArray, [in] BOOL bBlobUpdate, [out, size_is(,dwCount)] OPCITEMRESULT ** ppValidationResults, [out, size_is(,dwCount)] HRESULT ** ppErrors ); Assume that this is the signature in python comtypes server: def ValidateItems(self, count, p_item_array, update_blob): and this is the ctypes structure which should be returned in " ppValidationResults ": OpcDa.tagOPCITEMRESULT How would I create these structures (especially ppValidationResults), its contents and the pointers so that I would not create any memory issues, null pointers or whatsoever? My implementation creates a few items by calling validation_result = OpcDa.tagOPCITEMRESULT() filling in the contents with e.g. validation_result.hServer = server_item_handle adding it to a list validation_results.append(validation_result) then converting it to a pointer to an array with a helper function: def p_list(items): c_items = (type(items[0])*len(items))(*items) p_items = cast(c_items, POINTER(type(items[0]))) return p_items (...) p_validation_results = p_list(validation_results) doing the same with "errors" and then returning it: return p_validation_results, p_errors Is that correct? Do I have to keep references to the list, the pointer or the item strcuture objects to avoid them beeing garbage collected? Thanks a lot! -------------------------------------------------------------------------------- > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > https://mail.python.org/mailman/listinfo/python-win32 > From 2281570025 at qq.com Fri Dec 13 13:02:19 2013 From: 2281570025 at qq.com (=?ISO-8859-1?B?aU1hdGg=?=) Date: Fri, 13 Dec 2013 20:02:19 +0800 Subject: [python-win32] how to access SHOpenFolderAndSelectItems() by ctypes Message-ID: I want to build a cross-platform application ,I used a windows API called SHOpenFolderAndSelectItems(). Although I found example called it by pywin32,but pywin32 is not available on Linux , I don't want to call a Windows API on linux,just don't want to make another code version for Linux,so I wonder how to access it by ctypes? yes,this API cannot be called on Linux ,I just want to make it silent in the code so that I can freeze the Python scripts into executables by cx_Freeze without pywin32 module-missing error happend . from win32com.shell import shell, shellcon import os def launch_file_explorer(path, files): ''' Given a absolute base path and names of its children (no path), open up one File Explorer window with all the child files selected ''' folder_pidl = shell.SHILCreateFromPath(path,0)[0] desktop = shell.SHGetDesktopFolder() shell_folder = desktop.BindToObject(folder_pidl, None,shell.IID_IShellFolder) name_to_item_mapping = dict([(desktop.GetDisplayNameOf(item, shellcon.SHGDN_FORPARSING|shellcon.SHGDN_INFOLDER), item) for item in shell_folder]) print(name_to_item_mapping) to_show = [] for file in files: if file in name_to_item_mapping: to_show.append(name_to_item_mapping[file]) # else: # raise Exception('File: "%s" not found in "%s"' % (file, path)) shell.SHOpenFolderAndSelectItems(folder_pidl, to_show, 0) p=r'E:\aa' print(os.listdir(p)) launch_file_explorer(p, os.listdir(p)) -------------- next part -------------- An HTML attachment was scrubbed... URL: From vernondcole at gmail.com Fri Dec 13 18:52:49 2013 From: vernondcole at gmail.com (Vernon D. Cole) Date: Fri, 13 Dec 2013 18:52:49 +0100 Subject: [python-win32] how to access SHOpenFolderAndSelectItems() by ctypes In-Reply-To: References: Message-ID: Right. You can't call a Windows service unless you are on Windows. You will want to build a "shim" function which you call with a generic name. It looks at what operating system it is running on, and then calls the appropriate operating system specific code to perform the operation. The import of the operating system specific routines is done by that inner routine. (I will use dots to replace spaces below.) import sys def launch_file_explorer(foo, bar): ..if sys.platform == 'linux2': ....launch_linux_explorer(foo, bar) ..else: ....launch_win_explorer(foo, bar) def launch_win_explorer(foo, bar): ..from win32.com import shell, shelcon ..# etcetera Remember that "import" is an executable statement. It is not like the "include" compiler directive you may be used to from a "C" like language. It does not look for the imported module until you tell it to at run time. If you never execute the "import" statement, no one cares whether the module is actually present or whether it works. Have you ever tried typing "import antigravity" at a Python command prompt? I think that is the sort of action you want. Look at the standard library source (it is in your Python distribution folders) and read 'antigravity.py' which in turn calls 'webbrowser.py' and see how the experts do it. Happy coding. -- Vernon Cole On Fri, Dec 13, 2013 at 1:02 PM, iMath <2281570025 at qq.com> wrote: > I want to build a cross-platform application ,I used a windows API called > SHOpenFolderAndSelectItems(). > Although I found example called it by pywin32,but pywin32 is not available > on Linux , I don't want to call a Windows API on linux,just don't want to > make another code version for Linux,so I wonder how to access it by ctypes? > yes,this API cannot be called on Linux ,I just want to make it silent in > the code so that I can freeze the Python scripts into executables by > cx_Freeze without pywin32 module-missing error happend . > > from win32com.shell import shell, shellconimport osdef launch_file_explorer(path, files): > ''' > Given a absolute base path and names of its children (no path), open > up one File Explorer window with all the child files selected > ''' > folder_pidl = shell.SHILCreateFromPath(path,0)[0] > desktop = shell.SHGetDesktopFolder() > shell_folder = desktop.BindToObject(folder_pidl, None,shell.IID_IShellFolder) > name_to_item_mapping = dict([(desktop.GetDisplayNameOf(item, shellcon.SHGDN_FORPARSING|shellcon.SHGDN_INFOLDER), item) for item in shell_folder]) > print(name_to_item_mapping) > to_show = [] > for file in files: > if file in name_to_item_mapping: > to_show.append(name_to_item_mapping[file]) > # else: > # raise Exception('File: "%s" not found in "%s"' % (file, path)) > > > shell.SHOpenFolderAndSelectItems(folder_pidl, to_show, 0) > > > > > > > p=r'E:\aa'print(os.listdir(p)) > launch_file_explorer(p, os.listdir(p)) > > > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > https://mail.python.org/mailman/listinfo/python-win32 > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Fri Dec 13 20:05:11 2013 From: timr at probo.com (Tim Roberts) Date: Fri, 13 Dec 2013 11:05:11 -0800 Subject: [python-win32] how to access SHOpenFolderAndSelectItems() by ctypes In-Reply-To: References: Message-ID: <52AB5A67.8050400@probo.com> iMath wrote: > > I want to build a cross-platform application ,I used a windows API > called SHOpenFolderAndSelectItems() > . > Although I found example called it by pywin32,but pywin32 is not > available on Linux , I don't want to call a Windows API on linux,just > don't want to make another code version for Linux,so I wonder how to > access it by ctypes? > Your problem is more fundamental than that. Your function is trying to open a "File Explorer", but the whole concept of a File Explorer is a Windows concept. The Mac has Finder, but there isn't a standard file manager app for Linux. You will have to think about what you are really trying to do on non-Windows systems. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. -------------- next part -------------- An HTML attachment was scrubbed... URL: From 2281570025 at qq.com Fri Dec 13 13:07:54 2013 From: 2281570025 at qq.com (=?ISO-8859-1?B?aU1hdGg=?=) Date: Fri, 13 Dec 2013 20:07:54 +0800 Subject: [python-win32] how to access SHOpenFolderAndSelectItems() by ctypes Message-ID: I want to build a cross-platform application ,I used a windows API called SHOpenFolderAndSelectItems(). Although I found example called it by pywin32,but pywin32 is not available on Linux , I don't want to call a Windows API on linux,just don't want to make another code version for Linux,so I wonder how to access it by ctypes? yes,this API cannot be called on Linux ,I just want to make it silent in the code so that I can freeze the Python scripts into executables by cx_Freeze without pywin32 module-missing error happend . formatted code here http://stackoverflow.com/questions/20565401/how-to-access-shopenfolderandselectitems-by-ctypes from win32com.shell import shell, shellcon import os def launch_file_explorer(path, files): ''' Given a absolute base path and names of its children (no path), open up one File Explorer window with all the child files selected ''' folder_pidl = shell.SHILCreateFromPath(path,0)[0] desktop = shell.SHGetDesktopFolder() shell_folder = desktop.BindToObject(folder_pidl, None,shell.IID_IShellFolder) name_to_item_mapping = dict([(desktop.GetDisplayNameOf(item, shellcon.SHGDN_FORPARSING|shellcon.SHGDN_INFOLDER), item) for item in shell_folder]) print(name_to_item_mapping) to_show = [] for file in files: if file in name_to_item_mapping: to_show.append(name_to_item_mapping[file]) # else: # raise Exception('File: "%s" not found in "%s"' % (file, path)) shell.SHOpenFolderAndSelectItems(folder_pidl, to_show, 0) p=r'E:\aa' print(os.listdir(p)) launch_file_explorer(p, os.listdir(p)) -------------- next part -------------- An HTML attachment was scrubbed... URL: From Jim at JC-Bell.com Sat Dec 14 22:28:41 2013 From: Jim at JC-Bell.com (Jim Bell) Date: Sat, 14 Dec 2013 15:28:41 -0600 Subject: [python-win32] Callback RemQueryInterface gives E_NOINTERFACE Message-ID: <52ACCD89.3010303@JC-Bell.com> I've been though all the demos and scoured the web, and am stumped. But I think I'm close. I have a 3rd-party .dll/.tlb. I run makepy.py and it works fine. I need to pass a callback interface, which they define, into one of their functions. Here's where I'm stumped. gencache.EnsureModule('{F8EF...}', 0, 1, 0) # via makepy -i -v # IID defined in the 3rd-party library... cbIID = IID('{188....}') # valid IID of ITheirCallBack # My callback class... class MyCallBack: _public_methods_ = [ 'GotMsg' ] _com_interfaces_ = [ cbIID ] # as defined above def GotMsg(self, msg): print 'GotMsg: %s' % str(msg) # Hey! # This doesn't work: 'Library not registered' win32com.universal.RegisterInterfaces('{188...}', 0, 1, 0, [ 'ITheirCallBack']) # Instantiate my callback... cbRaw = MyCallBack() # Works fine. # If I pass cbIID as param 2 here, I get 'No such interface supported' cbCom = win32com.server.util.wrap(cbRaw) cliObj = win32com.client.Dispatch('theirlib.Server.1') # Fine! # Crux: we make the call, # but Wireshark shows RemQueryInterface back to us, # for ITheirCallBack/cbIID, # and our machine returns E_NOINTERFACE cliObj.InitServer(cbCom) # Doesn't crash, but fails. From wangmengnansi1045 at sogou-inc.com Sun Dec 15 12:37:40 2013 From: wangmengnansi1045 at sogou-inc.com (=?gb2312?B?V2FuZ01lbmdOYW4o18DD5srC0rWyvyk=?=) Date: Sun, 15 Dec 2013 11:37:40 +0000 Subject: [python-win32] pywintypes.com_error: (-2147221164 Message-ID: <0361EFE72249CA47AE08B5E5D647D8A9072914@SOGOUEXMB01.sogou-inc.com> Hi?All? Sorry to bother you. I have a python2.7 program,my pc's environment is win7,32bit.I want to use win32com,and I have installed win32com for python2.7. When I worte the code"xls = client.Dispatch("Excel.Application")",an error happened: Traceback (most recent call last): File "D:\JackieCodeProject\python\newvenus\excel_yanxiaoqing.py", line 168, in write_to_mysql(r'C:\V4.2.xlsx',"???",1294) File "D:\JackieCodeProject\python\newvenus\excel_yanxiaoqing.py", line 76, in write_to_mysql case_list = getlist_from_excel(file_name) File "D:\JackieCodeProject\python\newvenus\excel_yanxiaoqing.py", line 27, in getlist_from_excel xls = client.Dispatch("Excel.Application") File "C:\Python27\lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx) File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 108, in _GetGoodDispatchAndUserName return (_GetGoodDispatch(IDispatch, clsctx), userName) File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 85, in _GetGoodDispatch IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch) pywintypes.com_error: (-2147221164, '\xc3\xbb\xd3\xd0\xd7\xa2\xb2\xe1\xc0\xe0', None, None) I need you help. -------------- next part -------------- An HTML attachment was scrubbed... URL: From skippy.hammond at gmail.com Mon Dec 16 03:54:52 2013 From: skippy.hammond at gmail.com (Mark Hammond) Date: Mon, 16 Dec 2013 13:54:52 +1100 Subject: [python-win32] Callback RemQueryInterface gives E_NOINTERFACE In-Reply-To: <52ACCD89.3010303@JC-Bell.com> References: <52ACCD89.3010303@JC-Bell.com> Message-ID: <52AE6B7C.6040604@gmail.com> On 15/12/2013 8:28 AM, Jim Bell wrote: > I've been though all the demos and scoured the web, and am stumped. But > I think I'm close. I have a 3rd-party .dll/.tlb. I run makepy.py and it > works fine. I need to pass a callback interface, which they define, > into one of their functions. Here's where I'm stumped. > > gencache.EnsureModule('{F8EF...}', 0, 1, 0) # via makepy -i -v > > # IID defined in the 3rd-party library... > cbIID = IID('{188....}') # valid IID of ITheirCallBack > > # My callback class... > class MyCallBack: > _public_methods_ = [ 'GotMsg' ] > _com_interfaces_ = [ cbIID ] # as defined above > > def GotMsg(self, msg): > print 'GotMsg: %s' % str(msg) # Hey! > > # This doesn't work: 'Library not registered' > win32com.universal.RegisterInterfaces('{188...}', 0, 1, 0, [ > 'ITheirCallBack']) The first param is the UUID of the typelib, not the interface. > > # Instantiate my callback... > cbRaw = MyCallBack() # Works fine. > > # If I pass cbIID as param 2 here, I get 'No such interface supported' > cbCom = win32com.server.util.wrap(cbRaw) This will be due to the failing registration above. HTH, Mark > > cliObj = win32com.client.Dispatch('theirlib.Server.1') # Fine! > > # Crux: we make the call, > # but Wireshark shows RemQueryInterface back to us, > # for ITheirCallBack/cbIID, > # and our machine returns E_NOINTERFACE > cliObj.InitServer(cbCom) # Doesn't crash, but fails. > > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > https://mail.python.org/mailman/listinfo/python-win32 From skippy.hammond at gmail.com Mon Dec 16 03:57:10 2013 From: skippy.hammond at gmail.com (Mark Hammond) Date: Mon, 16 Dec 2013 13:57:10 +1100 Subject: [python-win32] pywintypes.com_error: (-2147221164 In-Reply-To: <0361EFE72249CA47AE08B5E5D647D8A9072914@SOGOUEXMB01.sogou-inc.com> References: <0361EFE72249CA47AE08B5E5D647D8A9072914@SOGOUEXMB01.sogou-inc.com> Message-ID: <52AE6C06.20503@gmail.com> On 15/12/2013 10:37 PM, WangMengNan(?????) wrote: > Hi?All? > > Sorry to bother you. > > I have a python2.7 program,my pc's environment is win7,32bit.I want to > use win32com,and I have installed > > win32com for python2.7. When I worte the code"xls = > client.Dispatch("Excel.Application")",an error happened: > > Traceback (most recent call last): > > _File "D:\JackieCodeProject\python\newvenus\excel_yanxiaoqing.py", line > 168, in _ > > write_to_mysql(r'C:\V4.2.xlsx',"???",1294) > > _File "D:\JackieCodeProject\python\newvenus\excel_yanxiaoqing.py", line > 76, in write_to_mysql_ > > case_list = getlist_from_excel(file_name) > > _File "D:\JackieCodeProject\python\newvenus\excel_yanxiaoqing.py", line > 27, in getlist_from_excel_ > > xls = client.Dispatch("Excel.Application") > > _File "C:\Python27\lib\site-packages\win32com\client\__init__.py", line > 95, in Dispatch_ > > dispatch, userName = > dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx) > > _File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line > 108, in _GetGoodDispatchAndUserName_ > > return (_GetGoodDispatch(IDispatch, clsctx), userName) > > _File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line > 85, in _GetGoodDispatch_ > > IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, > pythoncom.IID_IDispatch) > > pywintypes.com_error: (-2147221164, > '\xc3\xbb\xd3\xd0\xd7\xa2\xb2\xe1\xc0\xe0', None, None) This is "Class not registered". I suspected you have a 64bit version of Python, but only a 32bit version of Excel installed (or vice-versa), but you mention you are running a 32bit environment - are you completely sure about that? Otherwise, it simply seems Excel wasn't correctly installed. HTH, Mark > > I need you help. > > > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > https://mail.python.org/mailman/listinfo/python-win32 > From Jim at JC-Bell.com Mon Dec 16 19:36:21 2013 From: Jim at JC-Bell.com (Jim Bell) Date: Mon, 16 Dec 2013 12:36:21 -0600 Subject: [python-win32] Callback RemQueryInterface gives E_NOINTERFACE In-Reply-To: <52AE6B7C.6040604@gmail.com> References: <52ACCD89.3010303@JC-Bell.com> <52AE6B7C.6040604@gmail.com> Message-ID: <52AF4825.5020203@JC-Bell.com> It works! Thank you! I must have missed this in my myriad iterations. The calls succeed and S_OK replaces E_NOINTERFACE on the wire, as expected. For posterity, a few more notes: I omitted the imports before, but here they are: import win32com.client import win32com.server import win32com.server.util import win32com.universal On 2013-12-15 8:54 PM, Mark Hammond wrote: > On 15/12/2013 8:28 AM, Jim Bell wrote: >> I've been though all the demos and scoured the web, and am stumped. But >> I think I'm close. I have a 3rd-party .dll/.tlb. I run makepy.py and it >> works fine. I need to pass a callback interface, which they define, >> into one of their functions. Here's where I'm stumped. >> >> gencache.EnsureModule('{F8EF...}', 0, 1, 0) # via makepy -i -v >> >> # IID defined in the 3rd-party library... >> cbIID = IID('{188....}') # valid IID of ITheirCallBack >> >> # My callback class... >> class MyCallBack: >> _public_methods_ = [ 'GotMsg' ] >> _com_interfaces_ = [ cbIID ] # as defined above >> >> def GotMsg(self, msg): >> print 'GotMsg: %s' % str(msg) # Hey! >> >> # This doesn't work: 'Library not registered' >> win32com.universal.RegisterInterfaces('{188...}', 0, 1, 0, [ >> 'ITheirCallBack']) > > The first param is the UUID of the typelib, not the interface. # Here's the working line: # '{F8EF...}' as from EnsureModule() above... win32com.universal.RegisterInterfaces('{F8EF...}', 0, 1, 0, [ 'ITheirCallBack' ]) > >> >> # Instantiate my callback... >> cbRaw = MyCallBack() # Works fine. >> >> # If I pass cbIID as param 2 here, I get 'No such interface supported' >> cbCom = win32com.server.util.wrap(cbRaw) > > This will be due to the failing registration above. > > HTH, > > Mark >> >> cliObj = win32com.client.Dispatch('theirlib.Server.1') # Fine! >> >> # Crux: we make the call, >> # but Wireshark shows RemQueryInterface back to us, >> # for ITheirCallBack/cbIID, >> # and our machine returns E_NOINTERFACE >> cliObj.InitServer(cbCom) # Doesn't crash, but fails. >> >> >> _______________________________________________ >> python-win32 mailing list >> python-win32 at python.org >> https://mail.python.org/mailman/listinfo/python-win32 > > From Jim at JC-Bell.com Tue Dec 17 01:15:27 2013 From: Jim at JC-Bell.com (Jim Bell) Date: Mon, 16 Dec 2013 18:15:27 -0600 Subject: [python-win32] Bypassing gen_py, accessing makepy-generated class directly Message-ID: <52AF979F.4020203@JC-Bell.com> I have a somelib.dll/somelib.tlb that doesn't register, and I want to bypass the gen_py mechanism to package it better. I run makepy -o somelib.py. I should be able to instantiate it more directly, not through client.Dispatch(), shouldn't I? Manually wrap it analogously to the server? I see somelib.SomeApplication inherits CoClassBaseClass, and that wants to construct with some sort of object, but what? # Like this import somelib # Not win32com.client.Dispatch(...) app = somelib.SomeApplication(someMagicHere) # Above raises 'Class not registered' if passed None. This thread seemed to be in the ballpark, but I'm still missing something... https://mail.python.org/pipermail/python-win32/2009-December/009860.html And I know that, conceptually, something actually needs to reference the .dll somewhere, and I don't see that happening. (And that sure seems like ctypes domain, too.) Where's my disconnect? From greg.antal at ata-e.com Tue Dec 17 02:39:10 2013 From: greg.antal at ata-e.com (Greg Antal) Date: Mon, 16 Dec 2013 17:39:10 -0800 Subject: [python-win32] Bypassing gen_py, accessing makepy-generated class directly In-Reply-To: <52AF979F.4020203@JC-Bell.com> References: <52AF979F.4020203@JC-Bell.com> Message-ID: <52AFAB3E.80907@ata-e.com> An HTML attachment was scrubbed... URL: From jacob at blindza.co.za Tue Dec 17 04:44:51 2013 From: jacob at blindza.co.za (Jacob Kruger) Date: Tue, 17 Dec 2013 05:44:51 +0200 Subject: [python-win32] Exception handling wrapper/function for something like a whole class Message-ID: <875CBCF8A9B043C2B0EBE07DF0FB22DB@JakesPC> Like subject line says, and while would generally prefer to implement specific pieces of error handling try...except code blocks, etc., per code/functionality section, am currently trying to figure out why a test user is experiencing issues with some code making use of things like user app data file locations, etc., and am not exactly sure how/why/when errors/exceptions are occuring, and since this is happening on something like a windows7 machine with UAC turned on, etc., and since these are currently executing/operating as sort of py2exe 'compiled' applets, it's unable to generate the sort of automatic error log files at the moment either - not sure if relevant, but, used os.chdir to try changing the sort of active/current directory to the app specific user data location early on during instantiation of the classes, etc., but, doesn't seem to affect automated error logging target location as such, and, I think the app trying to then generate those automated error log files is then also raising file system access issues itself. Anyway, while can implement try...except blocks in all of the pieces of code, event handlers, function calls etc., I would like to, for now implement something like where in PHP you can just assign your own function to be the sort of default exception/error handler at some stages, and just wondering how you could possibly do something like that for a class object/element, etc.,such that it could then handle either all, or multiple exception types, etc.? And, if am confused, or targeting the wrong approach, you are also welcome to offer better suggestions/guidelines relating to any form of exception handling approach, etc.? TIA Jacob Kruger Blind Biker Skype: BlindZA '...fate had broken his body, but not his spirit...' -------------- next part -------------- An HTML attachment was scrubbed... URL: From jan.wedel at ettex.de Tue Dec 17 09:36:59 2013 From: jan.wedel at ettex.de (Wedel, Jan) Date: Tue, 17 Dec 2013 08:36:59 +0000 Subject: [python-win32] Missing memory de/allocation in com server causes APPCRASH? In-Reply-To: References: <47EE7F193EDC7E468E74BB0ACFB17929011692C1CA@EX10MBOX1B.hosting.inetserver.de> <47EE7F193EDC7E468E74BB0ACFB17929011692C5FE@EX10MBOX1B.hosting.inetserver.de> Message-ID: <47EE7F193EDC7E468E74BB0ACFB179290135F8D9F0@EX10MBOX1A.hosting.inetserver.de> Hi all, I actually wrote a reply but it seems it has never been sent or I just it to Rogers address instead of the mailing list. To answer your (Rogers) suggestion again: The value that gets partially overwritten is 32Bit where the first 16Bit gets overwritten. Plus, this only happens for the first array element. So I'm pretty sure that this is not directly related to a 32/64 bit problem. However, I would not deny that there is a possibility that another 64Bit issue that indirectly causes this symptom. So, here's the thing: We've traced the problem a bit down. 1. The pointer casting is not necessary. return add_results, errors Is equivalent or at least, it results in the same behavior and problems, AFAIK. 2. Some cases we've tried: - If we create the array, than return it, we see the memory corruption on the client, but not on the server. - If we create the array, but overwrite the elements with new structs in each loop, we can see the first element gets corrupted as soon we assign the second element to a new item. This corruption is already visible on the server side. This is probably caused by creating items in the context of the loop and their references being freed once the loop iterates to the next index. - In both cases (especially in the second case), if we keep python references to the structures by adding them to a python list in self (or the array itself in case 1), the memory corruption is gone at least on the server side. The client never receives the return values but a COMError. We tried to catch exceptions on the server and add trace messages on comtypes but with no luck. There seems to be no exception in the python code. This leads me to the following assumptions: 1. Returning pointers is not sufficient. You need to keep the references to that actual objects to prevent their memory being freed. 2. Keeping the references leads to a strange COMError that must be caused by the COM internals like (un)mashalling for example. Unfortunately, I found no way to get some insights. This a hughe black box where the server inserts some data and the client receives a meaningless error. 3. Windows 7 / Server 2008 behaves differently regarding memory allocation, freeing and. But I still don't have a solution. Does anybody has an idea on how to solve or at least on how to trace down what causes the issue? I'm pretty desperate and thankful for any advice. // Jan -----Urspr?ngliche Nachricht----- Von: python-win32 [mailto:python-win32-bounces+jan.wedel=ettex.de at python.org] Im Auftrag von Roger Upole Gesendet: Freitag, 13. Dezember 2013 01:17 An: python-win32 at python.org Betreff: Re: [python-win32] Missing memory de/allocation in com server causes APPCRASH? I'm guessing you have a 32/64 bit problem, as most XP installs are 32-bit. I'd take a closer look at hServer, since handles are pointer-sized (4 bytes on 32 bit and 8 bytes on x64). Roger "Wedel, Jan" wrote in message news:47EE7F193EDC7E468E74BB0ACFB17929011692C5FE at EX10MBOX1B.hosting.inetserver.de... Ok, being pretty desperate, I tried a few ways of returning the data until I got it partially working. 1. I returned null pointers: return POINTER(OpcDa.tagOPCITEMRESULT)(), POINTER(HRESULT)() Obviously, it did not return any sensible data, but it did not crash! The client actually receives the null pointer which is better that crashing without any information. 2. Using the above knowledge, I tried to refactor the existing code as follows: - creating the arrays in advance: add_results = (OpcDa.tagOPCITEMRESULT*count)() errors = (HRESULT*count)() - looping over all elements of the array and filling in the data: (...) add_results[index].hServer = server_item_handle (...) Errors[index] = HRESULT(S_OK) - returning a new pointer to the arrays return POINTER(OpcDa.tagOPCITEMRESULT)(add_results), POINTER(HRESULT)(errors) - Do not store the arrays in python's "self" Using this procedure, it does not crash the client and it does return data. Now, I am wondering why I had to do this on Win Server 2008 and on Xp the old code worked. However, this led me to next problem: hServer is of type c_ulong which means 4 bytes and is the first element of the tagOPCITEMRESULT structure. Reproducibly, the first two bytes of the first element of the array gets corrupted *somewhere* in the same way, more specifically it gets overwritten to 0x4A00. The value 0x4A doesn't ring any bells that could reveal the cause for that. All following elements of the array are not corrupted. The question is, how could that happen? What could possible overwrite memory? Do I have to prevent freeing memory used by these arrays somehow before returning them via COM? Thanks, //Jan Von: python-win32 [mailto:python-win32-bounces+jan.wedel=ettex.de at python.org] Im Auftrag von Wedel, Jan Gesendet: Mittwoch, 11. Dezember 2013 10:38 An: python-win32 at python.org Betreff: [python-win32] Missing memory de/allocation in com server causes APPCRASH? Hi, I already posted a related question on the comtypes mailing list but unfortunately Thomas Heller told me that he cannot actively provide support anymore. So I'm hoping to get some help here because it might also relate more to ctypes. At first, sorry for the long mail but it's a rather complex issue and I want to provide as much information and context as required. Heres the problem: We wrote a COM server using comtypes which worked well on Win XP. However, on Windows 2008 and Win 7, the same code crashes after calling a specific method that our server provides. By "crashes" I mean the COM client (Tried it with a C++ and python client) receives a COMError: _ctypes.COMError: (-2147417851, 'Ausnahmefehler des Servers.', (None, None, None, 0, None)) The Server does *not* throw any exceptions as far as I can see and keeps on running. I added some printf debugging in comtypes but everything seems fine and ends up calling some win32api functions after message dispatching is done. Every time this happens, in the windows application event log, there is an entry saying "python.exe" was the offending application, "ntdll.dll" was the offending module. I also set up windows debugging modules with shows the following stack trace (just first few lines at the top): ntdll!RtlpLowFragHeapFree+0x31 (FPO: [Non-Fpo]) 01 0021ed04 76f49c46 00390000 00000000 029e76e0 ntdll!RtlFreeHeap+0x101 02 0021ed18 7718afbd 00390000 00000000 029e76e8 kernel32!HeapFree+0x14 03 0021ed2c 7718afd9 7725f6f8 029e76e8 0021ed54 ole32!CRetailMalloc_Free+0x1c (FPO: [Non-Fpo]) 04 0021ed3c 75be6efc 029e76e8 01f685fe 0021edcc ole32!CoTaskMemFree+0x13 Since the problem arises reproducibly when calling one method the has a pointer to an array as input and output, I believe this is some kind of memory issue (which also the stack trace suggests) that was probably just not recognized/caught by WinXP before but now shows up in more recent windows versions. My assumption is, that either I need to actively allocate or deallocate memory for in/out parameters. This is the method signature of the method that our server provides and that crashes: IOPCItemMgt::ValidateItems HRESULT ValidateItems( [in] DWORD dwCount, [in, size_is(dwCount)] OPCITEMDEF * pItemArray, [in] BOOL bBlobUpdate, [out, size_is(,dwCount)] OPCITEMRESULT ** ppValidationResults, [out, size_is(,dwCount)] HRESULT ** ppErrors ); Assume that this is the signature in python comtypes server: def ValidateItems(self, count, p_item_array, update_blob): and this is the ctypes structure which should be returned in " ppValidationResults ": OpcDa.tagOPCITEMRESULT How would I create these structures (especially ppValidationResults), its contents and the pointers so that I would not create any memory issues, null pointers or whatsoever? My implementation creates a few items by calling validation_result = OpcDa.tagOPCITEMRESULT() filling in the contents with e.g. validation_result.hServer = server_item_handle adding it to a list validation_results.append(validation_result) then converting it to a pointer to an array with a helper function: def p_list(items): c_items = (type(items[0])*len(items))(*items) p_items = cast(c_items, POINTER(type(items[0]))) return p_items (...) p_validation_results = p_list(validation_results) doing the same with "errors" and then returning it: return p_validation_results, p_errors Is that correct? Do I have to keep references to the list, the pointer or the item strcuture objects to avoid them beeing garbage collected? Thanks a lot! -------------------------------------------------------------------------------- > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > https://mail.python.org/mailman/listinfo/python-win32 > _______________________________________________ python-win32 mailing list python-win32 at python.org https://mail.python.org/mailman/listinfo/python-win32 From jacob at blindza.co.za Tue Dec 17 10:04:44 2013 From: jacob at blindza.co.za (Jacob Kruger) Date: Tue, 17 Dec 2013 11:04:44 +0200 Subject: [python-win32] Exception handling wrapper/function for somethinglike a whole class In-Reply-To: <875CBCF8A9B043C2B0EBE07DF0FB22DB@JakesPC> References: <875CBCF8A9B043C2B0EBE07DF0FB22DB@JakesPC> Message-ID: <2ED0B7AC89544907A61C42132346CD97@JakesPC> Ok, one thing now came across is the cgitb module, and, the following bit of code somewhere near top might help it at least log errors a bit better: import cgitb, os cgitb.enable(format="text", logdir=os.environ["APPDATA"] + \\appAuthor\\appName) That should then, hopefully, at least generate a form of error/exception log in the location I specify as logdir. Stay well Jacob Kruger Blind Biker Skype: BlindZA '...fate had broken his body, but not his spirit...' ----- Original Message ----- From: Jacob Kruger To: python-win32 at python.org Sent: Tuesday, December 17, 2013 05:44 AM Subject: [python-win32] Exception handling wrapper/function for somethinglike a whole class Like subject line says, and while would generally prefer to implement specific pieces of error handling try...except code blocks, etc., per code/functionality section, am currently trying to figure out why a test user is experiencing issues with some code making use of things like user app data file locations, etc., and am not exactly sure how/why/when errors/exceptions are occuring, and since this is happening on something like a windows7 machine with UAC turned on, etc., and since these are currently executing/operating as sort of py2exe 'compiled' applets, it's unable to generate the sort of automatic error log files at the moment either - not sure if relevant, but, used os.chdir to try changing the sort of active/current directory to the app specific user data location early on during instantiation of the classes, etc., but, doesn't seem to affect automated error logging target location as such, and, I think the app trying to then generate those automated error log files is then also raising file system access issues itself. Anyway, while can implement try...except blocks in all of the pieces of code, event handlers, function calls etc., I would like to, for now implement something like where in PHP you can just assign your own function to be the sort of default exception/error handler at some stages, and just wondering how you could possibly do something like that for a class object/element, etc.,such that it could then handle either all, or multiple exception types, etc.? And, if am confused, or targeting the wrong approach, you are also welcome to offer better suggestions/guidelines relating to any form of exception handling approach, etc.? TIA Jacob Kruger Blind Biker Skype: BlindZA '...fate had broken his body, but not his spirit...' ------------------------------------------------------------------------------ _______________________________________________ python-win32 mailing list python-win32 at python.org https://mail.python.org/mailman/listinfo/python-win32 -------------- next part -------------- An HTML attachment was scrubbed... URL: From opticar at opticar.fr Tue Dec 17 10:53:41 2013 From: opticar at opticar.fr (OptiCar) Date: Tue, 17 Dec 2013 10:53:41 +0100 Subject: [python-win32] monitoring access to files In-Reply-To: References: Message-ID: Hello, i've not found method or module on python to monitor access to file, on linux i've found dazuko, all i found can monitor change, deleting renaming, i've secondarly to monitor process, windows title and user operations, in my research, i found that it is possible to catch the interruption 21 or else, in scribing the adress of our code in Interrution Vector Table, i would like a code wich works in every computer for every interruptions, keyboard, mouse, files.... i think antivirus does done the same way, to "catch" files access. on windows we have pyhook, does any module could catch more than mouse or keyboard, and directly files access? we have to enter deep in computer works in assembler, but i think it could be done. does anybody heard a module or how could we monitor file access, independently of partition table, or system in use. thanks OptiCar From jacob at blindza.co.za Tue Dec 17 11:48:06 2013 From: jacob at blindza.co.za (Jacob Kruger) Date: Tue, 17 Dec 2013 12:48:06 +0200 Subject: [python-win32] monitoring access to files In-Reply-To: References: Message-ID: <06F2C86282EA4970A6DD917FAB73FB2B@JakesPC> In windows at least, I can use os.stat(sFileName) to retrieve file attributes, including modified time, accessed time, etc.? Haven't used it, but, anyway: http://docs.python.org/2/library/os.html#os.stat Jacob Kruger Blind Biker Skype: BlindZA '...fate had broken his body, but not his spirit...' ----- Original Message ----- From: "OptiCar" To: Sent: Tuesday, December 17, 2013 11:53 AM Subject: [python-win32] monitoring access to files > Hello, > i've not found method or module on python to monitor access to file, > on linux i've found dazuko, > all i found can monitor change, deleting renaming, > i've secondarly to monitor process, windows title and user operations, > in my research, i found that it is possible to catch the interruption 21 > or else, > in scribing the adress of our code in Interrution Vector Table, > i would like a code wich works in every computer for every interruptions, > keyboard, mouse, files.... > i think antivirus does done the same way, to "catch" files access. > on windows we have pyhook, > does any module could catch more than mouse or keyboard, and directly > files access? > we have to enter deep in computer works in assembler, but i think it could > be done. > does anybody heard a module or how could we monitor file access, > independently of partition table, or system in use. > thanks > OptiCar > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > https://mail.python.org/mailman/listinfo/python-win32 > From skippy.hammond at gmail.com Tue Dec 17 12:13:53 2013 From: skippy.hammond at gmail.com (Mark Hammond) Date: Tue, 17 Dec 2013 22:13:53 +1100 Subject: [python-win32] Bypassing gen_py, accessing makepy-generated class directly In-Reply-To: <52AF979F.4020203@JC-Bell.com> References: <52AF979F.4020203@JC-Bell.com> Message-ID: <52B031F1.2030806@gmail.com> [oops - resend with cc to list] It should be fine if the typelib itself doesn't register, so long as the objects themselves are registered. You should still run makepy over the typelib normally (so the generated file is still in the normal directory), but generating it to its own file should still work ok too - CoClassBaseClass is defined in win32com.client(.__init__.py) - it's possible the generation with -i doesn't import this and will need a manual fixup) Then you can do something like: ob = win32com.client.Dispatch("The.ClassId") at which point 'ob' is going to be a "dumb dispatch" object as it can't find the typelib. Then, if you ran makepy "normally" you could do: kls = win32com.client.gencache.GetClassForProgID("The.ClassId") # wrap the dumb object in the generated class ob = kls(ob) or with makepy -i, something like: import somelib # wrap the dumb object in the generated class ob = somelib.TheClassName(ob) Hope that answers the question! Mark On 17/12/2013 11:15 AM, Jim Bell wrote: > I have a somelib.dll/somelib.tlb that doesn't register, and I want to > bypass the gen_py mechanism to package it better. I run makepy -o > somelib.py. > > I should be able to instantiate it more directly, not through > client.Dispatch(), shouldn't I? Manually wrap it analogously to the server? > > I see somelib.SomeApplication inherits CoClassBaseClass, and that wants > to construct with some sort of object, but what? > > # Like this > import somelib > # Not win32com.client.Dispatch(...) > app = somelib.SomeApplication(someMagicHere) > # Above raises 'Class not registered' if passed None. > > This thread seemed to be in the ballpark, but I'm still missing > something... > https://mail.python.org/pipermail/python-win32/2009-December/009860.html > > And I know that, conceptually, something actually needs to reference the > .dll somewhere, and I don't see that happening. (And that sure seems > like ctypes domain, too.) > > Where's my disconnect? > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > https://mail.python.org/mailman/listinfo/python-win32 From skippy.hammond at gmail.com Tue Dec 17 12:16:31 2013 From: skippy.hammond at gmail.com (Mark Hammond) Date: Tue, 17 Dec 2013 22:16:31 +1100 Subject: [python-win32] Bypassing gen_py, accessing makepy-generated class directly In-Reply-To: <52B031F1.2030806@gmail.com> References: <52AF979F.4020203@JC-Bell.com> <52B031F1.2030806@gmail.com> Message-ID: <52B0328F.5090605@gmail.com> oops 2 :) - where I said "-i" I meant "-o" Mark On 17/12/2013 10:13 PM, Mark Hammond wrote: > [oops - resend with cc to list] > > It should be fine if the typelib itself doesn't register, so long as the > objects themselves are registered. You should still run makepy over the > typelib normally (so the generated file is still in the normal > directory), but generating it to its own file should still work ok too - > CoClassBaseClass is defined in win32com.client(.__init__.py) - it's > possible the generation with -i doesn't import this and will need a > manual fixup) > > Then you can do something like: > > ob = win32com.client.Dispatch("The.ClassId") > > at which point 'ob' is going to be a "dumb dispatch" object as it can't > find the typelib. Then, if you ran makepy "normally" you could do: > > kls = win32com.client.gencache.GetClassForProgID("The.ClassId") > # wrap the dumb object in the generated class > ob = kls(ob) > > or with makepy -i, something like: > > import somelib > # wrap the dumb object in the generated class > ob = somelib.TheClassName(ob) > > Hope that answers the question! > > Mark > > > On 17/12/2013 11:15 AM, Jim Bell wrote: >> I have a somelib.dll/somelib.tlb that doesn't register, and I want to >> bypass the gen_py mechanism to package it better. I run makepy -o >> somelib.py. >> >> I should be able to instantiate it more directly, not through >> client.Dispatch(), shouldn't I? Manually wrap it analogously to the >> server? >> >> I see somelib.SomeApplication inherits CoClassBaseClass, and that wants >> to construct with some sort of object, but what? >> >> # Like this >> import somelib >> # Not win32com.client.Dispatch(...) >> app = somelib.SomeApplication(someMagicHere) >> # Above raises 'Class not registered' if passed None. >> >> This thread seemed to be in the ballpark, but I'm still missing >> something... >> https://mail.python.org/pipermail/python-win32/2009-December/009860.html >> >> And I know that, conceptually, something actually needs to reference the >> .dll somewhere, and I don't see that happening. (And that sure seems >> like ctypes domain, too.) >> >> Where's my disconnect? >> >> _______________________________________________ >> python-win32 mailing list >> python-win32 at python.org >> https://mail.python.org/mailman/listinfo/python-win32 > From Jim at JC-Bell.com Tue Dec 17 17:00:08 2013 From: Jim at JC-Bell.com (Jim Bell) Date: Tue, 17 Dec 2013 10:00:08 -0600 Subject: [python-win32] Bypassing gen_py, accessing makepy-generated class directly In-Reply-To: <52B0328F.5090605@gmail.com> References: <52AF979F.4020203@JC-Bell.com> <52B031F1.2030806@gmail.com> <52B0328F.5090605@gmail.com> Message-ID: <52B07508.9010009@JC-Bell.com> Thanks everyone for the info. Generating with -o is fine, needs no fixups that I can tell. I was confusing bypassing the gen_py mechanism (which is possible) with bypassing the entire COM registration (which isn't possible). makepy presents everything pythonishly, but ultimately it still needs to be COM, which comes from the COM mechanisms, with types and interfaces, and private ties to the DLL. Going directly to the DLL with ctypes doesn't stand a chance. So that old thread is spot-on: win32com.client.GetObject() is it. On 2013-12-17 5:16 AM, Mark Hammond wrote: > oops 2 :) - where I said "-i" I meant "-o" > > Mark > > On 17/12/2013 10:13 PM, Mark Hammond wrote: >> [oops - resend with cc to list] >> >> It should be fine if the typelib itself doesn't register, so long as the >> objects themselves are registered. You should still run makepy over the >> typelib normally (so the generated file is still in the normal >> directory), but generating it to its own file should still work ok too - >> CoClassBaseClass is defined in win32com.client(.__init__.py) - it's >> possible the generation with -i doesn't import this and will need a >> manual fixup) >> >> Then you can do something like: >> >> ob = win32com.client.Dispatch("The.ClassId") >> >> at which point 'ob' is going to be a "dumb dispatch" object as it can't >> find the typelib. Then, if you ran makepy "normally" you could do: >> >> kls = win32com.client.gencache.GetClassForProgID("The.ClassId") >> # wrap the dumb object in the generated class >> ob = kls(ob) >> >> or with makepy -i, something like: >> >> import somelib >> # wrap the dumb object in the generated class >> ob = somelib.TheClassName(ob) >> >> Hope that answers the question! >> >> Mark >> >> >> On 17/12/2013 11:15 AM, Jim Bell wrote: >>> I have a somelib.dll/somelib.tlb that doesn't register, and I want to >>> bypass the gen_py mechanism to package it better. I run makepy -o >>> somelib.py. >>> >>> I should be able to instantiate it more directly, not through >>> client.Dispatch(), shouldn't I? Manually wrap it analogously to the >>> server? >>> >>> I see somelib.SomeApplication inherits CoClassBaseClass, and that wants >>> to construct with some sort of object, but what? >>> >>> # Like this >>> import somelib >>> # Not win32com.client.Dispatch(...) >>> app = somelib.SomeApplication(someMagicHere) >>> # Above raises 'Class not registered' if passed None. >>> >>> This thread seemed to be in the ballpark, but I'm still missing >>> something... >>> https://mail.python.org/pipermail/python-win32/2009-December/009860.html >>> >>> >>> And I know that, conceptually, something actually needs to reference >>> the >>> .dll somewhere, and I don't see that happening. (And that sure seems >>> like ctypes domain, too.) >>> >>> Where's my disconnect? >>> >>> _______________________________________________ >>> python-win32 mailing list >>> python-win32 at python.org >>> https://mail.python.org/mailman/listinfo/python-win32 >> > > From jcasale at activenetwerx.com Wed Dec 18 01:55:54 2013 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Wed, 18 Dec 2013 00:55:54 +0000 Subject: [python-win32] Setting ownership and permissions Message-ID: I have a situation where I need to remove large directories and in doing so I must take ownership. I get a stack trace about the logon I impersonate generating to many security ids as I recursively iterate and take ownership. What workarounds have you guys utilized in this scenario? I suspect there is room for optimizing the approach I am using, where I pass the sid of the new owner in to this function that leverages the unc path in self.unc: def owner_set(self, owner_sid): new_privs = ( (win32security.LookupPrivilegeValue( '', ntsecuritycon.SE_RESTORE_NAME), win32con.SE_PRIVILEGE_ENABLED), (win32security.LookupPrivilegeValue( '', ntsecuritycon.SE_TAKE_OWNERSHIP_NAME), win32con.SE_PRIVILEGE_ENABLED)) thread = win32api.GetCurrentThread() handle = win32security.OpenThreadToken( thread, win32security.TOKEN_ALL_ACCESS | win32con.TOKEN_ADJUST_PRIVILEGES | win32con.TOKEN_IMPERSONATE, False) win32security.AdjustTokenPrivileges(handle, 0, new_privs) fs = win32security.GetFileSecurity( self.unc, win32security.OWNER_SECURITY_INFORMATION) fs.SetSecurityDescriptorOwner(owner_sid, True) win32security.SetFileSecurity( self.unc, win32security.OWNER_SECURITY_INFORMATION, fs) Thanks, jlc From wangmengnansi1045 at sogou-inc.com Wed Dec 18 08:28:27 2013 From: wangmengnansi1045 at sogou-inc.com (=?utf-8?B?V2FuZ01lbmdOYW4o5qGM6Z2i5LqL5Lia6YOoKQ==?=) Date: Wed, 18 Dec 2013 07:28:27 +0000 Subject: [python-win32] =?utf-8?b?562U5aSNOiAgcHl3aW50eXBlcy5jb21fZXJyb3I6?= =?utf-8?q?_=28-2147221164?= In-Reply-To: <52AE6C06.20503@gmail.com> References: <0361EFE72249CA47AE08B5E5D647D8A9072914@SOGOUEXMB01.sogou-inc.com> <52AE6C06.20503@gmail.com> Message-ID: <0361EFE72249CA47AE08B5E5D647D8A907E1C9@SOGOUEXMB01.sogou-inc.com> Thank you very much. You are right.The problem is my office is not correct.When I reinstalled my Microsoft office, The problem solved.Thank you . Best wishes to you. -----????----- ???: Mark Hammond [mailto:skippy.hammond at gmail.com] ????: 2013?12?16? 10:57 ???: WangMengNan(?????); python-win32 at python.org ??: Re: [python-win32] pywintypes.com_error: (-2147221164 On 15/12/2013 10:37 PM, WangMengNan(?????) wrote: > Hi?All? > > Sorry to bother you. > > I have a python2.7 program,my pc's environment is win7,32bit.I want to > use win32com,and I have installed > > win32com for python2.7. When I worte the code"xls = > client.Dispatch("Excel.Application")",an error happened: > > Traceback (most recent call last): > > _File "D:\JackieCodeProject\python\newvenus\excel_yanxiaoqing.py", > line 168, in _ > > write_to_mysql(r'C:\V4.2.xlsx',"???",1294) > > _File "D:\JackieCodeProject\python\newvenus\excel_yanxiaoqing.py", > line 76, in write_to_mysql_ > > case_list = getlist_from_excel(file_name) > > _File "D:\JackieCodeProject\python\newvenus\excel_yanxiaoqing.py", > line 27, in getlist_from_excel_ > > xls = client.Dispatch("Excel.Application") > > _File "C:\Python27\lib\site-packages\win32com\client\__init__.py", > line 95, in Dispatch_ > > dispatch, userName = > dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx) > > _File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line > 108, in _GetGoodDispatchAndUserName_ > > return (_GetGoodDispatch(IDispatch, clsctx), userName) > > _File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line > 85, in _GetGoodDispatch_ > > IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, > pythoncom.IID_IDispatch) > > pywintypes.com_error: (-2147221164, > '\xc3\xbb\xd3\xd0\xd7\xa2\xb2\xe1\xc0\xe0', None, None) This is "Class not registered". I suspected you have a 64bit version of Python, but only a 32bit version of Excel installed (or vice-versa), but you mention you are running a 32bit environment - are you completely sure about that? Otherwise, it simply seems Excel wasn't correctly installed. HTH, Mark > > I need you help. > > > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > https://mail.python.org/mailman/listinfo/python-win32 > From Jim at JC-Bell.com Wed Dec 18 19:09:26 2013 From: Jim at JC-Bell.com (Jim Bell) Date: Wed, 18 Dec 2013 12:09:26 -0600 Subject: [python-win32] A tale of two COM servers (same py code works differently) Message-ID: <52B1E4D6.6000208@JC-Bell.com> I have two COM servers. One works, the other doesn't, using the same python client code, which seems to work differently behind the scenes. I'm profiling both with SysInternals' ProcMon. Windows7x64, running 32-bit python 2.7.3. The python code isn't much more than: import sys, os import win32.client cli = win32.client.Dispatch('Server.Application.1') # 'Broken.Application.1') Profile for python client, working server: 1. Looks for 'Working.Server.1' in HKCU\Software\Classes, doesn't find it. 2. Looks for it in HKCR\Working.Server.1, finds it. 3. Gets CLSID from above CLSID subkey. 4. Looks for CLSID in HKCU\Software\Classes\Wow6432Node, doesn't find it. *5. Looks for it in HKCR\Wow6432Node\CLSID\{8...}, finds it.* 6. Dispatch() succeeds and we carry on... Profile for python client, broken server: 1. Looks for 'Broken.Application.1' in HKCU\Software\Classes, doesn't find it. 2. Looks for it in HKCR\Broken.Application.1, finds it. 3. Gets CLSID from above CLSID subkey. 4. Looks for CLSID in HKCR\CLSID\{4...}, doesn't find it. *5. **Stops looking and gives up, **throwing pywintypes.com_error: (-2147221164, 'Class not registered', None, None)* So why does it stop looking for one but keep looking for the other? Comparing registry entries for HKCR\Working.Server.1 and HKCR\Broken.Application.1, there's no difference. Each refers to its CLSID, and permissions are the same. Comparing HKCR\Wow6432Node\CLSID\{8...} and HKCR\Wow6432Node\CLSID\{4...}, I see some differences, but the python client never got as far as finding this second one, so how could that matter? -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Wed Dec 18 19:35:43 2013 From: timr at probo.com (Tim Roberts) Date: Wed, 18 Dec 2013 10:35:43 -0800 Subject: [python-win32] A tale of two COM servers (same py code works differently) In-Reply-To: <52B1E4D6.6000208@JC-Bell.com> References: <52B1E4D6.6000208@JC-Bell.com> Message-ID: <52B1EAFF.4010905@probo.com> Jim Bell wrote: > I have two COM servers. One works, the other doesn't, using the same > python client code, which seems to work differently behind the scenes. > I'm profiling both with SysInternals' ProcMon. Windows7x64, running > 32-bit python 2.7.3. The python code isn't much more than: > > import sys, os > import win32.client > > cli = win32.client.Dispatch('Server.Application.1') # > 'Broken.Application.1') > > Profile for python client, working server: > 1. Looks for 'Working.Server.1' in HKCU\Software\Classes, doesn't > find it. > 2. Looks for it in HKCR\Working.Server.1, finds it. > 3. Gets CLSID from above CLSID subkey. > 4. Looks for CLSID in HKCU\Software\Classes\Wow6432Node, doesn't find it. > *5. Looks for it in HKCR\Wow6432Node\CLSID\{8...}, finds it.* > 6. Dispatch() succeeds and we carry on... > > Profile for python client, broken server: > 1. Looks for 'Broken.Application.1' in HKCU\Software\Classes, doesn't > find it. > 2. Looks for it in HKCR\Broken.Application.1, finds it. > 3. Gets CLSID from above CLSID subkey. > 4. Looks for CLSID in HKCR\CLSID\{4...}, doesn't find it. > *5. **Stops looking and gives up, **throwing pywintypes.com_error: > (-2147221164, 'Class not registered', None, None)* > > So why does it stop looking for one but keep looking for the other? Are you absolutely sure that the Python client on the broken server is using a 32-bit Python? 64-bit processes are not subjected to the registry redirection. Is the broken server running the application as a service, or in an elevated context, or in a scheduled task that is running as the system user? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. -------------- next part -------------- An HTML attachment was scrubbed... URL: From Jim at JC-Bell.com Wed Dec 18 20:11:14 2013 From: Jim at JC-Bell.com (Jim Bell) Date: Wed, 18 Dec 2013 13:11:14 -0600 Subject: [python-win32] A tale of two COM servers (same py code works differently) In-Reply-To: <52B1EAC4.8030608@probo.com> References: <52B1E4D6.6000208@JC-Bell.com> <52B1EAC4.8030608@probo.com> Message-ID: <52B1F352.303@JC-Bell.com> On 2013-12-18 12:34 PM, Tim Roberts wrote: > Jim Bell wrote: >> I have two COM servers. .... >> 4. Looks for CLSID in HKCR\CLSID\{4...}, doesn't find it. >> *5. **Stops looking and gives up, **throwing pywintypes.com_error: >> (-2147221164, 'Class not registered', None, None)* >> >> So why does it stop looking for one but keep looking for the other? > > Are you absolutely sure that the Python client on the broken server is > using a 32-bit Python? 64-bit processes are not subjected to the > registry redirection. > > Is the broken server running the application as a service, or in an > elevated context, or in a scheduled task that is running as the system > user? Both client runs are from the same command-line, with just the tag replaced. Same path, env, everything. But it does seem like a 32/64 bit issue somehow. The working one is a demand-started .EXE, and the broken one is a .DLL, but I don't see it getting far enough to care. Both were installed as Admin, as that's the Windows7 way. Script was run non-elevated (both times). Thanks for your thoughts. -Jim -------------- next part -------------- An HTML attachment was scrubbed... URL: From jacob at blindza.co.za Sun Dec 22 06:00:33 2013 From: jacob at blindza.co.za (Jacob Kruger) Date: Sun, 22 Dec 2013 07:00:33 +0200 Subject: [python-win32] wxPython layout based on a form of markup? Message-ID: <2726E3E5EB244E4FB0647A7B38CF828F@JakesPC> Aside from either using layout-by-code, or just working with wxPython itself, is there any form of markup-based wxPython layout implementation known of by anyone, off-hand? As in, a way to control/handle wxPython layout using something like XML, HTML, etc. etc.? Would be perfectly OK to handle effect implementation thereafter, but, since none of the GUI designers have come across seem all that usable to me, am just wondering? Suppose could also try something like the use of iron python inside a slightly older version of MS VS.Net, and see if that could handle wxPython layout for me, and then just try move it back to a sort of stock python implementation, but, just thought might as well ask here first/anyway..? KNow there are also some sort of modules like GTK to handle implementing layout using HTML inside wrappers etc., but, haven't gotten to really trying to use those yet - have run GTK install here, nd while it's there under /python27/lib/site-packages, don't seem to be able to import it as of yet, either, and, part of reason am specifically asking about wxPython is that for UI, tkinter doesn't work well enough with screen readers/accessibility packages, and wxPython is best bet thus far, but, I work primarily in web development, so, yes, would be nice to work with web layout implementation as well... TIA Jacob Kruger Blind Biker Skype: BlindZA '...fate had broken his body, but not his spirit...' -------------- next part -------------- An HTML attachment was scrubbed... URL: From afsal.kurikkal3 at gmail.com Tue Dec 24 20:00:11 2013 From: afsal.kurikkal3 at gmail.com (afsal.kurikkal3 at gmail.com) Date: Wed, 25 Dec 2013 00:30:11 +0530 Subject: [python-win32] ImportError: DLL load failed: The specified procedure could not be found. Message-ID: <52b9d9c3.e7ed440a.5ed9.ffff8158@mx.google.com> perfect -------------- next part -------------- An HTML attachment was scrubbed... URL: From mhysnq1964 at icloud.com Tue Dec 31 11:10:20 2013 From: mhysnq1964 at icloud.com (Sean Murphy) Date: Tue, 31 Dec 2013 21:10:20 +1100 Subject: [python-win32] Win32 GUI for beginners. Message-ID: Hi all. I am very very new to Python. I have read the book on programming for Windows with Python that was released in 2000. The book is very good but doesn't give me the basic information I am seeking. Since I am a beginner programmer. I want to create a GUI windows app with Python. The program has to use default Windows 32 or 64 bit objects. I wish to get the following components: Menu bar Listview Treeview Richedit or a multiline edit field A couple of buttons. All objects must be able to be access by the keyboard. either via tab stops (using the tab or shift tab key) and short cut keys. I have a 70 mb text file that is marked up using YML. I wish to show each section in the edit field. The list view shows the name of each item. The tree view will contain categories. I have seen PYGUI which I am not sure if it is easier then using the MSF approach which the book above mentions. So I really need assistance to progress this home bobbie project to expand my programming skills. Any wikis, documentations, good code examples with explanations, etc I would love to get my hands on. I am reading about 3 or 4 books on Python to get up to speed. But only found one book on Win32 programming. I do not want to have to turn around and learn win32 or MFC. If I have to then please point me towards a good book or resource. Regards Sean From gelonida at gmail.com Tue Dec 31 16:14:11 2013 From: gelonida at gmail.com (Gelonida N) Date: Tue, 31 Dec 2013 16:14:11 +0100 Subject: [python-win32] winpexpect like library keeping process in a 'tty' Message-ID: Hi, pexpect is a python library for non windows OSes allowing to start a process connected to a pseudotty, capture its output and control its input. There is some kind of equivalent module, which is called winpexpect. I noticed one difference however: let's imagine, that I want to launch a Python script with following code print sys.stdout.isatty() # find out whether running in a console then a process started under linux with pexpect still believes it is run in a console, whereas a process started with winpexpect will believe it is NOT running in a console. Is there any way to start a subprocess under Windows, let it believe it is running in a console, but still capture its output? From cyrfer at gmail.com Tue Dec 31 17:47:58 2013 From: cyrfer at gmail.com (John Grant) Date: Tue, 31 Dec 2013 08:47:58 -0800 Subject: [python-win32] Win32 GUI for beginners. In-Reply-To: References: Message-ID: Hi Sean, My opinion is that you would be better served learning Qt. In some ways this additional dependency might cloud matters, but for the features you ask for, Qt will make your development streamlined. You can find more information about the Python bindings at: https://wiki.python.org/moin/PyQt Good luck, John On Dec 31, 2013 3:11 AM, "Sean Murphy" wrote: > Hi all. > > I am very very new to Python. I have read the book on programming for > Windows with Python that was released in 2000. The book is very good but > doesn't give me the basic information I am seeking. Since I am a beginner > programmer. > > I want to create a GUI windows app with Python. The program has to use > default Windows 32 or 64 bit objects. I wish to get the following > components: > > Menu bar > Listview > Treeview > Richedit or a multiline edit field > A couple of buttons. > All objects must be able to be access by the keyboard. either via tab > stops (using the tab or shift tab key) and short cut keys. > > > I have a 70 mb text file that is marked up using YML. I wish to show each > section in the edit field. The list view shows the name of each item. The > tree view will contain categories. > > I have seen PYGUI which I am not sure if it is easier then using the MSF > approach which the book above mentions. > > So I really need assistance to progress this home bobbie project to expand > my programming skills. Any wikis, documentations, good code examples with > explanations, etc I would love to get my hands on. > > I am reading about 3 or 4 books on Python to get up to speed. But only > found one book on Win32 programming. I do not want to have to turn around > and learn win32 or MFC. If I have to then please point me towards a good > book or resource. > > > Regards > Sean > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > https://mail.python.org/mailman/listinfo/python-win32 > -------------- next part -------------- An HTML attachment was scrubbed... URL: From heang.s.lim at gmail.com Tue Dec 31 19:26:22 2013 From: heang.s.lim at gmail.com (Heang Lim) Date: Tue, 31 Dec 2013 11:26:22 -0700 Subject: [python-win32] Win32 GUI for beginners. In-Reply-To: References: Message-ID: Hi Sean, I have been using Qt to automate test cases for the different network security applications and Voice over IP products I used to work on for my current company and my last company for the last ten years. I have built a couple GUI apps using both Qt (PyQt4) and Python scripts for these two companies to run automated tests from the GUI drop-down menus, text boxes, buttons, etc. that I designed using Qt 4 Designer. Qt 4 Designer supports all the various GUI components you mentioned above and more, and you can design it the way you wanted. I recommend using Qt 4 Designer. A few pointers to learn Qt/Qt 4 Designer: 1. Use Qt 4 Designer to design your GUI to start of instead of trying to write the code yourself. Begin by creating a a button, for instance, and keep building and adding more GUI widgets as you go, and save into a file let's called guiApp.ui. Use pyuic4 batch file to compile and convert your widget file into Python code: pyuic4 guiApp.ui -o guiApp.py 2. When you convert your guiApp.ui into guiApp.py, it creates a Python class (e.g Ui_Test_Automation for my apps) with widget objects you need to call to trigger widget actions/signals. You will need to look into guiApp.py Python script to learn to use the objects it creates for various widgets/buttons, drop-down menu, etc. For instance, if you create a push button called RUN_TESTS, pyuic4 will create something like the following: class Ui_Test_Automation(object): def setupUi(self, Test_Automation): self.RUN_TESTS=QtGui.QPushButton(Test_Automation) .... (Google this part as each widget has different actions.signals it can perform) 3. For my GUI apps I created, I have another Python script to import guiApp file I created from step 1 above as follows to run my tests: from guiApp import Ui_Test_Automation 4. When I need to trigger an action for the RUN_TESTS button, the code for that looks something like this: def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.ui = Ui_Test_Automation() QtCore.QObject.connect(self.ui.RUN_TESTS, QtCore.SIGNAL("clicked()"), self.RUN_SELECTED_TESTS) ... def RUN_SELECTED_TESTS(): #This method will run all selected tests on the GUI. 5. Google for sample Qt scripts and how to use and trigger Qt button signals. There are a lot of sample codes out there. I hope this helps. Heang Lim On Tue, Dec 31, 2013 at 9:47 AM, John Grant wrote: > Hi Sean, > My opinion is that you would be better served learning Qt. In some ways > this additional dependency might cloud matters, but for the features you > ask for, Qt will make your development streamlined. You can find more > information about the Python bindings at: > https://wiki.python.org/moin/PyQt > > Good luck, > John > On Dec 31, 2013 3:11 AM, "Sean Murphy" wrote: > >> Hi all. >> >> I am very very new to Python. I have read the book on programming for >> Windows with Python that was released in 2000. The book is very good but >> doesn't give me the basic information I am seeking. Since I am a beginner >> programmer. >> >> I want to create a GUI windows app with Python. The program has to use >> default Windows 32 or 64 bit objects. I wish to get the following >> components: >> >> Menu bar >> Listview >> Treeview >> Richedit or a multiline edit field >> A couple of buttons. >> All objects must be able to be access by the keyboard. either via tab >> stops (using the tab or shift tab key) and short cut keys. >> >> >> I have a 70 mb text file that is marked up using YML. I wish to show each >> section in the edit field. The list view shows the name of each item. The >> tree view will contain categories. >> >> I have seen PYGUI which I am not sure if it is easier then using the MSF >> approach which the book above mentions. >> >> So I really need assistance to progress this home bobbie project to >> expand my programming skills. Any wikis, documentations, good code examples >> with explanations, etc I would love to get my hands on. >> >> I am reading about 3 or 4 books on Python to get up to speed. But only >> found one book on Win32 programming. I do not want to have to turn around >> and learn win32 or MFC. If I have to then please point me towards a good >> book or resource. >> >> >> Regards >> Sean >> _______________________________________________ >> python-win32 mailing list >> python-win32 at python.org >> https://mail.python.org/mailman/listinfo/python-win32 >> > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > https://mail.python.org/mailman/listinfo/python-win32 > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rays at blue-cove.com Tue Dec 31 20:20:59 2013 From: rays at blue-cove.com (RayS) Date: Tue, 31 Dec 2013 11:20:59 -0800 Subject: [python-win32] Win32 GUI for beginners. In-Reply-To: References: Message-ID: <201312311920.rBVJKv2h029915@blue-cove.com> I was in a similar place about 12 years ago, and settled on wx http://wiki.wxpython.org/How%20to%20Learn%20wxPython and BoaConstructor http://sourceforge.net/projects/boa-constructor/, which has served well since. A good book I'd bought is now online http://eduunix.ccut.edu.cn/index2/pdf/Manning.Publications.wxPython.in.Action.Mar.2006.pdf Qt also has a nice widget set and examples etc, but is not LGPL - a factor for me. - Ray >On Dec 31, 2013 3:11 AM, "Sean Murphy" ><mhysnq1964 at icloud.com> wrote: >Hi all. > >I am very very new to Python. I have read the book on programming >for Windows with Python that was released in 2000. The book is very >good but doesn't give me the basic information I am seeking. Since I >am a beginner programmer. > >I want to create a GUI windows app with Python. The program has to >use default Windows 32 or 64 bit objects. I wish to get the >following components: > >Menu bar >Listview >Treeview >Richedit or a multiline edit field >A couple of buttons. >All objects must be able to be access by the keyboard. either via >tab stops (using the tab or shift tab key) and short cut keys. > > >I have a 70 mb text file that is marked up using YML. I wish to show >each section in the edit field. The list view shows the name of each >item. The tree view will contain categories. > >I have seen PYGUI which I am not sure if it is easier then using the >MSF approach which the book above mentions. > >So I really need assistance to progress this home bobbie project to >expand my programming skills. Any wikis, documentations, good code >examples with explanations, etc I would love to get my hands on. > >I am reading about 3 or 4 books on Python to get up to speed. But >only found one book on Win32 programming. I do not want to have to >turn around and learn win32 or MFC. If I have to then please point >me towards a good book or resource. > > >Regards >Sean -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Tue Dec 31 21:06:41 2013 From: timr at probo.com (Tim Roberts) Date: Tue, 31 Dec 2013 12:06:41 -0800 Subject: [python-win32] Win32 GUI for beginners. In-Reply-To: References: Message-ID: <52C323D1.3030808@probo.com> Sean Murphy wrote: > I am very very new to Python. I have read the book on programming for Windows with Python that was released in 2000. The book is very good but doesn't give me the basic information I am seeking. Since I am a beginner programmer. I want to caution you that you have an awful lot of fundamental concepts to get down before you're ready to tackle something like this. You have to learn the Python language, which means learning the concepts of class-based and object-oriented programming. After getting straight-line programming, you'll have to learn the concepts of event-driven programming, which is the paradigm used by all of the modern GUIs. Then, you'll need to learn the idiosyncracies of whatever GUI library you choose, all of which make compromises to mate with the variations in the operating systems they support. > I want to create a GUI windows app with Python. The program has to use default Windows 32 or 64 bit objects. I'm curious to know what you meant by that. Do you simply mean you don't want to buy any components? Because essentially all of the major Python GUI toolkits have their own library of components that are vastly simpler to use than the SDK components. If you REALLY just want to write an MFC program in Python, it's possible to do that using pywin32, but it's not really very Python-like. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc.