Hi
all,
I'm trying to
extend the RMB popup menu in Excel to let the user easily select the project
she's working on. The construction of the (hierarchical) menu is written in a
Python COM server. This server is used by some VBA code in the paricular
workbook (a 'timesheet'), in the Workbook_Open() function.
The problem is
that i can't seem to set the (event-) callback function, ie what happens when a
user selects a given menu item. Below is the code I'd hoped would work but
doesn't:
excel =
Dispatch("Excel.application")
cbr = excel.CommandBars("Cell")
# make a
sub-menu
smp = cbr.Controls.Add(Type =
constants.msoControlPopup)
smp.Caption = "[BB] Projecten"
smp.Tag = "[BB] Projecten"
#
make a menu item
smpo = CastTo(smp,
"CommandBarPopup")
nc = smpo.Controls.Add(Type =
constants.msoControlButton)
nc.Caption = "Butt"
#
callback
nc.
class=921350310-19072006> # <--
PROBLEM
onProject() can be a global function, an instancemethod or a
staticmethod, it always says this: <exceptions.TypeError: Objects of type
'function' can not be converted to a COM VARIANT>.
I
did some research and came up with the following
strategy:
a.
Write a callback class, deriving from some COM
interface
b.
Convert (an object of) this class to the appropriate 'COM
VARIANT'
My questions
are:
1. Is this the way
to do this? If not, what is?
2. If so, what is
the interface to inherit from? Functions to override (eg
Invoke())?
3. Do I use pythoncom.WrapObject() for b.? If so, what should be my
gatewayIID & interfaceIID?
Thank you very
much for your time,
g
PS: In VBA you
have to give it the name of a macro, eg nc.>
_______________________________________________ Python-win32 mailing list Python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32