Beispiel #1
0
class ListDictTable(EditableTable):

    #: List of dictionaries where list index maps to row and dictionary key
    #: maps to column.
    data = d_(List())

    #: List of column names. If not provided, defaults to dictionary keys
    #: provided by the first entry in `data`.
    columns = d_(List())

    def get_columns(self):
        if self.columns:
            return self.columns
        if (self.data is not None) and (len(self.data) != 0):
            return list(self.data[0].keys())
        return []

    def get_data(self, row_index, column_index):
        column = self.get_columns()[column_index]
        return self.data[row_index][column]

    def set_data(self, row_index, column_index, value):
        value = self.coerce_to_type(column_index, value)
        column = self.get_columns()[column_index]
        self.data[row_index][column] = value

    def get_default_row(self):
        values = super().get_default_row()
        keys = self.get_columns()
        return dict(zip(keys, values))

    def insert_row(self, row_index):
        values = self.get_default_row()
        self.data.insert(row_index + 1, values)

    def remove_row(self, row_index):
        self.data.pop(row_index)
Beispiel #2
0
class DataFrameTable(EditableTable):

    data = d_(Typed(pd.DataFrame))
    columns = d_(Typed(object))

    def _observe_columns(self, event):
        self._reset_model()

    @d_func
    def get_columns(self):
        if self.columns is not None:
            return self.columns
        if self.data is None:
            return []
        return self.data.columns

    def get_data(self, row_index, column_index):
        row_label = self.data.index[row_index]
        column_label = self.get_columns()[column_index]
        return self.data.at[row_label, column_label]

    def set_data(self, row_index, column_index, value):
        value = self.coerce_to_type(column_index, value)
        row_label = self.data.index[row_index]
        column_label = self.get_columns()[column_index]
        self.data.at[row_label, column_label] = value

    def remove_row(self, row_index):
        label = self.data.index[row_index]
        self.data.drop(label, inplace=True)
        self.data.index = range(len(self.data))

    def insert_row(self, row_index):
        values = self.get_default_row()
        self.data.loc[row_index + 0.5] = values
        self.data.sort_index(inplace=True)
        self.data.index = range(len(self.data))
class AutoCompleteTextView(EditText):
    """ A simple control for displaying read-only text.

    """

    #: Auto complete choices
    choices = d_(List())

    #: Sets the current height for the auto-complete drop down list.
    drop_down_height = d_(Int())

    #: Sets the current width for the auto-complete drop down list.
    drop_down_width = d_(Int())

    #: Selected item within the list
    list_selection = d_(Int())

    #: Specifies the minimum number of characters the user has to type
    #: in the edit box before the drop down list is shown.
    threshold = d_(Int())

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

    @observe(
        'choices',
        'drop_down_height',
        'drop_down_width'
        'list_selection',
        'threshold',
    )
    def _update_proxy(self, change):
        """ An observer which sends the state change to the proxy.

        """
        # The superclass implementation is sufficient.
        super(AutoCompleteTextView, self)._update_proxy(change)
class Parameter(ContextItem):
    '''
    A context item that can be evaluated dynamically, but cannot be included as
    part of a selector.  This is typically used for settings that must be
    determined before values are drawn from the selectors (e.g., probability of
    a go trial).
    '''
    # Default value of the context item when used as part of a selector.
    default = d_(Value())

    expression = d_(Str()).tag(preference=True)

    # Defines the span over which the item's value does not change:
    # * experiment - the value cannot change once the experiment begins
    # * trial - The value cannot change once a trial begins. This is the only
    #   type of item that can be roved using a selector.
    # * arbitrary - The value can be changd at any time but it does not make
    #   sense for it to be a roving item.
    scope = d_(Enum('trial', 'experiment', 'arbitrary'))

    # Is the value of this item managed by a selector?
    rove = d_(Bool()).tag(preference=True)

    def _default_expression(self):
        return str(self.default)

    def _default_dtype(self):
        return np.array(self.default).dtype.str

    def _default_label(self):
        return self.name

    def to_expression(self, value):
        return str(value)

    def set_value(self, value):
        self.expression = self.to_expression(value)
