예제 #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)
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 __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)
예제 #4
0
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()
예제 #5
0
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()
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_()
예제 #7
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()
예제 #8
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)
예제 #9
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)
예제 #10
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
예제 #11
0
 def test_qt(self, qtapp):
     assert Display.from_qt()