From Jim.Vickroy@noaa.gov Wed Apr 3 16:50:12 2002 From: Jim.Vickroy@noaa.gov (Jim Vickroy) Date: Wed, 03 Apr 2002 09:50:12 -0700 Subject: [python-win32] Help creating simple COM example Message-ID: <3CAB32C4.28FD5180@noaa.gov> I am unable to properly create and use a simple COM server. Here is the script: class PyCOMtest_3: _public_methods_ = ['hits'] _reg_progid_ = 'PyCOM.Test3' _reg_clsid_ = '{F7F5808C-7280-4545-9F88-8DC2A395D039}' current_value = 0 def hits(self): self.current_value += 1 return self.current_value if __name__ == '__main__': import win32com.server.register win32com.server.register.UseCommandLine(PyCOMtest_3) Now, here is an interactive session after registering it: >>> Registered: PyCOM.Test3 >>> pct = win32com.client.Dispatch('PyCOM.Test3') Traceback (most recent call last): File "", line 1, in ? File "C:\Python22\lib\site-packages\win32com\client\__init__.py", line 92, in Dispatch dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx) File "C:\Python22\lib\site-packages\win32com\client\dynamic.py", line 81, in _GetGoodDispatchAndUserName return (_GetGoodDispatch(IDispatch, clsctx), userName) File "C:\Python22\lib\site-packages\win32com\client\dynamic.py", line 72, in _GetGoodDispatch IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch) com_error: (-2147221231, 'ClassFactory cannot supply requested class', None, None) What am I doing that is incorrect? Thanks. From niki@vintech.bg Thu Apr 4 08:32:05 2002 From: niki@vintech.bg (Niki Spahiev) Date: Thu, 04 Apr 2002 11:32:05 +0300 Subject: [python-win32] Help creating simple COM example References: <3CAB32C4.28FD5180@noaa.gov> Message-ID: <3CAC0F85.2040207@vintech.bg> Jim Vickroy wrote: > I am unable to properly create and use a simple COM server. > > Here is the script: > > class PyCOMtest_3: > _public_methods_ = ['hits'] > _reg_progid_ = 'PyCOM.Test3' > _reg_clsid_ = '{F7F5808C-7280-4545-9F88-8DC2A395D039}' > current_value = 0 > > def hits(self): > self.current_value += 1 > return self.current_value > > if __name__ == '__main__': > import win32com.server.register > win32com.server.register.UseCommandLine(PyCOMtest_3) > > > Now, here is an interactive session after registering it: > > >>>>Registered: PyCOM.Test3 >>>>pct = win32com.client.Dispatch('PyCOM.Test3') >>> > Traceback (most recent call last): > File "", line 1, in ? > File "C:\Python22\lib\site-packages\win32com\client\__init__.py", line > 92, in Dispatch > dispatch, userName = > dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx) > File "C:\Python22\lib\site-packages\win32com\client\dynamic.py", line > 81, in _GetGoodDispatchAndUserName > return (_GetGoodDispatch(IDispatch, clsctx), userName) > File "C:\Python22\lib\site-packages\win32com\client\dynamic.py", line > 72, in _GetGoodDispatch > IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, > pythoncom.IID_IDispatch) > com_error: (-2147221231, 'ClassFactory cannot supply requested class', > None, None) > > > What am I doing that is incorrect? > You can't test python com server from same python process. Niki Spahiev From dave@primco.org Thu Apr 4 10:53:34 2002 From: dave@primco.org (David Primmer) Date: Thu, 4 Apr 2002 02:53:34 -0800 Subject: [python-win32] launching Word with COM..how to tell when it's closed? Message-ID: <000201c1dbc6$f8447c90$6400a8c0@redcloud> I have a wxWindows application that is starting a Word session from a button click with self.w = win32com.client.Dispatch("Word.Application") and I'd like to have Word be "modal" so that the user cannot do anything in my app while Word is open (I'm editing data with it). Is there any event that Word would trigger that I could capture to know when the user has saved and closed Word? I can test for the presence of the Word object within my program but I'm guessing that would require some kind of polling mechanism (I'm not sure how to do that either). Would I have to make my app a COM server and then send a message from Word when it closes? Don't really want to mess with something like that. Any ideas are appreciated. Thanks. davep From jens.jorgensen@tallan.com Thu Apr 4 15:28:33 2002 From: jens.jorgensen@tallan.com (Jens B. Jorgensen) Date: Thu, 04 Apr 2002 09:28:33 -0600 Subject: [python-win32] launching Word with COM..how to tell when it's closed? References: <000201c1dbc6$f8447c90$6400a8c0@redcloud> Message-ID: <3CAC7121.605@tallan.com> I'm going to say a good way to go (and one of few ways to go, to be sure) will be to get the process ID of the Word.exe process, open a handle on that process with syncronize permissions, and just WaitForSingleObject(...) on the handle. Just waiting on the handle should mean that the message loop cannot be run and thus you app will be hung until it returns. You app being hung may be a bit much in terms of not letting the user touch your app until Word exits since the app won't even repaint itself then and users might freak out. Unless there's some method in the Word app object that'll get you the process Id I'm guessing the only thing you can do to get the process id is to get a list of processes and just pick the first one called Word. The way to get a list of processes is to use the windows performance monitoring API. I've got a PerfData module that processes performance data blocks and a pyRegistry module that can properly get the performance data using the Registry interface. Here's an example I've cut out of an app I use: # query performance data to get the Process Id of # the CQMULATE process perf_data = PerfData.query('Process') pobj = perf_data.getObjectByName('Process') # look for the CQMULATE process try : ids = pobj.getCounterValue('CQMULATE', 'ID Process') except ValueError, e : try : s.send('CQMULATE process not running, will sleep for 10 seconds\r\n') if WaitForSingleObject(self.hWaitStop, 10*1000) == WAIT_OBJECT_0 : s.send('*** service shutting down***\r\n') s.close() return except socket.error, se : client_connected = 0 continue # now we have to open the process so we can wait on the # handle proch = OpenProcess(win32con.SYNCHRONIZE, 0, ids[0]) You can pick up my PerfData.py module from http://www.ultraemail.net/~jbj1/PerfData.py and find my pyRegistry module which you'll also need on http://www.ultraemail.net/~jbj1 David Primmer wrote: >I have a wxWindows application that is starting a Word session from a >button click with self.w = win32com.client.Dispatch("Word.Application") >and I'd like to have Word be "modal" so that the user cannot do anything >in my app while Word is open (I'm editing data with it). Is there any >event that Word would trigger that I could capture to know when the user >has saved and closed Word? > >I can test for the presence of the Word object within my program but I'm >guessing that would require some kind of polling mechanism (I'm not sure >how to do that either). > >Would I have to make my app a COM server and then send a message from >Word when it closes? Don't really want to mess with something like that. > >Any ideas are appreciated. Thanks. > >davep > > > >_______________________________________________ >Python-win32 mailing list >Python-win32@python.org >http://mail.python.org/mailman/listinfo/python-win32 > -- Jens B. Jorgensen jens.jorgensen@tallan.com From dave@primco.org Wed Apr 10 16:26:55 2002 From: dave@primco.org (David Primmer) Date: Wed, 10 Apr 2002 08:26:55 -0700 Subject: [python-win32] launching Word with COM..how to tell when it's closed? In-Reply-To: <3CAC7121.605@tallan.com> Message-ID: <000a01c1e0a4$260dc6e0$6400a8c0@redcloud> I'm still working on this problem but I think using the DocumentBeforeClose event in Word to send a message to users would be sufficient. However, there are a few problems with how I set this up from python. First, I'm editing html pages so I don't have a template that I can store macros / modules in. how do I copy a macro to the Word Doc at runtime and then call it from python? I've read that you can do Modules.Add() or something but I've got nothing else to go on. It says I need to do a Class Module for the event handler code. I have followed the Word instructions for implementing DocumentBeforeClose and I have it working. I'm thinking that since I have a word application object already in python I don't have to do all the Class Module stuff that I did within Word but this is a guess. However, it does say that I need to " declare an object of type Application with events" Is this any different, and if so, is there a special way to declare this kind of app object? Once I have that, I'm guessing that I can do the Register_Event_Handler() from within python. Or maybe I can do it all from within python???? Here's the DocumentBeforeClose function as it would appear in Word: Private Sub appWord_DocumentBeforeClose _ (ByVal Doc As Document, _ Cancel As Boolean) Dim intResponse As Integer intResponse = MsgBox("Do you really " _ & "want to close the document?", _ vbYesNo) If intResponse = vbNo Then Cancel = True End Sub >From Word VBA help: Before you can write procedures for the events of the Application object, you must create a new class module and declare an object of type Application with events. For example, assume that a new class module is created and called EventClassModule. The new class module contains the following code. Public WithEvents App As Word.Application >From word VBA help: Before the procedure will run, you must connect the declared object in the class module (App in this example) with the Application object. You can do this with the following code from any module. Dim X As New EventClassModule Sub Register_Event_Handler() Set X.App = Word.Application End Sub Run the Register_Event_Handler procedure. After the procedure is run, the App object in the class module points to the Microsoft Word Application object, and the event procedures in the class module will run when the events occur. > David Primmer wrote: > > >I have a wxWindows application that is starting a Word session from a > >button click with self.w = win32com.client.Dispatch("Word.Application") > >and I'd like to have Word be "modal" so that the user cannot do anything > >in my app while Word is new Object . Is there any > >event that Word would trigger that I could capture to know when the user > >has saved and closed Word? > > > >I can test for the presence of the Word object within my program but I'm > >guessing that would require some kind of polling mechanism (I'm not sure > >how to do that either). > > > >Would I have to make my app a COM server and then send a message from > >Word when it closes? Don't really want to mess with something like that. > > > >Any ideas are appreciated. Thanks. > > > >davep > > > > > > > >_______________________________________________ > >Python-win32 mailing list > >Python-win32@python.org > >http://mail.python.org/mailman/listinfo/python-win32 > > > > > -- > Jens B. Jorgensen > jens.jorgensen@tallan.com From jeff@ccvcorp.com Wed Apr 10 21:36:53 2002 From: jeff@ccvcorp.com (Jeff Shannon) Date: Wed, 10 Apr 2002 13:36:53 -0700 Subject: [python-win32] launching Word with COM..how to tell when it's closed? References: <20020410160007.12722.15052.Mailman@mail.python.org> Message-ID: <3CB4A265.6A7C119F@ccvcorp.com> > "David Primmer" wrote: > > I'm thinking that since I have a word application object already in > python I don't have to do all the Class Module stuff that I did within > Word but this is a guess. However, it does say that I need to " declare > an object of type Application with events" Is this any different, and if > so, is there a special way to declare this kind of app object? Yes, there is a special way. You first need to create a class that has methods implementing your event handlers: class WordEvents: def DocumentBeforeClose(self, Doc, Cancel): [...] # perform your checking, etc, here Then, instead of the usual way to create a COM object in Python, you use a special version that combines the COM wrapper with your event handler class: wordobj = win32com.client.DispatchWithEvents('Word.Application', WordEvents) # replaces wordobj = win32com.client.Dispatch('Word.Application') Now, provided that you've given your event handler functions the correct call signature (as defined by Word), they should be called automatically whenever the appropriate event happens in Word. (No need to explicitly register each event handler.) If you're doing *any* amount of COM work in Python, and especially if you're scripting MS Office, I cannot recommend strongly enough the book "Python Programming on Win32", by Mark Hammond and Andy Robinson (O'Reilly). It has detailed explanations and examples, including lots of working code for controlling Excel, and lots of examples of interacting with Visual Basic. Jeff Shannon Technician/Programmer Credit International From ianb@colorstudy.com Thu Apr 11 04:05:34 2002 From: ianb@colorstudy.com (Ian Bicking) Date: 10 Apr 2002 22:05:34 -0500 Subject: [python-win32] Drag and drop on Windows Message-ID: <1018494334.495.891.camel@localhost> I would like be able to drag files (or folders) onto a script in Windows, but I perhaps am not using the right words to get good search results. Could someone give me a hint as to where I look? Ian From amapy@snafu.de Thu Apr 11 12:04:46 2002 From: amapy@snafu.de (amapy@snafu.de) Date: Thu, 11 Apr 2002 11:04:46 GMT Subject: [python-win32] Some troubles with COMObject of the ClearCase Automation Library 4.1 Message-ID: This is a multi-part message in MIME format. --MailMan_Boundary Content-Type: text/plain --MailMan_Boundary Content-Type: text/plain; name="ccautoerror.txt" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="ccautoerror.txt" SGkgYWxsLA0KDQpJJ3ZlIHdyaXR0ZW4gYSBsaXR0bGUgc2NyaXB0IHVzaW5nIHRoZSBDbGVhckNh c2UgQXV0b21hdGlvbiBMaWJyYXJ5IDQuMQ0KDQpXaGVuIEknbSB0cnlpbmcgdG8gZ2V0IHRoZSBI aXN0b3J5UmVjb3JkcyBvZiBvbmUgZWxlbWVudCB0aGlzIGVycm9yIG1lc3NhZ2UNCmFwcGVhcnM6 DQotLS0tLS0tLS0tLS0tLS0tLS0NCj4+PiBoaXN0ID0gRWxlbS5IaXN0b3J5UmVjb3JkcygwKQ0K VHJhY2ViYWNrIChtb3N0IHJlY2VudCBjYWxsIGxhc3QpOg0KICBGaWxlICJDOlx3aW4zMmFwcFxQ eXRob24yMVxsaWJcc2l0ZS1wYWNrYWdlc1x3aW4zMmNvbVxjbGllbnRcZHluYW1pYy5weSIsIGxp bmUgMjc5LCBpbiBfbWFrZV9tZXRob2RfDQogICAgY29kZU9iamVjdCA9IGNvbXBpbGUobWV0aG9k Q29kZSwgIjxDT01PYmplY3QgJXM+IiAlIHNlbGYuX3VzZXJuYW1lXywiZXhlYyIpDQogIEZpbGUg IjxzdHJpbmc+IiwgbGluZSAxDQogICAgIGRlZiBIaXN0b3J5UmVjb3JkcyhzZWxmLCBwSUNDQnJh bmNoVHlwZT1weXRob25jb20uTWlzc2luZywgU2luY2U9PHRpbWUgb2JqZWN0IGF0IDAxM0JCMjQw PiwgVXNlcj0nJywgTWlub3I9MCwgRXhjbHVkZUNoZWNrT3V0RXZlbnRzPTAsIFJlY3Vyc2U9MCwg RGlyZWN0b3J5T25seT0wKToNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBeDQogU3ludGF4RXJyb3I6IGludmFsaWQg c3ludGF4DQpUcmFjZWJhY2sgKG1vc3QgcmVjZW50IGNhbGwgbGFzdCk6DQogIEZpbGUgIjxpbnRl cmFjdGl2ZSBpbnB1dD4iLCBsaW5lIDEsIGluID8NClR5cGVFcnJvcjogb2JqZWN0IG9mIHR5cGUg J05vbmUnIGlzIG5vdCBjYWxsYWJsZQ0KLS0tLS0tLS0tLS0tLS0NCkl0IHNlZW1zLCB0aGVyZSBp cyBzb21lIHRyb3VibGUgd2l0aCB0aGUgdGltZSBvYmplY3QuDQoNClRoZSBJREwtU3ludGF4IGZv ciB0aGUgSGlzdG9yeVJlY29yZHMgTWV0aG9kIGxvb2tzIGxpa2UgdGhpczoNCi0tLS0tLS0tLS0t LS0tLS0tLS0tLS0tLS0tLS0tLS0tDQogICAgICAgIFtpZCgweDAwMDAwMDA1KSwgcHJvcGdldCwg aGVscHN0cmluZygiR2V0cyB0aGUgY29sbGVjdGlvbiBvZiBoaXN0b3J5IHJlY29yZHMgZm9yIHRo aXMgb2JqZWN0IiksIGhlbHBjb250ZXh0KDB4MDAwMDBjODUpXQ0KICAgICAgICBIUkVTVUxUIEhp c3RvcnlSZWNvcmRzKA0KICAgICAgICAgICAgICAgICAgICAgICAgW2luXSBJQ0NCcmFuY2hUeXBl KiBwSUNDQnJhbmNoVHlwZSwNCiAgICAgICAgICAgICAgICAgICAgICAgIFtpbiwgb3B0aW9uYWws IGRlZmF1bHR2YWx1ZSgwMDowMDowMCldIERBVEUgU2luY2UsDQogICAgICAgICAgICAgICAgICAg ICAgICBbaW4sIG9wdGlvbmFsLCBkZWZhdWx0dmFsdWUoIiIpXSBCU1RSIFVzZXIsDQogICAgICAg ICAgICAgICAgICAgICAgICBbaW4sIG9wdGlvbmFsLCBkZWZhdWx0dmFsdWUoMCldIFZBUklBTlRf Qk9PTCBNaW5vciwNCiAgICAgICAgICAgICAgICAgICAgICAgIFtpbiwgb3B0aW9uYWwsIGRlZmF1 bHR2YWx1ZSgwKV0gVkFSSUFOVF9CT09MIEV4Y2x1ZGVDaGVja091dEV2ZW50cywNCiAgICAgICAg ICAgICAgICAgICAgICAgIFtpbiwgb3B0aW9uYWwsIGRlZmF1bHR2YWx1ZSgwKV0gVkFSSUFOVF9C T09MIFJlY3Vyc2UsDQogICAgICAgICAgICAgICAgICAgICAgICBbaW4sIG9wdGlvbmFsLCBkZWZh dWx0dmFsdWUoMCldIFZBUklBTlRfQk9PTCBEaXJlY3RvcnlPbmx5LA0KICAgICAgICAgICAgICAg ICAgICAgICAgW291dCwgcmV0dmFsXSBJQ0NIaXN0b3J5UmVjb3JkcyoqIHBIaXN0b3J5UmVjb3Jk cyk7DQogICAgICAgIFtpZCgweDAwMDAwMDA2KSwgcHJvcGdldCwgaGVscHN0cmluZygiR2V0cyB0 aGUgY29sbGVjdGlvbiBvZiBoeXBlcmxpbmtzIGFzc29jaWF0ZWQgd2l0aCB0aGlzIFZPQiBvYmpl Y3QiKSwgaGVscGNvbnRleHQoMHgwMDAwMGM4NildDQotLS0tLS0tLS0tLS0tLQ0KDQpJZiB5b3Ug bmVlZCBtb3JlIGluZm9ybWF0aW9uLCBwbGVhc2UgbGV0IG1lIGtub3cNCg0KTWFueSBUaGFua3MN Cg0KQW5kcmVhcw0K --MailMan_Boundary-- From amapy@snafu.de Thu Apr 11 12:16:41 2002 From: amapy@snafu.de (amapy@snafu.de) Date: Thu, 11 Apr 2002 11:16:41 GMT Subject: [python-win32] Some troubles with COMObject of the ClearCase Automation Library 4.1 Message-ID: Sorry, I had some troubles with my mail web-interface :-( Here is the message again: Hi all, I've written a little script using the ClearCase Automation Library 4.1 When I'm trying to get the HistoryRecords of one element this error message appears: ------------------ >>> hist = Elem.HistoryRecords(0) Traceback (most recent call last): File "C:\win32app\Python21\lib\site-packages\win32com\client\dynamic.py", line 279, in _make_method_ codeObject = compile(methodCode, "" % self._username_,"exec") File "", line 1 def HistoryRecords(self, pICCBranchType=pythoncom.Missing, Since=