diff options
author | Tom Tromey <tom@tromey.com> | 2020-02-22 11:48:26 -0700 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2020-02-22 12:57:25 -0700 |
commit | 01b1af321f804ef6dfd40d3054c8757f31096ea8 (patch) | |
tree | 03c14bda00b71bb7322ff5d2bfc3e2355b37e932 /gdb/testsuite/gdb.python | |
parent | fc96d20b2c6d7ff24349ad015119438077d3f1e9 (diff) | |
download | binutils-01b1af321f804ef6dfd40d3054c8757f31096ea8.zip binutils-01b1af321f804ef6dfd40d3054c8757f31096ea8.tar.gz binutils-01b1af321f804ef6dfd40d3054c8757f31096ea8.tar.bz2 |
Allow TUI windows in Python
This patch adds support for writing new TUI windows in Python.
2020-02-22 Tom Tromey <tom@tromey.com>
* NEWS: Add entry for gdb.register_window_type.
* tui/tui-layout.h (window_factory): New typedef.
(tui_register_window): Declare.
* tui/tui-layout.c (saved_tui_windows): New global.
(tui_apply_current_layout): Use it.
(tui_register_window): New function.
* python/python.c (do_start_initialization): Call
gdbpy_initialize_tui.
(python_GdbMethods): Add "register_window_type" function.
* python/python-internal.h (gdbpy_register_tui_window)
(gdbpy_initialize_tui): Declare.
* python/py-tui.c: New file.
* Makefile.in (SUBDIR_PYTHON_SRCS): Add py-tui.c.
gdb/doc/ChangeLog
2020-02-22 Tom Tromey <tom@tromey.com>
* python.texi (Python API): Add menu item.
(TUI Windows In Python): New node.
gdb/testsuite/ChangeLog
2020-02-22 Tom Tromey <tom@tromey.com>
* gdb.python/tui-window.exp: New file.
* gdb.python/tui-window.py: New file.
Change-Id: I85fbfb923a1840450a00a7dce113a05d7f048baa
Diffstat (limited to 'gdb/testsuite/gdb.python')
-rw-r--r-- | gdb/testsuite/gdb.python/tui-window.exp | 51 | ||||
-rw-r--r-- | gdb/testsuite/gdb.python/tui-window.py | 37 |
2 files changed, 88 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.python/tui-window.exp b/gdb/testsuite/gdb.python/tui-window.exp new file mode 100644 index 0000000..1a4feeb --- /dev/null +++ b/gdb/testsuite/gdb.python/tui-window.exp @@ -0,0 +1,51 @@ +# Copyright (C) 2020 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# Test a TUI window implemented in Python. + +load_lib gdb-python.exp +load_lib tuiterm.exp + +# This test doesn't care about the inferior. +standard_testfile py-arch.c + +if {[build_executable "failed to prepare" ${testfile} ${srcfile}] == -1} { + return -1 +} + +Term::clean_restart 24 80 $testfile + +# Skip all tests if Python scripting is not enabled. +if { [skip_python_tests] } { continue } + +set remote_python_file [gdb_remote_download host \ + ${srcdir}/${subdir}/${testfile}.py] +gdb_test_no_output "source ${remote_python_file}" \ + "source ${testfile}.py" + +gdb_test_no_output "tui new-layout test test 1 status 0 cmd 1" + +if {![Term::enter_tui]} { + unsupported "TUI not supported" +} + +Term::command "layout test" +Term::check_contents "test title" \ + "This Is The Title" +Term::check_contents "Window display" "Test: 0" + +Term::resize 51 51 +# Remember that a resize request actually does two resizes... +Term::check_contents "Window was updated" "Test: 2" diff --git a/gdb/testsuite/gdb.python/tui-window.py b/gdb/testsuite/gdb.python/tui-window.py new file mode 100644 index 0000000..4deb585 --- /dev/null +++ b/gdb/testsuite/gdb.python/tui-window.py @@ -0,0 +1,37 @@ +# Copyright (C) 2020 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# A TUI window implemented in Python. + +import gdb + +the_window = None + +class TestWindow: + def __init__(self, win): + global the_window + the_window = win + self.count = 0 + self.win = win + win.title = "This Is The Title" + + def render(self): + self.win.erase() + w = self.win.width + h = self.win.height + self.win.write("Test: " + str(self.count) + " " + str(w) + "x" + str(h)) + self.count = self.count + 1 + +gdb.register_window_type("test", TestWindow) |