Пример #1
0
def load_interfaces():
    """
    Need to load interface classes to auto register them
    (see :class:`openalea.core.interface.IInterfaceMetaClass`)
    """
    for plugin in plugins('openalea.interface'):
        plugin.implementation
Пример #2
0
def load_interfaces():
    """
    Need to load interface classes to auto register them
    (see :class:`openalea.core.interface.IInterfaceMetaClass`)
    """
    for plugin in plugins('openalea.interface'):
        plugin.implementation
Пример #3
0
    def add(self, project, name, code, dtype=None, category=None):
        if dtype is None:

            dtypes = [ModelClass.default_name for ModelClass in plugins('oalab.modelclass')]
        else:
            dtypes = [dtype]

        if category:
            categories = [category]
        else:
            categories = Project.DEFAULT_CATEGORIES.keys()
        selector = SelectCategory(filename=name, categories=categories, dtypes=dtypes)
        dialog = ModalDialog(selector)
        if dialog.exec_():
            category = selector.category()
            filename = selector.name()
            dtype = selector.dtype()
            path = project.path / category / filename
            if path.exists():
                box = QtGui.QMessageBox.information(self, 'Data yet exists',
                                                    'Data with name %s already exists in this project, just add it' % filename)
                code = None
            data = project.add(category=category, filename=filename, content=code, dtype=dtype)
            if data:
                return category, data
        return None, None
Пример #4
0
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_class in plugins('oalab.lab'):
            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.gui.pluginselector import select_plugin
            plugin_class = select_plugin('oalab.lab',
                                         size=(400, 10),
                                         title='Select a Laboratory')
            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)
Пример #5
0
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)
Пример #6
0
    def __init__(self, category, parent=None):
        WelcomePage.__init__(self, parent=parent)

        self._actions = {}
        self._sorted_actions = []
        for plugin_class in plugins(category):
            action = QtGui.QAction(obj_icon(plugin_class), alias(plugin_class), self)
            action.triggered.connect(self._on_action_triggered)
            self._actions[action] = plugin_class
            self._sorted_actions.append(action)

        self.set_actions(self._sorted_actions)
Пример #7
0
def plugin_doc(plugin_func):
    __doc__ = ['Implemented plugins:']
    for plugin_class in plugins(plugin_func._group, plugin_func._tags, plugin_func._criteria):
        __doc__.append(' * "' + plugin_class.identifier + '"') # modulename and objectname
        if plugin_class.__doc__:
            __doc__[-1] += ' - ' + (" " * (len(__doc__[-1]) + 3)).join(line.strip()
                                                                       for line in plugin_class.__doc__.splitlines())
    __doc__.append('')
    __doc__.append('Defined aliases:')
    for alias in plugin_func._aliases:
        __doc__.append(' * "' + alias + '" - Alias for plugin "' + plugin_func._aliases[alias] + '"')
    return '\n'.join(__doc__)
Пример #8
0
    def __init__(self, category, parent=None):
        WelcomePage.__init__(self, parent=parent)

        self._actions = {}
        self._sorted_actions = []
        for plugin_class in plugins(category):
            action = QtGui.QAction(obj_icon(plugin_class), alias(plugin_class),
                                   self)
            action.triggered.connect(self._on_action_triggered)
            self._actions[action] = plugin_class
            self._sorted_actions.append(action)

        self.set_actions(self._sorted_actions)