Beispiel #5
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)]
Beispiel #6
0
class FrameLayout(ViewGroup):
    """ FrameLayout is a view group that displays
        child views in relative positions.

    """
    #: Describes how the child views are positioned.
    #: Defaults to Gravity.START | Gravity.TOP.
    foreground_gravity = d_(Int())

    measure_all_children = d_(Bool())

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

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

        """
        # The superclass implementation is sufficient.
        super(FrameLayout, self)._update_proxy(change)
Beispiel #7
0
class Workspace(Declarative):
    """ A declarative class for defining a workspace object.

    """
    #: Extra information to display in the window title bar.
    window_title = d_(Str())

    #: The primary window content for the workspace. This will be
    #: destroyed automatically when the workspace is disposed.
    content = d_(Typed(Container))

    #: The workbench object which owns the workspace. This will be
    #: assigned when the ui plugin creates the workspace. It will
    #: be available by the time the 'start' method is called.
    workbench = Typed(Workbench)

    def start(self):
        """ Start the workspace.

        This method is called when the UI plugin starts the workspace.
        This can be used to load content or any other resource which
        should exist for the life of the workspace.

        """
        pass

    def stop(self):
        """ Stop the workspace.

        This method is called when the UI plugin closes the workspace.
        This should be used to release any resources acquired during
        the lifetime of the workspace. The content Container will be
        destroyed automatically after this method returns.

        """
        pass
Beispiel #8
0
class Parabola(Edge):
    """ Creates a parabola with its local coordinate system "A2" and it's focal length "Focal". 
        The XDirection of A2 defines the axis of symmetry of the parabola. 
        The YDirection of A2 is parallel to the directrix of the parabola. 
        The Location point of A2 is the vertex of the parabola 
        Raises ConstructionError if Focal < 0.0 Raised if Focal < 0.0. 
    """
    proxy = Typed(ProxyParabola)

    #: Focal length of the parabola
    focal_length = d_(Float(1, strict=False)).tag(view=True)

    @observe('focal_length')
    def _update_proxy(self, change):
        super(Parabola, self)._update_proxy(change)
Beispiel #9
0
class Hyperbola(Edge):
    """ Creates a hyperbola with radii MajorRadius and MinorRadius, positioned in the space by the coordinate system A2 such that:

        - the origin of A2 is the center of the hyperbola,
        - the "X Direction" of A2 defines the major axis of the hyperbola, that is, the major radius MajorRadius is measured along this axis, and
        - the "Y Direction" of A2 defines the minor axis of the hyperbola, that is, the minor radius MinorRadius is measured along this axis. 
        
        Note: This class does not prevent the creation of a hyperbola where:
        - MajorAxis is equal to MinorAxis, or
        - MajorAxis is less than MinorAxis. Exceptions Standard_ConstructionError if MajorAxis or MinorAxis is negative. 
        
        Raises ConstructionError if MajorRadius < 0.0 or MinorRadius < 0.0 Raised if MajorRadius < 0.0 or MinorRadius < 0.0
    """
    proxy = Typed(ProxyHyperbola)

    #: Major radius of the hyperbola
    major_radius = d_(Float(1, strict=False)).tag(view=True)

    #: Minor radius of the hyperbola
    minor_radius = d_(Float(1, strict=False)).tag(view=True)

    @observe('major_radius', 'minor_radius')
    def _update_proxy(self, change):
        super(Hyperbola, self)._update_proxy(change)
Beispiel #10
0
class SwipeRefreshLayout(ViewGroup):
    """ SwipeRefreshLayout is a view group that displays
        child views in relative positions.

    """
    #: Enabled
    enabled = d_(Bool(True))

    #: Must be a
    indicator_color = d_(Unicode())

    #: Must be a
    indicator_background_color = d_(Unicode())

    #: Set the distance to trigger a sync in dips
    trigger_distance = d_(Int())

    #: Triggered when the user swipes
    refreshed = d_(Event())

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

    # -------------------------------------------------------------------------
    # Observers
    # -------------------------------------------------------------------------
    @observe('enabled', 'indicator_color', 'indicator_background_color',
             'trigger_distance', 'refeshed')
    def _update_proxy(self, change):
        """ An observer which sends the state change to the proxy.

        """
        if change['type'] == 'event':
            self.proxy.set_refreshed(True)
        else:
            super(SwipeRefreshLayout, self)._update_proxy(change)
Beispiel #11
0
class State(Declarative):
    """ Declarative class for defining a workbench state.

    State object can be contributed as extensions child to the 'states'
    extension point of a state plugin.

    Attributes
    ----------
    id : unicode
        The globally unique identifier for the state

    description : str
        An optional description of what the state provides.

    sync_members : list(str)
        The list of plugin members whose values should be reflected in the
        state object

    prop_getters : dict(str, str)
        Dictionnary mapping property namer of the state object to the name of
        the method on the plugin which can be used as the property getter.

    """
    id = d_(Unicode())

    description = d_(Str())

    # Will be used to dynamically create an atom class with value members,
    # and observe plugin to update state object in consequence
    sync_members = d_(List(Str()))

    # getters to build properties for things that are updated on the model only
    # somebody needs it (Beware don't use in UI as you wouldn't get any updates
    # ). key is the name of the property in the state, value the name of the
    # property getter on the plugin
    prop_getters = d_(Dict(Str(), Str()))
Beispiel #12
0
class ImageView(Control):
    """ A widget which can display an Image with optional scaling.

    """
    #: The image to display in the viewer.
    image = d_(Typed(Image))

    #: Whether or not to scale the image with the size of the component.
    scale_to_fit = d_(Bool(False))

    #: Whether to allow upscaling of an image if scale_to_fit is True.
    allow_upscaling = d_(Bool(True))

    #: Whether or not to preserve the aspect ratio if scaling the image.
    preserve_aspect_ratio = d_(Bool(True))

    #: An image view hugs its width weakly by default.
    hug_width = set_default('weak')

    #: An image view hugs its height weakly by default.
    hug_height = set_default('weak')

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

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

        """
        # The superclass handler implementation is sufficient.
        super(ImageView, self)._update_proxy(change)
