Пример #1
0
 def ap_candidate(self, candi):
     '''append candidate to lookup_table'''
     _p_index = self.get_index('phrase')
     #   _fkey = self.get_index('m0')
     _tbks = u''.join(
         map(self._deparser, candi[len(self._tabkey_list):_p_index]))
     _phrase = candi[_p_index]
     # further color implementation needed :)
     # here -2 is the pos of num, -1 is the pos of . 0 is the pos of string
     #attrs = ibus.AttrList ([ibus.AttributeForeground (0x8e2626, -2, 1)])
     attrs = ibus.AttrList()
     # this is the part of tabkey
     #attrs.append( ibus.AttributeForeground ( 0x1973a2, 0, \
     #    len(_phrase) + len(_tbks)))
     if candi[-2] < 0:
         # this is a user defined phrase:
         attrs.append(ibus.AttributeForeground(0x7700c3, 0, len(_phrase)))
     elif candi[-1] > 0:
         # this is a sys phrase used by user:
         attrs.append(ibus.AttributeForeground(0x000000, 0, len(_phrase)))
     else:
         # this is a system phrase haven't been used:
         attrs.append(ibus.AttributeForeground(0x000000, 0, len(_phrase)))
     self._lookup_table.append_candidate(ibus.Text(_phrase, attrs))
     self._lookup_table.show_cursor(False)
Пример #2
0
    def __update(self):
        prompt, prefix, word, suffix = self.__tutcode.preedit_components()
        prefix_start = len(prompt)
        word_start = prefix_start + len(prefix)
        suffix_start = word_start + len(word)
        suffix_end = suffix_start + len(suffix)
        attrs = ibus.AttrList()
        # Display "[DictEdit]" way different from other components
        # (black/lightsalmon).
        attrs.append(
            ibus.AttributeForeground(ibus.RGB(0, 0, 0), 0, prefix_start))
        attrs.append(
            ibus.AttributeBackground(ibus.RGB(255, 160, 122), 0, prefix_start))
        if self.__tutcode.conv_state == tutcode.CONV_STATE_SELECT:
            # Use colors from tutcode-henkan-face-default (black/darkseagreen2).
            attrs.append(
                ibus.AttributeForeground(ibus.RGB(0, 0, 0), word_start,
                                         suffix_start))
            attrs.append(
                ibus.AttributeBackground(ibus.RGB(180, 238, 180), word_start,
                                         suffix_start))
            attrs.append(
                ibus.AttributeUnderline(ibus.ATTR_UNDERLINE_SINGLE,
                                        suffix_start, suffix_end))
        else:
            attrs.append(
                ibus.AttributeUnderline(ibus.ATTR_UNDERLINE_SINGLE, word_start,
                                        suffix_end))
        # Color cursor, currently disabled.
        #
        # if self.__tutcode.abbrev:
        #     cursor_color = self.ABBREV_CURSOR_COLOR
        # else:
        #     cursor_color = self.INPUT_MODE_CURSOR_COLORS.get(\
        #         self.__tutcode.input_mode)
        # attrs.append(ibus.AttributeBackground(ibus.RGB(*cursor_color),
        #                                       suffix_end, suffix_end + 1))
        # preedit = ''.join((prompt, prefix, word, suffix, u' '))
        #
        preedit = ''.join((prompt, prefix, word, suffix))
        self.update_preedit_text(ibus.Text(preedit, attrs), len(preedit),
                                 len(preedit) > 0)
        visible = self.__candidate_selector.lookup_table_visible()
        self.update_lookup_table(self.__lookup_table, visible)
        self.__update_input_mode()

        if self.__tutcode.conv_state is not tutcode.CONV_STATE_SELECT:
            gobject.idle_add(self.__possibly_update_config,
                             priority=gobject.PRIORITY_LOW)

        self.__is_invalidate = False
