コード例 #1
0
class BaseRecordSource(Atom):
    name = Str()
    title = Str()

    schema = Typed(RecordSchema)
    output_fieldnames = List()

    max_record_count = Int(0)
    reference_timestamps = List()
    reference_interval = Float(1.0)

    record_class = Value()
    cached_records = List()

    def _default_output_fieldnames(self):
        return ['timestamp'] + [f.name for f in self.schema.fields]

    def _default_record_class(self):
        attrs = dict(timestamp=Coerced(np.int64), )
        for field in self.schema.fields:
            if field.name in attrs:
                log.warn(
                    "Duplicate key: %s in field specification for record source: %s - skipping"
                    % (field.name, self.name))
                continue
            attrs[field.name] = Value()
        return new.classobj("RecordClass_%s" % self.name, (Atom, ), attrs)

    def clear_cache(self):
        self.cached_records = []

    def __iter__(self):
        if len(self.cached_records) > 0:
            for cached_record in self.cached_records:
                yield cached_record
            return

        raise NotImplemented()
コード例 #2
0
ファイル: while_task.py プロジェクト: zoulianmp/HQCMeas
class WhileTask(ComplexTask):
    """ Task breaking out of a loop when a condition is met.

    See Python break statement documenttaion.

    """
    logic_task = True

    condition = Str().tag(pref=True)

    task_database_entries = set_default({'index' : 1})

    def check(self, *args, **kwargs):
        """

        """
        test, traceback = super(WhileTask, self).check(*args, **kwargs)

        try:
            self.format_and_eval_string(self.condition)
        except Exception as e:
            test = False
            mess = 'Task did not succeed to compute the break condition: {}'
            traceback[self.task_path + '/' + self.task_name + '-cond'] = \
                mess.format(e)

        return test, traceback

    def perform(self):
        """

        """
        i = 1
        root = self.root_task
        while True:
            self.write_in_database('index', i)
            i += 1
            if not self.format_and_eval_string(self.condition):
                break

            if handle_stop_pause(root):
                return

            try:
                for child in self.children_task:
                    child.perform_(child)
            except BreakException:
                break
            except ContinueException:
                continue
コード例 #3
0
class Picomotor(Prop):
    # must keep track of position changes and send only difference
    serial_number = Str()
    motor_number = Str()
    desired_position = Member()
    current_position = Int()
    max_angle_error = Float(
        0)  # necessary so I don't have to define a new enaml container

    def __init__(self, name, experiment, description=''):
        super(Picomotor, self).__init__(name, experiment, description)
        self.desired_position = IntProp('desired_position', experiment,
                                        'the desired position', '0')
        self.properties += [
            'serial_number', 'motor_number', 'desired_position',
            'max_angle_error'
        ]
        self.current_position = self.desired_position.value

    def update(self):
        # calculate relative move necessary
        relative_move = self.desired_position.value - self.current_position
        return '{},{},{}'.format(serial_number, motor_number, relative_move)
コード例 #4
0
ファイル: conditional_task.py プロジェクト: rassouly/exopy
class ConditionalTask(ComplexTask):
    """Task calling its children only if a given condition is met.

    """
    #: Condition to meet in order to perform the children tasks.
    condition = Str().tag(pref=True, feval=Feval())

    def perform(self):
        """Call the children task if the condition evaluate to True.

        """
        if self.format_and_eval_string(self.condition):
            for child in self.children:
                child.perform_()
コード例 #5
0
class EnvironmentKey(Atom):
    is_default = Bool(False)
    is_existing = Bool(False)
    is_active = Bool(False)

    key = Str()
    values = List(EnvironmentValue)

    def get_value_as_string(self):
        return os.pathsep.join([v.value for v in self.values])


    def __repr__(self):
        return u"Key<%s>:%s" % (self.key, self.values)
