File: status_bar.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 (88 lines) | stat: -rw-r--r-- 2,886 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
#------------------------------------------------------------------------------
# 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, Bool

from enaml.core.declarative import d_, observe

from .status_item import StatusItem
from .widget import Widget, ProxyWidget


class ProxyStatusBar(ProxyWidget):
    """ The abstract definition of a proxy StatusBar object.

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

    def set_size_grip_enabled(self, enabled):
        raise NotImplementedError

    def show_message(self, message, timeout=0):
        raise NotImplementedError

    def clear_message(self):
        raise NotImplementedError


class StatusBar(Widget):
    """ A widget used as a status bar in a MainWindow.

    A status bar can be used to display temporary messages or display
    persistent widgets by declaring StatusItem children.

    """
    #: Whether or not the size grip in the right corner is enabled.
    size_grip_enabled = d_(Bool(True))

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

    def status_items(self):
        """ Get the list of status items defined on the status bar.

        """
        return [c for c in self.children if isinstance(c, StatusItem)]

    #--------------------------------------------------------------------------
    # Observers
    #--------------------------------------------------------------------------
    @observe('size_grip_enabled')
    def _update_proxy(self, change):
        """ Update the proxy when the status bar data changes.

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

    #--------------------------------------------------------------------------
    # Public API
    #--------------------------------------------------------------------------
    def show_message(self, message, timeout=0):
        """ Show a temporary message in the status bar.

        Parameters
        ----------
        message : unicode
            The message to show in the status bar.

        timeout : int, optional
            The number of milliseconds to show the message. The default
            is 0, which will show the message until a new message is
            shown or 'clear_message()' is called.

        """
        if self.proxy_is_active:
            self.proxy.show_message(message, timeout)

    def clear_message(self):
        """ Clear any temporary message displayed in the status bar.

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