def main(): from argparse import ArgumentParser from synaptiks import __version__ from synaptiks.x11 import Display, DisplayError from synaptiks.touchpad import Touchpad, NoTouchpadError parser = ArgumentParser( description='synaptiks touchpad configuration utility', epilog="""\ Copyright (C) 2010 Sebastian Wiesner <*****@*****.**>, distributed under the terms of the BSD License""") parser.add_argument('--version', help='Show synaptiks version', action='version', version=__version__) actions = parser.add_subparsers(title='Actions') init_act = actions.add_parser( 'init', help='Initialize touchpad configuration. Should not be ' 'called manually, but automatically at session startup.') init_act.set_defaults(action='init') load_act = actions.add_parser( 'load', help='Load the touchpad configuration') load_act.add_argument( 'filename', nargs='?', help='File to load the configuration from. If ' 'empty, the default configuration file is loaded.') load_act.set_defaults(action='load') save_act = actions.add_parser( 'save', help='Save the current touchpad configuration') save_act.add_argument( 'filename', nargs='?', help='File to save the configuration to. If ' 'empty, the default configuration file is used.') save_act.set_defaults(action='save') # default filename to load configuration from parser.set_defaults(filename=None) # we don't have any arguments, but need to make sure, that the builtin # arguments (--help mainly) are handled args = parser.parse_args() try: with Display.from_name() as display: touchpad = Touchpad.find_first(display) if args.action == 'init': driver_defaults = TouchpadConfiguration(touchpad) driver_defaults.save(get_touchpad_defaults_file_path()) if args.action in ('init', 'load'): TouchpadConfiguration.load(touchpad, filename=args.filename) if args.action == 'save': current_config = TouchpadConfiguration(touchpad) current_config.save(filename=args.filename) except DisplayError: parser.error('could not connect to X11 display') except NoTouchpadError: parser.error('no touchpad found')
def main(): with Display.from_name() as display: _, xrecord_version = xrecord.query_version(display) print('xrecord version:', '.'.join(map(str, xrecord_version))) key_events = (xlib.KEY_PRESS, xlib.KEY_RELEASE) with xrecord.context(display, xrecord.ALL_CLIENTS, device_events=key_events) as context: disable = disable_context_handler(context) signal.signal(signal.SIGINT, disable) signal.signal(signal.SIGTERM, disable) xrecord.enable_context(display, context, handle_event, None)
def run(self): # create a special display connection for recording with Display.from_name() as recording_display: # record all key presses and releases, as these events indicate # keyboard activity key_events = (xlib.KEY_PRESS, xlib.KEY_RELEASE) with xrecord.context(recording_display, xrecord.ALL_CLIENTS, device_events=key_events) as context: self._context = context # create the recording context and enable it. This function # does not return until disable_context is called, which # happens in stop. xrecord.enable_context(recording_display, context, self._callback, None)
def handler(signum, frame): with Display.from_name() as display: xrecord.disable_context(display, context)
def main(): from argparse import ArgumentParser from synaptiks import __version__ from synaptiks.x11 import Display, DisplayError from synaptiks.touchpad import Touchpad, NoTouchpadError parser = ArgumentParser( description='synaptiks touchpad configuration utility', epilog="""\ Copyright (C) 2010 Sebastian Wiesner <*****@*****.**>, distributed under the terms of the BSD License""") parser.add_argument('--version', help='Show synaptiks version', action='version', version=__version__) actions = parser.add_subparsers(title='Actions') init_act = actions.add_parser( 'init', help='Initialize touchpad configuration. Should not be ' 'called manually, but automatically at session startup.') init_act.set_defaults(action='init') load_act = actions.add_parser('load', help='Load the touchpad configuration') load_act.add_argument('filename', nargs='?', help='File to load the configuration from. If ' 'empty, the default configuration file is loaded.') load_act.set_defaults(action='load') save_act = actions.add_parser( 'save', help='Save the current touchpad configuration') save_act.add_argument('filename', nargs='?', help='File to save the configuration to. If ' 'empty, the default configuration file is used.') save_act.set_defaults(action='save') # default filename to load configuration from parser.set_defaults(filename=None) # we don't have any arguments, but need to make sure, that the builtin # arguments (--help mainly) are handled args = parser.parse_args() try: with Display.from_name() as display: touchpad = Touchpad.find_first(display) if args.action == 'init': driver_defaults = TouchpadConfiguration(touchpad) driver_defaults.save(get_touchpad_defaults_file_path()) if args.action in ('init', 'load'): TouchpadConfiguration.load(touchpad, filename=args.filename) if args.action == 'save': current_config = TouchpadConfiguration(touchpad) current_config.save(filename=args.filename) except DisplayError: parser.error('could not connect to X11 display') except NoTouchpadError: parser.error('no touchpad found')
def test_error(self): with mock.patch.dict(os.environ, {}, clear=True): with pytest.raises(DisplayError): Display.from_name()
def test_context(self): with Display.from_name() as display: assert display assert not display
def test_open_close(self): display = Display.from_name() assert display display.close() assert not display