Exemplo n.º 1
0
    def update(self, obj, path, protocol=None, **kwds):
        project = obj
        default_metadata = kwds.pop('default_metadata',
                                    project.DEFAULT_METADATA)
        default_categories = kwds.pop('default_categories',
                                      project.DEFAULT_CATEGORIES)
        config_filename = kwds.pop('config_filename', 'oaproject.cfg')

        config = ConfigObj(path / config_filename)
        if 'metadata' in config:
            for info in config["metadata"].keys():
                if info == 'name':
                    info = 'alias'
                    value = config['metadata']['name']
                elif info == 'author':
                    info = 'authors'
                    value = config['metadata']['author']
                elif info == 'author_email':
                    continue
                else:
                    value = config['metadata'][info]
                if interface_name(
                        default_metadata[info].interface) == 'ISequence':
                    if isinstance(value, basestring):
                        value = value.split(',')
                setattr(project, info, value)

        if 'manifest' in config:
            # Load file names in right place (dict.keys()) but don't load entire object:
            # ie. load keys but not values
            for category in config["manifest"].keys():

                # Backward compatibility
                if category == 'src':
                    category = 'model'
                    old_category = 'src'
                else:
                    old_category = category

                if category in default_categories:
                    filenames = config["manifest"][old_category]
                    if not isinstance(filenames, list):
                        filenames = [filenames]
                    for filename in filenames:
                        section = '%s.path' % category
                        if section in config:
                            if filename in config[section]:
                                project._add_item(
                                    category,
                                    path=config[section][filename],
                                    mode=project.MODE_LINK)
                            else:
                                project._add_item(category,
                                                  filename=filename,
                                                  mode=project.MODE_COPY)
                        else:
                            project._add_item(category,
                                              filename=filename,
                                              mode=project.MODE_COPY)
        return project
Exemplo n.º 2
0
def qt_editor_class(iname, shape=None, preferred=None):
    iname = interface_name(iname)
    # Get all widget plugin for "iname" interface
    widget_plugins = qt_widget_plugins(iname)

    # If preferred widget(s) is/are specified, try to find it
    if isinstance(preferred, str):
        preferred_widgets = [preferred]
    else:
        preferred_widgets = preferred

    if preferred_widgets:
        for preferred in preferred_widgets:
            # Load widget specified with control
            for plugin in widget_plugins:
                if preferred == plugin.name:
                    widget_class = plugin.implementation
                    return widget_class

    # No preferred widget specified or preferred widget not found.
    # We try to find a widget corresponding to shapes
    if shape is None:
        shapes = ['hline', 'large', 'small']
    elif isinstance(shape, str):
        shapes = [shape]
    else:
        shapes = list(shape)

    for shape in shapes:
        for plugin in widget_plugins:
            if shape in plugin.edit_shape or 'responsive' in plugin.edit_shape:
                widget_class = plugin.implementation
                widget_class.shape = shape
                return widget_class
    return None
Exemplo n.º 3
0
def qt_editor_class(iname, shape=None, preferred=None):
    iname = interface_name(iname)
    # Get all widget plugin for "iname" interface
    widget_plugins = qt_widget_plugins(iname)

    # If preferred widget(s) is/are specified, try to find it
    if isinstance(preferred, str):
        preferred_widgets = [preferred]
    else:
        preferred_widgets = preferred

    if preferred_widgets:
        for preferred in preferred_widgets:
            # Load widget specified with control
            for plugin in widget_plugins:
                if preferred == plugin.name:
                    widget_class = plugin.load()
                    return widget_class

    # No preferred widget specified or preferred widget not found.
    # We try to find a widget corresponding to shapes
    if shape is None:
        shapes = ['hline', 'large', 'small']
    elif isinstance(shape, str):
        shapes = [shape]
    else:
        shapes = list(shape)

    for shape in shapes:
        for plugin in widget_plugins:
            if shape in plugin.edit_shape or 'responsive' in plugin.edit_shape:
                widget_class = plugin.load()
                widget_class.shape = shape
                return widget_class
    return None
