add stop notifications

Fixes #38
This commit is contained in:
Tom Tromey
2015-09-29 12:28:05 -06:00
parent 6caa2acfc3
commit 48e2764916
3 changed files with 114 additions and 0 deletions

View File

@@ -22,3 +22,6 @@ import gui.commands
import gui.params
import gui.toplevel
import gui.framecache
# Hooks in to gdb.
import gui.notify

76
gui/notify.py Normal file
View File

@@ -0,0 +1,76 @@
# 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/>.
# 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)

View File

@@ -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}]')