Exemplo n.º 1
0
def main(config):

    handler_class = None
    try:
        if sys.platform.startswith('linux'):
            from plover.oslayer.log_dbus import DbusNotificationHandler
            handler_class = DbusNotificationHandler
        elif sys.platform.startswith('darwin'):
            from plover.oslayer.log_osx import OSXNotificationHandler
            handler_class = OSXNotificationHandler
    except Exception:
        log.info('could not import platform gui log', exc_info=True)
    if handler_class is not None:
        try:
            handler = handler_class()
        except Exception:
            log.info('could not initialize platform gui log', exc_info=True)
        else:
            log.add_handler(handler)

    engine = Engine(config, KeyboardEmulation())
    if not engine.load_config():
        return 3
    quitting = Event()
    engine.hook_connect('quit', quitting.set)
    engine.start()
    try:
        quitting.wait()
    except KeyboardInterrupt:
        pass
    engine.quit()
    engine.join()

    return 0
Exemplo n.º 2
0
def main(config, controller):
    engine = Engine(config, controller, KeyboardEmulation())
    if not engine.load_config():
        return 3
    quitting = Event()
    engine.hook_connect('quit', quitting.set)
    engine.start()
    try:
        quitting.wait()
    except KeyboardInterrupt:
        engine.quit()
    return engine.join()
Exemplo n.º 3
0
def main(config: Config, controller=None):
    # this screws things up
    # hax tho
    log.remove_handler(__logger._print_handler)

    # mor hax ... I don't wanna see QT notifications
    log.remove_handler(__logger._platform_handler)
    __logger._platform_handler = None

    for option in console_ui_options:
        config._OPTIONS[option.name] = option

    engine = ConsoleEngine(config, KeyboardEmulation(), layout, controller)

    if not engine.load_config():
        return 3

    engine.hook_connect(
        "config_changed",
        partial(config_saver, config, layout.output_to_console),
    )

    notification_handler.set_output(layout.output_to_console)
    notification_handler.setLevel(engine.config["console_ui_loglevel"])
    log.add_handler(notification_handler)

    if engine.config["show_suggestions_display"]:
        layout.toggle_suggestions()

    if engine.config["show_stroke_display"]:
        layout.toggle_tape()

    fg = engine.config["console_ui_fg"]
    bg = engine.config["console_ui_bg"]

    application.style = create_style(fg, bg)

    quitting = Event()
    engine.hook_connect("quit", quitting.set)

    engine.start()
    code = application.run()

    engine.quit()
    quitting.wait()
    engine.join()
    return code
Exemplo n.º 4
0
    def __init__(self, config, controller, use_qt_notifications):

        # This is done dynamically so localization
        # support can be configure beforehand.
        from plover.gui_qt.main_window import MainWindow

        self._app = None
        self._win = None
        self._engine = None
        self._translator = None

        QCoreApplication.setApplicationName(__software_name__.capitalize())
        QCoreApplication.setApplicationVersion(__version__)
        QCoreApplication.setOrganizationName('Open Steno Project')
        QCoreApplication.setOrganizationDomain('openstenoproject.org')

        self._app = QApplication([])
        self._app.setAttribute(Qt.AA_UseHighDpiPixmaps)

        # Enable localization of standard Qt controls.
        log.info('setting language to: %s', _.lang)
        self._translator = QTranslator()
        translations_dir = QLibraryInfo.location(QLibraryInfo.TranslationsPath)
        self._translator.load('qtbase_' + _.lang, translations_dir)
        self._app.installTranslator(self._translator)

        QApplication.setQuitOnLastWindowClosed(False)

        self._app.engine = self._engine = Engine(config, controller,
                                                 KeyboardEmulation())
        # On macOS, quitting through the dock will result
        # in a direct call to `QCoreApplication.quit`.
        self._app.aboutToQuit.connect(self._app.engine.quit)

        signal.signal(signal.SIGINT, lambda signum, stack: self._engine.quit())

        # Make sure the Python interpreter runs at least every second,
        # so signals have a chance to be processed.
        self._timer = QTimer()
        self._timer.timeout.connect(lambda: None)
        self._timer.start(1000)

        self._win = MainWindow(self._engine, use_qt_notifications)
Exemplo n.º 5
0
 def __init__(self, engine_command_callback, engine):
     self.engine_command_callback = engine_command_callback
     self.keyboard_control = KeyboardEmulation()
     self.engine = engine
