Exemple #1
0
 def _advanced_config(self, event=None):
     # Brings up a more detailed configuration UI, if available.
     if self.config_class:
         machine_type = self.choice.GetStringSelection()
         if self.config_class is Serial:
             if self.config_instance is None:
                 self.config_instance = conf.get_serial_params(
                     machine_type, self.config)
             scd = serial_config.SerialConfigDialog(self.config_instance,
                                                    self)
             scd.ShowModal()
             scd.Destroy()
Exemple #2
0
 def _advanced_config(self, event=None):
     # Brings up a more detailed configuration UI, if available.
     if self.config_class:
         machine_type = self.choice.GetStringSelection()
         if self.config_class is Serial:
             if self.config_instance is None:
                 self.config_instance = conf.get_serial_params(machine_type,
                                                               self.config)
             scd = serial_config.SerialConfigDialog(self.config_instance,
                                                    self)
             scd.ShowModal()
             scd.Destroy()
Exemple #3
0
    def __init__(self):
        """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
        self.config = conf.get_config()

        # Set the machine module and any initialization variables.
        machine_type = self.config.get(conf.MACHINE_CONFIG_SECTION,
                                       conf.MACHINE_TYPE_OPTION)
        self.machine_module = conf.import_named_module(machine_type,
                                                       machine.supported)
        if self.machine_module is None:
            raise ValueError('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__)

        # Set the steno dictionary format module.
        dictionary_format = self.config.get(conf.DICTIONARY_CONFIG_SECTION,
                                            conf.DICTIONARY_FORMAT_OPTION)
        self.dictionary_module = conf.import_named_module(dictionary_format,
                                                          dictionary.supported)
        if self.dictionary_module is None:
            raise ValueError('Invalid configuration value for %s: %s' %
                             (conf.DICTIONARY_FORMAT_OPTION, dictionary_format))

        # Load the dictionary. The dictionary path can be either
        # absolute or relative to the configuration directory.
        dictionary_filename = self.config.get(conf.DICTIONARY_CONFIG_SECTION,
                                              conf.DICTIONARY_FILE_OPTION)
        dictionary_path = os.path.join(conf.CONFIG_DIR, dictionary_filename)
        if not os.path.isfile(dictionary_path):
            raise ValueError('Invalid configuration value for %s: %s' %
                             (conf.DICTIONARY_FILE_OPTION, dictionary_path))
        dictionary_extension = os.path.splitext(dictionary_path)[1]
        if dictionary_extension == conf.JSON_EXTENSION:
            try:
                with open(dictionary_path, 'r') as f:
                    self.dictionary = json.load(f)
            except UnicodeDecodeError:
                with open(dictionary_path, 'r') as f:
                    self.dictionary = json.load(f, conf.ALTERNATIVE_ENCODING)
        else:
            raise ValueError('The value of %s must end with %s.' %
                             (conf.DICTIONARY_FILE_OPTION, conf.JSON_EXTENSION))

        # Initialize the logger.
        log_file = os.path.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 = logging.handlers.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.output = keyboardcontrol.KeyboardEmulation()
        self.translator = steno.Translator(self.machine,
                                           self.dictionary,
                                           self.dictionary_module)
        self.formatter = formatting.Formatter(self.translator)
        auto_start = self.config.getboolean(conf.MACHINE_CONFIG_SECTION,
                                            conf.MACHINE_AUTO_START_OPTION)
        self.set_is_running(auto_start)

        # Add hooks for logging.
        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_callback(self._log_translation)

        # Start the machine monitoring for steno strokes.
        self.machine.start_capture()
Exemple #4
0
    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()
Exemple #5
0
    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()
Exemple #6
0
    def __init__(self):
        """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
        config_params_dict = conf.get_config()
        config_errors, config_values = check_steno_config(config_params_dict)
        machine_type, dictionary_format, user_dictionary = config_values
        self.config = config_params_dict

        for error in config_errors:
            # This will raise one of the configuration errors.
            raise error

        # 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__)

        # Set the steno dictionary format module.
        self.dictionary_module = conf.import_named_module(
                                                dictionary_format,
                                                SUPPORTED_DICTIONARIES_DICT)
        if self.dictionary_module is None:
            raise InvalidConfigurationError(
                'Invalid configuration value for %s: %s' %
                (conf.DICTIONARY_FORMAT_OPTION, dictionary_format))

        # 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.output = keyboardcontrol.KeyboardEmulation()
        self.translator = steno.Translator(self.machine,
                                           user_dictionary,
                                           self.dictionary_module)
        self.formatter = formatting.Formatter(self.translator)
        auto_start = self.config.getboolean(conf.MACHINE_CONFIG_SECTION,
                                            conf.MACHINE_AUTO_START_OPTION)
        self.set_is_running(auto_start)

        # Add hooks for logging.
        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_callback(self._log_translation)

        # Start the machine monitoring for steno strokes.
        self.machine.start_capture()
Exemple #7
0
    def __init__(self):
        """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
        self.config = conf.get_config()

        # Set the machine module and any initialization variables.
        machine_type = self.config.get(conf.MACHINE_CONFIG_SECTION,
                                       conf.MACHINE_TYPE_OPTION)
        self.machine_module = conf.import_named_module(machine_type,
                                                       machine.supported)
        if self.machine_module is None:
            raise ValueError('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__)

        # Set the steno dictionary format module.
        dictionary_format = self.config.get(conf.DICTIONARY_CONFIG_SECTION,
                                            conf.DICTIONARY_FORMAT_OPTION)
        self.dictionary_module = conf.import_named_module(
            dictionary_format, dictionary.supported)
        if self.dictionary_module is None:
            raise ValueError(
                'Invalid configuration value for %s: %s' %
                (conf.DICTIONARY_FORMAT_OPTION, dictionary_format))

        # Load the dictionary. The dictionary path can be either
        # absolute or relative to the configuration directory.
        dictionary_filename = self.config.get(conf.DICTIONARY_CONFIG_SECTION,
                                              conf.DICTIONARY_FILE_OPTION)
        dictionary_path = os.path.join(conf.CONFIG_DIR, dictionary_filename)
        if not os.path.isfile(dictionary_path):
            raise ValueError('Invalid configuration value for %s: %s' %
                             (conf.DICTIONARY_FILE_OPTION, dictionary_path))
        dictionary_extension = os.path.splitext(dictionary_path)[1]
        if dictionary_extension == conf.JSON_EXTENSION:
            try:
                with open(dictionary_path, 'r') as f:
                    self.dictionary = json.load(f)
            except UnicodeDecodeError:
                with open(dictionary_path, 'r') as f:
                    self.dictionary = json.load(f, conf.ALTERNATIVE_ENCODING)
        else:
            raise ValueError(
                'The value of %s must end with %s.' %
                (conf.DICTIONARY_FILE_OPTION, conf.JSON_EXTENSION))

        # Initialize the logger.
        log_file = os.path.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 = logging.handlers.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.output = keyboardcontrol.KeyboardEmulation()
        self.translator = steno.Translator(self.machine, self.dictionary,
                                           self.dictionary_module)
        self.formatter = formatting.Formatter(self.translator)
        auto_start = self.config.getboolean(conf.MACHINE_CONFIG_SECTION,
                                            conf.MACHINE_AUTO_START_OPTION)
        self.set_is_running(auto_start)

        # Add hooks for logging.
        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_callback(self._log_translation)

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