Johannes Bauer wrote: > What I'd like to add: I want the GUI users to supply plugin scripts, > i.e. offer some kind of API. That is, I want the user to write short > Python pieces which look something like > > import guiapp > > class myplugin(): > def __init__(self): > guiapp.add_menu("foobar") > > def exec(self, param): > print("foo") > > the GUI application should now browse the plugin directory and read > those plugin python files and somehow incorporate (i.e. discover what > modules are there, instanciate, etc.)
You will find ways to scan a directory using os.path and related things. In order to import a module, you add the base directory to sys.path. Since you have just a variable with the module name (excluding the .py), you can't use 'import' as it is. Instead, use the __import__ functio (I wonder if there is anything more elegant) which returns the plugin. Other than that, better steal ideas than reinventing them. I think e.g. xchat already provides ways to script the UI, which you could take as an inspiration. Have fun! Uli -- Sator Laser GmbH Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932 -- http://mail.python.org/mailman/listinfo/python-list