Пример #9
0
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
    """

    create_project_shortcut()
    session = Session()
    cli = CommandLineParser(session=session)
    cli.parse()

    if session.gui:
        from openalea.vpltk.qt import QtGui
        from openalea.oalab.gui.mainwindow import MainWindow

        app = QtGui.QApplication(sys.argv)

        win = None
        # Run all extension matching session.extension
        available_extensions = []

        if session.extension == '':
            session.extension = 'plant'
        for plugin_class in plugins('oalab.lab'):
            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:
                plugin = plugin_class()
                win = MainWindow(session)
                debug_plugin('oalab.lab', func=plugin, func_args=[win])
                win.show()
                win.raise_()
                break

        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)
Пример #10
0
def DataType(path=None, name=None, mimetype=None):
    if path:
        name = Path(path).ext[1:].lower()
        return name
    elif name:
        return Path(name).ext[1:].lower()
    elif mimetype:
        #         for ModelClass in iter_plugins('oalab.model'):
        #             if ModelClass.mimetype == mimetype:
        #                 return ModelClass.default_name
        for DataClass in plugins('oalab.dataclass', criteria=dict(implement='IData')):
            if DataClass.mimetype == mimetype:
                return DataClass.default_name
    else:
        return None
Пример #11
0
def DataType(path=None, name=None, mimetype=None):
    if path:
        name = Path(path).ext[1:].lower()
        return name
    elif name:
        return Path(name).ext[1:].lower()
    elif mimetype:
        #         for ModelClass in iter_plugins('oalab.model'):
        #             if ModelClass.mimetype == mimetype:
        #                 return ModelClass.default_name
        for DataClass in plugins('oalab.dataclass',
                                 criteria=dict(implement='IData')):
            if DataClass.mimetype == mimetype:
                return DataClass.default_name
    else:
        return None
Пример #12
0
    def reload(self):
        self.dtype = None

        self._name_to_applet = {}
        self._name_to_action = {}
        self._action_to_name = {}

        for plugin in plugins('oalab.plugin', criteria=dict(implement='IParadigmApplet')):
            applet = debug_plugin('oalab.plugin', func=plugin)
            if applet:
                name = applet.default_name
                self._name_to_applet[name] = applet
                action = QtGui.QAction(qicon(applet.icon), "New " + name, self._parent)
                action.triggered.connect(self._on_action_triggered)
                self._name_to_action[name] = action
                self._action_to_name[action] = name
Пример #13
0
    def init(self):
        self._registry_decode = set()
        self._registry_decode_plugin = {}

        self._registry_encode = set()
        self._registry_encode_plugin = {}

        for plugin in plugins('oalab.plugin', criteria=dict(implement='IQMimeCodec')):
            for k, v in plugin.qtdecode:
                codec = (unicode(k), unicode(v))
                self._registry_decode.add(codec)
                self._registry_decode_plugin[codec] = plugin
            for k, v in plugin.qtencode:
                codec = (unicode(k), unicode(v))
                self._registry_encode.add(codec)
                self._registry_encode_plugin[codec] = plugin
Пример #14
0
    def __init__(self, layout=None, **kwds):
        """
        tests: list of function runnable in shell (name changed to run_<funcname>)
        layout_file
        """
        OALabMainWin.__init__(self, layout=layout, **kwds)

        self.interp = interpreter()
        self.interp.user_ns['mainwin'] = self
        self.interp.user_ns['splittable'] = self.splittable
        self.interp.user_ns['debug'] = self.debug
        self.interp.user_ns['QtCore'] = QtCore
        self.interp.user_ns['QtGui'] = QtGui

        def applet(name):
            return plugin_instance('oalab.applet', name)

        def applets(name):
            return plugin_instances('oalab.applet', name)

        self.interp.user_ns['applet'] = applet
        self.interp.user_ns['applets'] = applets

        print 'VARIABLES AVAILABLE IN SHELL ...'

        print '\nAPPLICATION:'
        print '  - mainwin'
        print '  - splittable'
        print '  - QtCore'
        print '  - QtGui'

        print '\nAPPLETS:'
        for plugin in plugins('oalab.applet'):
            if plugin_instance_exists('oalab.applet', plugin.name):
                varname = camel_case_to_lower(plugin.name)
                self.interp.user_ns['plugin_%s' % varname] = plugin
                self.interp.user_ns[varname] = plugin_instance('oalab.applet', plugin.name)
                print '  -', varname

        print '\nFUNCTIONS:'
        for f in kwds.pop('tests', []):
            self.interp.user_ns['run_%s' % f.__name__] = f
            f.func_globals['ns'] = self.interp.user_ns
            print '  - run_%s' % f.__name__

        self.resize(QtCore.QSize(800, 600))
Пример #15
0
    def init(self):
        self._registry_decode = set()
        self._registry_decode_plugin = {}

        self._registry_encode = set()
        self._registry_encode_plugin = {}

        for plugin in plugins('oalab.plugin',
                              criteria=dict(implement='IQMimeCodec')):
            for k, v in plugin.qtdecode:
                codec = (unicode(k), unicode(v))
                self._registry_decode.add(codec)
                self._registry_decode_plugin[codec] = plugin
            for k, v in plugin.qtencode:
                codec = (unicode(k), unicode(v))
                self._registry_encode.add(codec)
                self._registry_encode_plugin[codec] = plugin
Пример #16
0
    def reload(self):
        self.dtype = None

        self._name_to_applet = {}
        self._name_to_action = {}
        self._action_to_name = {}

        for plugin in plugins('oalab.plugin',
                              criteria=dict(implement='IParadigmApplet')):
            applet = debug_plugin('oalab.plugin', func=plugin)
            if applet:
                name = applet.default_name
                self._name_to_applet[name] = applet
                action = QtGui.QAction(qicon(applet.icon), "New " + name,
                                       self._parent)
                action.triggered.connect(self._on_action_triggered)
                self._name_to_action[name] = action
                self._action_to_name[action] = name
Пример #17
0
    def search_path():
        """
        Return a list of all path containing projects
        """
        repositories = set()

        # 1. Add default user project dir
        repositories.add(Path(settings.get_project_dir()))

        # 2. Add project repositories defined by packages
        for plugin in plugins(
                'oalab.plugin',
                criteria=dict(implement="ProjectRepositoryList")):
            for repository in plugin():
                repositories.add(repository)

        # 3. Read repositories defined by users and saved in config
        config = settings.Settings()
        lst = list(repositories)
        try:
            s = config.get("ProjectManager", "Path")
            lst = eval(s, {"path": Path})
        except NoSectionError:
            config.add_section("ProjectManager")
            config.add_option("ProjectManager", "Path",
                              str([str(path) for path in lst]))
        except NoOptionError:
            config.add_option("ProjectManager", "Path",
                              str([str(path) for path in lst]))

        for repo in lst:
            repositories.add(repo)

        # Remove all paths to directories that don't exist
        final_list = set()
        for p in repositories:
            p = Path(p).abspath()
            if not p.isdir():
                continue
            final_list.add(p)

        return list(final_list)
Пример #18
0
    def search_path():
        """
        Return a list of all path containing projects
        """
        repositories = set()

        # 1. Add default user project dir
        repositories.add(Path(settings.get_project_dir()))

        # 2. Add project repositories defined by packages
        for plugin in plugins('oalab.plugin', criteria=dict(implement="ProjectRepositoryList")):
            for repository in plugin():
                repositories.add(repository)

        # 3. Read repositories defined by users and saved in config
        config = settings.Settings()
        lst = list(repositories)
        try:
            s = config.get("ProjectManager", "Path")
            lst = eval(s, {"path": Path})
        except NoSectionError:
            config.add_section("ProjectManager")
            config.add_option("ProjectManager", "Path", str([str(path) for path in lst]))
        except NoOptionError:
            config.add_option("ProjectManager", "Path", str([str(path) for path in lst]))

        for repo in lst:
            repositories.add(repo)

        # Remove all paths to directories that don't exist
        final_list = set()
        for p in repositories:
            p = Path(p).abspath()
            if not p.isdir():
                continue
            final_list.add(p)

        return list(final_list)
Пример #19
0
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self)
        self.setContentsMargins(0, 0, 0, 0)
        self._layout = QtGui.QHBoxLayout(self)
        self._layout.setContentsMargins(0, 0, 0, 0)

        self._cb_applets = QtGui.QComboBox()
        self._applet_label = []  # list of label sorted by name
        self._applet_plugins = {}  # label -> plugin class

        self._cb_applets.addItem('Select applet')
        for plugin in plugins('oalab.applet'):
            self._applet_label.append(plugin.label)
            self._applet_plugins[plugin.label] = plugin
        self._applet_label.sort()

        for label in self._applet_label:
            plugin_class = self._applet_plugins[label]
            self._cb_applets.addItem(obj_icon(plugin_class), label)

        self._layout.addWidget(self._cb_applets)

        self.setCurrentApplet('')
        self._cb_applets.currentIndexChanged.connect(self._on_current_applet_changed)
Пример #20
0
    def __init__(self, filename="", categories=None, dtypes=None, parent=None):
        super(SelectCategory, self).__init__(parent=parent)

        if categories is None:
            categories = Project.DEFAULT_CATEGORIES.keys()
        if dtypes is None:
            dtypes = [
                plugin.default_name for plugin in plugins(
                    'oalab.plugin',
                    criteria=dict(
                        implement='IParadigmApplet'))]
            dtypes.append('Other')
        self.categories = categories

        layout = QtGui.QFormLayout(self)

        self.label = QtGui.QLabel("Select in which category you want to add this file: ")
        self.l_dtypes = QtGui.QLabel("Data type")
        self.label2 = QtGui.QLabel("New filename: ")

        self.combo = QtGui.QComboBox(self)
        self.combo.addItems(categories)
        if 'model' in categories:
            self.combo.setCurrentIndex(categories.index('model'))

        self.combo_dtypes = QtGui.QComboBox(self)
        self.combo_dtypes.addItems(dtypes)
        self.combo_dtypes.setCurrentIndex(0)

        self.line = QtGui.QLineEdit(filename)

        layout.addRow(self.label, self.combo)
        layout.addRow(self.l_dtypes, self.combo_dtypes)
        layout.addRow(self.label2, self.line)

        self.setLayout(layout)
Пример #21
0
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self)
        self.setContentsMargins(0, 0, 0, 0)
        self._layout = QtGui.QHBoxLayout(self)
        self._layout.setContentsMargins(0, 0, 0, 0)

        self._cb_applets = QtGui.QComboBox()
        self._applet_alias = []  # list of alias sorted by name
        self._applet_plugins = {}  # alias -> plugin class

        self._cb_applets.addItem('Select applet')
        for plugin_class in plugins('oalab.applet'):
            self._applet_alias.append(plugin_class.alias)
            self._applet_plugins[plugin_class.alias] = plugin_class
        self._applet_alias.sort()

        for alias in self._applet_alias:
            plugin_class = self._applet_plugins[alias]
            self._cb_applets.addItem(obj_icon(plugin_class), alias)

        self._layout.addWidget(self._cb_applets)

        self.setCurrentApplet('')
        self._cb_applets.currentIndexChanged.connect(self._on_current_applet_changed)
Пример #22
0
    def add(self, project, name, code, dtype=None, category=None):
        if dtype is None:

            dtypes = [
                ModelClass.default_name
                for ModelClass in plugins('oalab.modelclass')
            ]
        else:
            dtypes = [dtype]

        if category:
            categories = [category]
        else:
            categories = Project.DEFAULT_CATEGORIES.keys()
        selector = SelectCategory(filename=name,
                                  categories=categories,
                                  dtypes=dtypes)
        dialog = ModalDialog(selector)
        if dialog.exec_():
            category = selector.category()
            filename = selector.name()
            dtype = selector.dtype()
            path = project.path / category / filename
            if path.exists():
                box = QtGui.QMessageBox.information(
                    self, 'Data yet exists',
                    'Data with name %s already exists in this project, just add it'
                    % filename)
                code = None
            data = project.add(category=category,
                               filename=filename,
                               content=code,
                               dtype=dtype)
            if data:
                return category, data
        return None, None
Пример #23
0
from openalea.core.path import path as Path
from openalea.core.service.plugin import plugins
from openalea.core.data import Data

import mimetypes

__all__ = ["DataFactory", "DataClass", "MimeType", "DataType"]

REGISTERY_MIME_CLASS = {}
for pl in plugins('openalea.core', criteria=dict(implement='IData')):
    REGISTERY_MIME_CLASS[pl.mimetype] = pl
# for ModelClass in iter_plugins('oalab.model'):
#     REGISTERY_MIME_CLASS[ModelClass.mimetype] = ModelClass

REGISTERY_NAME_MIME = {}
for pl in plugins('openalea.core', criteria=dict(implement='IData')):
    REGISTERY_NAME_MIME[pl.default_name.lower()] = pl.mimetype
    REGISTERY_NAME_MIME[pl.extension.lower()] = pl.mimetype

# for ModelClass in iter_plugins('oalab.model'):
#     REGISTERY_NAME_MIME[ModelClass.default_name.lower()] = ModelClass.mimetype
#     REGISTERY_NAME_MIME[ModelClass.extension.lower()] = ModelClass.mimetype


def MimeType(path=None, name=None):
    """
    Return mimetype for path.
    First, try to find extension in registery filled by models.
    If datatype is not found, use builtin module "mimetypes".
    If it cannot guess, returns False.
