def main(): """ 1. Parse command line arguments. 2. If GUI enabled (session.gui), launch QApplication 3. Search an extension in "oalab.extension" plugins. - If found, launch extension - If not found, quit application and shows available extensions """ class Session(object): pass session = Session() cli = CommandLineParser(session=session) cli.parse() if session.gui: from openalea.vpltk.qt import QtGui from openalea.core.settings import get_openalea_home_dir from openalea.core.path import path as Path app = QtGui.QApplication(sys.argv) win = None # Run all extension matching session.extension available_extensions = [] for plugin in plugins('oalab.lab'): plugin_class = plugin.__class__ try: ext = plugin_class.name except AttributeError: continue else: # register plugin info for user. args = dict(EXT=ext, MODULE=plugin_class.__module__, CLASS=plugin_class.__name__) text = ' - \033[94m%(EXT)s\033[0m (provided by class %(CLASS)s defined in %(MODULE)s)' % args available_extensions.append(text) if session.extension == ext: win = launch_lab(plugin_class) break if win is None: from openalea.oalab.manager.selector import select_manager_item from openalea.core.service.plugin import default_plugin_manager from openalea.oalab.widget.pages import WelcomePage plugin_class = select_manager_item(default_plugin_manager(), 'oalab.lab', title='Select a Laboratory', style=WelcomePage.STYLE_LARGE) if plugin_class: win = launch_lab(plugin_class) if win: app.exec_() else: print 'Extension %r not found' % session.extension print 'Please choose a valid \033[94mextension\033[0m:' print '\n'.join(available_extensions)
return plugin_class if __name__ == '__main__': import sys from openalea.vpltk.qt import QtGui from openalea.core.service.project import default_project_manager from openalea.core.service.plugin import default_plugin_manager instance = QtGui.QApplication.instance() if instance is None: qapp = QtGui.QApplication(sys.argv) else: qapp = instance plm = default_plugin_manager() pm = default_project_manager() managers = [ (pm, 'local'), (plm, 'oalab.applet'), (plm, 'oalab.lab'), (plm, 'openalea.image'), ] class TestPluginSelector(QtGui.QWidget): def __init__(self): QtGui.QWidget.__init__(self) layout = QtGui.QVBoxLayout(self) self.pb_select = QtGui.QPushButton('select')