Debian Codegraph @

envisage/ui/gui_application.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 """
11 Envisage GUI Application
12 ------------------------
13
14 This class handles the life-cycle of a Pyface GUI. Plugins can
15 display windows via mechinisms such as edit_traits().
16
17 This is intended to be a very simple shell for lifting an existing
18 pure TraitsUI or Pyface (or even Qt) app into an Envisage app.
19
20 More sophisticated applications should use Tasks.
21
22 """
23
24 from traits.api import Event, Supports
25
26 from envisage.api import Application
27
28
29 class GUIApplication(Application):
30 """The entry point for an Envisage GUI application.
31
32 This class handles the life-cycle of a Pyface GUI. Plugins can
33 display windows via mechinisms such as edit_traits().
34
35 This is intended to be a very simple shell for lifting an existing
36 pure TraitsUI or Pyface (or even Qt) app into an Envisage app.
37
38 More sophisticated applications should use Tasks.
39
40 """
41
42 #### 'GUIApplication' interface #########################################
43
44 #: The Pyface GUI for the application.
45 gui = Supports("pyface.i_gui.IGUI")
46
47 #: The splash screen for the application. By default, there is no splash
48 #: screen.
49 splash_screen = Supports("pyface.i_splash_screen.ISplashScreen")
50
51 #### Application lifecycle events #########################################
52
53 #: Fired after the GUI event loop has been started.
54 application_initialized = Event
55
56 ###########################################################################
57 # 'IApplication' interface.
58 ###########################################################################
59
60 def run(self):
61 """Run the application.
62
63 Returns
64 -------
65 bool
66 Whether the application started successfully (i.e., without a
67 veto).
68
69 """
70
71 # Make sure the GUI has been created (so that, if required, the splash
72 # screen is shown).
73 gui = self.gui
74
75 started = self.start()
76 if started:
77 gui.set_trait_later(self, "application_initialized", self)
78 # Start the GUI event loop. The application will block here.
79 gui.start_event_loop()
80
81 # clean up plugins once event loop stops
82 self.stop()
83
84 return started
85
86 #### Trait initializers ###################################################
87
88 def _gui_default(self):
89 from pyface.api import GUI
90
91 return GUI(splash_screen=self.splash_screen)