ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> Python-win32
Python-win32
RE: [python-win32] accessing application object from OnConnectionmethod in another Class
by Mark Hammond other posts by this author
Sep 30 2004 10:32PM messages near this date
[python-win32] accessing application object from OnConnection method in another Class | [python-win32] MSWord: Server Busy
>  If you look at the example demo "ExcelAddin" that come with win32all,

FYI,
http://cvs.sourceforge.net/viewcvs.py/spambayes/spambayes/Outlook2000/addin.
py is a complete Office Addin, and has jumped through many hoops.

> 
>  def OnConnection(self, application, connectMode, addin, custom):
>       self.appHostApp = application
>       btnMyButton = self.toolbarButton =
>  DispatchWithEvents(btnMyButton, ButtonEvent)

Just ignore the man behind the curtain :)  Do it the way you would normally
do it!

  btnMyButton._application = self

should just store it in an instance variable.  Obviously you will want to
avoid conflict with Word's attribute names - we first try and set the
attribute to word, and it that fails, store it in the instance.

Another alterative is to just add your own method to the event class:

class ButtonEvent:
  # as normal
  def _MyFunkyMethod(self, whatever):
   ...

btnMyButton = DispatchWithEvents(btnMyButton, ButtonEvent)
btnMyButton._MyFunkyMethod(self)

Note that you need to be very careful with DispatchWithEvents and circular
references.  These DWI objects have a reference to the original object (eg,
the Excel object the events are being sourced from), and the original object
has a reference to the DWI object (as that is where it is delivering
events).

Eg,
a = Dispatch("Word.App")
e = DispatchWithEvents(a, myclass)

'e' has a reference to 'a', and 'a' has a reference to 'e' - this is a
circular reference that must be manually broken.

However:
a = Dispatch("Word.App")
e = WithEvents(a)

Avoids that circle - 'a' still holds a reference to 'e', but 'e' holds no
reference to a.  Thus, as soon as a or e go out of scope, it all still
destructs correctly.

That is one hoop SpamBayes had to jump through to stop certain events
leaking.

>  to name a few. I have also spent some time in the MSDN and Google and
>  still am confused. Have ordered Marks book "Python programming on
>  win32" but it will only be here in 10 days (i count the minutes). so

Mark.

_______________________________________________
Python-win32 mailing list
Python-win32@[...].org
http://mail.python.org/mailman/listinfo/python-win32
Thread:
Graeme Glass
Mark Hammond

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved