Python plug-in

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • toto

    Python plug-in

    Hi,

    I'm trying to find some howto, tutorial in order to create a python program
    that will allow plug-in programming. I've found various tutos on how to
    write a plug-in for soft A or soft B but none telling me how to do it in my
    own programs. Do you have any bookmarks ??

    Regards,

    Laurent.


  • bruno at modulix

    #2
    Re: Python plug-in

    toto wrote:[color=blue]
    > Hi,
    >
    > I'm trying to find some howto, tutorial in order to create a python program
    > that will allow plug-in programming. I've found various tutos on how to
    > write a plug-in for soft A or soft B but none telling me how to do it in my
    > own programs. Do you have any bookmarks ??[/color]

    Trac and MoinMoin have a plugin system IIRC.

    --
    bruno desthuilliers
    python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
    p in 'onurb@xiludom. gro'.split('@')])"

    Comment

    • Terry Hancock

      #3
      Re: Python plug-in

      toto wrote:
      [color=blue]
      >I'm trying to find some howto, tutorial in order to create a python program
      >that will allow plug-in programming. I've found various tutos on how to
      >write a plug-in for soft A or soft B but none telling me how to do it in my
      >own programs. Do you have any bookmarks ?
      >
      >[/color]
      There is more than one way to accomplish this, but one of the
      simplest is to provide a directory where plugins are loaded, and
      put an __init__.py in it which automatically finds files in the directory
      that conform to some standard, and imports them (or tries to).

      Here's a snippet from one of my projects:

      import sys, os
      from Operators import Operator, operate, Ops

      # Find and load all available plugin modules:

      operator_path = os.path.abspath (__path__[0])
      for module_file in filter(
      lambda n: n[-3:]=='.py' and n not in ('__init__.py', 'Operators.py') ,
      os.listdir(oper ator_path)):
      #print "Loading %s" % module_file
      f, e = os.path.splitex t(module_file)
      __import__(f, globals(), locals(), [])


      (Operators.py is in the same directory and includes general purpose
      code that the plugins use -- I think it might be better design to put
      that in the parent directory. But that's awkward until Python
      introduces relative import notation -- supposed to be coming in v2.5).

      Comment

      Working...