From 4b5a9b16eddcab956af312cd1b5c3c61d288d8b3 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Wed, 12 Jun 2013 10:30:12 -0600 Subject: [PATCH] add "info windows" and "delete window" This adds the "info windows" and "delete window" commands. "info windows" unfortunately overlaps with the TUI's "info win". So maybe we should rename this one. This also adds a new "toplevel" component that knows how to track windows. --- gui/__init__.py | 4 +++ gui/commands.py | 1 + gui/source.py | 6 +++- gui/toplevel.py | 93 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 gui/toplevel.py diff --git a/gui/__init__.py b/gui/__init__.py index 73e0db8..909265c 100644 --- a/gui/__init__.py +++ b/gui/__init__.py @@ -16,3 +16,7 @@ import os.path self_dir = os.path.abspath(os.path.dirname(__file__)) + +# Import anything that defines a command or parameter. +import gui.commands +import gui.toplevel diff --git a/gui/commands.py b/gui/commands.py index ae41c40..6b89e07 100644 --- a/gui/commands.py +++ b/gui/commands.py @@ -28,6 +28,7 @@ class GuiSourceCommand(gdb.Command): gdb.COMMAND_SUPPORT) def invoke(self, arg, from_tty): + self.dont_repeat() gui.startup.start_gtk() gui.startup.send_to_gtk(gui.source.SourceWindow) diff --git a/gui/source.py b/gui/source.py index 3a57562..488bd7a 100644 --- a/gui/source.py +++ b/gui/source.py @@ -17,8 +17,10 @@ import gdb from gui.invoker import Invoker +from gui.toplevel import Toplevel import gui.startup import os.path +import gui.toplevel from gi.repository import Gtk, GtkSource, GObject @@ -140,8 +142,10 @@ class LRUHandler: lru_handler = LRUHandler() -class SourceWindow: +class SourceWindow(Toplevel): def __init__(self): + super(SourceWindow, self).__init__() + self.frame = None self.do_step = Invoker("step") diff --git a/gui/toplevel.py b/gui/toplevel.py new file mode 100644 index 0000000..3731f38 --- /dev/null +++ b/gui/toplevel.py @@ -0,0 +1,93 @@ +# Copyright (C) 2013 Tom Tromey + +# 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 . + +# Toplevel handling. + +import gdb +import gui.startup +import threading + +class _ToplevelState(object): + def __init__(self): + # This lock must be held when using the other globals here. + self.toplevel_lock = threading.Lock() + self.next_toplevel = 1 + self.toplevels = {} + + def add(self, obj): + with self.toplevel_lock: + obj.number = self.next_toplevel + self.next_toplevel = self.next_toplevel + 1 + self.toplevels[obj.number] = obj + + def remove(self, obj): + with self.toplevel_lock: + del self.toplevels[obj.number] + + def get(self, winno): + window = None + with self.toplevel_lock: + if winno in self.toplevels: + window = self.toplevels[winno] + return window + + def display(self): + with self.toplevel_lock: + if len(self.toplevels) == 0: + print "No windows" + return + + print ' Num Name' + for winno in range(1, self.next_toplevel): + if winno in self.toplevels: + window = self.toplevels[winno] + print ' %3d %s' % (window.number, + window.window.get_title()) + +_toplevel_state = _ToplevelState() + +class Toplevel(object): + def __init__(self): + _toplevel_state.add(self) + # The subclass must set this. + self.window = None + + def destroy(self): + _toplevel_state.remove(self) + gui.startup.send_to_gtk(self.window.destroy) + +class InfoWindowsCommand(gdb.Command): + def __init__(self): + super(InfoWindowsCommand, self).__init__('info windows', + gdb.COMMAND_SUPPORT) + + def invoke(self, arg, from_tty): + self.dont_repeat() + _toplevel_state.display() + +class DeleteWindowsCommand(gdb.Command): + def __init__(self): + super(DeleteWindowsCommand, self).__init__('delete window', + gdb.COMMAND_SUPPORT) + + def invoke(self, arg, from_tty): + self.dont_repeat() + winno = int(arg) + window = _toplevel_state.get(winno) + if window is not None: + window.destroy() + +InfoWindowsCommand() +DeleteWindowsCommand()