Hi,
What I'm trying to do is to get the events which appear in MsWord's toolbar.
Thanks a million,
Radu.
----- Original Message ----
From: Thomas Heller <[EMAIL PROTECTED]>
To: comtypes-users@lists.sourceforge.net
Sent: Thursday, October 25, 2007 2:49:35 PM
Subject: Re: [comtypes-users] Generate word commandbar interface
Radu Adrian Ciora schrieb:
> Hi,
> I was trying to generate MSWord's commandbar's interface with the
following code:
>
> def generate_COM_interface(self, fname):
> global number
> def test(self):
> try:
> comtypes.typeinfo.LoadTypeLibEx(fname)
> except WindowsError:
> return comtypes.client.GetModule(fname)
>
>
> and then call it like this:
> l_i_face = self.generate_COM_interface("C:"+os.sep+"Program
Files"+os.sep+"Common Files"+os.sep+"Microsoft
Shared"+os.sep+"OFFICE11"+os.sep+"MSO.dll")
>
> but this returns None!
>
> Can anyone tell me where I'm wrong?
It returns None because the except clause does not trigger
(LoadTypeLibEx succeeds),
and there is no explicit 'return' statement executed.
BTW: instead of adding all the strings with os.sep between them you
should better write
generate_COM_interface(r"c:\Program Files\Common Files\Microsoft
Shared\OFFICE11\MSO.dll")
or, even more portable, using the 'CommonProgramFiles' environment
variable:
import os
generate_COM_interface(os.path.join(os.environ["CommonProgramFiles"],
r"Microsoft Shared\OFFICE11\MSO.dll"))
But what do you want to achieve?
comtypes.typeinfo.LoadTypeLibEx(fname) returns an ITypeLib pointer
which you probably do not need.
comtypes.client.GetModule(fname) is what you need - it creates the
typelib wrapper
which contains the interface definitions.
The GetModule() call returns the Python module, but it is probably
better to
import it with its short name that GetModule() also creates and prints!
For me, the name seems to be comtypes.gen.Office. So I would write:
# Create the typelib wrapper (if it does not yet exist):
GetModule(os.path.join(os.environ["CommonProgramFiles"], r"Microsoft
Shared\OFFICE11\MSO.dll"))
# Import the typelib wrapper
from comtypes.gen import Office
# Use it
print Office.CommandBars, Office.CommandBarControl
You might have to adjust the above code a bit, I don't have OFFICE11 on
my machine,
only OFFICE10.
Thomas
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
comtypes-users mailing list
comtypes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/comtypes-users
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
comtypes-users mailing list
comtypes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/comtypes-users