Beispiel #1
0
    def DoEditSession(self, edit_cookie):

        TS_DEFAULT_SELECTION = -1
        selection, count = self.input_context.GetSelection(edit_cookie, TS_DEFAULT_SELECTION, 1)

        _range = selection.range

        # FIXME:
        # Manual dispatching with state like this makes me cringe.
        # We should have separate CommitEditSession, DeleteEditSession, etc. classes.
        if self.editing_operation == "commit":
            text, length = self.text_to_commit

            inserter = self.input_context.QueryInterface(ITfInsertAtSelection)
            out = inserter.InsertTextAtSelection(edit_cookie, 0, text, length)

            # Move the carret to the end of our newly inserted string
            # _range.Collapse(edit_cookie, TF_ANCHOR_END)

            # style = TF_SELECTIONSTYLE()
            # style.ase = TF_AE_NONE
            # style.fInterimChar = False

            # new_selection = TF_SELECTION()
            # new_selection.style = style
            # new_selection.range = _range

            # self.input_context.SetSelection(edit_cookie, 1, new_selection)

        elif self.editing_operation == "delete-prev-chars":
            moved_chars = _range.ShiftStart(edit_cookie, -self.delete_count, None)
            logging.debug("moved_chars: %s", moved_chars)

            TF_ST_CORRECTION = 1
            _range.SetText(edit_cookie, TF_ST_CORRECTION, utils.text_to_ushort_array(""), 0)
Beispiel #2
0
    def _register(self, registrar):
        registrar._unregister(BoGoTextService, force=True)
        registrar._register(BoGoTextService)

        # Register input profile (supported languages, description,...)
        inputProcessorProfiles = comtypes.client.CreateObject(CLSID_TF_InputProcessorProfiles,
                                    clsctx=comtypes.CLSCTX_INPROC_SERVER,
                                    interface=ITfInputProcessorProfiles)

        profileGUIDPointer = serverGUIDPointer

        description = utils.text_to_ushort_array("BoGo")

        # http://msdn.microsoft.com/en-us/library/windows/desktop/dd318693%28v=vs.85%29.aspx
        VI_VN = 0x042A

        inputProcessorProfiles.Register(serverGUIDPointer)

        inputProcessorProfiles.AddLanguageProfile(
            serverGUIDPointer,
            VI_VN,
            profileGUIDPointer,
            description,
            4,                   # The description is 4-char long
            None,                # We don't have icons
            -1,
            -1)

        # Register categories (whether we do keyboard, voice,...)
        categoryManager = comtypes.client.CreateObject(CLSID_TF_CategoryMgr,
            clsctx=comtypes.CLSCTX_INPROC_SERVER,
            interface=ITfCategoryMgr)

        categoryManager.RegisterCategory(serverGUIDPointer,
            ctypes.pointer(GUID_TFCAT_TIP_KEYBOARD),
            serverGUIDPointer)
Beispiel #3
0
    def commit_text(self, text):
        logging.debug("commit_text(%s)", text)
        self.text_to_commit = utils.text_to_ushort_array(text), len(text)

        self.editing_operation = "commit"
        return self.input_context.RequestEditSession(self.client_id, self, TF_ES_SYNC | TF_ES_READWRITE)