Debian Codegraph @

envisage/ui/workbench/workbench.py

raw
1 # (C) Copyright 2007-2025 Enthought, Inc., Austin, TX
2 # All rights reserved.
3 #
4 # This software is provided without warranty under the terms of the BSD
5 # license included in LICENSE.txt and may be redistributed only under
6 # the conditions described in the aforementioned license. The license
7 # is also available online at http://www.enthought.com/licenses/BSD.txt
8 #
9 # Thanks for using Enthought open source!
10 """ The Envisage workbench. """
11
12
13 # Enthought library imports.
14 import pyface.workbench.api as pyface
15 from pyface.api import YES
16 from traits.api import Delegate, Instance
17
18 from envisage.api import IApplication
19
20 # Local imports.
21 from .workbench_preferences import WorkbenchPreferences
22 from .workbench_window import WorkbenchWindow
23
24
25 class Workbench(pyface.Workbench):
26 """The Envisage workbench.
27
28 There is (usually) exactly *one* workbench per application. The workbench
29 can create any number of workbench windows.
30
31 """
32
33 #### 'pyface.Workbench' interface #########################################
34
35 # The factory that is used to create workbench windows.
36 window_factory = WorkbenchWindow
37
38 #### 'Workbench' interface ################################################
39
40 # The application that the workbench is part of.
41 application = Instance(IApplication)
42
43 # Should the user be prompted before exiting the workbench?
44 prompt_on_exit = Delegate("_preferences")
45
46 #### Private interface ####################################################
47
48 # The workbench preferences.
49 _preferences = Instance(WorkbenchPreferences, ())
50
51 ###########################################################################
52 # Private interface.
53 ###########################################################################
54
55 def _exiting_changed(self, event):
56 """Called when the workbench is exiting."""
57
58 if self.prompt_on_exit:
59 answer = self.active_window.confirm(
60 "Exit %s?" % self.active_window.title, "Confirm Exit"
61 )
62 if answer != YES:
63 event.veto = True