Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

finish porting to gi

  • Loading branch information...
commit 526b8cf4e395dd8c6333b3ed4185596b1196fad8 1 parent 6d78cab
@mike-fabian mike-fabian authored
Showing with 336 additions and 145 deletions.
  1. +2 −2 engine/factory.py
  2. +334 −143 engine/table.py
View
4 engine/factory.py
@@ -62,7 +62,7 @@ def __init__ (self, bus, db="", icon=""):
object_path=IBus.PATH_FACTORY)
self.engine_id=0
- def create_engine(self, engine_name):
+ def do_create_engine(self, engine_name):
# because we need db to be past to Engine
# the type (engine_name) == dbus.String
name = engine_name.encode ('utf8')
@@ -104,6 +104,6 @@ def do_destroy (self):
for _db in self.dbdict:
self.dbdict[_db].sync_usrdb ()
##print "Have synced user db\n"
- super(EngineFactory,self).do_destroy()
+ super(EngineFactory,self).destroy()
View
477 engine/table.py
@@ -27,10 +27,12 @@
import os
from gi.repository import IBus
+from gi.repository import GLib
from curses import ascii
#import tabsqlitedb
import tabdict
import re
+
patt_edit = re.compile (r'(.*)###(.*)###(.*)')
patt_uncommit = re.compile (r'(.*)@@@(.*)')
@@ -38,7 +40,110 @@
_ = lambda a : dgettext ("ibus-table", a)
N_ = lambda a : a
-import dbus
+def variant_to_value(variant):
+ if type(variant) != GLib.Variant:
+ return variant
+ type_string = variant.get_type_string()
+ if type_string == 's':
+ return variant.get_string()
+ elif type_string == 'i':
+ return variant.get_int32()
+ elif type_string == 'b':
+ return variant.get_boolean()
+ elif type_string == 'as':
+ # In the latest pygobject3 3.3.4 or later, g_variant_dup_strv
+ # returns the allocated strv but in the previous release,
+ # it returned the tuple of (strv, length)
+ if type(GLib.Variant.new_strv([]).dup_strv()) == tuple:
+ return variant.dup_strv()[0]
+ else:
+ return variant.dup_strv()
+ else:
+ print 'error: unknown variant type:', type_string
+ return variant
+
+def argb(a, r, g, b):
+ return ((a & 0xff)<<24) + ((r & 0xff) << 16) + ((g & 0xff) << 8) + (b & 0xff)
+
+def rgb(r, g, b):
+ return argb(255, r, g, b)
+
+__half_full_table = [
+ (0x0020, 0x3000, 1),
+ (0x0021, 0xFF01, 0x5E),
+ (0x00A2, 0xFFE0, 2),
+ (0x00A5, 0xFFE5, 1),
+ (0x00A6, 0xFFE4, 1),
+ (0x00AC, 0xFFE2, 1),
+ (0x00AF, 0xFFE3, 1),
+ (0x20A9, 0xFFE6, 1),
+ (0xFF61, 0x3002, 1),
+ (0xFF62, 0x300C, 2),
+ (0xFF64, 0x3001, 1),
+ (0xFF65, 0x30FB, 1),
+ (0xFF66, 0x30F2, 1),
+ (0xFF67, 0x30A1, 1),
+ (0xFF68, 0x30A3, 1),
+ (0xFF69, 0x30A5, 1),
+ (0xFF6A, 0x30A7, 1),
+ (0xFF6B, 0x30A9, 1),
+ (0xFF6C, 0x30E3, 1),
+ (0xFF6D, 0x30E5, 1),
+ (0xFF6E, 0x30E7, 1),
+ (0xFF6F, 0x30C3, 1),
+ (0xFF70, 0x30FC, 1),
+ (0xFF71, 0x30A2, 1),
+ (0xFF72, 0x30A4, 1),
+ (0xFF73, 0x30A6, 1),
+ (0xFF74, 0x30A8, 1),
+ (0xFF75, 0x30AA, 2),
+ (0xFF77, 0x30AD, 1),
+ (0xFF78, 0x30AF, 1),
+ (0xFF79, 0x30B1, 1),
+ (0xFF7A, 0x30B3, 1),
+ (0xFF7B, 0x30B5, 1),
+ (0xFF7C, 0x30B7, 1),
+ (0xFF7D, 0x30B9, 1),
+ (0xFF7E, 0x30BB, 1),
+ (0xFF7F, 0x30BD, 1),
+ (0xFF80, 0x30BF, 1),
+ (0xFF81, 0x30C1, 1),
+ (0xFF82, 0x30C4, 1),
+ (0xFF83, 0x30C6, 1),
+ (0xFF84, 0x30C8, 1),
+ (0xFF85, 0x30CA, 6),
+ (0xFF8B, 0x30D2, 1),
+ (0xFF8C, 0x30D5, 1),
+ (0xFF8D, 0x30D8, 1),
+ (0xFF8E, 0x30DB, 1),
+ (0xFF8F, 0x30DE, 5),
+ (0xFF94, 0x30E4, 1),
+ (0xFF95, 0x30E6, 1),
+ (0xFF96, 0x30E8, 6),
+ (0xFF9C, 0x30EF, 1),
+ (0xFF9D, 0x30F3, 1),
+ (0xFFA0, 0x3164, 1),
+ (0xFFA1, 0x3131, 30),
+ (0xFFC2, 0x314F, 6),
+ (0xFFCA, 0x3155, 6),
+ (0xFFD2, 0x315B, 9),
+ (0xFFE9, 0x2190, 4),
+ (0xFFED, 0x25A0, 1),
+ (0xFFEE, 0x25CB, 1)]
+
+def unichar_half_to_full (c):
+ code = ord (c)
+ for half, full, size in __half_full_table:
+ if code >= half and code < half + size:
+ return unichr (full + code - half)
+ return c
+
+def unichar_full_to_half (c):
+ code = ord (c)
+ for half, full, size in __half_full_table:
+ if code >= full and code < full + size:
+ return unichr (half + code - full)
+ return c
class KeyEvent:
def __init__(self, keyval, is_press, state):
@@ -82,13 +187,25 @@ def __init__ (self, config, phrase_table_index,valid_input_chars, max_key_length
# self._candidates: hold candidates selected from database [[now],[pre]]
self._candidates = [[],[]]
# __orientation: lookup table orientation
- __orientation = self._config.get_value (
+ __orientation = variant_to_value(self._config.get_value(
self._config_section,
- "LookupTableOrientation",
- self.db.get_orientation())
+ "LookupTableOrientation"))
+ if __orientation == None:
+ __orientation = self.db.get_orientation()
+ # __page_size: lookup table page size
+ # this is computed from the select_keys, so should be done after it
+ __page_size = self.db.get_page_size()
# self._lookup_table: lookup table
- self._lookup_table = IBus.LookupTable ()
+ self._lookup_table = IBus.LookupTable.new(
+ page_size=__page_size,
+ cursor_pos=0,
+ cursor_visible=False,
+ round=True)
+ self._lookup_table.set_cursor_visible(False)
+ self._lookup_table.set_page_size(__page_size)
self._lookup_table.set_orientation (__orientation)
+ # self._select_keys: a list of chars for select keys
+ self.init_select_keys()
# self._py_mode: whether in pinyin mode
self._py_mode = False
# self._zi: the last Zi commit to preedit
@@ -96,7 +213,11 @@ def __init__ (self, config, phrase_table_index,valid_input_chars, max_key_length
# self._caret: caret position in lookup_table
self._caret = 0
# self._onechar: whether we only select single character
- self._onechar = self._config.get_value (self._config_section, "OneChar", False)
+ self._onechar = variant_to_value(self._config.get_value(
+ self._config_section,
+ "OneChar"))
+ if self._onechar == None:
+ self_onechar = False
# self._chinese_mode: the candidate filter mode,
# 0 is simplify Chinese
# 1 is traditional Chinese
@@ -104,33 +225,27 @@ def __init__ (self, config, phrase_table_index,valid_input_chars, max_key_length
# 3 is Big charset mode, but traditional Chinese first
# 4 is Big charset mode.
# we use LC_CTYPE or LANG to determine which one to use
- self._chinese_mode = self._config.get_value (
+ self._chinese_mode = variant_to_value(self._config.get_value(
self._config_section,
- "ChineseMode",
- self.get_chinese_mode())
-
- # self._select_keys: a list of chars for select keys
- self.init_select_keys()
-
- # __page_size: lookup table page size
- # this is computed from the select_keys, so should be done after it
- __page_size = self.db.get_page_size()
- self._lookup_table.set_page_size(__page_size)
+ "ChineseMode"))
+ if self._chinese_mode == None:
+ self.chinese_mode = self.get_chinese_mode()
def init_select_keys(self):
# __select_keys: lookup table select keys/labels
- __select_keys = self._config.get_value (
+ __select_keys = variant_to_value(self._config.get_value(
self._config_section,
- "LookupTableSelectKeys",
- self.db.get_select_keys())
+ "LookupTableSelectKeys"))
+ if __select_keys == None:
+ __select_keys = self.db.get_select_keys()
if __select_keys:
self.set_select_keys(__select_keys)
def set_select_keys(self, astring):
"""astring: select keys setting. e.g. 1,2,3,4,5,6,7,8,9"""
self._select_keys = [x.strip() for x in astring.split(",")]
- labels = [IBus.Text("{}.".format(x)) for x in self._select_keys]
- self._lookup_table.set_labels(labels)
+ for x in self._select_keys:
+ self._lookup_table.append_label(IBus.Text.new_from_string("{}.".format(x)))
def get_select_keys(self):
"""@return: a list of chars as select keys: ["1", "2", ...]"""
@@ -170,7 +285,7 @@ def change_chinese_mode (self):
self._config.set_value (
self._config_section,
"ChineseMode",
- self._chinese_mode )
+ GLib.Variant.new_int32(self._chinese_mode))
def clear (self):
'''Remove data holded'''
@@ -191,8 +306,8 @@ def clear_input (self):
'''
self._chars = [[],[],[]]
self._tabkey_list = []
- self._lookup_table.clean()
- self._lookup_table.show_cursor(False)
+ self._lookup_table.clear()
+ self._lookup_table.set_cursor_visible(False)
self._candidates = [[],[]]
def over_input (self):
@@ -491,19 +606,28 @@ def ap_candidate (self, candi):
#attrs = IBus.AttrList ([IBus.AttributeForeground (0x8e2626, -2, 1)])
attrs = IBus.AttrList ()
# this is the part of tabkey
- attrs.append( IBus.AttributeForeground ( 0x1973a2, 0, \
+ attrs.append(IBus.attr_foreground_new(rgb(0x19,0x73,0xa2), 0, \
len(_phrase) + len(_tbks)))
if candi[-2] < 0:
# this is a user defined phrase:
- attrs.append ( IBus.AttributeForeground (0x7700c3, 0, len(_phrase)) )
+ attrs.append(IBus.attr_foreground_new(rgb(0x77,0x00,0xc3), 0, len(_phrase)))
elif candi[-1] > 0:
# this is a sys phrase used by user:
- attrs.append ( IBus.AttributeForeground (0x000000, 0, len(_phrase)) )
+ attrs.append(IBus.attr_foreground_new(rgb(0x00,0x00,0x00), 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 + _tbks, attrs) )
- self._lookup_table.show_cursor (False)
+ attrs.append(IBus.attr_foreground_new(rgb(0x00,0x00,0x00), 0, len(_phrase)))
+ text = IBus.Text.new_from_string(_phrase + _tbks)
+ i = 0
+ while attrs.get(i) != None:
+ attr = attrs.get(i)
+ text.append_attribute(attr.get_attr_type(),
+ attr.get_value(),
+ attr.get_start_index(),
+ attr.get_end_index())
+ i += 1
+ self._lookup_table.append_candidate (text)
+ self._lookup_table.set_cursor_visible(False)
def filter_candidates (self, candidates):
'''Filter candidates if IME is Chinese'''
@@ -544,8 +668,8 @@ def update_candidates (self):
# check whether last time we have only one candidate
only_one_last = self.one_candidate()
# do enquiry
- self._lookup_table.clean ()
- self._lookup_table.show_cursor (False)
+ self._lookup_table.clear()
+ self._lookup_table.set_cursor_visible(False)
if self._tabkey_list:
# here we need to consider two parts, table and pinyin
# first table
@@ -589,8 +713,8 @@ def update_candidates (self):
# return res
#else:
# self.pop_input ()
- # self._lookup_table.clean()
- # self._lookup_table.show_cursor (False)
+ # self._lookup_table.clear()
+ # self._lookup_table.set_cursor_visible(False)
# return False
###################
## new manner, we add new char to invalid input
@@ -623,8 +747,8 @@ def update_candidates (self):
return res
else:
self.pop_input ()
- self._lookup_table.clean()
- self._lookup_table.show_cursor (False)
+ self._lookup_table.clear()
+ self._lookup_table.set_cursor_visible(False)
return False
else:
# this is not a punct or not a valid phrase
@@ -635,8 +759,8 @@ def update_candidates (self):
pass
self._candidates[0] =[]
else:
- self._lookup_table.clean()
- self._lookup_table.show_cursor (False)
+ self._lookup_table.clear()
+ self._lookup_table.set_cursor_visible(False)
self._candidates[1] = self._candidates[0]
return True
@@ -702,7 +826,7 @@ def fill_lookup_table(self):
add more entries from _candidiate[0] to _lookup_table.'''
lookup = self._lookup_table
- looklen = len(lookup)
+ looklen = lookup.get_number_of_candidates()
psize = lookup.get_page_size()
if (lookup.get_cursor_pos() + psize >= looklen and
looklen < len(self._candidates[0])):
@@ -750,16 +874,23 @@ def page_up(self):
return res
def select_key(self, char):
- '''Select the candidates in Lookup Table'''
+ '''
+ Commit a candidate in the lookup table which was selected
+ by typing a selection key
+ '''
try:
index = self._select_keys.index(char)
except ValueError:
return False
- self._lookup_table.set_cursor_pos_in_current_page ( index )
- if index != self._lookup_table.get_cursor_pos_in_current_page ():
- # the index given is out of range we do not commit string
+ cursor_pos = self._lookup_table.get_cursor_pos()
+ cursor_in_page = self._lookup_table.get_cursor_in_page()
+ current_page_start = cursor_pos - cursor_in_page
+ real_index = current_page_start + index
+ if real_index >= len (self._candidates[0]):
+ # the index given is out of range we do not commit anything
return False
+ self._lookup_table.set_cursor_pos(real_index)
self.commit_to_preedit ()
return True
@@ -770,11 +901,13 @@ def alt_select_key(self, char):
except ValueError:
return False
- cps = self._lookup_table.get_current_page_start()
- pos = cps + index
- if len (self._candidates[0]) > pos:
+ cursor_pos = self._lookup_table.get_cursor_pos()
+ cursor_in_page = self._lookup_table.get_cursor_in_page()
+ current_page_start = cursor_pos - cursor_in_page
+ real_index = current_page_start + index
+ if len (self._candidates[0]) > real_index:
# this index is valid
- can = self._candidates[0][pos]
+ can = self._candidates[0][real_index]
if can[-2] < 0:
# freq of this candidate is -1, means this a user phrase
self.db.remove_phrase (can)
@@ -933,7 +1066,7 @@ def __init__ (self, bus, obj_path, db ):
else:
self._ime_py = False
else:
- print 'We coult not find "pinyin_mode" entry in database, is it a outdated database?'
+ print 'We could not find "pinyin_mode" entry in database, is it an outdated database?'
self._ime_py = False
self._status = self.db.get_ime_property('status_prompt').encode('utf8')
@@ -984,29 +1117,36 @@ def __init__ (self, bus, obj_path, db ):
# [EnMode,TabMode] we get TabMode properties from db
self._full_width_letter = [
- self._config.get_value (self._config_section,
- "EnDefFullWidthLetter",
- False),
- self._config.get_value (self._config_section,
- "TabDefFullWidthLetter",
- self.db.get_ime_property('def_full_width_letter').lower() == u'true' )
- ]
+ variant_to_value(self._config.get_value(
+ self._config_section,
+ "EnDefFullWidthLetter")),
+ variant_to_value(self._config.get_value(
+ self._config_section,
+ "TabDefFullWidthLetter"))
+ ]
+ if self._full_width_letter[0] == None:
+ self._full_width_letter[0] = False
+ if self._full_width_letter[1] == None:
+ self._full_width_letter[1] = self.db.get_ime_property('def_full_width_letter').lower() == u'true'
self._full_width_punct = [
- self._config.get_value (self._config_section,
- "EnDefFullWidthPunct",
- False),
- self._config.get_value (self._config_section,
- "TabDefFullWidthPunct",
- self.db.get_ime_property('def_full_width_punct').lower() == u'true' )
- ]
+ variant_to_value(self._config.get_value(
+ self._config_section,
+ "EnDefFullWidthPunct")),
+ variant_to_value(self._config.get_value(
+ self._config_section,
+ "TabDefFullWidthPunct"))
+ ]
+ if self._full_width_punct[0] == None:
+ self._full_width_punct[0] = False
+ if self._full_width_punct[1] == None:
+ self._full_width_punct[1] = self.db.get_ime_property('def_full_width_punct').lower() == u'true'
# some properties we will involved, Property is taken from scim.
#self._setup_property = Property ("setup", _("Setup"))
- try:
+ self._auto_commit = variant_to_value(self._config.get_value(
+ self._config_section,
+ "AutoCommit"))
+ if self._auto_commit == None:
self._auto_commit = self.db.get_ime_property('auto_commit').lower() == u'true'
- except:
- self._auto_commit = False
- self._auto_commit = self._config.get_value (self._config_section, "AutoCommit",
- self._auto_commit)
# the commit phrases length
self._len_list = [0]
# connect to SpeedMeter
@@ -1034,31 +1174,62 @@ def reset (self):
def do_destroy(self):
self.reset ()
- self.focus_out ()
+ self.do_focus_out ()
#self.db.sync_usrdb ()
- super(tabengine,self).do_destroy()
+ super(tabengine,self).destroy()
def _init_properties (self):
self.properties= IBus.PropList ()
- self._status_property = IBus.Property(u'status')
+ self._status_property = IBus.Property(key=u'status',
+ label=None,
+ icon=None,
+ tooltip=None,
+ sensitive=True,
+ visible=True)
+ self.properties.append(self._status_property)
if self.db._is_chinese:
- self._cmode_property = IBus.Property(u'cmode')
- self._letter_property = IBus.Property(u'letter')
- self._punct_property = IBus.Property(u'punct')
- self._py_property = IBus.Property(u'py_mode')
- self._onechar_property = IBus.Property(u'onechar')
- self._auto_commit_property = IBus.Property(u'acommit')
- for prop in (self._status_property,
- self._letter_property,
- self._punct_property,
- self._py_property,
- self._onechar_property,
- self._auto_commit_property
- #self._setup_property
- ):
- self.properties.append(prop)
- if self.db._is_chinese:
- self.properties.insert( 1, self._cmode_property )
+ self._cmode_property = IBus.Property(key=u'cmode',
+ label=None,
+ icon=None,
+ tooltip=None,
+ sensitive=True,
+ visible=True)
+ self.properties.append(self._cmode_property)
+ self._letter_property = IBus.Property(key=u'letter',
+ label=None,
+ icon=None,
+ tooltip=None,
+ sensitive=True,
+ visible=True)
+ self.properties.append(self._letter_property)
+ self._punct_property = IBus.Property(key=u'punct',
+ label=None,
+ icon=None,
+ tooltip=None,
+ sensitive=True,
+ visible=True)
+ self.properties.append(self._punct_property)
+ self._py_property = IBus.Property(key=u'py_mode',
+ label=None,
+ icon=None,
+ tooltip=None,
+ sensitive=True,
+ visible=True)
+ self.properties.append(self._py_property)
+ self._onechar_property = IBus.Property(key=u'onechar',
+ label=None,
+ icon=None,
+ tooltip=None,
+ sensitive=True,
+ visible=True)
+ self.properties.append(self._onechar_property)
+ self._auto_commit_property = IBus.Property(key=u'acommit',
+ label=None,
+ icon=None,
+ tooltip=None,
+ sensitive=True,
+ visible=True)
+ self.properties.append(self._auto_commit_property)
self.register_properties (self.properties)
self._refresh_properties ()
@@ -1072,31 +1243,37 @@ def _refresh_properties (self):
self._set_property(self._status_property, 'ibus-table.svg', self._status, _('Switch to English mode'))
else:
self._set_property(self._status_property, 'english.svg', _('English Mode'), _('Switch to Table mode'))
+ self.update_property(self._status_property)
if self._full_width_letter[self._mode]:
self._set_property(self._letter_property, 'full-letter.svg', _('Full Letter'), _('Switch to half-width letter'))
else:
self._set_property(self._letter_property, 'half-letter.svg', _('Half Letter'), _('Switch to full-width letter'))
+ self.update_property(self._letter_property)
if self._full_width_punct[self._mode]:
self._set_property(self._punct_property, 'full-punct.svg', _('Full-width Punctuation'), _('Switch to half-width punctuation'))
else:
self._set_property(self._punct_property, 'half-punct.svg', _('Half-width Punctuation'), _('Switch to full-width punctuation'))
+ self.update_property(self._punct_property)
if self._editor._py_mode:
self._set_property(self._py_property, 'py-mode.svg', _('PinYin Mode'), _('Switch to Table mode'))
else:
self._set_property(self._py_property, 'tab-mode.svg', _('Table Mode'), _('Switch to PinYin mode'))
+ self.update_property(self._py_property)
if self._editor._onechar:
self._set_property(self._onechar_property, 'onechar.svg', _('Single Char Mode'), _('Switch to phrase mode'))
else:
self._set_property(self._onechar_property, 'phrase.svg', _('Phrase Mode'), _('Switch to single char mode'))
+ self.update_property(self._onechar_property)
if self._auto_commit:
self._set_property(self._auto_commit_property, 'acommit.svg', _('Direct Commit Mode'), _('Switch to normal commit mode, which use space to commit'))
else:
self._set_property(self._auto_commit_property, 'ncommit.svg', _('Normal Commit Mode'), _('Switch to direct commit mode'))
+ self.update_property(self._auto_commit_property)
# the chinese_mode:
if self.db._is_chinese:
@@ -1110,14 +1287,12 @@ def _refresh_properties (self):
self._set_property(self._cmode_property, 'tcb-mode.svg', _('Traditional Chinese First Big Charset Mode'), _('Switch to Big Charset Mode'))
elif self._editor._chinese_mode == 4:
self._set_property(self._cmode_property, 'cb-mode.svg', _('Big Chinese Mode'), _('Switch to Simplified Chinese Mode'))
-
- # use buildin method to update properties :)
- map (self.update_property, self.properties)
+ self.update_property(self._cmode_property)
def _set_property (self, property, icon, label, tooltip):
property.set_icon ( u'%s%s' % (self._icon_dir, icon ) )
- property.set_label ( unicode(label) )
- property.set_tooltip ( unicode(tooltip) )
+ property.set_label (IBus.Text.new_from_string(unicode(label)))
+ property.set_tooltip (IBus.Text.new_from_string(unicode(tooltip)))
def _change_mode (self):
'''Shift input mode, TAB -> EN -> TAB
@@ -1126,7 +1301,7 @@ def _change_mode (self):
self.reset ()
self._update_ui ()
- def property_activate (self, property,prop_state = IBus.PropState.UNCHECKED):
+ def do_property_activate (self, property, prop_state = IBus.PropState.UNCHECKED):
'''Shift property'''
if property == u"status":
self._change_mode ()
@@ -1134,36 +1309,36 @@ def property_activate (self, property,prop_state = IBus.PropState.UNCHECKED):
self._editor.r_shift ()
elif property == u'onechar':
self._editor._onechar = not self._editor._onechar
- self._config.set_value( self._config_section,
+ self._config.set_value(self._config_section,
"OneChar",
- self._editor._onechar)
+ GLib.Variant.new_boolean(self._editor._onechar))
elif property == u'acommit':
self._auto_commit = not self._auto_commit
self._config.set_value( self._config_section,
"AutoCommit",
- self._auto_commit)
+ GLib.Variant.new_boolean(self._auto_commit))
elif property == u'letter':
self._full_width_letter [self._mode] = not self._full_width_letter [self._mode]
if self._mode:
- self._config.set_value( self._config_section,
+ self._config.set_value(self._config_section,
"TabDefFullWidthLetter",
- self._full_width_letter [self._mode])
+ GLib.Variant.new_boolean(self._full_width_letter [self._mode]))
else:
- self._config.set_value( self._config_section,
+ self._config.set_value(self._config_section,
"EnDefFullWidthLetter",
- self._full_width_letter [self._mode])
+ GLib.Variant.new_boolean(self._full_width_letter [self._mode]))
elif property == u'punct':
self._full_width_punct [self._mode] = not self._full_width_punct [self._mode]
if self._mode:
- self._config.set_value( self._config_section,
+ self._config.set_value(self._config_section,
"TabDefFullWidthPunct",
- self._full_width_punct [self._mode])
+ GLib.Variant.new_boolean(self._full_width_punct [self._mode]))
else:
- self._config.set_value( self._config_section,
+ self._config.set_value(self._config_section,
"EnDefFullWidthPunct",
- self._full_width_punct [self._mode])
+ GLib.Variant.new_boolean(self._full_width_punct [self._mode]))
elif property == u'cmode':
self._editor.change_chinese_mode()
self.reset()
@@ -1177,7 +1352,7 @@ 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)
+ super(tabengine, self).update_preedit_text(IBus.Text.new_from_string(u''), 0, False)
else:
attrs = IBus.AttrList()
res = patt_edit.match (_str)
@@ -1188,36 +1363,51 @@ def _update_preedit (self):
_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) )
+ attrs.append(IBus.attr_foreground_new(rgb(0x1b,0x3f,0x03),0,lc))
+ attrs.append(IBus.attr_foreground_new(rgb(0x08,0x95,0xa2),lc,lu))
lg1 = len (_str)
else:
_str += res.group (1)
lg1 = len ( res.group(1) )
- attrs.append (IBus.AttributeForeground(0x1b3f03,0,lg1) )
+ attrs.append(IBus.attr_foreground_new(rgb(0x1b,0x3f,0x03),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) )
+ attrs.append(IBus.attr_foreground_new(rgb(0x0e,0x0e,0xa0),lg1,lg2))
+ attrs.append(IBus.attr_foreground_new(rgb(0x1b,0x3f,0x03),lg1+lg2,lg3))
else:
- attrs.append( IBus.AttributeForeground(0x1b3f03,0,len(_str)) )
+ attrs.append(IBus.attr_foreground_new(rgb(0x1b,0x3f,0x03),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, attrs), self._editor.get_caret(), True)
+ attrs.append(IBus.attr_underline_new(IBus.AttrUnderline.SINGLE, 0, len(_str)))
+ text = IBus.Text.new_from_string(_str)
+ i = 0
+ while attrs.get(i) != None:
+ attr = attrs.get(i)
+ text.append_attribute(attr.get_attr_type(),
+ attr.get_value(),
+ attr.get_start_index(),
+ attr.get_end_index())
+ i += 1
+ super(tabengine, self).update_preedit_text(text, self._editor.get_caret(), True)
def _update_aux (self):
'''Update Aux String in UI'''
_ic = self._editor.get_aux_strings ()
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)
+ attrs = IBus.AttrList()
+ attrs.append(IBus.attr_foreground_new(rgb(0x95,0x15,0xb5),0, len(_ic)))
+ text = IBus.Text.new_from_string(_ic)
+ i = 0
+ while attrs.get(i) != None:
+ attr = attrs.get(i)
+ text.append_attribute(attr.get_attr_type(),
+ attr.get_value(),
+ attr.get_start_index(),
+ attr.get_end_index())
+ i += 1
+ super(tabengine, self).update_auxiliary_text(text, True)
else:
self.hide_auxiliary_text()
#self.update_aux_string (u'', None, False)
@@ -1227,7 +1417,7 @@ def _update_lookup_table (self):
if self._editor.is_empty ():
self.hide_lookup_table()
return
- self.update_lookup_table ( self._editor.get_lookup_table(), True, True )
+ self.update_lookup_table(self._editor.get_lookup_table(), True)
def _update_ui (self):
'''Update User Interface'''
@@ -1245,7 +1435,7 @@ def _update_ui (self):
def commit_string (self,string):
self._editor.clear ()
self._update_ui ()
- super(tabengine,self).commit_text ( IBus.Text(string) )
+ super(tabengine,self).commit_text(IBus.Text.new_from_string(string))
self._prev_char = string[-1]
def _convert_to_full_width (self, c):
@@ -1296,7 +1486,7 @@ def _convert_to_full_width (self, c):
if self._mode:
return u"\u300f"
- return IBus.unichar_half_to_full (c)
+ return unichar_half_to_full (c)
def _match_hotkey (self, key, code, mask):
@@ -1308,7 +1498,7 @@ def _match_hotkey (self, key, code, mask):
return False
- def process_key_event(self, keyval, keycode, state):
+ def do_process_key_event(self, keyval, keycode, state):
'''Process Key Events
Key Events include Key Press and Key Release,
modifier means Key Pressed
@@ -1324,18 +1514,18 @@ def process_key_event(self, keyval, keycode, state):
def _process_key_event (self, key):
'''Internal method to process key event'''
# Match mode switch hotkey
- if not self._editor._t_chars and ( self._match_hotkey (key, IBus.KEY_Shift_L, IBus.ModifierType.SHIFT_MASK + IBus.ModifierType.RELEASE_MASK)):
+ if not self._editor._t_chars and ( self._match_hotkey (key, IBus.KEY_Shift_L, IBus.ModifierType.SHIFT_MASK | IBus.ModifierType.RELEASE_MASK)):
self._change_mode ()
return True
# Match full half letter mode switch hotkey
if self._match_hotkey (key, IBus.KEY_space, IBus.ModifierType.SHIFT_MASK):
- self.property_activate ("letter")
+ self.do_property_activate ("letter")
return True
# Match full half punct mode switch hotkey
if self._match_hotkey (key, IBus.KEY_period, IBus.ModifierType.CONTROL_MASK):
- self.property_activate ("punct")
+ self.do_property_activate ("punct")
return True
# we ignore all hotkeys
@@ -1360,7 +1550,7 @@ def _english_mode_process_key_event (self, key):
if key.code >= 128:
return False
# we ignore all hotkeys here
- if key.mask & IBus.ModifierType.CONTROL_MASK+IBus.ModifierType.MOD1_MASK:
+ if key.mask & (IBus.ModifierType.CONTROL_MASK|IBus.ModifierType.MOD1_MASK):
return False
keychar = unichr (key.code)
@@ -1392,35 +1582,35 @@ def _table_mode_process_key_event (self, key):
# We have to process the pinyin mode change key event here,
# because we ignore all Release event below.
- if self._match_hotkey (key, IBus.KEY_Shift_R, IBus.ModifierType.SHIFT_MASK + IBus.ModifierType.RELEASE_MASK) and self._ime_py:
+ if self._match_hotkey (key, IBus.KEY_Shift_R, IBus.ModifierType.SHIFT_MASK | IBus.ModifierType.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, IBus.KEY_Shift_R, IBus.ModifierType.SHIFT_MASK + IBus.ModifierType.RELEASE_MASK) or self._match_hotkey (key, IBus.KEY_Shift_L, IBus.ModifierType.SHIFT_MASK + IBus.ModifierType.RELEASE_MASK):
+ if self._match_hotkey (key, IBus.KEY_Shift_R, IBus.ModifierType.SHIFT_MASK | IBus.ModifierType.RELEASE_MASK) or self._match_hotkey (key, IBus.KEY_Shift_L, IBus.ModifierType.SHIFT_MASK | IBus.ModifierType.RELEASE_MASK):
res = self._editor.l_shift ()
self._update_ui ()
return res
# Left ALT key to cycle candidates in the current page.
- if self._match_hotkey (key, keysyms.Alt_L, modifier.ALT_MASK + modifier.RELEASE_MASK):
+ if self._match_hotkey (key, IBus.KEY_Alt_L, IBus.ModifierType.MOD1_MASK | IBus.ModifierType.RELEASE_MASK):
res = self._editor.l_alt ()
self._update_ui ()
return res
# Match single char mode switch hotkey
if self._match_hotkey (key, IBus.KEY_comma, IBus.ModifierType.CONTROL_MASK):
- self.property_activate ( u"onechar" )
+ self.do_property_activate ( u"onechar" )
return True
# Match direct commit mode switch hotkey
if self._match_hotkey (key, IBus.KEY_slash, IBus.ModifierType.CONTROL_MASK):
- self.property_activate ( u"acommit" )
+ self.do_property_activate ( u"acommit" )
return True
# Match Chinese mode shift
if self._match_hotkey (key, IBus.KEY_semicolon, IBus.ModifierType.CONTROL_MASK):
- self.property_activate ( u"cmode" )
+ self.do_property_activate ( u"cmode" )
return True
# Match speedmeter shift
@@ -1441,7 +1631,7 @@ def _table_mode_process_key_event (self, key):
if self._editor.is_empty ():
# we have not input anything
if key.code >= 32 and key.code <= 127 and ( keychar not in self._valid_input_chars ) \
- and (not key.mask & IBus.ModifierType.MOD1_MASK + IBus.ModifierType.CONTROL_MASK):
+ and (not (key.mask & (IBus.ModifierType.MOD1_MASK | IBus.ModifierType.CONTROL_MASK))):
if key.code == IBus.KEY_space:
#self.commit_string (cond_letter_translate (keychar))
# little hack to make ibus to input space in gvim :)
@@ -1557,7 +1747,7 @@ def _table_mode_process_key_event (self, key):
self._update_ui ()
return True
# now we ignore all else hotkeys
- elif key.mask & IBus.ModifierType.CONTROL_MASK+IBus.ModifierType.MOD1_MASK:
+ elif key.mask & (IBus.ModifierType.CONTROL_MASK|IBus.ModifierType.MOD1_MASK):
return False
elif key.mask & IBus.ModifierType.MOD1_MASK:
@@ -1655,7 +1845,7 @@ def _table_mode_process_key_event (self, key):
return False
# below for initial test
- def focus_in (self):
+ def do_focus_in (self):
if self._on:
self.register_properties (self.properties)
self._refresh_properties ()
@@ -1668,22 +1858,22 @@ def focus_in (self):
#except:
# pass
- def focus_out (self):
+ def do_focus_out (self):
#try:
# self._sm.Hide()
#except:
# pass
pass
- def enable (self):
+ def do_enable (self):
#try:
# self._sm.Reset()
#except:
# pass
self._on = True
- self.focus_in()
+ self.do_focus_in()
- def disable (self):
+ def do_disable (self):
self.reset()
#try:
# self._sm.Hide()
@@ -1692,19 +1882,20 @@ def disable (self):
self._on = False
- def page_up (self):
+ def do_page_up (self):
if self._editor.page_up ():
self._update_lookup_table ()
return True
return False
- def page_down (self):
+ def do_page_down (self):
if self._editor.page_down ():
self._update_lookup_table ()
return True
return False
def config_value_changed_cb (self, config, section, name, value):
+ value = variant_to_value(value)
if section == self._config_section:
if name == u'AutoCommit':
self._auto_commit = value
Please sign in to comment.
Something went wrong with that request. Please try again.