It still fails, follow example
#coding: gbk from win32com import universal from win32com.server.exception import COMException from win32com.client import gencache, DispatchWithEvents import winerror import pythoncom from win32com.client import constants, Dispatch import sys import win32com.client # Support for COM objects we use. gencache.EnsureModule('{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}', 0, 2, 1, bForDemand=True) # Office 9 gencache.EnsureModule('{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}', 0, 2, 5, bForDemand=True) # The TLB defiining the interfaces we implement universal.RegisterInterfaces('{AC0714F2-3D04-11D1-AE7D-00A0C90F26F4}', 0, 1, 0, ["_IDTExtensibility2"]) universal.RegisterInterfaces('{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}', 0, 2, 5, ["IRibbonExtensibility", "IRibbonControl"]) class ButtonEvent: def OnClick(self, button, cancel): import win32ui # Possible, but not necessary, to use a Pythonwin GUI import win32con win32ui.MessageBox("Hello from Python","PythonTest",win32con.MB_OKCANCEL) return cancel class WordAddin: _com_interfaces_ = ['_IDTExtensibility2', 'IRibbonExtensibility'] _public_methods_ = ['do','GetImage'] _reg_clsctx_ = pythoncom.CLSCTX_INPROC_SERVER _reg_clsid_ = "{C5482ECA-F559-45A0-B078-B2036E6F011A}" _reg_progid_ = "Python.Test.WordAddin" _reg_policy_spec_ = "win32com.server.policy.EventHandlerPolicy" def __init__(self): self.appHostApp = None def do(self,ctrl): import win32ui # Possible, but not necessary, to use a Pythonwin GUI import win32con win32ui.MessageBox("Hello from Python","PythonTest",win32con.MB_OKCANCEL) def GetImage(self,ctrl): from gdiplus import LoadImage i = LoadImage( 'c:/edit.png' ) print i, 'ddd' return i def GetCustomUI(self,control): s = ''' <mso:customUI xmlns:x1=" http://schemas.microsoft.com/office/2009/07/customui/macro" xmlns:mso=" http://schemas.microsoft.com/office/2009/07/customui"> <ribbon startFromScratch="false"> <tabs> <tab id="CustomTab" label="JJ"> <group id="MainGroup" label="Main"> <button id="Button" label="doo" imageMso="HappyFace" size="large" onAction="do" /> <button id="Button2" label="doo2" getImage='GetImage' size="large" onAction="do" /> </group> </tab> </tabs> </ribbon> </customUI> ''' return s def OnConnection(self, application, connectMode, addin, custom): print "OnConnection", application, connectMode, addin, custom try: self.appHostApp = application except pythoncom.com_error, (hr, msg, exc, arg): print "The Excel call failed with code %d: %s" % (hr, msg) if exc is None: print "There is no extended error information" else: wcode, source, text, helpFile, helpId, scode = exc print "The source of the error is", source print "The error message is", text print "More info can be found in %s (id=%d)" % (helpFile, helpId) def OnDisconnection(self, mode, custom): print "OnDisconnection" #self.appHostApp.CommandBars("PythonBar").Delete self.appHostApp=None def OnAddInsUpdate(self, custom): print "OnAddInsUpdate", custom def OnStartupComplete(self, custom): print "OnStartupComplete", custom def OnBeginShutdown(self, custom): print "OnBeginShutdown", custom def RegisterAddin(klass): import _winreg key = _winreg.CreateKey(_winreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Office\\Word\\Addins") subkey = _winreg.CreateKey(key, klass._reg_progid_) _winreg.SetValueEx(subkey, "CommandLineSafe", 0, _winreg.REG_DWORD, 0) _winreg.SetValueEx(subkey, "LoadBehavior", 0, _winreg.REG_DWORD, 3) _winreg.SetValueEx(subkey, "Description", 0, _winreg.REG_SZ, "Word Addin") _winreg.SetValueEx(subkey, "FriendlyName", 0, _winreg.REG_SZ, "JJ Word Addin") def UnregisterAddin(klass): import _winreg try: _winreg.DeleteKey(_winreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Office\\Word\\Addins\\" + klass._reg_progid_) except WindowsError: pass if __name__ == '__main__': import win32com.server.register win32com.server.register.UseCommandLine( WordAddin ) if "--unregister" in sys.argv: UnregisterAddin( WordAddin ) else: RegisterAddin( WordAddin ) att Claudemir 2015-02-12 9:00 GMT-02:00 <python-win32-requ...@python.org>: > Send python-win32 mailing list submissions to > python-win32@python.org > > To subscribe or unsubscribe via the World Wide Web, visit > https://mail.python.org/mailman/listinfo/python-win32 > or, via email, send a message with subject or body 'help' to > python-win32-requ...@python.org > > You can reach the person managing the list at > python-win32-ow...@python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of python-win32 digest..." > > > Today's Topics: > > 1. Re: question about word addin , IRibbonExtensibility, > GetCustomUI, getImage, IPicture (Tim Roberts) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Wed, 11 Feb 2015 10:21:55 -0800 > From: Tim Roberts <t...@probo.com> > To: Python-Win32 List <python-win32@python.org> > Subject: Re: [python-win32] question about word addin , > IRibbonExtensibility, GetCustomUI, getImage, IPicture > Message-ID: <54db9dc3.4080...@probo.com> > Content-Type: text/plain; charset="utf-8" > > Claudemir de almeida rosa wrote: > > can you send me an example to read image in addin with ribbon > > Your question is not clear. Where is the image coming from, and where > do you want it to go? > > The title of your message was copied word-for-word from a three-year-old > message on this mailing list, so I assume you've been through that > thread. From that, you can see that it's not easy. Did you have any > success? > > -- > Tim Roberts, t...@probo.com > Providenza & Boekelheide, Inc. > > > > ------------------------------ > > Subject: Digest Footer > > _______________________________________________ > python-win32 mailing list > python-win32@python.org > https://mail.python.org/mailman/listinfo/python-win32 > > > ------------------------------ > > End of python-win32 Digest, Vol 143, Issue 7 > ******************************************** >
_______________________________________________ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32