class UnorderedContextMeta(ContextMeta):

    values = d_(Coerced(set))

    def add_item(self, item):
        if item not in self.values:
            values = self.values.copy()
            values.add(item)
            self.values = values

    def remove_item(self, item):
        if item in self.values:
            values = self.values.copy()
            values.remove(item)
            self.values = values
Beispiel #14
0
class ToggleButton(CompoundButton):
    """ A simple control for displaying a ToggleButton.

    """

    #: Sets the text for when the button is not in the checked state.
    text_off = d_(Unicode())

    #: Sets the text for when the button is in the checked state.
    text_on = d_(Unicode())

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

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

        """
        # The superclass implementation is sufficient.
        super(ToggleButton, self)._update_proxy(change)
Beispiel #15
0
class Markdown(Raw):
    """ A block for rendering Markdown source. """

    #: Extensions to use when rendering
    extensions = d_(
        List(default=[
            "markdown.extensions.codehilite",
            "markdown.extensions.fenced_code",
            "markdown.extensions.tables",
        ])).tag(attr=False)

    #: Configuration for them
    extension_configs = d_(
        Dict(default={
            'markdown.extensions.codehilite': {
                'css_class': 'highlight'
            },
        })).tag(attr=False)

    #: Disallow raw HTMl
    safe_mode = d_(Bool()).tag(attr=False)

    #: Output format
    output_format = d_(Enum("xhtml", "html5")).tag(attr=False)

    #: Tab size
    tab_length = d_(Int(4)).tag(attr=False)

    #: Reference to the proxy
    proxy = Typed(ProxyMarkdown)

    @observe('extensions', 'extension_configs', 'safe_mode', 'output_format',
             'tab_length')
    def _update_proxy(self, change):
        """ The superclass implementation is sufficient. """
        super(Markdown, self)._update_proxy(change)
class ActivityIndicator(View):
    """ A simple control for displaying an ActivityIndicator.

    """

    #: Style for indeterminate
    size = d_(Enum('normal', 'small', 'large'))

    #: Sets the color of the indicator.
    color = d_(Unicode())

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

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

        """
        # The superclass implementation is sufficient.
        super(ActivityIndicator, self)._update_proxy(change)
