How to use the enaml.core.declarative.Declarative function in enaml

To help you get started, we’ve selected a few enaml examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nucleic / enaml / enaml / widgets / styling.py View on Github external
#------------------------------------------------------------------------------
# Copyright (c) 2013, Nucleic Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING.txt, distributed with this software.
#------------------------------------------------------------------------------
from collections import defaultdict

from atom.api import Atom, Unicode, Typed, observe

from enaml.application import deferred_call
from enaml.core.declarative import Declarative, d_


class Rule(Declarative):
    """ A declarative class for defining a rule in a rule set.

    If a Rule has a parent, it must be a RuleSet object. Failing to
    adhere to this condition is a programming error.

    """
    #: The style property to which the rule applies. An empty property
    #: name will cause the rule to be ignored. The properties supported
    #: by a widget are toolkit dependent.
    property = d_(Unicode())

    #: The value to apply to the style property. An empty value will
    #: cause the rule to be ignored.
    value = d_(Unicode())

    def destroy(self):
github nucleic / enaml / enaml / workbench / extension.py View on Github external
#------------------------------------------------------------------------------
# Copyright (c) 2013, Nucleic Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file LICENSE, distributed with this software.
#------------------------------------------------------------------------------
from __future__ import unicode_literals
from atom.api import Callable, Int, Str

from enaml.core.declarative import Declarative, d_


class Extension(Declarative):
    """ A declarative class which represents a plugin extension.

    An Extension must be declared as a child of a PluginManifest.

    """
    #: The globally unique identifier for the extension.
    id = d_(Str())

    #: The fully qualified id of the target extension point.
    point = d_(Str())

    #: An optional rank to use for order the extension among others.
    rank = d_(Int())

    #: A callable which will create the implementation object for the
    #: extension point. The call signature and return type are defined
github inkcut / inkcut / inkcut / ui / extensions.py View on Github external
SETTINGS_PAGE_POINT = 'inkcut.ui.settings.page'


class DockItem(Declarative):

    #: The plugin to pass to this dock item
    plugin_id = d_(Unicode())

    #: The factory for creating this dock item
    factory = d_(Callable())

    #: Where to layout this item in the dock area
    layout = d_(Enum('main', 'top', 'left', 'right', 'bottom'))


class SettingsPage(Declarative):

    #: Settings page name that is displayed in the ui
    name = d_(Unicode())

    #: The plugin to pass to this dock item
    plugin_id = d_(Unicode())

    #: Attribute to pull from the plugin using getattr to retrieve the model
    #: for the settings page. If blank, the plugin will be used.
    model = d_(Unicode())

    #: The factory for creating this settings page. Must return a view class
    #: with a 'model' attribute to pass to a MappedView instance.
    factory = d_(Callable())
github inkcut / inkcut / src / inkcut / workbench / core / device.py View on Github external
#     def make_connection(self, job):
#         self.endpoint = TCP4ClientEndpoint(reactor, self.address, self.port)
#         protocol = super(INetDriver, self).make_connection(job)
#         yield connectProtocol(self.endpoint,protocol)
#         #return protocol
#     
#     def lose_connection(self,protocol):
#         protocol.transport.loseConnection()
# 
def generic_factory(driver_def,protocol):
    """ Generate the correct device from the Driver """
    from inkcut.workbench.core import device
    DriverFactory = getattr(device,"{}Driver".format(driver_def.connections[0].title()))
    return DriverFactory(protocol=protocol)
         
class DeviceDriver(Declarative):
    """ Provide meta info about this device """
    # ID of the device
    # If none exits one i created from manufacturer.model
    id = d_(Unicode())
    
    # Name of the device (optional)
    name = d_(Unicode())
    # Model of the device (optional)
    model = d_(Unicode())
    
    # Manufacturer of the device (optional)
    manufacturer = d_(Unicode())
    
    # Width of the device (required)
    width = d_(Unicode())
github MatthieuDartiailh / HQCMeas / hqc_meas / debug / debugger.py View on Github external
plugin = ForwardTyped(_debugger_plugin)

    #: Reference to the manifest used for cretaing this debugger.
    declaration = ForwardTyped(lambda: Debugger)

    def release_ressources(self):
        """ Ask the debugger to release all ressources it is actively using.

        This method is called when the activity of the debugger is about to
        stop.

        """
        pass