Пример #24
0
def discover_qt_controls():
    return plugins('oalab.plugin', criteria=dict(implement='IWidgetSelector'))
Пример #25
0
    def __init__(self, parent=None):
        super(ParadigmContainer, self).__init__(parent=parent)

        self.setTabsClosable(True)

        self.applets = []
        self._open_tabs = {}
        self.paradigms = {}
        self._new_file_actions = {}
        self.paradigms_actions = []
        for plugin_class in plugins('oalab.paradigm_applet'):
            plugin = plugin_class()
            paradigm_applet = debug_plugin('oalab.paradigm_applet', func=plugin)
            if paradigm_applet:
                self.paradigms[plugin_class.name] = paradigm_applet

        self._open_objects = {}

        self.projectManager = ProjectManager()

        self.setAccessibleName("Container")
        self.setElideMode(QtCore.Qt.ElideLeft)

        self.actionNewFile = QtGui.QAction(qicon("new.png"), "New file", self)
        self.actionOpenFile = QtGui.QAction(qicon("open.png"), "Open file", self)
        self.actionSave = QtGui.QAction(qicon("save.png"), "Save File", self)
        self.actionSaveAs = QtGui.QAction(qicon("save.png"), "Save As", self)
        self.actionRun = QtGui.QAction(qicon("run.png"), "Run", self)
        self.actionAnimate = QtGui.QAction(qicon("play.png"), "Animate", self)
        self.actionStep = QtGui.QAction(qicon("step.png"), "Step", self)
        self.actionStop = QtGui.QAction(qicon("pause.png"), "Stop", self)
        self.actionInit = QtGui.QAction(qicon("rewind.png"), "Init", self)
        self.actionCloseCurrent = QtGui.QAction(qicon("closeButton.png"), "Close current tab", self)

        self.actionRunSelection = QtGui.QAction(qicon("run.png"), "Run subpart", self)

        self.actionUndo = QtGui.QAction(qicon("editundo.png"), "Undo", self)
        self.actionRedo = QtGui.QAction(qicon("editredo.png"), "Redo", self)
        self.actionSearch = QtGui.QAction(qicon("editfind.png"), "Search", self)

        self.actionComment = QtGui.QAction(qicon("commentOn.png"), "Comment", self)
        self.actionUnComment = QtGui.QAction(qicon("commentOff.png"), "Uncomment", self)
        self.actionGoto = QtGui.QAction(qicon("next-green.png"), "Go To", self)

        self.actionNewFile.setShortcut(self.tr("Ctrl+N"))
        self.actionOpenFile.setShortcut(
            QtGui.QApplication.translate("MainWindow", "Ctrl+O", None, QtGui.QApplication.UnicodeUTF8))

        self.actionRunSelection.setShortcut(
            QtGui.QApplication.translate("MainWindow", "Ctrl+E", None, QtGui.QApplication.UnicodeUTF8))

        self.actionCloseCurrent.setShortcut(
            QtGui.QApplication.translate("MainWindow", "Ctrl+W", None, QtGui.QApplication.UnicodeUTF8))
        self.actionSearch.setShortcut(
            QtGui.QApplication.translate("MainWindow", "Ctrl+F", None, QtGui.QApplication.UnicodeUTF8))
        self.actionGoto.setShortcut(
            QtGui.QApplication.translate("MainWindow", "Ctrl+G", None, QtGui.QApplication.UnicodeUTF8))
        self.actionSave.setShortcut(
            QtGui.QApplication.translate("MainWindow", "Ctrl+S", None, QtGui.QApplication.UnicodeUTF8))
        # self.actionRun.setShortcut(QtGui.QApplication.translate("MainWindow", "Ctrl+R", None, QtGui.QApplication.UnicodeUTF8))
        self.actionRun.setShortcuts([QtGui.QApplication.translate("MainWindow", "F1", None, QtGui.QApplication.UnicodeUTF8), QtGui.QApplication.translate(
            "MainWindow", "Ctrl+R", None, QtGui.QApplication.UnicodeUTF8)])
        self.actionAnimate.setShortcut(
            QtGui.QApplication.translate("MainWindow", "F2", None, QtGui.QApplication.UnicodeUTF8))
        self.actionStep.setShortcut(
            QtGui.QApplication.translate("MainWindow", "F3", None, QtGui.QApplication.UnicodeUTF8))
        self.actionStop.setShortcut(
            QtGui.QApplication.translate("MainWindow", "F4", None, QtGui.QApplication.UnicodeUTF8))
        self.actionInit.setShortcut(
            QtGui.QApplication.translate("MainWindow", "F5", None, QtGui.QApplication.UnicodeUTF8))

        self.actionNewFile.triggered.connect(self.new_file)
        self.actionOpenFile.triggered.connect(self.open)
        self.actionSave.triggered.connect(self.save_current)
