xpra icon
Bug tracker and wiki

Ticket #2264: test.py

File test.py, 1.5 KB (added by totaamwin32, 17 months ago)

simplte test case - updated to be python version agnostic

Line 
1#!/usr/bin/env python
2# This file is part of Xpra.
3# Copyright (C) 2017-2018 Antoine Martin <antoine@xpra.org>
4# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
5# later version. See the file COPYING for details.
6
7from ctypes import wintypes, WINFUNCTYPE
8import signal
9import ctypes
10import mmap
11import sys
12
13# Function prototype for the handler function. Returns BOOL, takes a DWORD.
14HandlerRoutine = WINFUNCTYPE(wintypes.BOOL, wintypes.DWORD)
15
16def _ctrl_handler(sig):
17    """Handle a sig event and return 0 to terminate the process"""
18    if sig == signal.CTRL_C_EVENT:
19        print("CTRL_C_EVENT")
20    elif sig == signal.CTRL_BREAK_EVENT:
21        print("CTRL_BREAK_EVENT")
22    else:
23        print("UNKNOWN EVENT")
24    return 0
25
26ctrl_handler = HandlerRoutine(_ctrl_handler)
27
28
29SetConsoleCtrlHandler = ctypes.windll.kernel32.SetConsoleCtrlHandler
30SetConsoleCtrlHandler.argtypes = (HandlerRoutine, wintypes.BOOL)
31SetConsoleCtrlHandler.restype = wintypes.BOOL
32
33if __name__ == "__main__":
34    # Add our console control handling function with value 1
35    if not SetConsoleCtrlHandler(ctrl_handler, 1):
36        print("Unable to add SetConsoleCtrlHandler")
37        exit(-1)
38
39    try:
40        import glib
41    except ImportError:
42        import gi
43        from gi.repository import GLib                  #@UnresolvedImport
44        if gi.version_info<(3, 11):
45            GLib.threads_init()
46        glib = GLib
47       
48    loop = glib.MainLoop()
49    try:
50        loop.run()
51    except:
52        print("exception!")
53        raise