Exemplo n.º 4
0
    def update(self, obj, path, protocol=None, **kwds):
        project = obj
        default_metadata = kwds.pop('default_metadata', project.DEFAULT_METADATA)
        default_categories = kwds.pop('default_categories', project.categories)
        config_filename = kwds.pop('config_filename', 'oaproject.cfg')

        config = ConfigObj(path / config_filename)
        if 'metadata' in config:
            for info in config["metadata"].keys():
                if info == 'name':
                    info = 'alias'
                    value = config['metadata']['name']
                elif info == 'author':
                    info = 'authors'
                    value = config['metadata']['author']
                elif info == 'author_email':
                    continue
                else:
                    value = config['metadata'][info]
                if interface_name(default_metadata[info].interface) == 'ISequence':
                    if isinstance(value, basestring):
                        value = value.split(',')
                setattr(project, info, value)

        if 'manifest' in config:
            # Load file names in right place (dict.keys()) but don't load entire object:
            # ie. load keys but not values
            for category in config["manifest"].keys():

                # Backward compatibility
                if category == 'src':
                    category = 'model'
                    old_category = 'src'
                else:
                    old_category = category

                if category in default_categories:
                    filenames = config["manifest"][old_category]
                    if not isinstance(filenames, list):
                        filenames = [filenames]
                    for filename in filenames:
                        section = '%s.path' % category
                        try:
                            if section in config:
                                if filename in config[section]:
                                    project._add_item(category, path=config[section][filename], mode=project.MODE_LINK)
                                else:
                                    project._add_item(category, filename=filename, mode=project.MODE_COPY)
                            else:
                                project._add_item(category, filename=filename, mode=project.MODE_COPY)
                        except ErrorInvalidItem:
                            pass
        return project
Exemplo n.º 5
0
def test_new_and_get_class():
    iclass1 = interface_class('IInt')
    assert interface_class(iclass1) == iclass1
    assert issubclass(iclass1, IInterface)


    iname0 = 'IInt'
    iname1 = interface_name(iname0)
    iname2 = interface_name(iclass1)
    iname3 = interface_name(iclass1())
    iname4 = interface_name(int)
    iname5 = interface_name('int')

    assert iname1 == iname0
    assert iname2 == iname0
    assert iname3 == iname0
    assert iname4 == iname0
    assert iname5 == iname0

    interface1 = new_interface(iname1, min=1, max=1)
    interface2 = new_interface(iclass1, min=1, max=2)
    interface3 = new_interface(interface2, min=1, max=3)
    interface4 = new_interface(iname1, 1, min=1, max=4)
    interface5 = new_interface(value=1, min=1, max=5)

    assert isinstance(interface1, iclass1)
    assert isinstance(interface2, iclass1)
    assert isinstance(interface3, iclass1)
    assert isinstance(interface4, iclass1)
    assert isinstance(interface5, iclass1)

    # Warning, normal behaviour is to keep interface unchanged if interface is yet an instance
    assert(interface3.max == 2)

    assert(interface1.max == 1)
    assert(interface2.max == 2)
    assert(interface4.max == 4)
    assert(interface5.max == 5)
Exemplo n.º 6
0
def notebook_editor(control, shape=None, preferred=None, preferences=None):
    iname = interface_name(control.interface)
    notebookclass = None
    if preferred:
        notebookclass = preferred
    elif preferences and iname in preferences:
        notebookclass = preferences[iname].value
    elif iname in preferred_widgets:
        notebookclass = preferred_widgets[iname].values()[0]

    if notebookclass:
        widget = NotebookControlWidget(notebookclass=notebookclass)
        widget.set(control)
        return widget
Exemplo n.º 7
0
def notebook_editor(control, shape=None, preferred=None, preferences=None):
    iname = interface_name(control.interface)
    notebookclass = None
    if preferred:
        notebookclass = preferred
    elif preferences and iname in preferences:
        notebookclass = preferences[iname].value
    elif iname in preferred_widgets:
        notebookclass = preferred_widgets[iname].values()[0]

    if notebookclass:
        widget = NotebookControlWidget(notebookclass=notebookclass)
        widget.set(control)
        return widget
Exemplo n.º 8
0
 def namespace(self, interface=None):
     """
     Returns namespace (dict control name -> value).
     :param tag: returns namespace corresponding to given tag.
                 Default, returns global namespace
     """
     ns = {}
     for control in self.controls():
         if interface is None:
             ns[control.name] = copy.deepcopy(control.value)
         else:
             from openalea.core.service.interface import interface_name
             if interface_name(control.interface) == interface:
                 ns[control.name] = copy.deepcopy(control.value)
     return ns
Exemplo n.º 9
0
 def namespace(self, interface=None):
     """
     Returns namespace (dict control name -> value).
     :param tag: returns namespace corresponding to given tag.
                 Default, returns global namespace
     """
     ns = {}
     for control in self.controls():
         if interface is None:
             ns[control.name] = copy.deepcopy(control.value)
         else:
             from openalea.core.service.interface import interface_name
             if interface_name(control.interface) == interface:
                 ns[control.name] = copy.deepcopy(control.value)
     return ns