コード例 #6
0
class JobFilter(Atom):
    #: A fixed type name for the UI to extract without using isinstance
    type = ""

    #: Name to display in the UI
    name = Str()

    #: If NOT enabled then apply_filter is called which should return the
    #: path with the filtered path elements REMOVED.
    enabled = Bool(True)

    @classmethod
    def get_filter_options(cls, job, doc):
        """ Get the list of options that can be filtered from the document

        Parameters
        ----------
        job: inkcut.models.Job
            The job that is being processed. This should only be used to
            reference settings.
        doc: QtSvgDoc
            The document to filter.

        Returns
        -------
        results: List[cls]
            The list of filterable options to choose from.

        """
        raise NotImplementedError()

    def apply_filter(self, job, doc):
        """ Apply the filter to the path by removing paths that are excluded
        by this filter.  This is only called if the `enabled` is set to false.

        Parameters
        ----------
        job: inkcut.models.Job
            The job that is being processed. This should only be used to
            reference settings.
        doc: QtSvgDoc
            The document to filter.

        Returns
        -------
        doc: QtSvgDoc
            The filtered document.

        """
        raise NotImplementedError()
コード例 #7
0
class Plot2D(BasePlot):
    """"""

    #: Data for the plot.
    data = Typed(Plot2DData).tag(sync=True)

    #: Colormap to use.
    colormap = Str("viridis")

    # --- Proxy connection

    def _post_setattr_data(self, old, new):
        if self.proxy:
            self.proxy.set_data(new)
コード例 #8
0
class EnamlDef(ASTNode):
    """ An ASTNode representing an enamldef block.

    """
    #: The type name given to the enamldef.
    typename = Str()

    #: The name of the base class which is being inherited.
    base = Str()

    #: The identifier given to the enamldef.
    identifier = Str()

    #: The docstring for the enamldef.
    docstring = Str()

    #: The list of decorator for the enamldef. This will be composed of
    #: Python nodes.
    decorators = List()

    #: The list of body nodes for the enamldef. This will be composed
    #: of StorageDef, Binding, and ChildDef nodes.
    body = List()
コード例 #9
0
ファイル: person.py プロジェクト: zxyfanta/enaml
class Person(Atom):
    """ A simple class representing a person object.

    """
    last_name = Str()

    first_name = Str()

    age = Range(low=0)

    debug = Bool(False)

    @observe('age')
    def debug_print(self, change):
        """ Prints out a debug message whenever the person's age changes.

        """
        if self.debug:
            templ = "{first} {last} is {age} years old."
            s = templ.format(
                first=self.first_name, last=self.last_name, age=self.age,
            )
            print(s)
コード例 #10
0
class IconThemeExtension(Declarative):
    """Declarative object used to contribute new icons to an existing theme.

    """
    #: Unicsue id of the extension.
    id = d_(Str())

    #: Id of the icon theme to which to contribute the children Icon objects.
    theme = d_(Str())

    def icons(self):
        """List the associated icons.

        """
        if not self._icons:
            self._icons = [c for c in self.children if isinstance(c, Icon)]

        return self._icons

    # --- Private API ---------------------------------------------------------

    #: Private list of contributed icons.
    _icons = List()
コード例 #11
0
class Icon(Declarative):
    """Declarative object used to contribute an icon.

    """
    #: Unique id describing the icon. It should provide a clear description
    #: of the icon purpose.
    id = d_(Str())

    @d_func
    def get_icon(self, manager, theme):
        """Generate the corresponding enaml icon object.

        """
        raise NotImplementedError()
コード例 #12
0
class ApplyMagFieldTask(InstrumentTask):
    """Use a supraconducting magnet to apply a magnetic field. Parallel task.
    """
    loopable = True

    target_field = Str().tag(pref=True)
    rate = Float().tag(pref=True)
    auto_stop_heater = Bool(True).tag(pref=True)

    task_database_entries = set_default({'Bfield': 0.01})
    driver_list = ['IPS12010']

    def __init__(self, **kwargs):
        super(ApplyMagFieldTask, self).__init__(**kwargs)
        self.make_parallel('instr')

    @smooth_instr_crash
    def process(self, target_value=None):
        """
        """
        if not self.driver:
            self.start_driver()

        if (self.driver.owner != self.task_name
                or not self.driver.check_connection()):
            self.driver.owner = self.task_name
            self.driver.make_ready()

        if target_value is None:
            target_value = format_and_eval_string(self.target_field,
                                                  self.task_path,
                                                  self.task_database)
        self.driver.go_to_field(target_value, self.rate, self.auto_stop_heater)
        self.write_in_database('Bfield', target_value)

    def check(self, *args, **kwargs):
        """
        """
        test, traceback = super(ApplyMagFieldTask, self).check(*args, **kwargs)
        if self.target_field:
            try:
                val = format_and_eval_string(self.target_field, self.task_path,
                                             self.task_database)
            except:
                test = False
                traceback[self.task_path + '/' + self.task_name + '-field'] = \
                    'Failed to eval the target field formula {}'.format(
                                                            self.target_field)
            self.write_in_database('Bfield', val)
        return test, traceback
