File: i_application_window.py

package info (click to toggle)
python-pyface 8.0.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 13,944 kB
  • sloc: python: 54,107; makefile: 82
file content (163 lines) | stat: -rw-r--r-- 5,018 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# (C) Copyright 2005-2023 Enthought, Inc., Austin, TX
# All rights reserved.
#
# This software is provided without warranty under the terms of the BSD
# license included in LICENSE.txt and may be redistributed only under
# the conditions described in the aforementioned license. The license
# is also available online at http://www.enthought.com/licenses/BSD.txt
#
# Thanks for using Enthought open source!

""" The interface of a top-level application window. """


from traits.api import HasTraits, Instance, List

from pyface.action.i_menu_bar_manager import IMenuBarManager
from pyface.action.i_status_bar_manager import IStatusBarManager
from pyface.action.i_tool_bar_manager import IToolBarManager
from pyface.i_window import IWindow
from pyface.ui_traits import Image


class IApplicationWindow(IWindow):
    """ The interface for a top-level application window.

    The application window has support for a menu bar, tool bar and a status
    bar (all of which are optional).

    Notes
    -----

    To use, create a sub-class of this class and override the
    :py:meth:`._create_contents` method.
    """

    # 'IApplicationWindow' interface ---------------------------------------

    #: The window icon.  The default is toolkit specific.
    icon = Image()

    #: The menu bar manager for the window.
    menu_bar_manager = Instance(IMenuBarManager)

    #: The status bar manager for the window.
    status_bar_manager = Instance(IStatusBarManager)

    #: The collection of tool bar managers for the window.
    tool_bar_managers = List(Instance(IToolBarManager))

    # ------------------------------------------------------------------------
    # Protected 'IApplicationWindow' interface.
    # ------------------------------------------------------------------------

    def _create_contents(self, parent):
        """ Create and return the window's contents.

        Parameters
        ----------
        parent : toolkit control
            The window's toolkit control to be used as the parent for
            widgets in the contents.

        Returns
        -------
        control : toolkit control
            A control to be used for contents of the window.
        """

    def _create_menu_bar(self, parent):
        """ Creates the menu bar (if required).

        Parameters
        ----------
        parent : toolkit control
            The window's toolkit control.
        """

    def _create_status_bar(self, parent):
        """ Creates the status bar (if required).

        Parameters
        ----------
        parent : toolkit control
            The window's toolkit control.
        """

    def _create_tool_bar(self, parent):
        """ Creates the tool bar (if required).

        Parameters
        ----------
        parent : toolkit control
            The window's toolkit control.
        """

    def _create_trim_widgets(self, parent):
        """ Creates the 'trim' widgets (the widgets around the window).

        Parameters
        ----------
        parent : toolkit control
            The window's toolkit control.
        """

    def _set_window_icon(self):
        """ Sets the window icon (if required). """


class MApplicationWindow(HasTraits):
    """ The mixin class that contains common code for toolkit specific
    implementations of the :py:class:`IApplicationWindow` interface.

    Implements: destroy(), _create_trim_widgets()
    """

    #: The icon to display in the application window title bar.
    icon = Image()

    #: The menu bar manager for the window.
    menu_bar_manager = Instance(IMenuBarManager)

    #: The status bar manager for the window.
    status_bar_manager = Instance(IStatusBarManager)

    #: The collection of tool bar managers for the window.
    tool_bar_managers = List(Instance(IToolBarManager))

    # ------------------------------------------------------------------------
    # 'IWidget' interface.
    # ------------------------------------------------------------------------

    def destroy(self):
        """ Destroy the control if it exists. """

        if self.menu_bar_manager is not None:
            self.menu_bar_manager.destroy()

        if self.status_bar_manager is not None:
            self.status_bar_manager.destroy()

        for tool_bar_manager in self.tool_bar_managers:
            tool_bar_manager.destroy()

        super().destroy()

    # ------------------------------------------------------------------------
    # Protected 'IApplicationWindow' interface.
    # ------------------------------------------------------------------------

    def _create_trim_widgets(self, parent):
        """ Creates the 'trim' widgets (the widgets around the window).

        Parameters
        ----------
        parent : toolkit control
            The window's toolkit control.
        """

        # All of these are optional.
        self._set_window_icon()
        self._create_menu_bar(parent)
        self._create_tool_bar(parent)
        self._create_status_bar(parent)