[python-win32] creating a long-running Python COM server

2006-09-14 Thread David Goodger
I'm trying to figure out how to create a COM server as part of a
Python GUI app, such that an Excel client can connect to the *already
running* instance of the server in the app. IOW, I want Excel to talk
to the existing Python process, and not start a new one.

BTW, I know very little about win32com; please excuse any mistakes in
terminology. I have a copy of the "Python Programming on Win32" book
[1], and searched the web and the python-win32 archives, but I am
unable to find the information I need.

Any pointers (page nos, URLs, example code)? Thanks.

[1] A borrowed copy; I can't get one of my own (Amazon.ca can't find
me one). Does anyone know of a new edition any time soon?

--
David Goodger 
___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] creating a long-running Python COM server

2006-09-14 Thread David Goodger
I wrote:
> I'm trying to figure out how to create a COM server as part of a
> Python GUI app, such that an Excel client can connect to the *already
> running* instance of the server in the app. IOW, I want Excel to talk
> to the existing Python process, and not start a new one.

This may clarify my issue.  I found this in the VB help:

' Test to see if there is a copy of Microsoft Excel already running.
On Error Resume Next
' Getobject function called without the first argument returns a
' reference to an instance of the application. If the application isn't
' running, an error occurs.
Set MyXL = Getobject(, "Excel.Application")
If Err.Number <> 0 Then ExcelWasNotRunning = True

I'd like to do the same thing with my app.  How can I register the COM
server and/or tell Windows that my application is now running so that
I get the same behavior as the above?  I don't want an instance of my
server class created in a new Python process; I want the existing,
running Python process.

-- 
David Goodger 
___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] creating a long-running Python COM server

2006-09-14 Thread Mark Hammond
Basically, you must:
* Arrange for your process to be started
* In your process, create a COM server object - ie, create an object with
the _public_methods_ etc attributes, then use win32com.server.wrap to wrap
it
* Call pythoncom.RegisterActiveObject passing it this object.

That should be enough to have GetObject attach to your instance.

Mark

> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] Behalf Of David Goodger
> Sent: Friday, 15 September 2006 6:22 AM
> To: python-win32@python.org
> Subject: Re: [python-win32] creating a long-running Python COM server
>
>
> I wrote:
> > I'm trying to figure out how to create a COM server as part of a
> > Python GUI app, such that an Excel client can connect to
> the *already
> > running* instance of the server in the app. IOW, I want
> Excel to talk
> > to the existing Python process, and not start a new one.
>
> This may clarify my issue.  I found this in the VB help:
>
> ' Test to see if there is a copy of Microsoft Excel
> already running.
> On Error Resume Next
> ' Getobject function called without the first argument returns a
> ' reference to an instance of the application. If the
> application isn't
> ' running, an error occurs.
> Set MyXL = Getobject(, "Excel.Application")
> If Err.Number <> 0 Then ExcelWasNotRunning = True
>
> I'd like to do the same thing with my app.  How can I register the COM
> server and/or tell Windows that my application is now running so that
> I get the same behavior as the above?  I don't want an instance of my
> server class created in a new Python process; I want the existing,
> running Python process.
>
> --
> David Goodger 
> ___
> Python-win32 mailing list
> Python-win32@python.org
> http://mail.python.org/mailman/listinfo/python-win32
>

___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


[python-win32] Re: How to implement a COM interface (that is not part

2006-09-14 Thread Roger Upole
Ken Channing wrote:

> Hi -- the COM object I'm working on has a number of methods I am able
> to use fairly well by following the various win32com examples around.
> 
> However, one of the methods' arguments takes a callback that
> "implements an interface" (I'm new to win COM terminology but I think
> this phrase has a specific context when applied here -- my guess is an
> 'interface' is similar to a 'template' in C++?).
> 
> I searched for examples of implementing callbacks such as this one:
> 
> class ContextEvents(win32com.client.getevents("SAPI.SpSharedRecoContext")):
>   """Called when a word/phrase is successfully recognized  -
>   ie it is found in a currently open grammar with a sufficiently high
>   confidence"""
>   def OnRecognition(self, StreamNumber, StreamPosition,
> RecognitionType, Result):
>   newResult = win32com.client.Dispatch(Result)
>   print "You said: ",newResult.PhraseInfo.GetText()
> 
> However, in my case, the interface is not associated with any class
> that I can find,
> so I can't use DispatchWithEvents or getevents to get an object to
> subclass from.  (When I try to use getevents on the clsid of the
> interface from the makepy generated file, it returns None)
> 
> I think the post here outlines a similar problem:
> http://mail.python.org/pipermail/python-win32/2004-May/001990.html
> 
> Is there some obvious way to do this that I'm missing?
> In the VB version of the program I'm trying to re-implement in python,
> it seems to be able to
> implement the interface by simply calling "Implements Foo" and subclassing by
> "Private Sub Foo_OnSomeEvent(..."
> 
> Thanks for any help!

You should be able to implement it just as you would a small COM server.
Basically, your class would need to specify the interface with
 _com_interfaces_=[iid of Foo]
and define an event method.
def OnSomeEvent(self,.):

 Roger



___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


[python-win32] iTunes 7 vs Juice: ugly!

2006-09-14 Thread Garth T Kidd
Ladies and gentlemen of the jury, I throw myself on your mercy.

Can anyone help me nut out what happened to the COM interface to
iTunes with the iTunes 7 upgrade?

iface = "iTunes.Application"
iTunes = win32com.client.dynamic.Dispatch(iface)
iTunes.Stop()

... used to work just fine. Now we get AttributeError for everything.
I'm trying both static and dynamic dispatch, with no success, yet the
makepy output shows lots of familiar interfaces.

I'd much appreciate ANY help anyone can offer with this one. We don't
necessarily have that much in the way of market-share with Juice, but
with the size of the market there are still tens of thousands of users
I'd prefer not to leave in the lurch...

Yours,
Garth.
___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] iTunes 7 vs Juice: ugly!

2006-09-14 Thread David Nicolson
Hi Garth,

I've been developing a py2exe app that dispatches a COM object since  
iTunes 4 and I've seen this problem a bit.

I'm not exactly sure what causes it, I think in certain circumstances  
the iTunes installer can fail to register the type library.  
Reinstalling iTunes usually solves the problem. It also seems as  
though win32com and py2exe are more sensitive to this.

Dave


On 15/09/2006, at 1:28 PM, Garth T Kidd wrote:

> Ladies and gentlemen of the jury, I throw myself on your mercy.
>
> Can anyone help me nut out what happened to the COM interface to
> iTunes with the iTunes 7 upgrade?
>
> iface = "iTunes.Application"
> iTunes = win32com.client.dynamic.Dispatch(iface)
> iTunes.Stop()
>
> ... used to work just fine. Now we get AttributeError for everything.
> I'm trying both static and dynamic dispatch, with no success, yet the
> makepy output shows lots of familiar interfaces.
>
> I'd much appreciate ANY help anyone can offer with this one. We don't
> necessarily have that much in the way of market-share with Juice, but
> with the size of the market there are still tens of thousands of users
> I'd prefer not to leave in the lurch...
>
> Yours,
> Garth.



___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32