Example #1
0
    def __on_key_common(self, keyval):

        if self.__input_mode == INPUT_MODE_LATIN:
            # Input Latin chars
            char = unichr(keyval)
            self.__commit_string(char)
            return True

        elif self.__input_mode == INPUT_MODE_WIDE_LATIN:
            #  Input Wide Latin chars
            char = unichr(keyval)
            wide_char = symbol_rule.get(char, None)
            if wide_char == None:
                wide_char = ibus.unichar_half_to_full(char)
            self.__commit_string(wide_char)
            return True

        # Input Japanese
        if self.__convert_mode == CONV_MODE_ANTHY:
            i = 0
            for seg_index, text in self.__segments:
                self.__context.commit_segment(i, seg_index)
            self.__commit_string(self.__convert_chars)
        elif self.__convert_mode != CONV_MODE_OFF:
            self.__commit_string(self.__convert_chars)

        self.__preedit_ja_string.insert(unichr(keyval))
        self.__invalidate()
        return True
Example #2
0
    def __convert_to_full_width(self, c):
        if c == u".":
            return u"\u3002"
        elif c == u"\\":
            return u"\u3001"
        elif c == u"^":
            return u"\u2026\u2026"
        elif c == u"_":
            return u"\u2014\u2014"
        elif c == u"$":
            return u"\uffe5"
        elif c == u"\"":
            self.__double_quotation_state = not self.__double_quotation_state
            if self.__double_quotation_state:
                return u"\u201c"
            else:
                return u"\u201d"
        elif c == u"'":
            self.__single_quotation_state = not self.__single_quotation_state
            if self.__single_quotation_state:
                return u"\u2018"
            else:
                return u"\u2019"

        elif c == u"<":
            return u"\u300a"
        elif c == u">":
            return u"\u300b"

        return ibus.unichar_half_to_full(c)
    def __convert_to_full_width(self, c):
        if c == u".":
            return u"\u3002"
        elif c == u"\\":
            return u"\u3001"
        elif c == u"^":
            return u"\u2026\u2026"
        elif c == u"_":
            return u"\u2014\u2014"
        elif c == u"$":
            return u"\uffe5"
        elif c == u"\"":
            self.__double_quotation_state = not self.__double_quotation_state
            if self.__double_quotation_state:
                return u"\u201c"
            else:
                return u"\u201d"
        elif c == u"'":
            self.__single_quotation_state = not self.__single_quotation_state
            if self.__single_quotation_state:
                return u"\u2018"
            else:
                return u"\u2019"

        elif c == u"<":
            return u"\u300a"
        elif c == u">":
            return u"\u300b"

        return ibus.unichar_half_to_full(c)
Example #4
0
    def __on_key_space(self):
        if self.__input_mode == INPUT_MODE_WIDE_LATIN:
            #  Input Wide Latin chars
            char = unichr(keysyms.space)
            wide_char = symbol_rule.get(char, None)
            if wide_char == None:
                wide_char = ibus.unichar_half_to_full(char)
            self.__commit_string(wide_char)
            return True

        if self.__preedit_ja_string.is_empty():
            return False

        if self.__convert_mode != CONV_MODE_ANTHY:
            self.__begin_anthy_convert()
            self.__invalidate()
        elif self.__convert_mode == CONV_MODE_ANTHY:
            self.__lookup_table_visible = True
            self.cursor_down()
        return True
 def _convert_to_full_width (self, c):
     '''convert half width character to full width'''
     if c in [u".", u"\\", u"^", u"_", u"$", u"\"", u"'", u">", u"<" ]:
         if c == u".":
             if self._prev_char and self._prev_char.isdigit () \
                 and self._prev_key and chr (self._prev_key.code) == self._prev_char:
                 return u"."
             else:
                 return u"\u3002"
         elif c == u"\\":
             return u"\u3001"
         elif c == u"^":
             return u"\u2026\u2026"
         elif c == u"_":
             return u"\u2014\u2014"
         elif c == u"$":
             return u"\uffe5"
         elif c == u"\"":
             self._double_quotation_state = not self._double_quotation_state
             if self._double_quotation_state:
                 return u"\u201c"
             else:
                 return u"\u201d"
         elif c == u"'":
             self._single_quotation_state = not self._single_quotation_state
             if self._single_quotation_state:
                 return u"\u2018"
             else:
                 return u"\u2019"
         elif c == u"<":
             if self._mode:
                 return u"\u300a"
         elif c == u">":
             if self._mode:
                 return u"\u300b"
         
     return ibus.unichar_half_to_full (c)
    def _convert_to_full_width(self, c):
        '''convert half width character to full width'''
        if c in [u".", u"\\", u"^", u"_", u"$", u"\"", u"'", u">", u"<"]:
            if c == u".":
                if self._prev_char and self._prev_char.isdigit () \
                    and self._prev_key and chr (self._prev_key.code) == self._prev_char:
                    return u"."
                else:
                    return u"\u3002"
            elif c == u"\\":
                return u"\u3001"
            elif c == u"^":
                return u"\u2026\u2026"
            elif c == u"_":
                return u"\u2014\u2014"
            elif c == u"$":
                return u"\uffe5"
            elif c == u"\"":
                self._double_quotation_state = not self._double_quotation_state
                if self._double_quotation_state:
                    return u"\u201c"
                else:
                    return u"\u201d"
            elif c == u"'":
                self._single_quotation_state = not self._single_quotation_state
                if self._single_quotation_state:
                    return u"\u2018"
                else:
                    return u"\u2019"
            elif c == u"<":
                if self._mode:
                    return u"\u300a"
            elif c == u">":
                if self._mode:
                    return u"\u300b"

        return ibus.unichar_half_to_full(c)