Пример #3
0
    def _update_aux(self):
        '''Update Aux String in UI'''
        '''
        _ic = self._editor.get_strings ()
        if _ic:
            res = patt_edit.match (_ic)
            if res:
                _ic = u''
                ures = patt_uncommit.match (res.group(1))
                if ures:
                    _ic = u''.join (ures.groups())
                else:
                    _ic += res.group (1)
                _ic += res.group(2)
                _ic += res.group(3)
        if _ic in self._editor._ap_dict:
            _ic =  self._editor.get_aux_strings()+self._editor._ap_dict[_ic]
        '''
        _ic = self._editor.get_aux_strings()
        ins_str = ''
        _ic = None
        if _ic:
            attrs = ibus.AttrList(
                [ibus.AttributeForeground(0x9515b5, 0, len(_ic))])
            #attrs = [ scim.Attribute(0,len(_ic),scim.ATTR_FOREGROUND,0x5540c1)]

            super(tabengine,
                  self).update_auxiliary_text(ibus.Text(_ic, attrs), True)
        else:
            self.hide_auxiliary_text()
Пример #4
0
 def _update_aux(self):
     '''Update Aux String in UI'''
     _aux = self._aux_str
     if _aux:
         attrs = ibus.AttrList(
             [ibus.AttributeForeground(0x9515b5, 0, len(_aux))])
         super(tabengine, self).update_auxiliary_text(
             ibus.Text(_aux.decode('utf-8'), attrs), True)
     else:
         self.hide_auxiliary_text()
Пример #5
0
    def __update(self):
        try:
            #First, update our strings
            self.updateAuxString()
            self.updateGuessString()
            self.updateTableEntries()

            #Debug: update log
            #append_log('update called: ' + str([self.__typed_string, self.__preedit_string]))

            #Cache lengths
            preedit_len = len(self.__preedit_string)
            aux_len = len(self.__aux_string)
            prefix_len = len(self.__prefix_string)
            guess_len = len(self.__guess_string)

            #Get an attribute list for the preedit string
            attrs = ibus.AttrList()
            if self.__preedit_string:
                #Put the entire string in red; underline only the current "guessed" part
                attrs.append(ibus.AttributeForeground(0xff0000, 0, preedit_len))
                attrs.append(ibus.AttributeUnderline(pango.UNDERLINE_SINGLE, prefix_len, prefix_len + guess_len))

            #Now update all strings
            self.update_preedit_text(ibus.Text(self.__preedit_string, attrs), prefix_len, preedit_len > 0)

            #Additional attributes
            attrs = ibus.AttrList()
            attrs.append(ibus.AttributeForeground(0x000000, 0, aux_len))
            attrs.append(ibus.AttributeUnderline(pango.UNDERLINE_SINGLE, 0, 0))
            self.update_auxiliary_text(ibus.Text(self.__aux_string, attrs), aux_len > 0)
            

            #Update our lookup table, too
            self.__lookup_table.set_cursor_pos(self.model.getCurrSelectedID())
            self.update_lookup_table(self.__lookup_table, aux_len>0)

            #Done - now in a valid state
            self.__is_invalidate = False
        except:
           append_error()
           return False
Пример #6
0
 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
Пример #7
0
 def update_aux(self, s, start=0, end=0):
     '''更新輔助串
     [start, end) 定義了串中的高亮區間
     '''
     #logger.debug(u'aux: [%s]' % s)
     if not s:
         super(RimeSession, self).hide_auxiliary_text()
         return
     length = len(s)
     attrs = ibus.AttrList()
     if start < end:
         attrs.append(ibus.AttributeBackground(ibus.RGB(255, 255, 128), start, end))
         attrs.append(ibus.AttributeForeground(ibus.RGB(0, 0, 0), start, end))
     t = ibus.Text(s, attrs)
     super(RimeSession, self).update_auxiliary_text(t, True)
Пример #8
0
 def update_preedit(self, s, start=0, end=0):
     '''更新寫作串
     [start, end) 定義了串中的高亮區間
     '''
     #logger.debug(u'preedit: [%s]' % s)
     if not s:
         super(RimeSession, self).hide_preedit_text()
         return
     length = len(s)
     attrs = ibus.AttrList()
     attrs.append(ibus.AttributeUnderline(ibus.ATTR_UNDERLINE_SINGLE, 0, length))
     if start < end:
         attrs.append(ibus.AttributeBackground(ibus.RGB(255, 255, 128), start, end))
         attrs.append(ibus.AttributeForeground(ibus.RGB(0, 0, 0), start, end))
     t = ibus.Text(s, attrs)
     super(RimeSession, self).update_preedit_text(t, length, True)
