Example #1
0
 def __init__(self):
     """Monitor a Microsoft Sidewinder X4 keyboard via X events."""
     StenotypeBase.__init__(self)
     self._keyboard_emulation = keyboardcontrol.KeyboardEmulation()
     self._keyboard_capture = keyboardcontrol.KeyboardCapture()
     self._keyboard_capture.key_down = self._key_down
     self._keyboard_capture.key_up = self._key_up
     self.suppress_keyboard(True)
     self._down_keys = set()
     self._released_keys = set()
Example #2
0
 def __init__(self, params):
     """Monitor a Microsoft Sidewinder X4 keyboard via X events."""
     StenotypeBase.__init__(self)
     self._keyboard_emulation = keyboardcontrol.KeyboardEmulation()
     self._keyboard_capture = keyboardcontrol.KeyboardCapture()
     self._keyboard_capture.key_down = self._key_down
     self._keyboard_capture.key_up = self._key_up
     self.suppress_keyboard(True)
     self._down_keys = set()
     self._released_keys = set()
     self.arpeggiate = params['arpeggiate']
     self.keymap = params['keymap'].to_dict()
Example #3
0
 def __init__(self, params):
     """Monitor a Microsoft Sidewinder X4 keyboard via X events."""
     StenotypeBase.__init__(self)
     self.arpeggiate = params['arpeggiate']
     self.keymap = params['keymap'].to_dict()
     self._arpeggiate_key = None
     for key, mapping in self.keymap.items():
         if 'no-op' == mapping:
             self.keymap[key] = None
         if 'arpeggiate' == mapping:
             if self.arpeggiate:
                 self.keymap[key] = None
                 self._arpeggiate_key = key
             else:
                 # Don't suppress arpeggiate key if it's not used.
                 del self.keymap[key]
     self._down_keys = set()
     self._released_keys = set()
     self._keyboard_emulation = keyboardcontrol.KeyboardEmulation()
     self._keyboard_capture = keyboardcontrol.KeyboardCapture(self.keymap.keys())
     self._keyboard_capture.key_down = self._key_down
     self._keyboard_capture.key_up = self._key_up
     self.suppress_keyboard(True)
Example #4
0
File: app.py Project: gcr/plover
    def __init__(self, engine_command_callback):
        """Creates and configures a single steno pipeline."""
        self.subscribers = []
        self.is_running = False
        self.machine = None
        self.machine_init = {}
        self.translator = None
        self.formatter = None
        self.output = None

        # Check and use configuration
        self.config = conf.get_config()
        config_errors, config_values = check_steno_config(self.config)
        for error in config_errors:
            # This will raise one of the configuration errors.
            raise error

        machine_type, user_dictionary = config_values

        # Set the machine module and any initialization variables.
        self.machine_module = conf.import_named_module(
            machine_type, SUPPORTED_MACHINES_DICT)
        if self.machine_module is None:
            raise InvalidConfigurationError(
                'Invalid configuration value for %s: %s' %
                (conf.MACHINE_TYPE_OPTION, machine_type))

        if issubclass(self.machine_module.Stenotype,
                      plover.machine.base.SerialStenotypeBase):
            serial_params = conf.get_serial_params(machine_type, self.config)
            self.machine_init.update(serial_params.__dict__)

        # Initialize the logger.
        log_file = join(
            conf.CONFIG_DIR,
            self.config.get(conf.LOGGING_CONFIG_SECTION, conf.LOG_FILE_OPTION))
        self.logger = logging.getLogger(conf.LOGGER_NAME)
        self.logger.setLevel(logging.DEBUG)
        handler = RotatingFileHandler(
            log_file,
            maxBytes=conf.LOG_MAX_BYTES,
            backupCount=conf.LOG_COUNT,
        )
        handler.setFormatter(logging.Formatter(conf.LOG_FORMAT))
        self.logger.addHandler(handler)

        # Construct the stenography capture-translate-format-display pipeline.
        self.machine = self.machine_module.Stenotype(**self.machine_init)
        self.translator = translation.Translator()
        self.translator.set_dictionary(user_dictionary)
        self.formatter = formatting.Formatter()

        # Add hooks for logging. Do this first so logs appear in order.
        if self.config.getboolean(conf.LOGGING_CONFIG_SECTION,
                                  conf.ENABLE_STROKE_LOGGING_OPTION):
            self.machine.add_callback(self._log_stroke)
        if self.config.getboolean(conf.LOGGING_CONFIG_SECTION,
                                  conf.ENABLE_TRANSLATION_LOGGING_OPTION):
            self.translator.add_listener(self._log_translation)

        self.machine.add_callback(
            lambda x: self.translator.translate(steno.Stroke(x)))
        self.translator.add_listener(self.formatter.format)
        # This seems like a reasonable number. If this becomes a problem it can
        # be parameterized.
        self.translator.set_min_undo_length(10)
        keyboard_control = keyboardcontrol.KeyboardEmulation()
        bag = SimpleNamespace()
        bag.send_backspaces = keyboard_control.send_backspaces
        bag.send_string = keyboard_control.send_string
        bag.send_key_combination = keyboard_control.send_key_combination
        bag.send_engine_command = engine_command_callback
        self.full_output = bag
        bag = SimpleNamespace()
        bag.send_engine_command = engine_command_callback
        self.command_only_output = bag
        self.running_state = self.translator.get_state()

        auto_start = self.config.getboolean(conf.MACHINE_CONFIG_SECTION,
                                            conf.MACHINE_AUTO_START_OPTION)
        self.set_is_running(auto_start)

        # Start the machine monitoring for steno strokes.
        self.machine.start_capture()