コード例 #1
0
def create_keyboard_monitor(parent=None):
    """
    Create a new keyboard monitor:

    >>> monitor = create_keyboard_monitor(parent)
    >>> monitor.idle_time = 0.5
    >>> monitor.keys_to_ignore = monitor.IGNORE_MODIFIER_COMBOS
    >>> monitor.typingStarted.connect(lambda: print('typing started'))
    >>> monitor.typingStopped.connect(lambda: print('typing stopped'))
    >>> monitor.start()

    This function automatically chooses the "best" available implementation.
    Currently this means, that a :class:`RecordingKeyboardMonitor` is created,
    if the XRecord extension is available.  Otherwise this functions falls back
    to :class:`PollingKeyboardMonitor`.

    ``parent`` is the parent :class:`~PyQt4.QtCore.QObject`.

    Return an implementation of :class:`AbstractKeyboardMonitor`.
    """
    if xrecord:
        success, _ = xrecord.query_version(Display.from_qt())
        if success:
            return RecordingKeyboardMonitor(parent)
    return PollingKeyboardMonitor(parent)
コード例 #2
0
def main():
    about = KAboutData(
        b'synaptiks', '', ki18n('synaptiks'), str(synaptiks.__version__),
        ki18n('touchpad management and configuration application'),
        KAboutData.License_BSD,
        ki18n('Copyright (C) 2009, 2010 Sebastian Wiesner'))
    about.addAuthor(ki18n('Sebastian Wiesner'), ki18n('Maintainer'),
                    '*****@*****.**')
    about.addCredit(ki18n('Valentyn Pavliuchenko'),
                    ki18n('Debian packaging, russian translation, '
                          'bug reporting and testing'),
                    '*****@*****.**')
    about.setHomepage('http://synaptiks.lunaryorn.de/')
    about.setOrganizationDomain('synaptiks.lunaryorn.de')

    KCmdLineArgs.init(sys.argv, about)
    app = KApplication()
    window = KMainWindow()
    touchpad = Touchpad.find_first(Display.from_qt())
    config = TouchpadConfiguration(touchpad)
    config_widget = TouchpadConfigurationWidget(config)
    config_widget.configurationChanged.connect(
        partial(print, 'config changed?'))
    window.setCentralWidget(config_widget)
    window.show()
    app.exec_()
コード例 #3
0
def main():
    about = KAboutData(
        b'synaptiks', '', ki18n('synaptiks'), str(synaptiks.__version__),
        ki18n('touchpad management and configuration application'),
        KAboutData.License_BSD,
        ki18n('Copyright (C) 2009, 2010 Sebastian Wiesner'))
    about.addAuthor(ki18n('Sebastian Wiesner'), ki18n('Maintainer'),
                    '*****@*****.**')
    about.addCredit(
        ki18n('Valentyn Pavliuchenko'),
        ki18n('Debian packaging, russian translation, '
              'bug reporting and testing'), '*****@*****.**')
    about.setHomepage('http://synaptiks.lunaryorn.de/')
    about.setOrganizationDomain('synaptiks.lunaryorn.de')

    KCmdLineArgs.init(sys.argv, about)
    app = KApplication()
    window = KMainWindow()
    touchpad = Touchpad.find_first(Display.from_qt())
    config = TouchpadConfiguration(touchpad)
    config_widget = TouchpadConfigurationWidget(config)
    config_widget.configurationChanged.connect(
        partial(print, 'config changed?'))
    window.setCentralWidget(config_widget)
    window.show()
    app.exec_()
コード例 #4
0
ファイル: trayapplication.py プロジェクト: adaptee/synaptiks
    def __init__(self, parent=None):
        KStatusNotifierItem.__init__(self, parent)
        self.setTitle('synaptiks')
        self.setIconByName('synaptiks')
        self.setCategory(KStatusNotifierItem.Hardware)
        self.setStatus(KStatusNotifierItem.Passive)
        self.setup_actions()

        self._config = SynaptiksTrayConfiguration(self)

        try:
            self.touchpad = Touchpad.find_first(Display.from_qt())
        except Exception as error:
            # show an error message
            from synaptiks.kde.error import get_localized_error_message
            error_message = get_localized_error_message(error)
            options = KMessageBox.Options(KMessageBox.Notify |
                                          KMessageBox.AllowLink)
            KMessageBox.error(None, error_message, '', options)
            # disable all touchpad related actions
            for act in (self.touchpad_on_action, self.preferences_action):
                act.setEnabled(False)
            # disable synaptiks autostart, the user can still start synaptiks
            # manually again, if the reason of the error is fixed
            self._config.findItem('Autostart').setProperty(False)
            self._config.writeConfig()
        else:
            self.activateRequested.connect(self.show_configuration_dialog)
            # setup the touchpad manager
            self.setup_manager(self.touchpad)
コード例 #5
0
ファイル: conftest.py プロジェクト: sridharraman/synaptiks
def pytest_funcarg__qxdisplay(request):
    """
    Qt X11 display wrapper.
    """
    # need a qt application before connecting to the Qt display
    request.getfuncargvalue('qtapp')
    return Display.from_qt()