#         self.actionSaveAs.triggered.connect(self.save_as)
        self.actionRun.triggered.connect(self.run)
        self.actionAnimate.triggered.connect(self.animate)
        self.actionStep.triggered.connect(self.step)
        self.actionStop.triggered.connect(self.stop)
        self.actionInit.triggered.connect(self.init)
        self.actionCloseCurrent.triggered.connect(self.close_current)

        self.actionRunSelection.triggered.connect(self.execute)

        self.actionUndo.triggered.connect(self.undo)
        self.actionRedo.triggered.connect(self.redo)
        self.actionSearch.triggered.connect(self.search)
        self.actionGoto.triggered.connect(self.goto)
        self.actionComment.triggered.connect(self.comment)
        self.actionUnComment.triggered.connect(self.uncomment)

        self.actionAddFile = QtGui.QAction(qicon("bool.png"), "Add to Project", self)
        self.actionAddFile.triggered.connect(self.add_current_file)

        self.actionStop.setEnabled(False)

        self._run_actions = [
            self.actionAnimate,
            self.actionInit,
            self.actionRun,
            self.actionRunSelection,
            self.actionStep,
            self.actionStop,
        ]

        self._actions = [
            ["Project", "Manage", self.actionNewFile, 0],
            ["Project", "Manage", self.actionAddFile, 1],
            ["Project", "Manage", self.actionOpenFile, 1],
            ["Project", "Manage", self.actionSave, 1],
            ["Project", "Manage", self.actionCloseCurrent, 1],

            ["Project", "Play", self.actionRun, 0],
            ["Project", "Play", self.actionAnimate, 0],
            ["Project", "Play", self.actionStep, 0],
            ["Project", "Play", self.actionStop, 0],
            ["Project", "Play", self.actionInit, 0],

            ["Edit", "Text Edit", self.actionUndo, 0],
            ["Edit", "Text Edit", self.actionRedo, 0],
            ["Edit", "Text Edit", self.actionSearch, 0],
            ["Edit", "Text Edit", self.actionGoto, 0],
            ["Edit", "Text Edit", self.actionComment, 0],
            ["Edit", "Text Edit", self.actionUnComment, 0],
            ["Edit", "Text Edit", self.actionRunSelection, 0],
        ]

        self.connect_paradigm_container()
        self.extensions = ""
        self.connect(self, QtCore.SIGNAL('tabCloseRequested(int)'), self.autoClose)
        self.connect(self, QtCore.SIGNAL('currentChanged(int)'), self.safe_display_help)
        self.currentChanged.connect(self.on_current_tab_changed)

        self.addDefaultTab()
        self.fine_tune()