コード例 #13
0
class Part(Shape):
    """ A Part is a compound shape. It may contain
    any number of nested parts and is typically subclassed.

    Attributes
    ----------

    name: String
        An optional name for the part
    description: String
        An optional description for the part

    Examples
    --------

    enamldef Case(Part):
        TopCover:
            # etc..
        BottomCover:
            # etc..

    """
    #: Reference to the implementation control
    proxy = Typed(ProxyPart)

    #: Optional name of the part
    name = d_(Str())

    #: Optional description of the part
    description = d_(Str())

    #: Cache
    cache = {}

    @property
    def shapes(self):
        return [child for child in self.children if isinstance(child, Shape)]
コード例 #14
0
class InsertBorderItem(DockLayoutOp):
    """ A layout operation which inserts an item into an area border.

    This operation will remove an item from the current layout and
    insert it into the border of a dock area. If the item does not
    exist, the operation is a no-op.

    If the target -

    - is a normally docked item
        The item is inserted into the border of the dock area containing
        the target.

    - is docked in a tab group
        The item is inserted into the border of the dock area containing
        the tab group.

    - is docked in a dock bar
        The item is inserted into the border of the dock area containing
        the dock bar.

    - is a floating dock item
        A new dock area will be created and the item will be inserted
        into the border of the new dock area.

    - does not exist
        The item is inserted into the border of the primary dock area.

    """
    #: The name of the dock item to insert into the layout.
    item = Str()

    #: The name of the dock item to use as the target location.
    target = Str()

    #: The border position at which to insert the item.
    position = Enum('left', 'top', 'right', 'bottom')
コード例 #15
0
ファイル: base.py プロジェクト: rassouly/exopy
class BaseRule(HasPrefAtom):
    """Base class for all rules implementations.

    """
    #: Name of the rule.
    id = Str().tag(pref=True)

    #: Quick description of what this rule is intended for.
    description = d_(Str()).tag(pref=True)

    #: List of database entries suffixes used to identify the entries which
    #: contributes to the rule.
    suffixes = List(default=['']).tag(pref=True)

    #: Id of the class used for persistence.
    class_id = Str().tag(pref=True)

    def try_apply(self, new_entry, monitor):
        """ Attempt to apply the rule.

        Parameters
        ----------
        new_entry : str
            Database path of the newly added entry.

        monitor : TextMonitor
            Instance of the text monitor trying to apply the rule.

        """
        raise NotImplementedError()

    def _default_class_id(self):
        """Default factory for the class_id attribute

        """
        pack, _ = self.__module__.split('.', 1)
        return '.'.join((pack, type(self).__name__))
コード例 #16
0
class FitModel(Atom):
    """Back-end for the FitController

    """
    params = Dict()
    lmfit_params = Typed(Parameters)
    lmfit_model = Typed(Model)
    name = Str()
    show_advanced = Bool(False)
    show_basic = Bool(True)

    def __init__(self, lmfit_model, prefix, name=None):
        # print(lmfit_model)
        if name is None:
            name = str(lmfit_model.name)
        self.name = name
        if type(lmfit_model) is type:
            self.lmfit_model = lmfit_model(name=self.name, prefix=prefix)
        else:
            self.lmfit_model = lmfit_model
        # print(self.lmfit_model.name)
        # self.lmfit_model.prefix = "1"
        self.lmfit_params = self.lmfit_model.make_params()
        for name, param in six.iteritems(self.lmfit_params):
            p = ParameterModel()
            p.set_from_parameter(param)
            self.params[name] = p
        super(FitModel, self).__init__()

    @observe('show_advanced')
    def update_view(self, changed):
        self.show_basic = not self.show_advanced
        print('show_basic: {}'.format(self.show_basic))
        print('show_advanced: {}'.format(self.show_advanced))

    def update_params(self, params):
        """
        Parameters
        ----------
        params : list
            List of parameters that the fit model knows about. Silently ignore
            any parameters that are passed in that this model doesn't know about
        """
        for param in params:
            try:
                self.params[param.name].set_from_parameter(param)
            except KeyError:
                # silently ignore keys that are not in this model
                pass
