~ubuntu-branches/ubuntu/trusty/ibus-table/trusty

« back to all changes in this revision

Viewing changes to engine/table.py

  • Committer: Bazaar Package Importer
  • Author(s): LI Daobing
  • Date: 2009-09-14 19:18:22 UTC
  • mfrom: (1.1.4 upstream) (2.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20090914191822-vm2l84tc3xmohgtx
Tags: 1.2.0.20090912-1
new upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
 
56
56
class editor(object):
57
57
    '''Hold user inputs chars and preedit string'''
58
 
    def __init__ (self,phrase_table_index,valid_input_chars, max_key_length, database, parser = tabdict.parse, deparser = tabdict.deparse, max_length = 64):
 
58
    def __init__ (self, config, phrase_table_index,valid_input_chars, max_key_length, database, parser = tabdict.parse, deparser = tabdict.deparse, max_length = 64):
59
59
        self.db = database
 
60
        self._config = config
 
61
        self._name = self.db.get_ime_property('name')
 
62
        self._config_section = "engine/Table/%s" % self._name
60
63
        self._pt = phrase_table_index
61
64
        self._parser = parser
62
65
        self._deparser = deparser
89
92
        # self._caret: caret position in lookup_table
90
93
        self._caret = 0
91
94
        # self._onechar: whether we only select single character
92
 
        self._onechar = False
 
95
        self._onechar = self._config.get_value (self._config_section, "OneChar", False)
93
96
        # self._chinese_mode: the candidate filter mode,
94
97
        #   0 is simplify Chinese
95
98
        #   1 is traditional Chinese
96
99
        #   2 is Big charset mode, but simplify Chinese first
97
100
        #   3 is Big charset mode, but traditional Chinese first
98
101
        #   4 is Big charset mode.
99
 
        # we use LC_CTYPE to determine which one to use
100
 
        self._chinese_mode = self.get_chinese_mode()
 
102
        # we use LC_CTYPE or LANG to determine which one to use
 
103
        self._chinese_mode = self._config.get_value (
 
104
                self._config_section,
 
105
                "ChineseMode",
 
106
                self.get_chinese_mode())
101
107
 
102
108
    def get_chinese_mode (self):
103
109
        '''Use LC_CTYPE in your box to determine the _chinese_mode'''
126
132
    def change_chinese_mode (self):
127
133
        if self._chinese_mode != -1:
128
134
            self._chinese_mode = (self._chinese_mode +1 ) % 5
 
135
        self._config.set_value (
 
136
                self._config_section,
 
137
                "ChineseMode",
 
138
                self._chinese_mode )
129
139
 
130
140
    def clear (self):
131
141
        '''Remove data holded'''
593
603
        else:
594
604
            _p_index = 8
595
605
        try:
596
 
            self._strings.insert(self._cursor[0], self._candidates[0][ self.get_cursor_pos() ][_p_index])
597
 
            self._cursor [0] += 1
598
 
            if self._py_mode:
599
 
                self._zi = self._candidates[0][ self.get_cursor_pos() ][_p_index]
 
606
            if self._candidates[0]:
 
607
                self._strings.insert(self._cursor[0], self._candidates[0][ self.get_cursor_pos() ][_p_index])
 
608
                self._cursor [0] += 1
 
609
                if self._py_mode:
 
610
                    self._zi = self._candidates[0][ self.get_cursor_pos() ][_p_index]
600
611
            self.over_input ()
601
612
            self.update_candidates ()
602
613
        except:
814
825
 
815
826
    def __init__ (self, bus, obj_path, db ):
816
827
        super(tabengine,self).__init__ (bus,obj_path)
 
828
        self._bus = bus
817
829
        self._lookup_table = ibus.LookupTable (tabengine._page_size)
818
830
        # this is the backend sql db we need for our IME
819
831
        # we receive this db from IMEngineFactory
849
861
        self._pt = self.db.get_phrase_table_index ()
850
862
        self._ml = int(self.db.get_ime_property ('max_key_length'))
851
863
        
 
864
        # name for config section
 
865
        self._name = self.db.get_ime_property('name')
 
866
        self._config_section = "engine/Table/%s" % self._name
 
867
        
 
868
        # config module
 
869
        self._config = self._bus.get_config ()
852
870
        # Containers we used:
853
 
        self._editor = editor(self._pt, self._valid_input_chars, self._ml, self.db)
 
871
        self._editor = editor(self._config, self._pt, self._valid_input_chars, self._ml, self.db)
854
872
 
855
873
        # some other vals we used:
856
874
        # self._prev_key: hold the key event last time.
858
876
        self._prev_char = None
859
877
        self._double_quotation_state = False
860
878
        self._single_quotation_state = False
861
 
        # [ENmode,TABmode] we get TABmode properties from db
 
879
 
 
880
        # [EnMode,TabMode] we get TabMode properties from db
862
881
        self._full_width_letter = [
863
 
                False, 
864
 
                self.db.get_ime_property('def_full_width_letter').lower() == u'true'
 
882
                self._config.get_value (self._config_section,
 
883
                    "EnDefFullWidthLetter",
 
884
                    False),
 
885
                self._config.get_value (self._config_section, 
 
886
                    "TabDefFullWidthLetter", 
 
887
                    self.db.get_ime_property('def_full_width_letter').lower() == u'true' )
865
888
                ]
866
889
        self._full_width_punct = [
867
 
                False,
868
 
                self.db.get_ime_property('def_full_width_punct').lower() == u'true'
 
890
                self._config.get_value (self._config_section,
 
891
                    "EnDefFullWidthPunct",
 
892
                    False),
 
893
                self._config.get_value (self._config_section, 
 
894
                    "TabDefFullWidthPunct", 
 
895
                    self.db.get_ime_property('def_full_width_punct').lower() == u'true' )
869
896
                ]
870
897
        # some properties we will involved, Property is taken from scim.
871
898
        #self._setup_property = Property ("setup", _("Setup"))
873
900
            self._auto_commit = self.db.get_ime_property('auto_commit').lower() == u'true'
874
901
        except:
875
902
            self._auto_commit = False
 
903
        self._auto_commit = self._config.get_value (self._config_section, "AutoCommit",
 
904
                self._auto_commit)
876
905
        # the commit phrases length
877
906
        self._len_list = [0]
878
907
        # connect to SpeedMeter
1019
1048
            self._editor.r_shift ()
1020
1049
        elif property == u'onechar':
1021
1050
            self._editor._onechar = not self._editor._onechar
 
1051
            self._config.set_value( self._config_section,
 
1052
                    "OneChar",
 
1053
                    self._editor._onechar)
 
1054
 
1022
1055
        elif property == u'acommit':
1023
1056
            self._auto_commit = not self._auto_commit
 
1057
            self._config.set_value( self._config_section,
 
1058
                    "AutoCommit",
 
1059
                    self._auto_commit)
1024
1060
        elif property == u'letter':
1025
1061
            self._full_width_letter [self._mode] = not self._full_width_letter [self._mode]
 
1062
            if self._mode:
 
1063
                self._config.set_value( self._config_section,
 
1064
                        "TabDefFullWidthLetter",
 
1065
                        self._full_width_letter [self._mode])
 
1066
            else:
 
1067
                self._config.set_value( self._config_section,
 
1068
                        "EnDefFullWidthLetter",
 
1069
                        self._full_width_letter [self._mode])
 
1070
 
1026
1071
        elif property == u'punct':
1027
1072
            self._full_width_punct [self._mode] = not self._full_width_punct [self._mode]
 
1073
            if self._mode:
 
1074
                self._config.set_value( self._config_section,
 
1075
                        "TabDefFullWidthPunct",
 
1076
                        self._full_width_letter [self._mode])
 
1077
            else:
 
1078
                self._config.set_value( self._config_section,
 
1079
                        "EnDefFullWidthPunct",
 
1080
                        self._full_width_letter [self._mode])
1028
1081
        elif property == u'cmode':
1029
1082
            self._editor.change_chinese_mode()
1030
1083
            self.reset()
1518
1571
            self._update_lookup_table ()
1519
1572
            return True
1520
1573
        return False
1521
 
    
1522
 
    
 
1574
 
 
1575
    # for further implementation :)
 
1576
    @classmethod
 
1577
    def CONFIG_VALUE_CHANGED(cls, bus, section, name, value):
 
1578
        config = bus.get_config()
 
1579
        if section != self._config_section:
 
1580
            return
 
1581
    
 
1582
    @classmethod
 
1583
    def CONFIG_RELOADED(cls, bus):
 
1584
        config = bus.get_config()
 
1585
        if section != self._config_section:
 
1586
            return