Пример #9
0
    def _update_preedit(self):
        '''Update Preedit String in UI'''
        _str = self._preedit_str
        if _str == '':
            super(tabengine, self).update_preedit_text(ibus.Text('', None), 0,
                                                       False)
        else:
            attrs = ibus.AttrList()
            attrs.append(ibus.AttributeForeground(0x1b3f03, 0, len(_str)))
            # because ibus now can only insert preedit into txt, so...
            attrs = ibus.AttrList()
            attrs.append(
                ibus.AttributeUnderline(ibus.ATTR_UNDERLINE_SINGLE, 0,
                                        len(_str)))

            super(tabengine, self).update_preedit_text(
                ibus.Text(_str.decode('utf-8'), attrs), len(_str), True)
Пример #10
0
 def __update(self):
     preedit_len = len(self.__preedit_string)
     attrs = ibus.AttrList()
     self.__lookup_table.clean()
     if preedit_len > 0:
         if not self.__dict.check(self.__preedit_string):
             attrs.append(ibus.AttributeForeground(0xff0000, 0,
                                                   preedit_len))
             for text in self.__dict.suggest(self.__preedit_string):
                 self.__lookup_table.append_candidate(ibus.Text(text))
     self.update_auxiliary_text(ibus.Text(self.__preedit_string, attrs),
                                preedit_len > 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.__update_lookup_table()
     self.__is_invalidate = False
Пример #11
0
    def __update(self):
        preedit_len = len(self.__preedit_string)
        attrs = ibus.AttrList()
        self.__lookup_table.clean()
        if self.__input_method ==  "en_US":
        	if preedit_len > 0  :
        		autocompletion_list = self.__get_autocompletion()
        		for text in autocompletion_list:
        			self.__lookup_table.append_candidate(ibus.Text(text))     
        else:
	        if preedit_len > 0:
    			attrs.append(ibus.AttributeForeground(0xff0000, 0, preedit_len))
        		candidate_list = self.__keymap.get_candidates(self.__preedit_string)
        		for text in candidate_list:
        			self.__lookup_table.append_candidate(ibus.Text(text))
        		
        self.update_auxiliary_text(ibus.Text(self.__preedit_string, attrs), preedit_len > 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.__update_lookup_table()
        self.__is_invalidate = False
Пример #12
0
    def _update_preedit(self):
        '''Update Preedit String in UI'''
        _str = self._editor.get_preedit_strings()
        if _str == u'':
            super(tabengine, self).update_preedit_text(ibus.Text(u'', None), 0,
                                                       False)
        else:
            attrs = ibus.AttrList()
            res = patt_edit.match(_str)
            if res:
                _str = u''
                ures = patt_uncommit.match(res.group(1))
                if ures:
                    _str = u''.join(ures.groups())
                    lc = len(ures.group(1))
                    lu = len(ures.group(2))
                    attrs.append(ibus.AttributeForeground(0x1b3f03, 0, lc))
                    attrs.append(ibus.AttributeForeground(0x0895a2, lc, lu))
                    lg1 = len(_str)
                else:
                    _str += res.group(1)
                    lg1 = len(res.group(1))
                    attrs.append(ibus.AttributeForeground(0x1b3f03, 0, lg1))
                _str += res.group(2)
                _str += res.group(3)
                lg2 = len(res.group(2))
                lg3 = len(res.group(3))
                attrs.append(ibus.AttributeForeground(0x0e0ea0, lg1, lg2))
                attrs.append(ibus.AttributeForeground(0x1b3f03, lg1 + lg2,
                                                      lg3))
            else:
                attrs.append(ibus.AttributeForeground(0x1b3f03, 0, len(_str)))
#            attrs = ibus.AttrList()
#            attrs.append(ibus.AttributeUnderline(ibus.ATTR_UNDERLINE_SINGLE, 0, len(_str)))

            super(tabengine,
                  self).update_preedit_text(ibus.Text(_str, attrs),
                                            self._editor.get_caret(), True)