コード例 #17
0
ファイル: xbms.py プロジェクト: ulricheck/enaml
class XBM(Atom):
    """ A simple class representing an XMB image.

    """
    #: The width of the xbm image.
    width = Int()

    #: The height of the xbm image.
    height = Int()

    #: The bytestring of image data.
    data = Str()

    def __init__(self, width, height, data):
        """ Initialize an XBM image.

        Parameters
        ----------
        width : int
            The width of the bitmap.

        height : int
            The height of the bitmap.

        data : list
            A list of 1s and 0s which represent the bitmap data.
            The length must be equal to width * height.

        """
        assert len(data) == (width * height)
        bytes = []
        for row in xrange(height):
            val = 0
            offset = row * width
            for col in xrange(width):
                d = col % 8
                if col > 0 and d == 0:
                    bytes.append(chr(val))
                    val = 0
                v = data[offset + col]
                val |= v << (7 - d)
            bytes.append(chr(val))
        self.width = width
        self.height = height
        self.data = ''.join(bytes)

    def toBitmap(self):
        size = QSize(self.width, self.height)
        return QBitmap.fromData(size, self.data, QImage.Format_Mono)
コード例 #18
0
class Image(Atom):
    """ An object representing an image.

    Once an image is created it should be treated as read only. User
    code should create a new image object if the parameters need to
    be changed.

    """
    #: The format of the image. By default, the consumer of the image
    #: will probe the header to automatically infer a type.
    format = Enum(
        'auto',     # Automatically determine the image format
        'png',      # Portable Network Graphics
        'jpg',      # Joint Photographic Experts Group
        'gif',      # Graphics Interchange Format
        'bmp',      # Windows Bitmap
        'xpm',      # X11 Pixmap
        'xbm',      # X11 Bitmap
        'pbm',      # Portable Bitmap
        'pgm',      # Portable Graymap
        'ppm',      # Portable Pixmap
        'tiff',     # Tagged Image File Format
        'argb32',   # Raw data in the 0xAARRGGBB format.
                    # The `raw_size` of the image must be provided.
    )

    #: The (width, height) raw size of the image. This must be provided
    #: for images where the size is not encoded in the data stream.
    raw_size = Coerced(Size, (0, 0))

    #: The (width, height) size of the image. An invalid size indicates
    #: that the size of the image should be automatically inferred. A
    #: valid size indicates that the toolkit image should be scaled to
    #: the specified size.
    size = Coerced(Size, (-1, -1))

    #: The aspect ratio mode to use when the toolkit scales the image.
    aspect_ratio_mode = Enum('ignore', 'keep', 'keep_by_expanding')

    #: The transform mode to use when the toolkit scales the image.
    transform_mode = Enum('smooth', 'fast')

    # XXX this needs to be augmented to support arrays.
    #: The bytestring holding the data for the image.
    data = Str()

    #: Storage space for use by a toolkit backend to use as needed.
    #: This should not typically be manipulated by user code.
    _tkdata = Value()
コード例 #19
0
ファイル: base_task_config.py プロジェクト: zoulianmp/HQCMeas
class AbstractConfigTask(Atom):
    """ Base class for task configurer.

    """
    # Task manager, necessary to retrieve task implementations.
    manager = ForwardTyped(task_manager)

    # Name of the task to create.
    task_name = Str('')

    # Class of the task to create.
    task_class = Subclass(BaseTask)

    # Bool indicating if the build can be done.
    config_ready = Bool(False)

    def check_parameters(self, change):
        """Check if enough parameters have been provided to build the task.

        This methodd should fire the config_ready event each time it is called
        sending True if everything is allright, False otherwise.

        """
        err_str = '''This method should be implemented by subclasses of
        AbstractConfigTask. This method is called each time a trait is changed
        to check if enough parameters has been provided to build the task.'''
        raise NotImplementedError(cleandoc(err_str))

    def build_task(self):
        """This method use the user parameters to build the task object

         Returns
        -------
            task : BaseTask
                Task object built using the user parameters. Ready to be
                inserted in a task hierarchy.

        """
        err_str = '''This method should be implemented by subclasses of
        AbstractConfigTask. This method is called when the user validate its
        choices and that the task must be built.'''
        raise NotImplementedError(cleandoc(err_str))

    def _default_task_name(self):
        names = self.manager.auto_task_names
        if names:
            return random.choice(names)
        else:
            return ''