Example #7
0
    def process_key_event(self, keyval, keycode, state):
        ## for key release events
        is_press = ((state & modifier.RELEASE_MASK) == 0)
        if is_press:
            self.__last_press_keyval = keyval
            pass
        ## Match Shift to switcc English/Chinese mode
        elif keyval == self.__last_press_keyval \
                and (keyval == keysyms.Shift_L or keyval == keysyms.Shift_R):
            self.property_activate("status")
            self.reset()
            return False
        ## ignore key release events
        else:
            return False

        if self.__is_input_english():
            if ascii.isprint(chr(keyval)) and self.__full_width_letter[self.__mode] :
                c = unichr(keyval)
                c = ibus.unichar_half_to_full(c)
                self.__commit_string(c)
                return True
            return False

        if self.__prepinyin_string:
            if keyval == keysyms.Return:
                if self.__full_width_letter[self.__mode]:
                    self.__prepinyin_string = u''.join(
                            (ibus.unichar_half_to_full(c) for c in self.__prepinyin_string)
                        )
                    pass
                self.__commit_string(self.__prepinyin_string)
                return True
            elif keyval == keysyms.Escape:
                self.__prepinyin_string = u""
                self.__update()
                return True
            elif keyval == keysyms.BackSpace:
                self.__prepinyin_string = self.__prepinyin_string[:-1]
                self.__invalidate()
                return True
            elif (keyval >= keysyms._1 and keyval <= keysyms._9) or keyval == keysyms.space: 
                if not self.__lookup_table.get_number_of_candidates() > 0:
                    self.__commit_string(self.__prepinyin_string)
                    return True
                if keyval == keysyms.space:
                    keyval = keysyms._1
                    pass
                ##
                index = keyval - keysyms._1
                if index >= self.__lookup_table.get_page_size():
                    return False
                index += self.__lookup_table.get_current_page_start()
                num = im_choose(int(index))
                self.__candidate_num = num
                if num == 1:
                    candidate = im_get_candidate(0)
                    if self.__trad_chinese[self.__mode]:
                        candidate = libopencc.convert(candidate)
                        pass
                    self.__commit_string(candidate)
                    im_reset_search()
                    if time.time() - self.__last_im_flush_cache_time > 300:
                        im_flush_cache()
                        self.__last_im_flush_cache_time = time.time()
                        pass
                    return True
                self.__update()
                return True
            # press , - Page_Up
            elif keyval == keysyms.comma or keyval == keysyms.minus or keyval == keysyms.Page_Up or keyval == keysyms.KP_Page_Up:
                self.page_up()
                return True
            # press . = Page_Down
            elif keyval == keysyms.period or keyval == keysyms.equal or keyval == keysyms.Page_Down or keyval == keysyms.KP_Page_Down:
                self.page_down()
                return True
            elif keyval == keysyms.Up:
                self.cursor_up()
                return True
            elif keyval == keysyms.Down:
                self.cursor_down()
                return True
            elif keyval == keysyms.Left or keyval == keysyms.Right:
                return True
        if keyval in xrange(keysyms.a, keysyms.z + 1) or \
                (keyval == keysyms.quoteright and self.__prepinyin_string):
            if self.__lookup_table.get_number_of_candidates() \
                    and len(self.__lookup_table.get_candidate(0).text.decode('utf8'))\
                        >= MAX_SPELLINGS:
                return True
            if state & (modifier.CONTROL_MASK | modifier.ALT_MASK) == 0:
                self.__prepinyin_string += unichr(keyval)
                self.__invalidate()
                return True
        else:
            c = unichr(keyval)
            if c == u"." and self.__prev_char and self.__prev_char.isdigit():
                return False
            if self.__full_width_punct[self.__mode] and c in u'~!$^&*()_[{]}\\|;:\'",<.>/?':
                c = self.__convert_to_full_width(c)
                self.__commit_string(c)
                return True
            if self.__full_width_letter[self.__mode] and ascii.isprint(chr(keyval)):
                c = ibus.unichar_half_to_full(c)
                self.__commit_string(c)
                return True
            if keyval < 128 and self.__prepinyin_string:
                self.__commit_string(self.__prepinyin_string)
                return True
            if c.isdigit():
                self.__commit_string(c)
                return True

        return False
    def process_key_event(self, keyval, keycode, state):
        ## for key release events
        is_press = ((state & modifier.RELEASE_MASK) == 0)
        if is_press:
            self.__last_press_keyval = keyval
            pass
        ## Match Shift to switcc English/Chinese mode
        elif keyval == self.__last_press_keyval \
                and (keyval == keysyms.Shift_L or keyval == keysyms.Shift_R):
            self.property_activate("status")
            self.reset()
            return False
        ## ignore key release events
        else:
            return False

        if self.__is_input_english():
            if ascii.isprint(chr(keyval)) and self.__full_width_letter[self.__mode] :
                c = unichr(keyval)
                c = ibus.unichar_half_to_full(c)
                self.__commit_string(c)
                return True
            return False

        if self.__prepinyin_string:
            if keyval == keysyms.Return:
                if self.__full_width_letter[self.__mode]:
                    self.__prepinyin_string = u''.join(
                            (ibus.unichar_half_to_full(c) for c in self.__prepinyin_string)
                        )
                    pass
                self.__commit_string(self.__prepinyin_string)
                return True
            elif keyval == keysyms.Escape:
                self.__prepinyin_string = u""
                self.__update()
                return True
            elif keyval == keysyms.BackSpace:
                self.__prepinyin_string = self.__prepinyin_string[:-1]
                self.__invalidate()
                return True
            elif (keyval >= keysyms._1 and keyval <= keysyms._9) or keyval == keysyms.space: 
                if not self.__lookup_table.get_number_of_candidates() > 0:
                    self.__commit_string(self.__prepinyin_string)
                    return True
                if keyval == keysyms.space:
                    keyval = keysyms._1
                    pass
                ##
                index = keyval - keysyms._1
                if index >= self.__lookup_table.get_page_size():
                    return False
                index += self.__lookup_table.get_current_page_start()
                num = im_choose(int(index))
                self.__candidate_num = num
                if num == 1:
                    candidate = im_get_candidate(0)
                    if self.__trad_chinese[self.__mode]:
                        candidate = libopencc.convert(candidate)
                        pass
                    self.__commit_string(candidate)
                    im_reset_search()
                    if time.time() - self.__last_im_flush_cache_time > 300:
                        im_flush_cache()
                        self.__last_im_flush_cache_time = time.time()
                        pass
                    return True
                self.__update()
                return True
            # press , - Page_Up
            elif keyval == keysyms.comma or keyval == keysyms.minus or keyval == keysyms.Page_Up or keyval == keysyms.KP_Page_Up:
                self.page_up()
                return True
            # press . = Page_Down
            elif keyval == keysyms.period or keyval == keysyms.equal or keyval == keysyms.Page_Down or keyval == keysyms.KP_Page_Down:
                self.page_down()
                return True
            elif keyval == keysyms.Up:
                self.cursor_up()
                return True
            elif keyval == keysyms.Down:
                self.cursor_down()
                return True
            elif keyval == keysyms.Left or keyval == keysyms.Right:
                return True
        if keyval in xrange(keysyms.a, keysyms.z + 1) or \
                (keyval == keysyms.quoteright and self.__prepinyin_string):
            if self.__lookup_table.get_number_of_candidates() \
                    and len(self.__lookup_table.get_candidate(0).text.decode('utf8'))\
                        >= MAX_SPELLINGS:
                return True
            if state & (modifier.CONTROL_MASK | modifier.ALT_MASK) == 0:
                self.__prepinyin_string += unichr(keyval)
                self.__invalidate()
                return True
        else:
            c = unichr(keyval)
            if c == u"." and self.__prev_char and self.__prev_char.isdigit():
                return False
            if self.__full_width_punct[self.__mode] and c in u'~!$^&*()_[{]}\\|;:\'",<.>/?':
                c = self.__convert_to_full_width(c)
                self.__commit_string(c)
                return True
            if self.__full_width_letter[self.__mode] and ascii.isprint(chr(keyval)):
                c = ibus.unichar_half_to_full(c)
                self.__commit_string(c)
                return True
            if keyval < 128 and self.__prepinyin_string:
                self.__commit_string(self.__prepinyin_string)
                return True
            if c.isdigit():
                self.__commit_string(c)
                return True

        return False