Hi,

I've got a flaky problem. I'm working on a win32com based Excel add-in. The problem I've got is that under python 2.7, importing wx (wxPython) inside the Excel add-in fails. Under python 2.6, the same code works. I've written a sample program (attached) to demonstrate. To run: install Python, Win32 extensions and wxPython, register test program, and fire up Excel. The install binaries I have are:

python-2.7.msi
pywin32-214.win32-py2.7.exe
wxPython2.8-win32-unicode-2.8.11.0-py27.exe

This is not obviously a wxPython problem (although it may be), as importing works ok outside Excel, as demonstrated by running the test program to register.

Any help or suggestions in tracking this down would be appreciated.

Thanks,

Robert Kaplan
robert2...@verizon.net

#	excel_wx_bug.py	demonstartion progam for bug in python 2.7, etc
#
#	This file was originally based on excelAddin.py demo file,
#	included in the win32 com distribution
#

print 'Start ----------------------'

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
from win32com.server.util import wrap, unwrap
import	win32ui
import	win32con
import sys
import	traceback

# Support for COM objects we use.
gencache.EnsureModule('{00020813-0000-0000-C000-000000000046}', 0, 1, 6, bForDemand=True) # Excel 12
gencache.EnsureModule('{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}', 0, 2, 4, bForDemand=True) # Office 12

# The TLB defiining the interfaces we implement
universal.RegisterInterfaces('{AC0714F2-3D04-11D1-AE7D-00A0C90F26F4}', 0, 1, 0, ["_IDTExtensibility2"])


Wx = True
try:
	import wx              
	msg = "import wx succeeded"
except Exception as e:
	Wx = False
	msg = "import wx failed: " + str (e)
	ei = sys. exc_info () 
	print ei
	traceback. print_tb (ei [2])


class ExcelAddin:
	_com_interfaces_ = ['_IDTExtensibility2']
	_public_methods_ = []
	_reg_clsctx_ = pythoncom.CLSCTX_INPROC_SERVER
	_reg_clsid_ = "{87FE1E96-F329-4212-BE46-91B008D2E1D7}"
	_reg_progid_ = "Python.WXBug"
	_reg_policy_spec_ = "win32com.server.policy.EventHandlerPolicy"

	def __init__(self):
		self.appHostApp = None     

	def OnConnection(self, application, connectMode, addin, custom):
		try:
			win32ui. MessageBox (msg, 'Info', win32con. MB_OKCANCEL)

		except Exception as e:
			pass

	def OnDisconnection(self, mode, custom):
		self.appHostApp=None

	def OnAddInsUpdate(self, custom):
		pass
	def OnStartupComplete(self, custom):
		pass
	def OnBeginShutdown(self, custom):
		pass


def RegisterAddin(klass):
	import _winreg
	key = _winreg.CreateKey(_winreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Office\\Excel\\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, "Excel Addin bug")
	_winreg.SetValueEx(subkey, "FriendlyName", 0, _winreg.REG_SZ, "Excel Addin bug")

def UnregisterAddin(klass):
	import _winreg
	try:
		_winreg.DeleteKey(_winreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Office\\Excel\\Addins\\" + klass._reg_progid_)
	except WindowsError:
		pass


if __name__ == '__main__':
	import win32com.server.register
	win32com.server.register.UseCommandLine(ExcelAddin)
	if "--unregister" in sys.argv:
		UnregisterAddin(ExcelAddin)
	else:
		RegisterAddin(ExcelAddin)

	print msg


print 'End ----------------------'
_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to