Home | History | Annotate | Line # | Download | only in gdb.python
      1 # Copyright (C) 2020-2024 Free Software Foundation, Inc.
      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.
     17 
     18 import gdb
     19 
     20 the_window = None
     21 
     22 
     23 class TestWindow:
     24     def __init__(self, win):
     25         global the_window
     26         the_window = self
     27         self.count = 0
     28         self.win = win
     29         win.title = "This Is The Title"
     30 
     31     def render(self):
     32         self.win.erase()
     33         w = self.win.width
     34         h = self.win.height
     35         self.win.write(
     36             string="Test: " + str(self.count) + " " + str(w) + "x" + str(h),
     37             full_window=False,
     38         )
     39         self.count = self.count + 1
     40 
     41     # Tries to delete the title attribute.  GDB will throw an error.
     42     def remove_title(self):
     43         del self.win.title
     44 
     45 
     46 gdb.register_window_type("test", TestWindow)
     47 
     48 
     49 # Call REMOVE_TITLE on the global window object.
     50 def delete_window_title():
     51     the_window.remove_title()
     52 
     53 
     54 # A TUI window "constructor" that always fails.
     55 def failwin(win):
     56     raise RuntimeError("Whoops")
     57 
     58 
     59 # Change the title of the window.
     60 def change_window_title():
     61     the_window.win.title = "New Title"
     62 
     63 
     64 gdb.register_window_type("fail", failwin)
     65