[wxPython] Frames within Excel

Niki Spahiev wrote:

Is this COM DLL server? I am interested in using wxPython as DLL plugin.

Yes, it is a COM DLL server. I had to do a few tricks to get it working as
you cannot use functions from within excel(2000) if they are defined in a
COM server, except from within VBA. I wrote a little excel .xla to load the
com server and forward the function calls to the python server.

You would call your python code in the following manner
=FTCall("date.AddDays,A11,10), within a cell. The FTCall function is
implemented in the .xla. The .xla then forwards the call and parameters to a
method defined in the com server. The com server then calls the correct
python method with the parameters.

This works extremely well for us. Once the .xla is written no futher
development work in VBA is required and you can write extensions to excel
with python.

You can pop dialogs, get values from excel, set values in excel etc.

If anyone else is interested I could elaborate a little more and maybe set
up a document on how to do this.

Regards
Gerrit van Dyk

···

-------------------------------------------------------------------------
This e-mail is intended only for the use of the individual or entity named
above and may contain information that is confidential and privileged,
proprietary to the company and protected by law. If you are not the intended
recipient, you are hereby notified that any dissemination, distribution or
copying of this e-mail is strictly prohibited. Opinions, conclusions and
other information in this message that do not relate to the official
business of our company shall be understood as neither given nor endorsed by
it.

Gerrit Van Dyk wrote:

Niki Spahiev wrote:

Is this COM DLL server? I am interested in using wxPython as DLL plugin.

Yes, it is a COM DLL server. I had to do a few tricks to get it working as
you cannot use functions from within excel(2000) if they are defined in a
COM server, except from within VBA. I wrote a little excel .xla to load the
com server and forward the function calls to the python server.

I am more interested in wxPython side. I was unable to start wxPython UI from COM server (not from excel). Can you share some hints?

regards,
Niki Spahiev

Niki Spahiev wrote:

Gerrit Van Dyk wrote:
> Niki Spahiev wrote:
>>Is this COM DLL server? I am interested in using wxPython as DLL plugin.
>
> Yes, it is a COM DLL server. I had to do a few tricks to get it working as
> you cannot use functions from within excel(2000) if they are defined in a
> COM server, except from within VBA. I wrote a little excel .xla to load the
> com server and forward the function calls to the python server.

I am more interested in wxPython side. I was unable to start wxPython UI
from COM server (not from excel). Can you share some hints?

I've got a wxPython UI running from within a COM server as well. There are some
issues with it still, but it (mostly) works, and I think I could resolve most of
those issues if I went over my code a bit more carefully...

The basic idea is that I have two threads, the COMserver thread and the wxPython
thread. The COMserver, on setup, creates the secondary thread, and a pair of
Queues for passing commands and data back and forth. When COM methods are
called, the parameters are attached to a command-token object as parameters, and
that object is dropped into the input queue. The secondary thread then creates
my wxPython app, and uses an idle event handler to check the input queue for
commands. When it finds one, it runs the appropriate method(s), attaches any
results to the command object, and dumps it back in the response queue.

The biggest issue with this is in ensuring that wxPython.wx is only imported from
the second thread. I managed this by only importing my App-module from within
the thread's run() method. (But I think I may have some other module getting
imported into the COM thread, because I get occasional errors to that effect when
starting up the program on Win2k (but not Win98) -- it works fine if I just hit
"cancel" though.)

There are also some problems with the application exiting. For some reason,
having the wxApp object handle an Exit request from the COM thread by simply
closing all the windows, resulted in the application locking up. It seems to
(almost) work if I follow that with wxApp.ExitMainloop() -- except that the
windows are then not removed from the display until some other event is sent to
one of them (mousing over them, for instance), at which point they all close. I
should be able to work around this by generating and sending some bogus event,
but haven't had the opportunity to do this quite yet.

(FWIW, the COM client in this case is a terminal emulator connected to a Pick
database host. It provides a COM bridge to allow routines on the host to call
COM objects on the local machine. The wxPython app displays a series of images
under the control of the database host.)

Jeff Shannon
Technician/Programmer
Credit International

If anyone else is interested I could elaborate a little more and maybe set
up a document on how to do this.

The wiki would be a good place for it.

···

--
Robin Dunn
Software Craftsman
robin@AllDunn.com Java give you jitters?
http://wxPython.org Relax with wxPython!