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
|
#------------------------------------------------------------------------------
# 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, Enum, Range
from enaml.core.declarative import d_, observe
from .toolkit_object import ToolkitObject, ProxyToolkitObject
from .widget import Widget
class ProxyStatusItem(ProxyToolkitObject):
""" The abstract definition of a proxy StatusItem object.
"""
#: A reference to the StatusItem declaration
declaration = ForwardTyped(lambda: StatusItem)
def set_mode(self, mode):
raise NotImplementedError
def set_stretch(self, stretch):
raise NotImplementedError
class StatusItem(ToolkitObject):
""" An item which holds a widget to include in a status bar.
"""
#: The mode of a status item. A 'normal' item can be obscured by
#: temporary status messages; a 'permanent' item cannot.
mode = d_(Enum('normal', 'permanent'))
#: The stretch factor to apply to this item, relative to the other
#: items in the status bar.
stretch = d_(Range(low=0))
#: A reference to the ProxyStatusItem object.
proxy = Typed(ProxyStatusItem)
def status_widget(self):
""" Get the status widget for the item.
The last Widget child is used as the status widget.
"""
for child in reversed(self.children):
if isinstance(child, Widget):
return child
#--------------------------------------------------------------------------
# Observers
#--------------------------------------------------------------------------
@observe('mode', 'stretch')
def _update_proxy(self, change):
""" Update the proxy when the status item data changes.
"""
# The superclass implementation is sufficient.
super(StatusItem, self)._update_proxy(change)
|