Danny.OOo.Listeners.ListenerProcAdapters.py

From Apache OpenOffice Wiki
Revision as of 20:00, 17 February 2015 by JZA (talk | contribs) (Adding categories)
Jump to: navigation, search

This module has various helpers that make it extremely easy to create listeners on the fly, and make them call an arbitrary python procedure. <source lang=python>

  1. Danny.OOo.Listeners.ListenerProcAdapters.py
  2. A module to easily work with OpenOffice.org.
  3. Copyright (c) 2003-2004 Danny Brewer
  4. d29583@groovegarden.com
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. This library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with this library; if not, write to the Free Software
  15. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. See: http://www.gnu.org/licenses/lgpl.html
  17. If you make changes, please append to the change log below.
  18. Change Log
  19. Danny Brewer Revised 2004-06-05-01


  1. OOo's libraries

import uno import unohelper



  1. --------------------------------------------------
  2. An ActionListener adapter.
  3. This object implements com.sun.star.awt.XActionListener.
  4. When actionPerformed is called, this will call an arbitrary
  5. python procedure, passing it...
  6. 1. the oActionEvent
  7. 2. any other parameters you specified to this object's constructor (as a tuple).

from com.sun.star.awt import XActionListener class ActionListenerProcAdapter( unohelper.Base, XActionListener ):

   def __init__( self, oProcToCall, tParams=() ): 
       self.oProcToCall = oProcToCall # a python procedure 
       self.tParams = tParams # a tuple 
   # oActionEvent is a com.sun.star.awt.ActionEvent struct. 
   def actionPerformed( self, oActionEvent ): 
       if callable( self.oProcToCall ): 
           apply( self.oProcToCall, (oActionEvent,) + self.tParams ) 


  1. --------------------------------------------------
  2. An ItemListener adapter.
  3. This object implements com.sun.star.awt.XItemListener.
  4. When itemStateChanged is called, this will call an arbitrary
  5. python procedure, passing it...
  6. 1. the oItemEvent
  7. 2. any other parameters you specified to this object's constructor (as a tuple).

from com.sun.star.awt import XItemListener class ItemListenerProcAdapter( unohelper.Base, XItemListener ):

   def __init__( self, oProcToCall, tParams=() ): 
       self.oProcToCall = oProcToCall # a python procedure 
       self.tParams = tParams # a tuple 
   # oItemEvent is a com.sun.star.awt.ItemEvent struct. 
   def itemStateChanged( self, oItemEvent ): 
       if callable( self.oProcToCall ): 
           apply( self.oProcToCall, (oItemEvent,) + self.tParams ) 


  1. --------------------------------------------------
  2. An TextListener adapter.
  3. This object implements com.sun.star.awt.XTextistener.
  4. When textChanged is called, this will call an arbitrary
  5. python procedure, passing it...
  6. 1. the oTextEvent
  7. 2. any other parameters you specified to this object's constructor (as a tuple).

from com.sun.star.awt import XTextListener class TextListenerProcAdapter( unohelper.Base, XTextListener ):

   def __init__( self, oProcToCall, tParams=() ): 
       self.oProcToCall = oProcToCall # a python procedure 
       self.tParams = tParams # a tuple 
   # oTextEvent is a com.sun.star.awt.TextEvent struct. 
   def textChanged( self, oTextEvent ): 
       if callable( self.oProcToCall ): 
           apply( self.oProcToCall, (oTextEvent,) + self.tParams ) 

<source>

Personal tools