Logo Search packages:      
Sourcecode: ibus-table version File versions  Download package

def table::tabengine::_table_mode_process_key_event (   self,
  key 
) [private]

Xingma Mode Process Key Event

Definition at line 1219 of file table.py.

01219                                                  :
        '''Xingma Mode Process Key Event'''
        cond_letter_translate = lambda (c): \
            self._convert_to_full_width (c) if self._full_width_letter [self._mode] else c
        cond_punct_translate = lambda (c): \
            self._convert_to_full_width (c) if self._full_width_punct [self._mode] else c
        
        # We have to process the pinyin mode change key event here,
        # because we ignore all Release event below.
        if self._match_hotkey (key, keysyms.Shift_R, modifier.SHIFT_MASK + modifier.RELEASE_MASK) and self._ime_py:
            res = self._editor.r_shift ()
            self._refresh_properties ()
            self._update_ui ()
            return res
        # process commit to preedit    
        if self._match_hotkey (key, keysyms.Shift_R, modifier.SHIFT_MASK + modifier.RELEASE_MASK) or self._match_hotkey (key, keysyms.Shift_L, modifier.SHIFT_MASK + modifier.RELEASE_MASK):
            res = self._editor.l_shift ()
            self._update_ui ()
            return res
        
        # Match single char mode switch hotkey
        if self._match_hotkey (key, keysyms.comma, modifier.CONTROL_MASK):
            self.property_activate ( u"onechar" )
            return True
        # Match direct commit mode switch hotkey
        if self._match_hotkey (key, keysyms.slash, modifier.CONTROL_MASK):
            self.property_activate ( u"dcommit" )
            return True
        
        # Ignore key release event now :)
        if key.mask & modifier.RELEASE_MASK:
            return True

        if self._editor.is_empty ():
            # we have not input anything
            if key.code <= 127 and (not key.mask & modifier.ALT_MASK + modifier.CONTROL_MASK):
                if key.code == keysyms.space:
                    self.commit_string (cond_letter_translate (unichr (key.code)))
                    return True
                if ascii.ispunct (key.code) and ( unichr(key.code) not in self._valid_input_chars ) :
                    self.commit_string (cond_punct_translate (unichr (key.code)))
                    return True
                if ascii.isdigit (key.code):
                    self.commit_string (cond_letter_translate (unichr (key.code)))
                    return True
            elif key.code > 127 and (not self._editor._py_mode):
                return False

        if key.code == keysyms.Escape:
            self.reset ()
            self._update_ui ()
            return True
        
        elif key.code in (keysyms.Return, keysyms.KP_Enter):
            commit_string = self._editor.get_all_input_strings ()
            self.commit_string (commit_string)
            return True
        
        #elif key.code in (keysyms.Down, keysyms.KP_Down) :
        #    res = self._editor.arrow_down ()
        #    self._update_ui ()
        #    return res
        
        #elif key.code in (keysyms.Up, keysyms.KP_Up):
        #    res = self._editor.arrow_up ()
        #    self._update_ui ()
        #    return res
        
        elif key.code in (keysyms.Left, keysyms.KP_Left) and key.mask & modifier.CONTROL_MASK:
            res = self._editor.control_arrow_left ()
            self._update_ui ()
            return res
        
        elif key.code in (keysyms.Right, keysyms.KP_Right) and key.mask & modifier.CONTROL_MASK:
            res = self._editor.control_arrow_right ()
            self._update_ui ()
            return res
        
        elif key.code in (keysyms.Left, keysyms.KP_Left):
            res = self._editor.arrow_left ()
            self._update_ui ()
            return res
        
        elif key.code in (keysyms.Right, keysyms.KP_Right):
            res = self._editor.arrow_right ()
            self._update_ui ()
            return res
        
        elif key.code == keysyms.BackSpace and key.mask & modifier.CONTROL_MASK:
            res = self._editor.control_backspace ()
            self._update_ui ()
            return res
        
        elif key.code == keysyms.BackSpace:
            res = self._editor.backspace ()
            self._update_ui ()
            return res
        
        elif key.code == keysyms.Delete  and key.mask & modifier.CONTROL_MASK:
            res = self._editor.control_delete ()
            self._update_ui ()
            return res
        
        elif key.code == keysyms.Delete:
            res = self._editor.delete ()
            self._update_ui ()
            return res

        elif key.code >= keysyms._1 and key.code <= keysyms._9 and self._editor._candidates[0] and key.mask & modifier.CONTROL_MASK:
            res = self._editor.number (key.code - keysyms._1)
            self._update_ui ()
            return res

        elif key.code >= keysyms._1 and key.code <= keysyms._9 and self._editor._candidates[0] and key.mask & modifier.ALT_MASK:
            res = self._editor.alt_number (key.code - keysyms._1)
            self._update_ui ()
            return res

        elif key.code == keysyms.space:
            o_py = self._editor._py_mode
            sp_res = self._editor.space ()
            #return (KeyProcessResult,whethercommit,commitstring)
            if sp_res[0]:
                self.commit_string (sp_res[1])
                self.add_string_len(sp_res[1])
                self.db.check_phrase (sp_res[1])
            else:
                if sp_res[1] == u' ':
                    self.commit_string (cond_letter_translate (u" "))
            if o_py != self._editor._py_mode:
                self._refresh_properties ()
                self._update_ui ()
            return True
        # now we ignore all else hotkeys
        elif key.mask & modifier.CONTROL_MASK+modifier.ALT_MASK:
            return False

        elif key.mask & modifier.ALT_MASK:
            return False

        elif unichr(key.code) in self._valid_input_chars or \
                ( self._editor._py_mode and \
                    unichr(key.code) in u'abcdefghijklmnopqrstuvwxyz!@#$%' ):
            if self._direct_commit and ( len(self._editor._chars[0]) == self._ml \
                    or len (self._editor._chars[0]) in self.db.pkeylens ):
                # it is time to direct commit
                sp_res = self._editor.space ()
                #return (whethercommit,commitstring)
                if sp_res[0]:
                    self.commit_string (sp_res[1])
                    self.add_string_len(sp_res[1])
                    self.db.check_phrase (sp_res[1])
            
            res = self._editor.add_input ( unichr(key.code) )
            if not res:
                if ascii.ispunct (key.code):
                    key_char = cond_punct_translate (unichr (key.code))
                else:
                    key_char = cond_letter_translate (unichr (key.code))
                sp_res = self._editor.space ()
                #return (KeyProcessResult,whethercommit,commitstring)
                if sp_res[0]:
                    self.commit_string (sp_res[1] + key_char)
                    self.add_string_len(sp_res[1])
                    self.db.check_phrase (sp_res[1])
                    return True
                else:
                    self.commit_string ( key_char )
                    return True
            else:
                if self._direct_commit and self._editor.one_candidate () and \
                        len(self._editor._chars[0]) == self._ml:
                    # it is time to direct commit
                    sp_res = self._editor.space ()
                    #return (whethercommit,commitstring)
                    if sp_res[0]:
                        self.commit_string (sp_res[1])
                        self.add_string_len(sp_res[1])
                        self.db.check_phrase (sp_res[1])
                        return True

            self._update_ui ()
            return True
        
        elif key.code in (keysyms.equal, keysyms.Page_Down, keysyms.KP_Page_Down) and self._editor._candidates[0]:
            res = self._editor.page_down()
            self._update_lookup_table ()
            return res

        elif key.code in (keysyms.minus, keysyms.Page_Up, keysyms.KP_Page_Up) and self._editor._candidates[0]:
            res = self._editor.page_up ()
            self._update_lookup_table ()
            return res
        
        elif key.code >= keysyms._1 and key.code <= keysyms._9 and self._editor._candidates[0]:
            res = self._editor.number (key.code - keysyms._1)
            if res:
                o_py = self._editor._py_mode
                commit_string = self._editor.get_preedit_strings ()
                self.commit_string (commit_string)
                self.add_string_len(commit_string)
                if o_py != self._editor._py_mode:
                    self._refresh_properties ()
                    self._update_ui ()
                # modify freq info
                self.db.check_phrase (commit_string)
            return True
        
        elif key.code <= 127:
            if not self._editor._candidates[0]:
                commit_string = self._editor.get_all_input_strings ()
            else:
                self._editor.commit_to_preedit ()
                commit_string = self._editor.get_preedit_strings ()
            self._editor.clear ()
            if ascii.ispunct (key.code):
                self.commit_string ( commit_string + cond_punct_translate (unichr (key.code)))
            else:
                self.commit_string ( commit_string + cond_letter_translate (unichr (key.code)))
            return True
        return False
    
    # below for initial test
    def focus_in (self):


Generated by  Doxygen 1.6.0   Back to index