From 48e2764916b052f976a21a6ad3a3830aee29128d Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Tue, 29 Sep 2015 12:28:05 -0600 Subject: [PATCH] add stop notifications Fixes #38 --- gui/__init__.py | 3 ++ gui/notify.py | 76 +++++++++++++++++++++++++++++++++++++++++++++++++ gui/params.py | 35 +++++++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 gui/notify.py diff --git a/gui/__init__.py b/gui/__init__.py index eea8e1c..07fdf90 100644 --- a/gui/__init__.py +++ b/gui/__init__.py @@ -22,3 +22,6 @@ import gui.commands import gui.params import gui.toplevel import gui.framecache + +# Hooks in to gdb. +import gui.notify diff --git a/gui/notify.py b/gui/notify.py new file mode 100644 index 0000000..bc780b0 --- /dev/null +++ b/gui/notify.py @@ -0,0 +1,76 @@ +# Copyright (C) 2015 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 . + +# Notifications + +import gdb +import gui.params +import gui.startup +import time + +from gi.repository import Notify +from gui.startup import in_gtk_thread, in_gdb_thread + +_initialized = False + +_last_time = None + +@in_gtk_thread +def _show_notification(title, content): + global _initialized + if not _initialized: + _initialized = True + Notify.init("gdb") + n = Notify.Notification.new(title, content) + n.show() + +@in_gdb_thread +def _on_stop(event): + global _last_time + t = _last_time + _last_time = None + + if (t is None + or not gui.params.stop_notification.value + or time.clock() - t < gui.params.stop_notification_seconds.value): + return + + if isinstance(event, gdb.ExitedEvent): + title = 'gdb - inferior exited' + if hasattr(event, 'exit_code'): + content = 'inferior exited with code ' + str(event.exit_code) + else: + content = 'inferior exited, code unavailable' + elif isinstance(event, gdb.BreakpointEvent): + title = 'gdb - inferior stopped' + content = ('inferior stopped at breakpoint ' + + str(event.breakpoints[0].number)) + elif isinstance(event, gdb.SignalEvent): + title = 'gdb - inferior stopped' + content = 'inferior stopped with signal: ' + event.stop_signal + else: + title = 'gdb - inferior stopped' + content = 'inferior stopped, reason unknown' + + gui.startup.send_to_gtk(lambda: _show_notification(title, content)) + +@in_gdb_thread +def _on_cont(event): + global _last_time + _last_time = time.clock() + +gdb.events.stop.connect(_on_stop) +gdb.events.cont.connect(_on_cont) +gdb.events.exited.connect(_on_stop) diff --git a/gui/params.py b/gui/params.py index 6ef155d..6f43c03 100644 --- a/gui/params.py +++ b/gui/params.py @@ -261,6 +261,39 @@ class _Tabs(_StoredParameter): gui.toplevel.state.set_tab_width(self.value) return "" +class _StopNotification(_StoredParameter): + # Silly gdb requirement. + "" + + set_doc = "Set whether stop notifications are displayed." + show_doc = "Show whether stop notifications are displayed." + + def __init__(self): + super(_StopNotification, self).__init__('%s', 'stop-notification', True, + gdb.COMMAND_RUNNING, + gdb.PARAM_BOOLEAN) + + @in_gdb_thread + def get_show_string(self, pvalue): + return "Whether stop notifications are displayed is: %s" % self.value + +class _StopNotificationSeconds(_StoredParameter): + # Silly gdb requirement. + "" + + set_doc = "Set stop notification timeout in seconds." + show_doc = "Show stop notification timeout." + + def __init__(self): + super(_StopNotificationSeconds, self).__init__('%s', + 'stop-notification-seconds', + 120, + gdb.COMMAND_RUNNING, + gdb.PARAM_ZINTEGER) + + @in_gdb_thread + def get_show_string(self, pvalue): + return "Stop notifications are displayed after %d seconds." % self.value _SetBase() _SetTitleBase() @@ -268,6 +301,8 @@ _ShowBase() _ShowTitleBase() source_theme = _Theme() font_manager = _Font() +stop_notification = _StopNotification() +stop_notification_seconds = _StopNotificationSeconds() _Title('source', '\\W{basename} [GDB Source @\\W{number}]') _Title('display', '\\W{command} [GDB Display @\\W{number}]')