コード例 #20
0
ファイル: rf_tasks.py プロジェクト: zoulianmp/HQCMeas
class SetRFOnOffTask(InterfaceableTaskMixin, InstrumentTask):
    """Switch on/off the output of the source.

    """
    # Desired state of the output, runtime value can be 0 or 1.
    switch = Str('Off').tag(pref=True)

    task_database_entries = set_default({'output': 0})
    loopable = True
    driver_list = ['AgilentE8257D', 'AnritsuMG3694', 'LabBrickLMS103']

    def check(self, *args, **kwargs):
        """
        """
        test, traceback = super(SetRFOnOffTask, self).check(*args, **kwargs)

        if self.switch:
            try:
                switch = self.format_and_eval_string(self.switch)
                self.write_in_database('output', switch)
            except Exception as e:
                mess = 'Failed to eval the output state {}: {}'
                traceback[self.task_path + '/' + self.task_name + '-switch'] =\
                    mess.format(self.switch, e)
                return False, traceback

            if switch not in ('Off', 'On', 0, 1):
                test = False
                traceback[self.task_path + '/' + self.task_name + '-switch'] =\
                    '{} is not an acceptable value.'.format(self.switch)

        return test, traceback

    def i_perform(self, switch=None):
        """

        """
        if not self.driver:
            self.start_driver()

        if switch is None:
            switch = self.format_and_eval_string(self.switch)

        if switch == 'On' or switch == 1:
            self.driver.output = 'On'
            self.write_in_database('output', 1)
        else:
            self.driver.output = 'Off'
            self.write_in_database('output', 0)
コード例 #21
0
class CompilerBase(ASTVisitor):
    """ A base class for defining compilers.

    """
    #: The filename for the code being generated.
    filename = Str()

    #: The code generator to use for this compiler.
    code_generator = Typed(CodeGenerator)

    def _default_code_generator(self):
        """ Create the default code generator instance.

        """
        return CodeGenerator(filename=self.filename)
コード例 #22
0
ファイル: base.py プロジェクト: MatthieuDartiailh/oculy
class BasePlot(PlotElement):
    """Base class for plot description."""

    #: Id of the plot used to identify it in an axes
    id = Str()

    #: Reference to the axes to which this plot belongs (or None)
    axes = ForwardTyped(_axes)

    #: What axes ("left", "bottom", etc) to use for "x", "y" ("x" acts as key)
    axes_mapping = Dict(str, str)

    #: Z order determining the order in which the plots are drawn.
    #: Smaller values are drawn first.
    zorder = Int(10)
コード例 #23
0
ファイル: plugin.py プロジェクト: swipswaps/declaracad
class ModelExporter(Atom):
    extension = ''
    path = Str()
    filename = Str()

    def _default_path(self):
        ext = self.extension.lower()
        filename = os.path.splitext(self.filename)[0]
        return "{}.{}".format(filename, ext)

    def export(self):
        """ Export a DeclaraCAD model from an enaml file to a 3D model format
        with the given options.

        """
        raise NotImplementedError

    @classmethod
    def get_options_view(cls):
        """ Return the options view used to define the paramters that can be
        used by this exporter.

        """
        raise NotImplementedError
コード例 #24
0
class ItemGroup(Declarative):
    """ A declarative class for defining an item group in a menu.

    """
    #: The identifier of group within the menu.
    id = d_(Str())

    #: Whether or not the group is visible.
    visible = d_(Bool(True))

    #: Whether or not the group is enabled.
    enabled = d_(Bool(True))

    #: Whether or not checkable ations in the group are exclusive.
    exclusive = d_(Bool(False))
コード例 #25
0
class Foo(Atom):
    name = Str()
    a = Int()
    b = Int()
    c = Int()

    groups = [
        Group('Ints',
              items=[
                  StrItem('name'),
                  IntItem('a'),
                  AltBlue('b'),
                  IntItem('c', foreground='red', font='bold 12pt arial'),
              ])
    ]