Beispiel #17
0
class ViewGroup(View):
    """ViewGroup is a view group that displays
    child views in relative positions.

    """

    # A layout transition for when children are added or removed
    transition = d_(Enum("", "default"))

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

    @observe("transition")
    def _update_proxy(self, change):
        super()._update_proxy(change)
Beispiel #18
0
class VTKCanvas(Control):
    """ A control which can be used to embded vtk renderers.

    """
    #: The vtk renderer to display in the window. This should be used
    #: if only a single renderer is required for the scene.
    renderer = d_(ForwardInstance(vtkRenderer))

    #: The list of vtk renderers to display in the window. This should
    #: be used if multiple renderers are required for the scene.
    renderers = d_(List(ForwardInstance(vtkRenderer)))

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

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

    def render(self):
        """ Request a render of the underlying scene.

        """
        if self.proxy_is_active:
            self.proxy.render()

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

        """
        # The superclass handler implementation is sufficient.
        super(VTKCanvas, self)._update_proxy(change)
Beispiel #19
0
class Spinner(ViewGroup):
    """ A simple control for displaying read-only text.

    """

    #: Set the mode
    mode = d_(Enum('dropdown', 'dialog'))

    #: Sets the prompt to display when the dialog is shown.
    prompt = d_(Unicode())

    #: Should the layout be a column or a row.
    selected = d_(Int(0))

    #: View gravity
    items = d_(List())

    #: Gravity setting for positioning the currently selected item.
    item_gravity = d_(Coerced(int, coercer=coerce_gravity))

    #: Set a horizontal offset in pixels for the spinner's popup window
    #: of choices.
    drop_down_horizontal_offset = d_(Int())

    #: Set a vertical offset in pixels for the spinner's popup window
    #: of choices.
    drop_down_vertical_offset = d_(Int())

    #: Set the width of the spinner's popup window of choices in pixels.
    drop_down_width = d_(Int())

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

    # -------------------------------------------------------------------------
    # Observers
    # -------------------------------------------------------------------------
    @observe('mode', 'prompt', 'selected', 'items', 'item_gravity',
             'drop_down_horizontal_offset', 'drop_down_vertical_offset',
             'drop_down_width')
    def _update_proxy(self, change):
        """ An observer which sends the state change to the proxy.

        """
        # The superclass implementation is sufficient.
        super(Spinner, self)._update_proxy(change)
Beispiel #20
0
class SeekBar(ProgressBar):
    """ A simple control for displaying read-only text.

    """

    #: Sets the amount of progress changed via the arrow keys.
    key_progress_increment = d_(Int())

    #: Specifies whether the track should be split by the thumb.
    split_track = d_(Bool())

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

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

        """
        # The superclass implementation is sufficient.
        super(SeekBar, self)._update_proxy(change)
Beispiel #21
0
class Plane(Shape):
    """ A Point at a specific position.

    Examples
    --------

    Plane:
        position = (10, 100, 0)
        direction = (0, 0, 1)

    """
    proxy = Typed(ProxyPlane)

    #: Bounds of plane (optional) a tuple of [(umin, umin), (vmax, vmax)]
    bounds = d_(List(Coerced(Pt, coercer=coerce_point)))
Beispiel #22
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_(Unicode())

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

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

    #: 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)
Beispiel #23
0
class Cylinder(Shape):
    """ A primitive Cylinder shape.

    Attributes
    ----------

    height: Float
        Height of the cylinder
    radius: Float
        Radius of the base of the cylinder
    angle:
        The angle to revolve (in radians) the base profile.

    Examples
    --------

    Cone:
        height = 10
        radius = 5

    """
    #: Proxy shape
    proxy = Typed(ProxyCylinder)

    #: Radius
    radius = d_(Float(1, strict=False)).tag(view=True)

    #: Height
    height = d_(Float(1, strict=False)).tag(view=True)

    #: Angle
    angle = d_(Float(0, strict=False)).tag(view=True)

    @observe('radius', 'height', 'angle')
    def _update_proxy(self, change):
        super(Cylinder, self)._update_proxy(change)