Пример #26
0
from openalea.core.path import path as Path
from openalea.core.service.plugin import plugins
from openalea.core.model import Model

import mimetypes

__all__ = ["ModelFactory", "ModelClass", "ModelType"]

REGISTERY_MIME_CLASS = {}
for pl in plugins('openalea.core', criteria=dict(implement='IModel')):
    REGISTERY_MIME_CLASS[pl.mimetype] = pl

REGISTERY_DTYPE_MIME = {}
for ModelClass in plugins('openalea.core', criteria=dict(implement='IModel')):
    REGISTERY_DTYPE_MIME[pl.dtype.lower()] = pl.mimetype


def ModelClass(dtype=None, mimetype=None):
    """
    Return class wich match dtype.
    For example, for 'python' dtype it return PythonModel class.

    Matching can be extended with plugins.
    if both dtype and mimetype is None, returns all available ModelClasses
    """
    if dtype is None and mimetype is None:
        return set([pl.implementation
                    for pl in REGISTERY_MIME_CLASS.values()] + [Model])

    if mimetype in REGISTERY_MIME_CLASS:
        return REGISTERY_MIME_CLASS[mimetype].implementation
Пример #27
0
from openalea.core.path import path as Path
from openalea.core.service.plugin import plugins
from openalea.core.data import Data

