File: mdi_window_menu.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 (178 lines) | stat: -rw-r--r-- 5,169 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# (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!

""" A menu that mimics the standard MDI window menu.

This is the menu that has the tile/cascade actions etc.

"""


from traits.api import Str


from .action.api import MenuManager, Separator, WindowAction


class Cascade(WindowAction):
    """ Cascades the windows. """

    # 'Action' interface ---------------------------------------------------

    name = Str("Ca&scade")
    tooltip = Str("Cascade the windows")

    # ------------------------------------------------------------------------
    # 'Action' interface.
    # ------------------------------------------------------------------------

    def perform(self, event):
        """ Cascades the windows. """

        self.window.control.Cascade()


class Tile(WindowAction):
    """ Tiles the windows horizontally. """

    # 'Action' interface ---------------------------------------------------

    name = Str("&Tile")
    tooltip = Str("Tile the windows")

    # ------------------------------------------------------------------------
    # 'Action' interface.
    # ------------------------------------------------------------------------

    def perform(self, event):
        """ Tiles the windows horizontally. """

        self.window.control.Tile()


class ArrangeIcons(WindowAction):
    """ Arranges the icons. """

    # 'Action' interface ---------------------------------------------------

    name = Str("&Arrange Icons")
    tooltip = Str("Arrange the icons")

    # ------------------------------------------------------------------------
    # 'Action' interface.
    # ------------------------------------------------------------------------

    def perform(self, event):
        """ Arranges the icons. """

        self.window.control.ArrangeIcons()


class Next(WindowAction):
    """ Activates the next window. """

    # 'Action' interface ---------------------------------------------------

    name = Str("&Next")
    tooltip = Str("Activate the next window")

    # ------------------------------------------------------------------------
    # 'Action' interface.
    # ------------------------------------------------------------------------

    def perform(self, event):
        """ Activates the next window. """

        self.window.control.ActivateNext()


class Previous(WindowAction):
    """ Activates the previous window. """

    # 'Action' interface ---------------------------------------------------

    name = Str("&Previous")
    tooltip = Str("Activate the previous window")

    # ------------------------------------------------------------------------
    # 'Action' interface.
    # ------------------------------------------------------------------------

    def perform(self, event):
        """ Activates the previous window. """

        self.window.control.ActivatePrevious()


class Close(WindowAction):
    """ Closes the current window. """

    # 'Action' interface ---------------------------------------------------

    name = Str("&Close")
    tooltip = Str("Close the current window")

    # ------------------------------------------------------------------------
    # 'Action' interface.
    # ------------------------------------------------------------------------

    def perform(self, event):
        """ Closes the current window. """

        page = self.window.control.GetActiveChild()
        if page is not None:
            page.Close()


class CloseAll(WindowAction):
    """ Closes all of the child windows. """

    # 'Action' interface ---------------------------------------------------

    name = Str("Close A&ll")
    tooltip = Str("Close all of the windows.")

    # ------------------------------------------------------------------------
    # 'Action' interface.
    # ------------------------------------------------------------------------

    def perform(self, event):
        """ Closes the child windows. """

        for page in self.window.control.GetChildren():
            page.Close()


class MDIWindowMenu(MenuManager):
    """ A menu that mimics the standard MDI window menus.

    This is the menu that has the tile/cascade actions etc.

    """

    # ------------------------------------------------------------------------
    # 'object' interface.
    # ------------------------------------------------------------------------

    def __init__(self, window):
        """ Creates a new MDI window menu. """

        # Base class constructor.
        super().__init__(
            Cascade(window=window),
            Tile(window=window),
            Separator(),
            ArrangeIcons(window=window),
            Next(window=window),
            Previous(window=window),
            Close(window=window),
            CloseAll(window=window),
            name="&Window",
        )