Beispiel #24
0
class RatingBar(ProgressBar):
    """ A simple control for displaying read-only text.

    """

    #: Whether this rating bar should only be an indicator
    #: (thus non-changeable by the user).
    is_indicator = d_(Bool())

    #: The number of stars set (via setNumStars(int) or in an XML layout)
    #: will be shown when the layout width is set to wrap content
    #: (if another layout width is set, the results may be unpredictable).
    layout_width = set_default('wrap_content')

    #: Sets the number of stars to show.
    num_stars = d_(Int())

    #: Sets the rating (the number of stars filled).
    rating = d_(Float(strict=False))

    #: Sets the step size (granularity) of this rating bar.
    step_size = d_(Float(strict=False))

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

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

        """
        # The superclass implementation is sufficient.
        super(RatingBar, self)._update_proxy(change)
Beispiel #25
0
class ListView(ViewGroup):
    """ A widget for displaying a large scrollable list of items.

    """

    #: List of items to display
    items = d_(List())

    #: Number of visible items
    visible_count = d_(Int(10), writable=False)

    #: Current index within the list
    current_index = d_(Int(), writable=False)

    #: Sets the height of the divider that will be drawn between each item
    #:  in the list.
    divider_height = d_(Int(-1))

    #: Enables or disables the drawing of the divider for header views.
    header_dividers = d_(Bool())

    #: Enables or disables the drawing of the divider for footer views.
    footer_dividers = d_(Bool())

    #: Indicates that the views created by the ListAdapter can contain
    #: focusable items.
    items_can_focus = d_(Bool())

    #: Sets the currently selected item.
    selected = d_(Int(-1))

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

    # -------------------------------------------------------------------------
    # Observers
    # -------------------------------------------------------------------------
    @observe('items', 'divider_height', 'header_dividers', 'footer_dividers',
             'items_can_focus', 'selected')
    def _update_proxy(self, change):
        """ An observer which sends the state change to the proxy.

        """
        # The superclass implementation is sufficient.
        super(ListView, self)._update_proxy(change)
Beispiel #26
0
class LinearLayout(ViewGroup):
    """A simple control for displaying read-only text."""

    #: Should the layout be a column or a row.
    orientation = d_(Enum("horizontal", "vertical"))

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

    # -------------------------------------------------------------------------
    # Observers
    # -------------------------------------------------------------------------
    @observe("orientation")
    def _update_proxy(self, change):

        super()._update_proxy(change)
Beispiel #27
0
class CompoundButton(Button):
    """A simple control for displaying read-only text."""

    #: Button is checked
    checked = d_(Bool())

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

    # -------------------------------------------------------------------------
    # Observers
    # -------------------------------------------------------------------------
    @observe("checked")
    def _update_proxy(self, change):

        super()._update_proxy(change)
Beispiel #28
0
class PinholeCamera(Camera):

    fov = d_(Float(60))

    @observe("viewport.box", "near", "far", "fov")
    def _update_projection_matrix(self, change):
        """
        :param change:

        recomputes the projection matrix if any of the inputs chnage
        :return:
        """
        left, right, bottom, top = self._device_coordinates(
            self.viewport, self.fov)
        self.projection_matrix = self.viewport.calculate_projection_matrix(
            left, right, bottom, top, self.near, self.far, self.fov)
Beispiel #29
0
class EmbeddedWindow(RawWidget):
    """ Create a widget that embeds the window from another application.
    This allows you to run expensive operations (ex 3D rendering) without
    blocking the main UI.

    """
    #: Expand by default
    hug_width = set_default('ignore')
    hug_height = set_default('ignore')

    #: Window ID of embedded application
    window_id = d_(Int())

    def create_widget(self, parent):
        window = QWindow.fromWinId(self.window_id)
        return QWidget.createWindowContainer(window, parent=parent)
Beispiel #30
0
class CameraView(TextureView):
    """A helper view to tie in a camera."""

    #: Display a preview
    preview = d_(Bool())

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

    @observe("preview")
    def _update_proxy(self, change):

        super()._update_proxy(change)

    def take_picture(self):
        self.proxy.take_picture()