Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / tui-window-disabled.py
CommitLineData
88b9d363 1# Copyright (C) 2021-2022 Free Software Foundation, Inc.
29db1eb3
AB
2#
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.
7#
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.
12#
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/>.
15
16# A TUI window implemented in Python that responds to, and displays,
17# stop and exit events.
18
19import gdb
20
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
24perform_valid_check = True
25update_title = False
26cleanup_properly = False
27
28# A global place into which we can write the window title.
29titles_at_the_close = {}
30
13123da8 31
29db1eb3 32class EventWindow:
13123da8 33 def __init__(self, win):
29db1eb3
AB
34 self._win = win
35 self._count = 0
36 win.title = "This Is The Event Window"
13123da8
SM
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)
29db1eb3
AB
41 self._events = []
42
43 # Ensure we can erase and write to the window from the
44 # constructor, the window should be valid by this point.
13123da8
SM
45 self._win.erase()
46 self._win.write("Hello world...")
29db1eb3 47
13123da8 48 def close(self):
29db1eb3
AB
49 global cleanup_properly
50 global titles_at_the_close
51
52 # Ensure that window properties can be read within the close method.
13123da8
SM
53 titles_at_the_close[self._win.title] = dict(
54 width=self._win.width, height=self._win.height
55 )
29db1eb3
AB
56
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.
13123da8
SM
60 self._win.erase()
61 self._win.write("Goodbye cruel world...")
29db1eb3
AB
62
63 if cleanup_properly:
64 # Disconnect the listeners and delete the lambda functions.
65 # This removes cyclic references to SELF, and so alows SELF to
66 # be deleted.
13123da8
SM
67 gdb.events.stop.disconnect(self._stop_listener)
68 gdb.events.exited.disconnect(self._exit_listener)
29db1eb3
AB
69 self._stop_listener = None
70 self._exit_listener = None
71
13123da8 72 def _event(self, type, event):
29db1eb3
AB
73 global perform_valid_check
74 global update_title
75
76 self._count += 1
13123da8
SM
77 self._events.insert(0, type)
78 if not perform_valid_check or self._win.is_valid():
29db1eb3 79 if update_title:
13123da8 80 self._win.title = "This Is The Event Window (" + str(self._count) + ")"
29db1eb3 81 else:
13123da8 82 self.render()
29db1eb3 83
13123da8
SM
84 def render(self):
85 self._win.erase()
29db1eb3
AB
86 w = self._win.width
87 h = self._win.height
13123da8
SM
88 for i in range(min(h, len(self._events))):
89 self._win.write(self._events[i] + "\n")
90
29db1eb3
AB
91
92gdb.register_window_type("events", EventWindow)
This page took 0.108816 seconds and 4 git commands to generate.