<commit_before># vim:set noet ts=4:
#
# ibus - The Input Bus
#
# Copyright (c) 2007-2008 <NAME> <<EMAIL>>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
# Boston, MA  02111-1307  USA

import dbus
import ibus
from ibus import keysyms
from ibus import modifier
from contextmanager import ContextManager
from factorymanager import FactoryManager
from connection import Connection
from panel import Panel, DummyPanel
from config import Config, DummyConfig
from register import Register

class IBus(ibus.Object):
	def __init__(self):
		super(IBus, self).__init__()
		self._context_manager = ContextManager()
		self._factory_manager = FactoryManager()
		self._panel = DummyPanel()
		self._config = DummyConfig()
		self._register = Register()
		self._config_watch = dict()

		self._focused_context = None
		self._last_focused_context = None
		self._context_handlers = list()

		self._last_key = None

	##########################################################
	# methods for im context
	##########################################################
	def create_input_context(self, name, conn):
		context = self._context_manager.create_input_context(name, conn)
		factory = self._factory_manager.get_default_factory()
		if factory:
			engine = factory.create_engine()
			context.set_engine(engine)
		return context.get_id()

	def release_input_context(self, ic, conn):
		self._context_manager.release_input_context(ic, conn)

	def focus_in(self, ic, conn):
		context = self._lookup_context(ic, conn)

		if self._focused_context != context and self._focused_context != None:
			self._remove_focused_context_handlers()
			self._focused_context.focus_out()

		self._focused_context = context
		self._install_focused_context_handlers()

		self._panel.focus_in(context.get_id())
		self._last_focused_context = context
		context.focus_in()

	def focus_out(self, ic, conn):
		context = self._lookup_context(ic, conn)

		if context == self._focused_context:
			self._remove_focused_context_handlers()
			self._focused_context = None

		context.focus_out()
		self._panel.focus_out(context.get_id())

	def reset(self, ic, conn):
		context = self._lookup_context(ic, conn)
		context.reset()

	def is_enabled(self, ic, conn):
		context = self._lookup_context(ic, conn)
		return context.is_enabled()

	def process_key_event(self, ic, keyval, is_press, state,
								conn, reply_cb, error_cb):
		context = self._lookup_context(ic, conn)

		if self._filter_hotkeys(context, keyval, is_press, state):
			reply_cb(True)
			return
		else:
			context.process_key_event(keyval, is_press, state, reply_cb, error_cb)

	def set_cursor_location(self, ic, x, y, w, h, conn):
		context = self._lookup_context(ic, conn)
		context.set_cursor_location(x, y, w, h)
		self._panel.set_cursor_location(x, y, w, h)

	def _filter_hotkeys(self, context, keyval, is_press, state):
		if is_press and keyval == keysyms.space \
			and (state & ~modifier.MOD2_MASK) == modifier.CONTROL_MASK:
			enable = not context.is_enabled()
			if context.get_engine() == None and enable:
				factory = self._factory_manager.get_default_factory()
				if factory:
					engine = factory.create_engine()
					context.set_engine(engine)
			context.set_enable(enable)
			self._panel.states_changed()
			return True
		return False

	def _lookup_context(self, ic, conn):<commit_msg>focus in engine, when create a new engine for a input context.<commit_after># vim:set noet ts=4:
#
# ibus - The Input Bus
#
# Copyright (c) 2007-2008 <NAME> <<EMAIL>>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
# Boston, MA  02111-1307  USA

import dbus
import ibus
from ibus import keysyms
from ibus import modifier
from contextmanager import ContextManager
from factorymanager import FactoryManager
from connection import Connection
from panel import Panel, DummyPanel
from config import Config, DummyConfig
from register import Register

class IBus(ibus.Object):
	def __init__(self):
		super(IBus, self).__init__()
		self._context_manager = ContextManager()
		self._factory_manager = FactoryManager()
		self._panel = DummyPanel()
		self._config = DummyConfig()
		self._register = Register()
		self._config_watch = dict()

		self._focused_context = None
		self._last_focused_context = None
		self._context_handlers = list()

		self._last_key = None

	##########################################################
	# methods for im context
	##########################################################
	def create_input_context(self, name, conn):
		context = self._context_manager.create_input_context(name, conn)
		factory = self._factory_manager.get_default_factory()
		if factory:
			engine = factory.create_engine()
			context.set_engine(engine)
		return context.get_id()

	def release_input_context(self, ic, conn):
		self._context_manager.release_input_context(ic, conn)

	def focus_in(self, ic, conn):
		context = self._lookup_context(ic, conn)

		if self._focused_context != context and self._focused_context != None:
			self._remove_focused_context_handlers()
			self._focused_context.focus_out()

		self._focused_context = context
		self._install_focused_context_handlers()

		self._panel.focus_in(context.get_id())
		self._last_focused_context = context
		context.focus_in()

	def focus_out(self, ic, conn):
		context = self._lookup_context(ic, conn)

		if context == self._focused_context:
			self._remove_focused_context_handlers()
			self._focused_context = None

		context.focus_out()
		self._panel.focus_out(context.get_id())

	def reset(self, ic, conn):
		context = self._lookup_context(ic, conn)
		context.reset()

	def is_enabled(self, ic, conn):
		context = self._lookup_context(ic, conn)
		return context.is_enabled()

	def process_key_event(self, ic, keyval, is_press, state,
								conn, reply_cb, error_cb):
		context = self._lookup_context(ic, conn)

		if self._filter_hotkeys(context, keyval, is_press, state):
			reply_cb(True)
			return
		else:
			context.process_key_event(keyval, is_press, state, reply_cb, error_cb)

	def set_cursor_location(self, ic, x, y, w, h, conn):
		context = self._lookup_context(ic, conn)
		context.set_cursor_location(x, y, w, h)
		self._panel.set_cursor_location(x, y, w, h)

	def _filter_hotkeys(self, context, keyval, is_press, state):
		if is_press and keyval == keysyms.space \
			and (state & ~modifier.MOD2_MASK) == modifier.CONTROL_MASK:
			enable = not context.is_enabled()
			if context.get_engine() == None and enable:
				factory = self._factory_manager.get_default_factory()
				if factory:
					engine = factory.create_engine()
					engine.focus_in()
					context.set_engine(engine)
			context.set_enable(enable)
			self._panel.states_changed()
			return True
		return False

	def _lookup_context(self, ic, conn):
{'fraction_non_alphanumeric': 0.117992992992993, 'fraction_numerical': 0.006256256256256257, 'mean_word_length': 4.859970674486804, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '4065438', 'n_tokens_mistral': 2681, 'n_tokens_neox': 2390, 'n_words': 725}