[Qgis-developer] Plugin tweaks

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Tue Dec 9 10:40:26 EST 2008


I'm just writing some code to muck about with plugin repositories and
I figured I'd download every plugin from the four main repos to see
how they are. I found a few plugins still import their main code from
their __init__.py and so can't be imported (easily) from outside Qgis.

Just to expound, instead of having:

from myplugin import myPlugin
def classFactory(iface):
  return myPlugin(iface)

it's better to have:

def classFactory(iface):
  from myplugin import myPlugin
  return myPlugin(iface)

 then code can import the plugin and get the version() methods and so
on, without needing to handle anything the plugin imports.

 The plugins that currently don't do this are:

newlayer
geocode
profiletool
scattergram

 I might wrote some kind of plugin quality control tester to check for
this. I'll also make it check that __init__.py supports the required
methods, but at the moment I'm not sure what the complete set of
required methods is...

 Eventually (as I think Tim may have said before) this information
ought to go in a config file rather than code. My plugins in SVN are
currently adopting both approaches, by having a config file that is
read by the code:

http://code.google.com/p/bsrplugins/source/browse/trunk/clickfu/__init__.py
http://code.google.com/p/bsrplugins/source/browse/trunk/clickfu/config.ini

 The ini file is read by python standard library calls. If we decide
to go this way, then all config info would go into the ini file, and
the plugin module would never need to be imported by anything except
Qgis...

 Okay that's enough from me...

Barry


More information about the Qgis-developer mailing list