コード例 #26
0
class WebView(Control):
    """ A widget which displays a web page.

    Unlike the simpler `Html` widget, this widget supports the features
    of a full web browser.

    """
    #: The URL to load in the web view. This can be a path to a remote
    #: resource or a path to a file on the local filesystem. This value
    #: is mutually exclusive of `html`.
    url = d_(Str())

    #: The html to load into the web view. This value is mutually
    #: exclusive of `url`.
    html = d_(Str())

    #: The base url for loading content in statically supplied 'html'.
    base_url = d_(Str())

    #: A web view expands freely in height and width by default.
    hug_width = set_default('ignore')
    hug_height = set_default('ignore')

    #: A reference to the ProxyWebView object.
    proxy = Typed(ProxyWebView)

    #--------------------------------------------------------------------------
    # Observers
    #--------------------------------------------------------------------------
    @observe('url', 'html')
    def _update_proxy(self, change):
        """ An observer which sends state change to the proxy.

        """
        # The superclass handler implementation is sufficient.
        super(WebView, self)._update_proxy(change)
コード例 #27
0
class _Aux(HasPrefAtom):

    string = Str().tag(pref=True)
    float_n = Float().tag(pref=True)
    enum = Enum('a', 'b').tag(pref=True)
    enum_float = Enum(1.0, 2.0).tag(pref=True)
    list_ = List(Float()).tag(pref=True)
    odict_ = Typed(OrderedDict,
                   ()).tag(pref=[ordered_dict_to_pref, ordered_dict_from_pref])
    value = Value().tag(pref=True)
    const = Constant('r').tag(pref=True)

    atom = Typed(_Aaux, ()).tag(pref=True)

    no_tag = Int()
コード例 #28
0
class Person(Atom):

    name = Str()

    # uses static constructor
    fido = Typed(Dog)

    # uses kwargs provided in the definition
    fluffy = Typed(Dog, kwargs=dict(name='Fluffy'))

    # uses an object provided in Person constructor
    new_dog = Typed(Dog)

    def _default_fido(self):
        return Dog(name='Fido', owner=self)
コード例 #29
0
ファイル: construct_nodes.py プロジェクト: MShaffar19/enaml
class StorageDefConstruct(ConstructNode):
    """ A construct node for a storage definition.

    """
    #: The kind of the state definition.
    kind = Enum('attr', 'event')

    #: The name of the state object being defined.
    name = Str()

    #: The typename of the allowed values for the state object.
    typename = Str()

    #: The resolved type class for using with the state def. This is
    #: updated during the resolution passes over the tree.
    typeclass = Typed(type)

    @classmethod
    def from_dict(cls, dct):
        self = super(StorageDefConstruct, cls).from_dict(dct)
        self.kind = dct['kind']
        self.name = dct['name']
        self.typename = dct['typename']
        return self
コード例 #30
0
class TTL_filters(Analysis):
    """This analysis monitors the TTL inputs and does either hard or soft cuts of the data accordingly.
    Low is good, high is bad."""

    text = Str()
    lines = Str('PXI1Slot6/port0')
    filter_level = Int()

    def __init__(self, name, experiment, description=''):
        super(TTL_filters, self).__init__(name, experiment, description)
        self.properties += ['lines', 'filter_level']

    def analyzeMeasurement(self, measurementResults, iterationResults,
                           experimentResults):
        text = 'none'
        if self.experiment.LabView.TTL.enable and (
                'TTL/data' in measurementResults['data']):
            a = measurementResults['data/TTL/data']
            #check to see if any of the inputs were True
            if numpy.any(a):
                #report the true inputs
                text = 'TTL Filters failed:\n'
                for i, b in enumerate(a):
                    #print out the row and column of the True input
                    text += 'Check {}: Laser(s) {}\n'.format(
                        i,
                        numpy.arange(len(b))[b])
                #record to the log and screen
                logger.warning(text)
                self.set_gui({'text': text})
                # User chooses whether or not to delete data.
                # max takes care of ComboBox returning -1 for no selection
                return max(0, self.filter_level)
            else:
                text = 'okay'
        self.set_gui({'text': text})