import mimetypes

__all__ = ["DataFactory", "DataClass", "MimeType", "DataType"]

REGISTERY_MIME_CLASS = {}
for pl in plugins('openalea.core', criteria=dict(implement='IData')):
    REGISTERY_MIME_CLASS[pl.mimetype] = pl
# for ModelClass in iter_plugins('oalab.model'):
#     REGISTERY_MIME_CLASS[ModelClass.mimetype] = ModelClass

REGISTERY_NAME_MIME = {}
for pl in plugins('openalea.core', criteria=dict(implement='IData')):
    REGISTERY_NAME_MIME[pl.default_name.lower()] = pl.mimetype
    REGISTERY_NAME_MIME[pl.extension.lower()] = pl.mimetype

# for ModelClass in iter_plugins('oalab.model'):
#     REGISTERY_NAME_MIME[ModelClass.default_name.lower()] = ModelClass.mimetype
#     REGISTERY_NAME_MIME[ModelClass.extension.lower()] = ModelClass.mimetype


def MimeType(path=None, name=None):
    """
    Return mimetype for path.
    First, try to find extension in registery filled by models.
    If datatype is not found, use builtin module "mimetypes".
    If it cannot guess, returns False.
Пример #28
0
    def __init__(self, parent=None):
        super(ParadigmContainer, self).__init__(parent=parent)

        self.setTabsClosable(True)

        self.applets = []
        self._open_tabs = {}
        self.paradigms = {}
        self._new_file_actions = {}
        self.paradigms_actions = []
        for plugin_class in plugins('oalab.paradigm_applet'):
            plugin = plugin_class()
            paradigm_applet = debug_plugin('oalab.paradigm_applet',
                                           func=plugin)
            if paradigm_applet:
                self.paradigms[plugin_class.name] = paradigm_applet

        self._open_objects = {}

        self.projectManager = ProjectManager()

        self.setAccessibleName("Container")
        self.setElideMode(QtCore.Qt.ElideLeft)

        self.actionNewFile = QtGui.QAction(qicon("new.png"), "New file", self)
        self.actionOpenFile = QtGui.QAction(qicon("open.png"), "Open file",
                                            self)
        self.actionSave = QtGui.QAction(qicon("save.png"), "Save File", self)
        self.actionSaveAs = QtGui.QAction(qicon("save.png"), "Save As", self)
        self.actionRun = QtGui.QAction(qicon("run.png"), "Run", self)
        self.actionAnimate = QtGui.QAction(qicon("play.png"), "Animate", self)
        self.actionStep = QtGui.QAction(qicon("step.png"), "Step", self)
        self.actionStop = QtGui.QAction(qicon("pause.png"), "Stop", self)
        self.actionInit = QtGui.QAction(qicon("rewind.png"), "Init", self)
        self.actionCloseCurrent = QtGui.QAction(qicon("closeButton.png"),
                                                "Close current tab", self)

        self.actionRunSelection = QtGui.QAction(qicon("run.png"),
                                                "Run subpart", self)

        self.actionUndo = QtGui.QAction(qicon("editundo.png"), "Undo", self)
        self.actionRedo = QtGui.QAction(qicon("editredo.png"), "Redo", self)
        self.actionSearch = QtGui.QAction(qicon("editfind.png"), "Search",
                                          self)

        self.actionComment = QtGui.QAction(qicon("commentOn.png"), "Comment",
                                           self)
        self.actionUnComment = QtGui.QAction(qicon("commentOff.png"),
                                             "Uncomment", self)
        self.actionGoto = QtGui.QAction(qicon("next-green.png"), "Go To", self)

        self.actionNewFile.setShortcut(self.tr("Ctrl+N"))
        self.actionOpenFile.setShortcut(
            QtGui.QApplication.translate("MainWindow", "Ctrl+O", None,
                                         QtGui.QApplication.UnicodeUTF8))

        self.actionRunSelection.setShortcut(
            QtGui.QApplication.translate("MainWindow", "Ctrl+E", None,
                                         QtGui.QApplication.UnicodeUTF8))

        self.actionCloseCurrent.setShortcut(
            QtGui.QApplication.translate("MainWindow", "Ctrl+W", None,
                                         QtGui.QApplication.UnicodeUTF8))
        self.actionSearch.setShortcut(
            QtGui.QApplication.translate("MainWindow", "Ctrl+F", None,
                                         QtGui.QApplication.UnicodeUTF8))
        self.actionGoto.setShortcut(
            QtGui.QApplication.translate("MainWindow", "Ctrl+G", None,
                                         QtGui.QApplication.UnicodeUTF8))
        self.actionSave.setShortcut(
            QtGui.QApplication.translate("MainWindow", "Ctrl+S", None,
                                         QtGui.QApplication.UnicodeUTF8))
        # self.actionRun.setShortcut(QtGui.QApplication.translate("MainWindow", "Ctrl+R", None, QtGui.QApplication.UnicodeUTF8))
        self.actionRun.setShortcuts([
            QtGui.QApplication.translate("MainWindow", "F1", None,
                                         QtGui.QApplication.UnicodeUTF8),
            QtGui.QApplication.translate("MainWindow", "Ctrl+R", None,
                                         QtGui.QApplication.UnicodeUTF8)
        ])
        self.actionAnimate.setShortcut(
            QtGui.QApplication.translate("MainWindow", "F2", None,
                                         QtGui.QApplication.UnicodeUTF8))
        self.actionStep.setShortcut(
            QtGui.QApplication.translate("MainWindow", "F3", None,
                                         QtGui.QApplication.UnicodeUTF8))
        self.actionStop.setShortcut(
            QtGui.QApplication.translate("MainWindow", "F4", None,
                                         QtGui.QApplication.UnicodeUTF8))
        self.actionInit.setShortcut(
            QtGui.QApplication.translate("MainWindow", "F5", None,
                                         QtGui.QApplication.UnicodeUTF8))

        self.actionNewFile.triggered.connect(self.new_file)
        self.actionOpenFile.triggered.connect(self.open)
        self.actionSave.triggered.connect(self.save_current)
        #         self.actionSaveAs.triggered.connect(self.save_as)
        self.actionRun.triggered.connect(self.run)
        self.actionAnimate.triggered.connect(self.animate)
        self.actionStep.triggered.connect(self.step)
        self.actionStop.triggered.connect(self.stop)
        self.actionInit.triggered.connect(self.init)
        self.actionCloseCurrent.triggered.connect(self.close_current)

        self.actionRunSelection.triggered.connect(self.execute)

        self.actionUndo.triggered.connect(self.undo)
        self.actionRedo.triggered.connect(self.redo)
        self.actionSearch.triggered.connect(self.search)
        self.actionGoto.triggered.connect(self.goto)
        self.actionComment.triggered.connect(self.comment)
        self.actionUnComment.triggered.connect(self.uncomment)

        self.actionAddFile = QtGui.QAction(qicon("bool.png"), "Add to Project",
                                           self)
        self.actionAddFile.triggered.connect(self.add_current_file)

        self.actionStop.setEnabled(False)

        self._run_actions = [
            self.actionAnimate,
            self.actionInit,
            self.actionRun,
            self.actionRunSelection,
            self.actionStep,
            self.actionStop,
        ]

        self._actions = [
            ["Project", "Manage", self.actionNewFile, 0],
            ["Project", "Manage", self.actionAddFile, 1],
            ["Project", "Manage", self.actionOpenFile, 1],
            ["Project", "Manage", self.actionSave, 1],
            ["Project", "Manage", self.actionCloseCurrent, 1],
            ["Project", "Play", self.actionRun, 0],
            ["Project", "Play", self.actionAnimate, 0],
            ["Project", "Play", self.actionStep, 0],
            ["Project", "Play", self.actionStop, 0],
            ["Project", "Play", self.actionInit, 0],
            ["Edit", "Text Edit", self.actionUndo, 0],
            ["Edit", "Text Edit", self.actionRedo, 0],
            ["Edit", "Text Edit", self.actionSearch, 0],
            ["Edit", "Text Edit", self.actionGoto, 0],
            ["Edit", "Text Edit", self.actionComment, 0],
            ["Edit", "Text Edit", self.actionUnComment, 0],
            ["Edit", "Text Edit", self.actionRunSelection, 0],
        ]

        self.connect_paradigm_container()
        self.extensions = ""
        self.connect(self, QtCore.SIGNAL('tabCloseRequested(int)'),
                     self.autoClose)
        self.connect(self, QtCore.SIGNAL('currentChanged(int)'),
                     self.safe_display_help)
        self.currentChanged.connect(self.on_current_tab_changed)

        self.addDefaultTab()
        self.fine_tune()
Пример #29
0
 def _on_group_changed(self, idx):
     group = self._cb_group.itemText(idx)
     self.set_items(plugins(group))
Пример #30
0
from openalea.oalab.service.applet import get_applet
from openalea.oalab.widget.mainwindow import MainWindow
from openalea.oalab.session.session import Session
from openalea.core.service.plugin import plugins
from openalea.core.service.ipython import interpreter

if __name__ == '__main__':
    instance = QtGui.QApplication.instance()
    if instance is None:
        app = QtGui.QApplication([])
    else:
        app = instance

    session = Session()
    mainwin = MainWindow(session)
    for plugin in plugins('oalab.applet'):
        if plugin.name in ('ProjectManager', 'EditorManager'):
            mainwin.add_plugin(plugin())

    pm = session.project_manager
    pm.cproject = pm.default()
    pmw = get_applet(identifier='ProjectManager', class_args=dict(mainwindow=mainwin))
    pcw = get_applet(identifier='EditorManager', class_args=dict(mainwindow=mainwin))

    interp = interpreter()
    interp.locals['pmw'] = pmw
    interp.locals['pcw'] = pcw

    mainwin.show()
    mainwin.raise_()
Пример #31
0
from openalea.oalab.service.applet import get_applet
from openalea.oalab.widget.mainwindow import MainWindow
from openalea.oalab.session.session import Session
from openalea.core.service.plugin import plugins
from openalea.core.service.ipython import interpreter

if __name__ == '__main__':
    instance = QtGui.QApplication.instance()
    if instance is None:
        app = QtGui.QApplication([])
    else:
        app = instance

    session = Session()
    mainwin = MainWindow(session)
    for plugin in plugins('oalab.applet'):
        if plugin.name in ('ProjectManager', 'EditorManager'):
            mainwin.add_plugin(plugin())

    pm = session.project_manager
    pm.cproject = pm.default()
    pmw = get_applet(identifier='ProjectManager',
                     class_args=dict(mainwindow=mainwin))
    pcw = get_applet(identifier='EditorManager',
                     class_args=dict(mainwindow=mainwin))

    interp = interpreter()
    interp.locals['pmw'] = pmw
    interp.locals['pcw'] = pcw

    mainwin.show()
Пример #32
0
 def _on_group_changed(self, idx):
     group = self._cb_group.itemText(idx)
     self.set_items(plugins(group))
Пример #33
0
def discover_qt_controls():
    return plugins('oalab.plugin', criteria=dict(implement='IWidgetSelector'))
Пример #34
0
from openalea.core.path import path as Path
from openalea.core.service.plugin import plugins
from openalea.core.model import Model

import mimetypes

__all__ = ["ModelFactory", "ModelClass", "ModelType"]

REGISTERY_MIME_CLASS = {}
for pl in plugins('openalea.core', criteria=dict(implement='IModel')):
    REGISTERY_MIME_CLASS[pl.mimetype] = pl

REGISTERY_DTYPE_MIME = {}
for ModelClass in plugins('openalea.core', criteria=dict(implement='IModel')):
    REGISTERY_DTYPE_MIME[pl.dtype.lower()] = pl.mimetype


def ModelClass(dtype=None, mimetype=None):
    """
    Return class wich match dtype.
    For example, for 'python' dtype it return PythonModel class.

    Matching can be extended with plugins.
    if both dtype and mimetype is None, returns all available ModelClasses
    """
    if dtype is None and mimetype is None:
        return set([pl.implementation for pl in REGISTERY_MIME_CLASS.values()] + [Model])

    if mimetype in REGISTERY_MIME_CLASS:
        return REGISTERY_MIME_CLASS[mimetype].implementation