コード例 #6
0
ファイル: conftest.py プロジェクト: Ascaf0/synaptiks
def pytest_funcarg__qxdisplay(request):
    """
    Qt X11 display wrapper.
    """
    # need a qt application before connecting to the Qt display
    request.getfuncargvalue('qtapp')
    return Display.from_qt()
コード例 #7
0
ファイル: config.py プロジェクト: Ascaf0/synaptiks
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')
コード例 #8
0
ファイル: try_xrecord.py プロジェクト: Ascaf0/synaptiks
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)
コード例 #9
0
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)
コード例 #10
0
 def stop(self):
     """
     Stop this recorder.
     """
     if not self.isRunning():
         return
     self._started.wait()
     xrecord.disable_context(Display.from_qt(), self._context)
     # immediately process the end of data event.  This allows us to wait
     # for this thread to terminate in the next line, thus making this
     # method synchronous.
     QApplication.instance().processEvents()
     self.wait()
     self._started.clear()
コード例 #11
0
 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)
コード例 #12
0
def make_kcm_widget(component_data, parent=None):
    """
    Create a KCModule object to configure the touchpad.

    This function tries to find a touchpad on this system and get the
    configuration of this touchpad.  If this succeeds, a
    :class:`TouchpadConfigurationKCM` is returned, allowing the user to
    configure the touchpad.

    Otherwise a :class:`TouchpadErrorKCM` is returned, which gives the user a
    description of the error and its cause.
    """
    from synaptiks.x11 import Display
    from synaptiks.touchpad import Touchpad
    from synaptiks.config import TouchpadConfiguration
    try:
        touchpad = Touchpad.find_first(Display.from_qt())
        config = TouchpadConfiguration(touchpad)
        return TouchpadConfigurationKCM(config, component_data, parent)
    except Exception as error:
        return TouchpadErrorKCM(error, component_data, parent)
コード例 #13
0
ファイル: kcm.py プロジェクト: adaptee/synaptiks
def make_kcm_widget(component_data, parent=None):
    """
    Create a KCModule object to configure the touchpad.

    This function tries to find a touchpad on this system and get the
    configuration of this touchpad.  If this succeeds, a
    :class:`TouchpadConfigurationKCM` is returned, allowing the user to
    configure the touchpad.

    Otherwise a :class:`TouchpadErrorKCM` is returned, which gives the user a
    description of the error and its cause.
    """
    from synaptiks.x11 import Display
    from synaptiks.touchpad import Touchpad
    from synaptiks.config import TouchpadConfiguration
    try:
        touchpad = Touchpad.find_first(Display.from_qt())
        config = TouchpadConfiguration(touchpad)
        return TouchpadConfigurationKCM(config, component_data, parent)
    except Exception as error:
        return TouchpadErrorKCM(error, component_data, parent)
コード例 #14
0
 def __init__(self, parent=None):
     AbstractKeyboardMonitor.__init__(self, parent)
     self.display = Display.from_qt()
     # this timer is started on every keyboard event, its timeout signals,
     # that the keyboard is to be considered inactive again
     self._idle_timer = QTimer(self)
     self._idle_timer.setInterval(self.DEFAULT_IDLETIME)
     self._idle_timer.timeout.connect(self.typingStopped)
     self._idle_timer.setSingleShot(True)
     # this object records events
     self._recorder = EventRecorder(self)
     self._recorder.keyPressed.connect(self._key_pressed)
     self._recorder.keyReleased.connect(self._key_released)
     self._recorder.started.connect(self.started)
     self._recorder.finished.connect(self.stopped)
     # a set of all known modifier keycodes
     modifier_mapping = xlib.get_modifier_mapping(self.display)
     self._modifiers = frozenset(keycode for modifiers in modifier_mapping
                                 for keycode in modifiers if keycode != 0)
     # a set holding all pressed, but not yet released modifier keys
     self._pressed_modifiers = set()
     # the value of keys to ignore
     self._keys_to_ignore = self.IGNORE_NO_KEYS
コード例 #15
0
ファイル: try_xrecord.py プロジェクト: Ascaf0/synaptiks
 def handler(signum, frame):
     with Display.from_name() as display:
         xrecord.disable_context(display, context)
コード例 #16
0
ファイル: test_x11.py プロジェクト: adaptee/synaptiks
 def test_open_close(self):
     display = Display.from_name()
     assert display
     display.close()
     assert not display
コード例 #17
0
 def handler(signum, frame):
     with Display.from_name() as display:
         xrecord.disable_context(display, context)
コード例 #18
0
ファイル: config.py プロジェクト: adaptee/synaptiks
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')
コード例 #19
0
ファイル: test_x11.py プロジェクト: adaptee/synaptiks
 def test_qt(self, qtapp):
     assert Display.from_qt()
コード例 #20
0
ファイル: test_x11.py プロジェクト: adaptee/synaptiks
 def test_error(self):
     with mock.patch.dict(os.environ, {}, clear=True):
         with pytest.raises(DisplayError):
             Display.from_name()
コード例 #21
0
ファイル: test_x11.py プロジェクト: adaptee/synaptiks
 def test_context(self):
     with Display.from_name() as display:
         assert display
     assert not display