class Debugger(Declarative):
    """ Extension for the 'debuggers' extension point of a DebuggerPlugin.

    The name member inherited from Object should always be set to an easily
    understandable name for the user.

    """
    #: Id of the debugger, this can be different from the id of the plugin
    #: declaring it but does not have to.
    id = d_(Unicode())

    #: Debugger description.
    description = d_(Unicode())

    #: Factory function returning an instance of the debugger. This callable
    #: should take as arguments the debugger declaration and the debugger
    #: plugin.
github nucleic / enaml / enaml / widgets / styling / styledata.py View on Github external
# Copyright (c) 2013, Nucleic Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING.txt, distributed with this software.
#------------------------------------------------------------------------------
from atom.api import Typed

from enaml.core.declarative import Declarative, d_

from .border import Border
from .margin import Margin
from .padding import Padding


class StyleData(Declarative):
    """ A declarative class for defining Enaml style data objects.

    A style data object is used to store the fully resolved values for
    the style properties.

    """
    #: The margin definition for the widget. This will be overridden by
    #: any Margin child defined on the style.
    margin = d_(Typed(Margin))

    #: The padding for the widget. This will be overridden by any
    #: Padding child defined on the style.
    padding = d_(Typed(Padding))

    #: The border definition for the widget. This will be overridden by
    #: any Border child defined on the style.
github nucleic / enaml / enaml / core / resolver.py View on Github external
def _resolve_child_globals(self, node):
        try:
            typeclass = self._f_globals[node.typename]
        except KeyError:
            self._raise_error(DeclarativeNameError, node.typename, node)
        if (not isinstance(typeclass, type) or
            not issubclass(typeclass, Declarative)):
            msg = "'%s' is not a Declarative subclass" % node.typename
            self._raise_error(DeclarativeError, msg, node)
        node.typeclass = typeclass
        for storage in node.storage_defs:
            self._resolve_storage_globals(storage)
        for binding in node.bindings:
            self._resolve_binding_globals(binding)
        for child in node.child_defs:
            self._resolve_child_globals(child)
github nucleic / enaml / enaml / core / dynamic_template.py View on Github external
#: The tag to apply to overflow return items from the template.
    startag = d_(Str())

    #: The data keywords to apply to the instantiated items.
    data = d_(Dict())

    #: The object dictionary which maps tag name to tagged object. This
    #: is updated automatically when the template is instantiated.
    tagged = Typed(ObjectDict, ())

    #: The internal task used to collapse template updates.
    _update_task = Typed(ScheduledTask)

    #: The internal list of items generated by the template.
    _items = List(Declarative)

    def initialize(self):
        """ A reimplemented initializer.

        This method will instantiate the template and initialize the
        items for the first time.

        """
        self._refresh()
        for item in self._items:
            item.initialize()
        super(DynamicTemplate, self).initialize()

    def destroy(self):
        """ A reimplemented destructor.
github nucleic / enaml / enaml / widgets / styling.py View on Github external
name = change['name']
            setattr(self, '_%ss' % name, None)  # clear the property cache
            StyleCache.rule_set_match_invalidated(self)

    @observe('pseudostate', 'subcontrol')
    def _invalidate_data_cache(self, change):
        """ An observer which invalidates the rule set data cache.

        """
        if change['type'] == 'update':
            name = change['name']
            setattr(self, '_%ss' % name, None)  # clear the property cache
            StyleCache.rule_set_data_invalidated(self)


class StyleSheet(Declarative):
    """ A declarative class for defining Enaml widget style sheets.

    """
    def destroy(self):
        """ A reimplemented destructor.

        This method informs the style cache when the sheet is destroyed.

        """
        super(StyleSheet, self).destroy()
        StyleCache.style_sheet_destroyed(self)

    def rule_sets(self):
        """ Get the rule sets declared for the style sheet.

        Returns
github nucleic / enaml / enaml / core / compiler_helpers.py View on Github external
def validate_declarative(klass):
    """ Validate that an object is a Declarative type.

    Parameters
    ----------
    klass : object
        The object to validate.

    """
    if not isinstance(klass, type):
        raise TypeError("%s is not a type" % klass)
    if not issubclass(klass, Declarative):
        raise TypeError("'%s' is not a Declarative type" % klass.__name__)