Source code for sylib.calculator.plugins

# This file is part of Sympathy for Data.
# Copyright (c) 2017, Combine Control Systems AB
#
# SYMPATHY FOR DATA COMMERCIAL LICENSE
# You should have received a link to the License with Sympathy for Data.
from sympathy.utils.components import get_components
from sympathy.api import component


[docs] class ICalcPlugin(component.NodePlugin): """Interface for calculator plugins.""" WEIGHT = 10000 @staticmethod def plugin_base_name(): return 'Calculator'
[docs] @staticmethod def gui_dict(): """ Return a dictionary with functions that will be shown in the configuration gui for the calculator node. Each dictionary in the globals_dict represents another level of subcategories in the tree view. The keys of the dict is used as labels for the subcategories. A list represents a list of functions. Each function in the list should be a tuple of three elements: label, code, tooltip/documentation. For example: {'My functions': [ ('My function 1', 'myplugin.func1()', "My function 1 is awesome..."), ('My function 2', 'myplugin.func2()', "My function 1 is also awesome...")]} This should result in a top level category called "My functions" containing the two functions "My function 1" and "My function 2". """ return {}
[docs] @staticmethod def globals_dict(): """ Return a dictionary that will be added to the globals dictionary when executing calculations. """ return {}
[docs] @staticmethod def hidden_items(): """ Reimplement this to hide some elements from other plugins. The hidden functions will still be available, but won't show up in the list of common functions in the calculator gui. The returned value should be a list of tuples with the "paths" in the gui_dict that should be hidden. E.g. ``[("Event detection",)]`` will hide the entire event detection subtree, while ``[("Event detection", "Changed")]`` will hide the function called "Changed" under "Event detection". """ return []
class MatlabCalcPlugin: """Interface for calculator plugins.""" WEIGHT = 10000 @staticmethod def gui_dict(generic): """ Return a dictionary with functions that will be shown in the configuration gui for the calculator node. """ return {} @staticmethod def globals_dict(): """ Return a dictionary that will be added to the globals dictionary when executing calculations. """ return {} def available_plugins(backend='python'): """Return all available plugins derived for a specific backend.""" plugin_classes = {'python': ICalcPlugin, 'matlab': MatlabCalcPlugin} return get_components('plugin_*.py', plugin_classes[backend]) class PluginWrapper: """ Merge two or more module-like objects into one. getattr calls on PluginWrapper objects are passed on to the module-like objects and the first one which doesn't raise AttributeError gets to return its result. """ def __init__(self, *namespaces): self._namespaces = list(namespaces) def __getattr__(self, attr): for ns in self._namespaces: try: return getattr(ns, attr) except AttributeError: pass raise AttributeError(attr)