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
def __update(self): prepinyin_len = len(self.__prepinyin_string) attrs = ibus.AttrList() self.__lookup_table.clean() if prepinyin_len > 0: #attrs.append(ibus.AttributeForeground(0x0000ff, 0, prepinyin_len)) num = im_search(self.__prepinyin_string.encode('utf8')) self.__candidate_num = num self.__lookup_candidate_num = min(num, self.__lookup_table.get_page_size() + 1) for i in range(self.__lookup_candidate_num): text = im_get_candidate(i) self.__lookup_table.append_candidate(ibus.Text(text)) pass pass preedit_string = self.__lookup_table \ and self.__lookup_table.get_number_of_candidates() \ and self.__lookup_table.get_candidate(0).text.decode('utf8') or u"" preedit_len = len(preedit_string) preedit_pos = im_get_fixed_len() self.update_auxiliary_text(ibus.Text(self.__prepinyin_string, attrs), prepinyin_len > 0) attrs.append(ibus.AttributeUnderline(pango.UNDERLINE_SINGLE, 0, preedit_len)) if prepinyin_len > preedit_pos: attrs.append(ibus.AttributeBackground(0xc8c8f0, preedit_pos, preedit_len)) self.update_preedit_text(ibus.Text(preedit_string, attrs), preedit_pos, preedit_len > 0) self.__update_lookup_table() self.__is_invalidate = False
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
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 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)
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)
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
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
def update_preedit(self, preedit_string, preedit_attrs, cursor_pos, visible): if preedit_attrs == None: preedit_attrs = ibus.AttrList() attr = ibus.AttributeUnderline(ibus.ATTR_UNDERLINE_SINGLE, 0, len(preedit_string)) preedit_attrs.append(attr) super(SulekhaEngine, self).update_preedit_text(ibus.Text(preedit_string, preedit_attrs), cursor_pos, visible)