1 # Copyright (C) 2021-2022 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # A TUI window implemented in Python that responds to, and displays,
17 # stop and exit events.
21 # When an event arrives we ask the window to redraw itself. We should
22 # only do this if the window is valid. When this flag is true we
23 # perform the is_valid check. When this flag is false
24 perform_valid_check
= True
26 cleanup_properly
= False
28 # A global place into which we can write the window title.
29 titles_at_the_close
= {}
33 def __init__(self
, win
):
36 win
.title
= "This Is The Event Window"
37 self
._stop
_listener
= lambda e
: self
._event
("stop", e
)
38 gdb
.events
.stop
.connect(self
._stop
_listener
)
39 self
._exit
_listener
= lambda e
: self
._event
("exit", e
)
40 gdb
.events
.exited
.connect(self
._exit
_listener
)
43 # Ensure we can erase and write to the window from the
44 # constructor, the window should be valid by this point.
46 self
._win
.write("Hello world...")
49 global cleanup_properly
50 global titles_at_the_close
52 # Ensure that window properties can be read within the close method.
53 titles_at_the_close
[self
._win
.title
] = dict(
54 width
=self
._win
.width
, height
=self
._win
.height
57 # The following calls are pretty pointless, but this ensures
58 # that we can erase and write to a window from the close
59 # method, the last moment a window should be valid.
61 self
._win
.write("Goodbye cruel world...")
64 # Disconnect the listeners and delete the lambda functions.
65 # This removes cyclic references to SELF, and so alows SELF to
67 gdb
.events
.stop
.disconnect(self
._stop
_listener
)
68 gdb
.events
.exited
.disconnect(self
._exit
_listener
)
69 self
._stop
_listener
= None
70 self
._exit
_listener
= None
72 def _event(self
, type, event
):
73 global perform_valid_check
77 self
._events
.insert(0, type)
78 if not perform_valid_check
or self
._win
.is_valid():
80 self
._win
.title
= "This Is The Event Window (" + str(self
._count
) + ")"
88 for i
in range(min(h
, len(self
._events
))):
89 self
._win
.write(self
._events
[i
] + "\n")
92 gdb
.register_window_type("events", EventWindow
)