Exemplo n.º 6
0
 def __init_plover(self):
     print "Init plover"
     self.machine = plover_machine.Stenotype({'arpeggiate': False})
     self.steno = Steno(self.machine, self)
     self.keyboard_control = KeyboardEmulation()
Exemplo n.º 7
0
class Engine(ibus.EngineBase):
    def __init__(self, bus, object_path):
        super(Engine, self).__init__(bus, object_path)
        self.__is_invalidate = False
        self.__preedit_string = u""
        self.__aux_string = u""
        #self.__lookup_table = ibus.LookupTable()
        self.__prop_list = ibus.PropList()
        self.__prop_list.append(ibus.Property(u"test", icon = u"ibus-locale"))
        self.__init_plover()

    def __init_plover(self):
        print "Init plover"
        self.machine = plover_machine.Stenotype({'arpeggiate': False})
        self.steno = Steno(self.machine, self)
        self.keyboard_control = KeyboardEmulation()

        # # Patch formatter
        # formatting.Formatter = aware_formatter.AwareFormatter
        # self.steno_engine = plover.app.StenoEngine()
        # # self.steno_engine.add_callback(self.__plover_update_status)
        # self.steno_engine.full_output.change_string = self.change_string
        # self.steno_engine.full_output.send_key_combination = self.send_key_combination
        # self.steno_engine.full_output.send_engine_command = self.send_engine_command
        # self.steno_engine.set_machine(self.machine)
        # self.steno_engine.set_output(
        #     Output(self.__plover_consume_command, self.steno_engine))

        # plover.app.init_engine(self.steno_engine, self.plover_config)
        #self.steno_engine.set_is_running(True)

    def process_key_event(self, keyval, keycode, state):
        # ignore key presses with modifiers (e.g. Control-C)
        if (state & ~modifier.RELEASE_MASK):
            return False

        is_press = ((state & modifier.RELEASE_MASK) == 0)
        try:
            if is_press:
                handled = self.machine.key_down(keycode)
            else:
                handled = self.machine.key_up(keycode)

            # # Show steno keys
            if self.__aux_string:
                self.__aux_string = ""
                self.__invalidate()
            # self.__aux_string = self.steno.get_steno_string()
            # self.__invalidate()
        except:
            import traceback
            traceback.print_exc()
        
        # Don't pass through key presses corresponding to steno keys
        if not handled:
            print "...", keyval, keycode, state
        return handled

        if self.__preedit_string:
            if keyval == keysyms.Return:
                self.__commit_string(self.__preedit_string)
                return True
            elif keyval == keysyms.Escape:
                self.__preedit_string = u""
                self.__update()
                return True
            elif keyval == keysyms.BackSpace:
                self.__preedit_string = self.__preedit_string[:-1]
                self.__invalidate()
                return True
            elif keyval == keysyms.space:
                # if self.__lookup_table.get_number_of_candidates() > 0:
                #     self.__commit_string(self.__lookup_table.get_current_candidate().text)
                # else:
                #     self.__commit_string(self.__preedit_string)
                self.__commit_string(self.__preedit_string)
                return False
            elif keyval == keysyms.Left or keyval == keysyms.Right:
                return True
        if keyval in xrange(keysyms.a, keysyms.z + 1) or \
            keyval in xrange(keysyms.A, keysyms.Z + 1):
            if state & (modifier.CONTROL_MASK | modifier.ALT_MASK) == 0:
                self.__preedit_string += unichr(keyval)
                self.__invalidate()
                return True
        else:
            if keyval < 128 and self.__preedit_string:
                self.__commit_string(self.__preedit_string)

        return False

    def __invalidate(self):
        if self.__is_invalidate:
            return
        self.__is_invalidate = True
        gobject.idle_add(self.__update, priority = gobject.PRIORITY_LOW)

    def __commit_string(self, text):
        self.commit_text(ibus.Text(text))
        self.__preedit_string = u""
        self.__update()

    def __update(self):
        preedit_len = len(self.__preedit_string)
        attrs = ibus.AttrList()
        if preedit_len > 0:
            attrs.append(ibus.AttributeForeground(0xff0000, 0, preedit_len))
        self.update_auxiliary_text(
            ibus.Text(self.__aux_string, ibus.AttrList()),
            len(self.__aux_string) > 0)
        attrs.append(
            ibus.AttributeUnderline(pango.UNDERLINE_SINGLE, 0, preedit_len))
        self.update_preedit_text(ibus.Text(self.__preedit_string, attrs),
                                 preedit_len, preedit_len > 0)
        self.__is_invalidate = False

    def focus_in(self):
        print "focus in %s" % self.__proxy._object_path
        sys.stdout.flush()
        #self.register_properties(self.__prop_list)

    def focus_out(self):
        pass

    def reset(self):
        pass

    def enable(self):
        # Tell IBus we want to use surrounding text later
        print "enable %s" % self.__proxy._object_path
        sys.stdout.flush()
        self.get_surrounding_text()

    def property_activate(self, prop_name):
        print "PropertyActivate(%s)" % prop_name

    def __plover_update_status(self, state):
        print "Plover update status:", state

    def __plover_consume_command(self, command):
        print "Plover consume command:", command

    # Plover callbacks
    def change_string(self, before, after):
        # Check if surrounding text matches text to delete
        s, p = self.get_surrounding_text()
        current_text = s.get_text()[p - len(before):p]
        if current_text != before:
            print "MISMATCH: '%s' != '%s'" % (before, current_text)
            return False
        offset = len(commonprefix([before, after]))
        print "____", offset, "___", before, '->', after
        #print "Changing ok: '%s'" % t
        delete_length = len(before[offset:])
        self.delete_surrounding_text(-delete_length, delete_length)
        self.__preedit_string += after[offset:]
        self.__commit_string(self.__preedit_string)
        return True

    def send_key_combination(self, c):
        print "**** Send key comb:", c
        # Does it need to be delayed?
        # wx.CallAfter(self.keyboard_control.send_key_combination, c)

        # Does it need to be protected so it's not picked up again? In
        # theory yes; but as long as key combos aren't sending steno
        # key codes it'll be ok.
        self.keyboard_control.send_key_combination(c)


    # TODO: test all the commands now
    def send_engine_command(self, c):
        print "**** Send engine command:", c
        result = self.engine_command_callback(c)
        # if result and not self.engine.is_running:
        #     self.engine.machine.suppress = self.send_backspaces

    def show_message(self, message):
        def set_message():
            self.__aux_string = message
            self.__invalidate()
        gobject.idle_add(set_message, priority = gobject.PRIORITY_LOW)
