Skip to content

Commit

Permalink
processing backspace correctly
Browse files Browse the repository at this point in the history
processing keys with shift
processing keys correctly when capslock key is toggled
flushing on focus out
by Choe Hwanjin <[email protected]>
  • Loading branch information
phuang committed Sep 21, 2008
1 parent 64e4be8 commit 02ba832
Showing 1 changed file with 29 additions and 19 deletions.
48 changes: 29 additions & 19 deletions engine/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ def cursor_up(self):
def cursor_down(self):
return True

def __update(self):
def __flush(self):
text = self.__context.flush()
self.hide_preedit()
self.commit_string(text)

def __update_preedit(self):
preedit_string = self.__context.get_preedit_string()
if preedit_string:
attrs = ibus.AttrList()
Expand All @@ -69,6 +74,8 @@ def __update(self):
self.update_preedit(preedit_string, attrs, l, True)
else:
self.hide_preedit()

def __commit_current(self):
commit_string = self.__context.get_commit_string()
if commit_string:
self.commit_string(commit_string)
Expand All @@ -77,24 +84,28 @@ def process_key_event(self, keyval, is_press, state):
# ignore key release events
if not is_press:
return False
state = state & (modifier.SHIFT_MASK | modifier.CONTROL_MASK | modifier.MOD1_MASK)

if state == 0:
if keyval >= keysyms.exclam and keyval <= keysyms.asciitilde:
if self.__context.process(keyval):
self.__update()
return True
elif keyval == keysyms.BackSpace:
if self.__context.backspace():
self.__update()
return True
else:
text = self.__context.flush()
self.hide_preedit()
self.commit_string(text)

if state & (modifier.CONTROL_MASK | modifier.MOD1_MASK):
return False

return False
res = False
if keyval == keysyms.BackSpace:
res = self.__context.backspace()
if res:
self.__update_preedit()
else:
if state & modifier.LOCK_MASK:
# toggle case
c = unichr(keyval)
if c.islower():
keyval = ord(c.upper())
else:
keyval = ord(c.lower())

res = self.__context.process(keyval)
self.__update_preedit()
self.__commit_current()
return res

def property_activate(self, prop_name, state):
pass
Expand All @@ -103,5 +114,4 @@ def focus_in(self):
pass

def focus_out(self):
pass

self.__flush()

0 comments on commit 02ba832

Please sign in to comment.