File: action.py

package info (click to toggle)
python-enaml 0.19.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,284 kB
  • sloc: python: 31,443; cpp: 4,499; makefile: 140; javascript: 68; lisp: 53; sh: 20
file content (114 lines) | stat: -rw-r--r-- 3,821 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#------------------------------------------------------------------------------
# Copyright (c) 2013-2025, 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 atom.api import Typed, ForwardTyped, Str, Bool, Event

from enaml.core.declarative import d_, observe
from enaml.icon import Icon

from .toolkit_object import ToolkitObject, ProxyToolkitObject


class ProxyAction(ProxyToolkitObject):
    """ The abstract definition of a proxy Action object.

    """
    #: A reference to the Action declaration.
    declaration = ForwardTyped(lambda: Action)

    def set_text(self, text):
        raise NotImplementedError

    def set_tool_tip(self, tool_tip):
        raise NotImplementedError

    def set_status_tip(self, status_tip):
        raise NotImplementedError

    def set_icon(self, icon):
        raise NotImplementedError

    def set_checkable(self, checkable):
        raise NotImplementedError

    def set_checked(self, checked):
        raise NotImplementedError

    def set_enabled(self, enabled):
        raise NotImplementedError

    def set_visible(self, visible):
        raise NotImplementedError

    def set_separator(self, separator):
        raise NotImplementedError


class Action(ToolkitObject):
    """ A non visible widget used in a ToolBar or Menu.

    An Action represents an actionable item in a ToolBar or a Menu.
    Though an Action itself is a non-visible component, it will be
    rendered in an appropriate fashion for the location where it is
    used.

    """
    #: The text label associate with the action.
    text = d_(Str())

    #: The tool tip text to use for this action. Typically displayed
    #: as a small label when the user hovers over the action.
    tool_tip = d_(Str())

    #: The text that is displayed in the status bar when the user
    #: hovers over the action.
    status_tip = d_(Str())

    #: The icon to use for the Action.
    icon = d_(Typed(Icon))

    #: Whether or not the action can be checked.
    checkable = d_(Bool(False))

    #: Whether or not the action is checked. This value only has meaning
    #: if 'checkable' is set to True.
    checked = d_(Bool(False))

    #: Whether or not the item representing the action is enabled.
    enabled = d_(Bool(True))

    #: Whether or not the item representing the action is visible.
    visible = d_(Bool(True))

    #: Whether or not the action should be treated as a separator. If
    #: this value is True, none of the other values have meaning.
    separator = d_(Bool(False))

    #: An event fired when the action is triggered by user interaction.
    #: They payload will be the current checked state. This event is
    #: triggered by the proxy object when the action is triggerd.
    triggered = d_(Event(bool), writable=False)

    #: An event fired when a checkable action changes its checked state.
    #: The payload will be the current checked state. This event is
    #: triggerd by the proxy object when the action is toggled.
    toggled = d_(Event(bool), writable=False)

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

    #--------------------------------------------------------------------------
    # Observers
    #--------------------------------------------------------------------------
    @observe('text', 'tool_tip', 'status_tip', 'icon', 'checkable', 'checked',
        'enabled', 'visible', 'separator')
    def _update_proxy(self, change):
        """ An observer which updates the proxy when the Action changes.

        """
        # The superclass implementation is sufficient
        super(Action, self)._update_proxy(change)