mirror of
https://github.com/tromey/gdb-gui.git
synced 2025-12-16 07:10:04 +01:00
set button sensitivity based on running state
This commit is contained in:
28
gui/gdbutil.py
Normal file
28
gui/gdbutil.py
Normal file
@@ -0,0 +1,28 @@
|
||||
# Copyright (C) 2015 Tom Tromey <tom@tromey.com>
|
||||
|
||||
# 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/>.
|
||||
|
||||
# Little gdb utilities.
|
||||
|
||||
import gdb
|
||||
from gui.startup import in_gdb_thread
|
||||
|
||||
@in_gdb_thread
|
||||
def is_running():
|
||||
"""Return True if the inferior is running."""
|
||||
# This seems good enough for now.
|
||||
# We can deal with scheduler locking and the rest later.
|
||||
if gdb.selected_thread() and gdb.selected_thread().is_running():
|
||||
return True
|
||||
return False
|
||||
@@ -42,7 +42,7 @@ class LogWindow(gui.toplevel.Toplevel):
|
||||
self.window.set_title('GDB Log @%d' % self.number)
|
||||
self.window.show()
|
||||
|
||||
def deleted(self, widget, event):
|
||||
def deleted(self, *args):
|
||||
if default_log_window == self:
|
||||
default_log_window = None
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
import gdb
|
||||
import gui
|
||||
import gui.updatewindow
|
||||
from gui.invoker import Invoker
|
||||
from gui.toplevel import Toplevel
|
||||
import gui.startup
|
||||
@@ -24,6 +25,7 @@ from gui.startup import in_gdb_thread, in_gtk_thread
|
||||
import gui.toplevel
|
||||
import gui.events
|
||||
import os.path
|
||||
import gui.gdbutil
|
||||
|
||||
from gi.repository import Gtk, GtkSource, GObject, Gdk, GdkPixbuf, Pango
|
||||
|
||||
@@ -174,17 +176,19 @@ class LRUHandler:
|
||||
|
||||
lru_handler = LRUHandler()
|
||||
|
||||
class SourceWindow(Toplevel):
|
||||
BUTTON_NAMES = ["step", "next", "continue", "finish", "stop"]
|
||||
|
||||
class SourceWindow(gui.updatewindow.UpdateWindow):
|
||||
def _get_pixmap(self, filename):
|
||||
path = os.path.join(gui.self_dir, filename)
|
||||
return GdkPixbuf.Pixbuf.new_from_file(path)
|
||||
|
||||
def __init__(self):
|
||||
super(SourceWindow, self).__init__()
|
||||
gui.startup.send_to_gtk(self._initialize)
|
||||
gdb.events.cont.connect(self._on_cont_event)
|
||||
|
||||
@in_gtk_thread
|
||||
def _initialize(self):
|
||||
def gtk_initialize(self):
|
||||
self.frame = None
|
||||
|
||||
self.do_step = Invoker("step")
|
||||
@@ -198,6 +202,11 @@ class SourceWindow(Toplevel):
|
||||
self.window = builder.get_object("sourcewindow")
|
||||
self.view = builder.get_object("view")
|
||||
|
||||
# Maybe there is a cleaner way?
|
||||
self.buttons = {}
|
||||
for name in BUTTON_NAMES:
|
||||
self.buttons[name] = builder.get_object(name)
|
||||
|
||||
font_desc = Pango.FontDescription('monospace')
|
||||
if font_desc:
|
||||
self.view.modify_font(font_desc)
|
||||
@@ -216,8 +225,31 @@ class SourceWindow(Toplevel):
|
||||
self.window.set_title('GDB Source @%d' % self.number)
|
||||
self.window.show()
|
||||
|
||||
def deleted(self, widget, event):
|
||||
@in_gtk_thread
|
||||
def _update_buttons(self, running):
|
||||
for button in BUTTON_NAMES:
|
||||
if button is "stop":
|
||||
self.buttons[button].set_sensitive(running)
|
||||
else:
|
||||
self.buttons[button].set_sensitive(not running)
|
||||
|
||||
@in_gdb_thread
|
||||
def on_event(self):
|
||||
running = gui.gdbutil.is_running()
|
||||
gui.startup.send_to_gtk(lambda: self._update_buttons(running))
|
||||
|
||||
@in_gdb_thread
|
||||
def _on_cont_event(self, event):
|
||||
self.on_event()
|
||||
|
||||
@in_gdb_thread
|
||||
def _disconnect_cont_event(self):
|
||||
gdb.events.cont.disconnect(self._on_cont_event)
|
||||
|
||||
def deleted(self, *args):
|
||||
lru_handler.remove(self)
|
||||
gdb.post_event(self._disconnect_cont_event)
|
||||
super(SourceWindow, self).deleted()
|
||||
|
||||
def line_mark_activated(self, view, textiter, event):
|
||||
if event.type != Gdk.EventType.BUTTON_PRESS:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# Copyright (C) 2013 Tom Tromey <tom@tromey.com>
|
||||
# Copyright (C) 2013, 2015 Tom Tromey <tom@tromey.com>
|
||||
|
||||
# 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
|
||||
@@ -65,6 +65,6 @@ class UpdateWindow(Toplevel):
|
||||
self.on_event()
|
||||
|
||||
@in_gtk_thread
|
||||
def deleted(self):
|
||||
def deleted(self, *args):
|
||||
gdb.post_event(self._disconnect_events)
|
||||
self.destroy()
|
||||
|
||||
Reference in New Issue
Block a user