Handle SIGINT from Ctrl+C in shell

Used when testing from the shell prompt using sugar-activity{,3}.
When Ctrl+C is pressed, close the activity.

May be used by other processes to request a clean activity stop, but
with save-as enabled may require user input.
This commit is contained in:
James Cameron 2018-07-04 06:31:47 +10:00 committed by Rahul Bothra
parent 06a28fae0e
commit 6730d129cd

View File

@ -161,6 +161,7 @@ You may copy it and use it as a template.
import gettext import gettext
import logging import logging
import os import os
import signal
import time import time
from hashlib import sha1 from hashlib import sha1
from functools import partial from functools import partial
@ -173,6 +174,7 @@ gi.require_version('Gtk', '3.0')
gi.require_version('Gdk', '3.0') gi.require_version('Gdk', '3.0')
gi.require_version('SugarExt', '1.0') gi.require_version('SugarExt', '1.0')
from gi.repository import GLib
from gi.repository import GObject from gi.repository import GObject
from gi.repository import Gdk from gi.repository import Gdk
from gi.repository import Gtk from gi.repository import Gtk
@ -314,6 +316,8 @@ class Activity(Window, Gtk.Container):
} }
def __init__(self, handle, create_jobject=True): def __init__(self, handle, create_jobject=True):
GLib.unix_signal_add(GLib.PRIORITY_DEFAULT, signal.SIGINT, self.close)
# Stuff that needs to be done early # Stuff that needs to be done early
icons_path = os.path.join(get_bundle_path(), 'icons') icons_path = os.path.join(get_bundle_path(), 'icons')
Gtk.IconTheme.get_default().append_search_path(icons_path) Gtk.IconTheme.get_default().append_search_path(icons_path)