add signal handler

This commit is contained in:
piotr
2021-10-27 03:30:37 +02:00
parent dedc30cf43
commit 4af24aa35e

View File

@@ -4,6 +4,7 @@ import os
import sys
import subprocess
import gi
import signal
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gdk, GLib
@@ -125,6 +126,15 @@ SKELETON_PANEL: dict = {
}
def signal_handler(sig, frame):
desc = {2: "SIGINT", 15: "SIGTERM", 10: "SIGUSR1"}
if sig == 2 or sig == 15:
print("Terminated with {}".format(desc[sig]))
Gtk.main_quit()
else:
print("{} signal received".format(sig))
def handle_keyboard(window, event):
if event.type == Gdk.EventType.KEY_RELEASE and event.keyval == Gdk.KEY_Escape:
window.close()
@@ -2331,6 +2341,10 @@ def main():
global selector_window
selector_window = PanelSelector()
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
signal.signal(signal.SIGUSR1, signal_handler)
Gtk.main()