<commit_before>#!/usr/bin/env python
import gobject
import gtk
import pango
import dbus
import ibus
import enchant
from ibus import keysyms
from ibus import interface

class Engine (interface.IEngine):
	_dict = enchant.Dict ()
	def __init__ (self, dbusconn, object_path):
		interface.IEngine.__init__ (self, dbusconn, object_path)
		self._dbusconn = dbusconn
		self._preedit_string = ""
		self._lookup_table = ibus.LookupTable ()

	# methods for dbus rpc
	def ProcessKeyEvent (self, keyval, is_press, state):
		# ignore key release events
		if not is_press:
			return False

		if self._preedit_string:
			if keyval == keysyms.Return:
				self.CommitString (self._preedit_string)
				self._preedit_string = ""
				self._update ()
				return True
			elif keyval == keysyms.BackSpace:
				self._preedit_string = self._preedit_string[:-1]
				self._update ()
				return True
			elif keyval == keysyms.space:
				self.CommitString (self._preedit_string)
				self._preedit_string = ""
				self._update ()
				return False
			elif keyval >= keysyms._1 and keyval <= keysyms._9:
				index = keyval - keysyms._1
				candidates = self._lookup_table.get_canidates_in_current_page ()
				if index >= len (candidates):
					return False
				candidate = candidates[index][0]
				self.CommitString (candidate + " ")
				self._preedit_string = ""
				self._update ()
				return True
			elif keyval == keysyms.Page_Up or keyval == keysyms.KP_Page_Up:
				if self._lookup_table.page_up ():
					self._update_lookup_table ()
				return True
			elif keyval == keysyms.Page_Down or keyval == keysyms.KP_Page_Down:
				if self._lookup_table.page_down ():
					self._update_lookup_table ()
				return True
		if (keyval >= keysyms.a and keyval <= keysyms.z) or \
			(keyval >= keysyms.A and keyval <= keysyms.Z):
			if state & (keysyms.CONTROL_MASK | keysyms.ALT_MASK) == 0:
				self._preedit_string += chr (keyval)
				self._update ()
				return True

		return False

	def _update (self):
		preedit_len = len (self._preedit_string)
		attrs = ibus.AttrList ()
		self._lookup_table.clean ()
		if preedit_len > 0:
			if not self._dict.check (self._preedit_string):
				attrs.append (ibus.AttributeForeground (0xff0000, 0, preedit_len))
				for text in self._dict.suggest (self._preedit_string):
					self._lookup_table.append_candidate (text)

		attrs.append (ibus.AttributeUnderline (pango.UNDERLINE_SINGLE, 0, preedit_len))
		self.PreeditChanged (self._preedit_string, attrs.to_dbus_value (), dbus.Int32 (preedit_len))
		self.AuxStringChanged (self._preedit_string, attrs.to_dbus_value ())<commit_msg>Remove underline attribute of aux string. Process symbols as commit key.<commit_after>#!/usr/bin/env python
import gobject
import gtk
import pango
import dbus
import ibus
import enchant
from ibus import keysyms
from ibus import interface

class Engine (interface.IEngine):
	_dict = enchant.Dict ()
	def __init__ (self, dbusconn, object_path):
		interface.IEngine.__init__ (self, dbusconn, object_path)
		self._dbusconn = dbusconn
		self._preedit_string = ""
		self._lookup_table = ibus.LookupTable ()

	# methods for dbus rpc
	def ProcessKeyEvent (self, keyval, is_press, state):
		# ignore key release events
		if not is_press:
			return False

		if self._preedit_string:
			if keyval == keysyms.Return:
				self.CommitString (self._preedit_string)
				self._preedit_string = ""
				self._update ()
				return True
			elif keyval == keysyms.BackSpace:
				self._preedit_string = self._preedit_string[:-1]
				self._update ()
				return True
			elif keyval == keysyms.space:
				self.CommitString (self._preedit_string)
				self._preedit_string = ""
				self._update ()
				return False
			elif keyval >= keysyms._1 and keyval <= keysyms._9:
				index = keyval - keysyms._1
				candidates = self._lookup_table.get_canidates_in_current_page ()
				if index >= len (candidates):
					return False
				candidate = candidates[index][0]
				self.CommitString (candidate + " ")
				self._preedit_string = ""
				self._update ()
				return True
			elif keyval == keysyms.Page_Up or keyval == keysyms.KP_Page_Up:
				if self._lookup_table.page_up ():
					self._update_lookup_table ()
				return True
			elif keyval == keysyms.Page_Down or keyval == keysyms.KP_Page_Down:
				if self._lookup_table.page_down ():
					self._update_lookup_table ()
				return True
		if keyval in xrange (keysyms.a, keysyms.z + 1) or \
			keyval in xrange (keysyms.A, keysyms.Z + 1):
			if state & (keysyms.CONTROL_MASK | keysyms.ALT_MASK) == 0:
				self._preedit_string += chr (keyval)
				self._update ()
				return True
		else:
			if keyval < 128 and self._preedit_string:
				self.CommitString (self._preedit_string)
				self._preedit_string = ""
				self._update ()

		return False

	def _update (self):
		preedit_len = len (self._preedit_string)
		attrs = ibus.AttrList ()
		self._lookup_table.clean ()
		if preedit_len > 0:
			if not self._dict.check (self._preedit_string):
				attrs.append (ibus.AttributeForeground (0xff0000, 0, preedit_len))
				for text in self._dict.suggest (self._preedit_string):
					self._lookup_table.append_candidate (text)

		self.AuxStringChanged (self._preedit_string, attrs.to_dbus_value ())
		attrs.append (ibus.AttributeUnderline (pango.UNDERLINE_SINGLE, 0, preedit_len))
		self.PreeditChanged (self._preedit_string, attrs.to_dbus_value (), dbus.Int32 (preedit_len))
{'fraction_non_alphanumeric': 0.10173604629456785, 'fraction_numerical': 0.006906850849355983, 'mean_word_length': 3.720704845814978, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '75916', 'n_tokens_mistral': 2147, 'n_tokens_neox': 1822, 'n_words': 424}