Exemplo n.º 8
0
 def __init_plover(self):
     print "Init plover"
     self.machine = plover_machine.Stenotype({'arpeggiate': False})
     self.steno = Steno(self.machine, self)
     self.keyboard_control = KeyboardEmulation()
Exemplo n.º 9
0
class Engine(ibus.EngineBase):
    def __init__(self, bus, object_path):
        super(Engine, self).__init__(bus, object_path)
        self.__is_invalidate = False
        self.__preedit_string = u""
        self.__aux_string = u""
        #self.__lookup_table = ibus.LookupTable()
        self.__prop_list = ibus.PropList()
        self.__prop_list.append(ibus.Property(u"test", icon=u"ibus-locale"))
        self.__init_plover()

    def __init_plover(self):
        print "Init plover"
        self.machine = plover_machine.Stenotype({'arpeggiate': False})
        self.steno = Steno(self.machine, self)
        self.keyboard_control = KeyboardEmulation()

        # # Patch formatter
        # formatting.Formatter = aware_formatter.AwareFormatter
        # self.steno_engine = plover.app.StenoEngine()
        # # self.steno_engine.add_callback(self.__plover_update_status)
        # self.steno_engine.full_output.change_string = self.change_string
        # self.steno_engine.full_output.send_key_combination = self.send_key_combination
        # self.steno_engine.full_output.send_engine_command = self.send_engine_command
        # self.steno_engine.set_machine(self.machine)
        # self.steno_engine.set_output(
        #     Output(self.__plover_consume_command, self.steno_engine))

        # plover.app.init_engine(self.steno_engine, self.plover_config)
        #self.steno_engine.set_is_running(True)

    def process_key_event(self, keyval, keycode, state):
        # ignore key presses with modifiers (e.g. Control-C)
        if (state & ~modifier.RELEASE_MASK):
            return False

        is_press = ((state & modifier.RELEASE_MASK) == 0)
        try:
            if is_press:
                handled = self.machine.key_down(keycode)
            else:
                handled = self.machine.key_up(keycode)

            # # Show steno keys
            if self.__aux_string:
                self.__aux_string = ""
                self.__invalidate()
            # self.__aux_string = self.steno.get_steno_string()
            # self.__invalidate()
        except:
            import traceback
            traceback.print_exc()

        # Don't pass through key presses corresponding to steno keys
        if not handled:
            print "...", keyval, keycode, state
        return handled

        if self.__preedit_string:
            if keyval == keysyms.Return:
                self.__commit_string(self.__preedit_string)
                return True
            elif keyval == keysyms.Escape:
                self.__preedit_string = u""
                self.__update()
                return True
            elif keyval == keysyms.BackSpace:
                self.__preedit_string = self.__preedit_string[:-1]
                self.__invalidate()
                return True
            elif keyval == keysyms.space:
                # if self.__lookup_table.get_number_of_candidates() > 0:
                #     self.__commit_string(self.__lookup_table.get_current_candidate().text)
                # else:
                #     self.__commit_string(self.__preedit_string)
                self.__commit_string(self.__preedit_string)
                return False
            elif keyval == keysyms.Left or keyval == keysyms.Right:
                return True
        if keyval in xrange(keysyms.a, keysyms.z + 1) or \
            keyval in xrange(keysyms.A, keysyms.Z + 1):
            if state & (modifier.CONTROL_MASK | modifier.ALT_MASK) == 0:
                self.__preedit_string += unichr(keyval)
                self.__invalidate()
                return True
        else:
            if keyval < 128 and self.__preedit_string:
                self.__commit_string(self.__preedit_string)

        return False

    def __invalidate(self):
        if self.__is_invalidate:
            return
        self.__is_invalidate = True
        gobject.idle_add(self.__update, priority=gobject.PRIORITY_LOW)

    def __commit_string(self, text):
        self.commit_text(ibus.Text(text))
        self.__preedit_string = u""
        self.__update()

    def __update(self):
        preedit_len = len(self.__preedit_string)
        attrs = ibus.AttrList()
        if preedit_len > 0:
            attrs.append(ibus.AttributeForeground(0xff0000, 0, preedit_len))
        self.update_auxiliary_text(
            ibus.Text(self.__aux_string, ibus.AttrList()),
            len(self.__aux_string) > 0)
        attrs.append(
            ibus.AttributeUnderline(pango.UNDERLINE_SINGLE, 0, preedit_len))
        self.update_preedit_text(ibus.Text(self.__preedit_string, attrs),
                                 preedit_len, preedit_len > 0)
        self.__is_invalidate = False

    def focus_in(self):
        print "focus in %s" % self.__proxy._object_path
        sys.stdout.flush()
        #self.register_properties(self.__prop_list)

    def focus_out(self):
        pass

    def reset(self):
        pass

    def enable(self):
        # Tell IBus we want to use surrounding text later
        print "enable %s" % self.__proxy._object_path
        sys.stdout.flush()
        self.get_surrounding_text()

    def property_activate(self, prop_name):
        print "PropertyActivate(%s)" % prop_name

    def __plover_update_status(self, state):
        print "Plover update status:", state

    def __plover_consume_command(self, command):
        print "Plover consume command:", command

    # Plover callbacks
    def change_string(self, before, after):
        # Check if surrounding text matches text to delete
        s, p = self.get_surrounding_text()
        current_text = s.get_text()[p - len(before):p]
        if current_text != before:
            print "MISMATCH: '%s' != '%s'" % (before, current_text)
            return False
        offset = len(commonprefix([before, after]))
        print "____", offset, "___", before, '->', after
        #print "Changing ok: '%s'" % t
        delete_length = len(before[offset:])
        self.delete_surrounding_text(-delete_length, delete_length)
        self.__preedit_string += after[offset:]
        self.__commit_string(self.__preedit_string)
        return True

    def send_key_combination(self, c):
        print "**** Send key comb:", c
        # Does it need to be delayed?
        # wx.CallAfter(self.keyboard_control.send_key_combination, c)

        # Does it need to be protected so it's not picked up again? In
        # theory yes; but as long as key combos aren't sending steno
        # key codes it'll be ok.
        self.keyboard_control.send_key_combination(c)

    # TODO: test all the commands now
    def send_engine_command(self, c):
        print "**** Send engine command:", c
        result = self.engine_command_callback(c)
        # if result and not self.engine.is_running:
        #     self.engine.machine.suppress = self.send_backspaces

    def show_message(self, message):
        def set_message():
            self.__aux_string = message
            self.__invalidate()

        gobject.idle_add(set_message, priority=gobject.PRIORITY_LOW)