%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/share/ibus-table/engine/__pycache__/
Upload File :
Create Path :
Current File : //usr/share/ibus-table/engine/__pycache__/table.cpython-312.pyc

�

��Xe����h�UdZdZddlmZddlmZddlmZddlmZddlmZddlmZdd	lm	Z	dd
lm
Z
ddlZddlZddl
Z
ddlZddlZddlZdZ	ddlZd
ZddlmZd�Ze
egefed<d�Ze
egefed<ddlmZedd�ddlmZedd�ddlmZedd�ddlmZddlm Z ddl!Z!ddl"Z"ddl#Z#ejHd�Z%e&d�a'dede(fd �Z)de!jTd!�e!jTd"�e!jTd#�e!jTd"�e!jTd$�e!jTd%�e!jTd&�e!jTd'�e!jTd(�d)�
Z+eeee(e&ffed*<d
e!jTd+�e!jTd,�e!jTd-�e!jTd.�e!jTd$�e!jTd/�e!jTd&�e!jTd'�e!jTd0�d)�
Z,eeee(e&ffed1<gd2�Z-eee&e&e&fed3<d4edefd5�Z.d4edefd6�Z/d7Z0d8Z1ejdejfejhfZ5Gd9�d:ejl�Z7e8d;k(r�ejrejt�<�Z;e%jyejz�e%j}e;�ddl?Z?e?j��\ZAZBeArej�d=�yej�d�yy#ef$rdZY���wxYw)>z5
This file implements the ibus engine for ibus-table
)�	TabEngine�)�Any)�List)�Tuple)�Iterable)�Dict)�Union)�Optional)�CallableNFT��dgettextc��td|�S)N�
ibus-tabler��as �%/usr/share/ibus-table/engine/table.py�<lambda>r6s
��H�\�1�$=���_c��|S)N�rs rrr7s��Q�r�N_)�require_version�IBusz1.0)r�Gioz2.0)r�GLib)r)�GObjectr�	character�returnc��t|dv�S)u
    Use our own function instead of ascii.ispunct()
    from “from curses import ascii” because the behaviour
    of the latter is kind of weird. In Python 3.3.2 it does
    for example:

        # >>> from curses import ascii
        # >>> ascii.ispunct('.')
        # True
        # >>> ascii.ispunct(u'.')
        # True
        # >>> ascii.ispunct('a')
        # False
        # >>> ascii.ispunct(u'a')
        # False
        # >>>
        # >>> ascii.ispunct(u'あ')
        # True
        # >>> ascii.ispunct('あ')
        # True
        # >>>

    あ isn’t punctuation. ascii.ispunct() only really works
    in the ascii range, it returns weird results when used
    over the whole unicode range. Maybe we should better use
    unicodedata.category(), which works fine to figure out
    what is punctuation for all of unicode. But at the moment
    I am only porting from Python2 to Python3 and just want to
    preserve the original behaviour for the moment.

    By the way, Python 3.6.6 does not seem the  above bug
    anymore, in Python 3.6.6 we  get

        # >>> from curses import ascii
        # >>> ascii.ispunct('あ')
        # False
        # >>>

    Examples:

    >>> ascii_ispunct('.')
    True
    >>> ascii_ispunct('a')
    False
    >>> ascii_ispunct('あ')
    False
    z !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~)�bool)rs r�
ascii_ispunctr"Is��`�	�D�D�E�Erz#1973a2z#000000z#7700c3z#00ff00z#f90f0fz#1edc1az#ff00ffz#9515b5)
�dark�candidate_text�
system_phrase�user_phrase�system_phrase_unused�
debug_text�preedit_left�
preedit_right�preedit_invalid�aux_text�THEMEz#7bc8f0z#ffffffz#c078eez#f0f0f0z#f9f90fz#dd70f9�
THEME_DARK)=)� i0�)�!i��^)�i��)�i�r0)�i�r0)�i�r0)�i�r0)i� i�r0)ia�i0r0)ib�i0r4)id�i0r0)ie�i�0r0)if�i�0r0)ig�i�0r0)ih�i�0r0)ii�i�0r0)ij�i�0r0)ik�i�0r0)il�i�0r0)im�i�0r0)in�i�0r0)io�i�0r0)ip�i�0r0)iq�i�0r0)ir�i�0r0)is�i�0r0)it�i�0r0)iu�i�0r4)iw�i�0r0)ix�i�0r0)iy�i�0r0)iz�i�0r0)i{�i�0r0)i|�i�0r0)i}�i�0r0)i~�i�0r0)i�i�0r0)i��i�0r0)i��i�0r0)i��i�0r0)i��i�0r0)i��i�0r0)i��i�0�)i��i�0r0)i��i�0r0)i��i�0r0)i��i�0r0)i��i�0�)i��i�0r0)i��i�0r0)i��i�0r9)i��i�0r0)i��i�0r0)i��id1r0)i��i11�)i�iO1r9)i�iU1r9)i�i[1�	)i�i�!�)i�i�%r0)i�i�%r0�__HALF_FULL_TABLE�charc��t|�}tD]*\}}}||cxkr	||zks�n�t||z|z
�cS|S)u
    Convert a character to full width if possible.

    :param char: A character to convert to full width

    Examples:

    >>> unichar_half_to_full('a')
    'a'
    >>> unichar_half_to_full('a')
    'a'
    >>> unichar_half_to_full('☺')
    '☺'
    ��ordr>�chr�r?�code�half�full�sizes     r�unichar_half_to_fullrI�sO���t�9�D�-�+���d�D��4�%�$��+�%��t�d�{�T�)�*�*�+��Krc��t|�}tD]*\}}}||cxkr	||zks�n�t||z|z
�cS|S)u-
    Convert a character to half width if possible.

    :param char: A character to convert to half width
    :type char: String
    :rtype: String

    Examples:

    >>> unichar_full_to_half('a')
    'a'
    >>> unichar_full_to_half('a')
    'a'
    >>> unichar_full_to_half('☺')
    '☺'
    rArDs     r�unichar_full_to_halfrK�sO��"�t�9�D�-�+���d�D��4�%�$��+�%��t�d�{�T�)�*�*�+��Kr�r;c�t��eZdZdZ	d�dej
dedededdf
�fd�
Z	dejfd	�Zd�d
�Zdefd�Z
d�d�Zd
edefd�Zdefd�Zdefd�Zdededdfd�Zd�d�Zd�d�Zd�d�Zd�d�Zdeeedfeeedfffd�Zdefd�Zdeeedfeeedfffd�Zdefd�Zdefd�Zd�d�Zd�d�Zd�d �Z d�d!�Z!				d�d"ed#ed$ed%eddf
d&�Z"e#d'e$ede$efd(��Z%d'e$ed)e$edefd*�Z&				d�d"ed#ed$ed%eddf
d+�Z'				d�d,ed#ed$ed%eddf
d-�Z(d�d.edefd/�Z)defd0�Z*dedefd1�Z+defd2�Z,d�d3�Z-defd4�Z.defd5�Z/defd6�Z0defd7�Z1dedefd8�Z2defd9�Z3dejfd:�Z4d�d;�Z5d�d<�Z6defd=�Z7defd>�Z8defd?�Z9d�d@�Z:d�fdA�Z;	d�dBedCeddfdD�Z<defdE�Z=	d�dFedCeddfdG�Z>defdH�Z?	d�dIedCeddfdJ�Z@defdK�ZA	d�dLedCeddfdM�ZBdefdN�ZC	d�dOeDeefdCeddfdP�ZEdefdQ�ZF	d�dReDeGee$efefdCeddfdS�ZHdeGee$effdT�ZI		d�dUedCeddfdV�ZJ		d�dWedCeddfdX�ZKdefdY�ZL		d�dZedCeddfd[�ZMdefd\�ZNd�d]eddfd^�ZOdefd_�ZPd�d]eddfd`�ZQdefda�ZR	d�d]edCeddfdb�ZSdefdc�ZT	d�d]edCeddfdd�ZUdefde�ZV	d�d]edCeddfdf�ZWdefdg�ZX	d�d]edCeddfdh�ZYdefdi�ZZ	d�d]edCeddfdj�Z[defdk�Z\	d�d
edCeddfdl�Z]defdm�Z^	d�d
edCeddfdn�Z_defdo�Z`	d�d]edCeddfdp�Zadefdq�Zb	d�dredCeddfds�Zcdefdt�Zd	d�duedCeddfdv�Zedefdw�Zf			d�d]edUedCeddfdx�Zgde$ehefdy�Zi			d�d]edUedCeddfdz�Zjde$ehefd{�Zk	d�d]edCeddfd|�Zldefd}�Zm	d�d~eGeefdeDeedfddfd��Zn	d�d�ed�eGeefdeddfd��Zod�d��Zpej�j�fd�ed�ej�ddfd��Zsd�d��Ztd�d��Zud�d��Zvd�fd��Zwd�d��Zxd�d��Zyd�d"ed#eddfd��Zzdefd��Z{d�d#ed"eddf�fd��
Z|defd��Z}d
edefd��Z~ded�ed�edefd��Zdefd��Z�defd��Z�defd��Z�defd��Z�defd��Z�defd��Z�defd��Z�defd��Z�defd��Z�defd��Z�defd��Z�defd��Z�defd��Z�defd��Z�defd��Z�defd��Z�d�edefd��Z�defd��Z�defd��Z�defd��Z�defd��Z�defd��Z�defd��Z�defd��Z�defd��Z�defd��Z�defd��Z�d�edefd��Z�defd��Z�defd��Z�defd��Z�defd��Z�defd��Z�defd��Z�defd��Z�defd��Z�defd��Z�defd��Z�d�edefd��Z�defd��Z�defd��Z�defd��Z�defd��Z�defd„Z�defdÄZ�defdĄZ�defdńZ�defdƄZ�defdDŽZ�	d�d�e��jdd�e�edeeeffdʄZ�d�ed�ed�edefd΄Z�d�e�jld�ed�ed�edef
dЄZ�d�ed�ed�edefdфZ�d�e��jddefd҄Z�d
edefdӄZ�d
edefdԄZ�d�e��jddefdՄZ�d�e��jddefdքZ�d�dׄZ�d�ed�eddfdڄZ�d�dۄZ�d�eddfd܄Z�d�d݄Z�d�ed�eddfd�Z�d�d�Z�d�d�Z�defd�Z�defd�Z�defd�Z�defd�Z�d�eʐj�d�eddfd�Z̈xZ�S)�rzThe IM Engine for Tables�bus�obj_path�database�	unit_testrNc��1��	tttjd���atdkDrtjd|||�tjddjttt���ttjj d�r6t"�|�I|j'�|d�	�tjd
�n4t"�|�I|j'�|��tjd�|j)d�||_d|_d|_||_||_d|_tjd
��tj6j8�d�tj6j8��|_tj6j=|j2j>�jAdd�jAdd�|_!tdkDr tjd|jB�tEjFdd|jBz��|_$|jHjKd|jL�i|_'i|_(g|_)i|_*i|_+i|_,i|_-i|_.i|_/i|_0i|_1i|_2i|_3i|_4i|_5i|_6i|_7i|_8i|_9d|_:d|_;tx|_=i|_>d|_?|j2j�j�d�|_B|j�r,t�|j�j��dk(�|_Bntjd�d|_B|j2j�j�d�|_E|j�r,t�|j�j��dk(�|_Entjd�d|_E|j2j�j�d�|_F|j��|j�dk(r*|j2j�j�d�|_F|j��d|_F|j�d k(rd!|_F|j�d"k(rd#|_F|j�d$k(rd%|_F|j2j�j�d&�|_Gd'|_Ht�j�|jHj�d(��|_L|j�dkrd|_L|j�d)kDrd)|_L|j�at�j�|jHj�d*��}|��|j2j�j�d+�rL|j2j�j�d+�j��dk(}tjd,�ntjd-�|�.t�j�|jHj�d*��}||_Nt�j�|jHj�d.��}|�y|j2j�j�d/�r&|j2j�j�d/�}n.t�j�|jHj�d.��}||_Ot�|j��dkDr|j�d|_Ot�j�|jHj�d0��}|�y|j2j�j�d1�r&|j2j�j�d1�}n.t�j�|jHj�d0��}||_Qt�|j��dkDr|j�d|_Qt�j�|jHj�d2��}|��|j2j�j�d3�rL|j2j�j�d3�j��dk(}tjd4�n.t�j�|jHj�d2��}||_Rt|j2j�j�d5��|_Sd6|_Tt�j�|jHj�d7��|_Ud|_V|j�r3t�j�|jHj�d8��|_Vt�j�|jHj�d9��|_Wd|_Xd|_Yt�j�|jHj�d:��|_Z|j�t�j�|jHj�d;��d�<�d|_\d|_]d|_^d|__d|_`d|_ad|_bd|_cddg|_dt�j�|jHj�d=��t�j�|jHj�d>��g|_d|j�d�h|j2j�j�d?�rC|j2j�j�d?�j��dk(|j�d<|j�d�;t�j�|jHj�d>��|j�d<ddg|_et�j�|jHj�d@��t�j�|jHj�dA��g|_e|j�d�h|j2j�j�dB�rC|j2j�j�dB�j��dk(|j�d<|j�d�;t�j�|jHj�dA��|j�d<t�j�|jHj�dC��}	|	��|j2j�j�dD�r7|j2j�j�dD�j��dk(}	n.t�j�|jHj�dC��}	|	|_ft�j�|jHj�dE��|_gt�j�|jHj�dF��}
|
��|j2j�j�dG�rL|j2j�j�dG�j��dk(}
tjdH�n.t�j�|jHj�dF��}
|
|_ht�j�|jHj�dI��}|��|j2j�j�dJ�rL|j2j�j�dJ�j��dk(}tjdK�n.t�j�|jHj�dI��}||_id|_jd|_kd|_ld|_mg|_ng|_og|_pg|_qd|_rt�|j2j�j�dL��|_tt�j�|jHj�dM��|_ut�j�|jHj�dN��}|� t�j�|j2�}ntdkDrtjdO|�||_wt�j�|jHj�dF��|_h|j��`|j2j�j�dG��;|j2j�j�dG�j��dk(|_h|j��3t�j�|jHj�dF��|_hi|_xt�j�|jH|j2�|_xt�j�|jHj�dP��|_{t�ddQ�D]4}
|j�dR|
dzzr�t�|
|j��|_{nt�j�|jHj�dP��}|�||_{t�j�|jHj�dS��}|�|j2j��}||_t�j�|jHj�dT��}|si}|�j|d�<�t�j�|jHj�dU��}|r|�jdd�<�|�j�|_�ddVdW�t	dX��t	dY�dZ�dd[d\�t	d]��t	d^�dZ�d_d`da�t	db��t	dc�dZ�dddedf�t	dg��t	dh�dZ�didjdk�t	dl��t	dm�dZ�dn�|_+do�t	dp��t	dq��t|j|dr�|jVds�|_*|j2�jrAddtdu�t	dv��t	dw�dZ�dd!d!dxdy�t	dz��t	d{�d|�d}�|_-nXdd~|j�zdu�t	d��t	d��dZ�dd�|j�zd��t	d���t	d��dZ�d}�|_-d��t	d���t	d���t|j|d��|jZds�|_,dd�d��t	d���t	d��dZ�dd�d��t	d���t	d��dZ�d��|_/d��t	d���t	d���t|j|d��|j^ds�|_.dd�d��t	d���t	d��dZ�dd�d��t	d���t	d��dZ�d��|_1d��t	d���t	d���t|j|d��|jbds�|_0dd�d��t	d���t	d��dZ�dd�d��t	d���t	d��dZ�d��|_3d��t	d���t	d���t|j|d��|jfds�|_2dd�d��t	d���t	d��dZ�dd�d��t	d���t	d��dZ�d��|_5d��t	d���t	d���t|j|d��|jjds�|_4dd�d��t	d���t	d��dZ�dd�d��t	d���t	d��dZ�d��|_7d��t	d���t	d«�t|j|d��|jnds�|_6dd�dŐt	dƫ�t	dǫdZ�dd�dɐt	d��t	dʫdZ�d˜|_9d̐t	dͫ�t	dΫ�t|j|d��|jrds�|_8|�j�d|_��t�j�|_��t|_��t|_�|�j��t!�j"d|�j$�|_�|jKd�|�j(�tjdѫy#t
tf$rtd�aY���wxYw)�N�IBUS_TABLE_DEBUG_LEVELrr0z4TabEngine.__init__(bus=%s, obj_path=%s, database=%s)zibus version = %s�.�has_focus_idT)�
connection�object_pathrUzThis ibus version has focus id.)rVrWz+This ibus version does *not* have focus id.�IBUS_TABLE_LOCATION�iconsz.db�� rzself._engine_name = %sz!org.freedesktop.ibus.engine.tablez&/org/freedesktop/ibus/engine/table/%s/)�schema�path�changed�pinyin_mode�truezNWe could not find "pinyin_mode" entry in database, is it an outdated database?F�suggestion_modezRWe could not find "suggestion_mode" entry in database, is it an outdated database?�symbol�
status_prompt�CNu中�YauЯ�YiuЇ�valid_input_charszabcdefghijklmnopqrstuvwxyz!@#$%�
debuglevel��
dynamicadjust�dynamic_adjustz)Got "dynamic_adjust" entry from database.zPCould not find "dynamic_adjust" entry from database, is it an outdated database?�singlewildcardchar�single_wildcard_char�multiwildcardchar�multi_wildcard_char�autowildcard�
auto_wildcardz(Got "auto_wildcard" entry from database.�max_key_length��rememberinputmode�	inputmode�soundbackend�
errorsound�errorsoundfile��update_gsettings�endeffullwidthletter�tabdeffullwidthletter�def_full_width_letter�endeffullwidthpunct�tabdeffullwidthpunct�def_full_width_punct�
autocommit�auto_commit�commitinvalidmode�
autoselect�auto_selectz&Got "auto_select" entry from database.�alwaysshowlookup�always_show_lookupz-Got "always_show_lookup" entry from database.�char_prompts�onechar�chinesemodez(Chinese mode found in Gsettings, mode=%s�lookuptablepagesize�
�commit_candidate_%s�lookuptableorientation�keybindings�	darkthemeu簡zsc-mode.svgzSimplified Chineseu(Switch to “Simplified Chinese only”.)�numberrb�icon�label�tooltipu繁ztc-mode.svgzTraditional Chineseu)Switch to “Traditional Chinese only”.r4u簡/大zscb-mode.svgzSimplified Chinese firstu6Switch to “Simplified Chinese before traditional”.�u繁/大ztcb-mode.svgzTraditional Chinese firstu6Switch to “Traditional Chinese before simplified”.r=u大zcb-mode.svgzAll Chinese charactersu'Switch to “All Chinese characters”.)zChineseMode.SimplifiedzChineseMode.TraditionalzChineseMode.SimplifiedFirstzChineseMode.TraditionalFirstzChineseMode.All�ChineseModezChinese modezSwitch Chinese mode�switch_to_next_chinese_mode)�keyr�r��
shortcut_hint�sub_propertiesu英zenglish.svg�EnglishzSwitch to English inputu拼音zchinese.svg�ChinesezSwitch to Chinese input)r�rb�symbol_table�
symbol_pinyinr�r�r�)zInputMode.Direct�InputMode.Tableu☐�DirectzSwitch to direct inputu☑zibus-table.svg�TablezSwitch to table input�	InputModez
Input modezSwitch Input mode�toggle_input_mode_on_offu◑zhalf-letter.svg�HalfzSwitch to halfwidth lettersu●zfull-letter.svg�FullzSwitch to fullwidth letters)zLetterWidth.HalfzLetterWidth.Full�LetterWidthzLetter widthzSwitch letter width�toggle_letter_widthz,.zhalf-punct.svgzSwitch to halfwidth punctuationu、。zfull-punct.svgzSwitch to fullwidth punctuation)zPunctuationWidth.HalfzPunctuationWidth.Full�PunctuationWidthzPunctuation widthzSwitch punctuation width�toggle_punctuation_widthu
☐ 拼音ztab-mode.svgzSwitch to table modeu
☑ 拼音zpy-mode.svg�PinyinzSwitch to pinyin mode)zPinyinMode.TablezPinyinMode.Pinyin�
PinyinModezPinyin modezSwitch pinyin mode�toggle_pinyin_modeu
☐ 联想zSuggestion disabledzSwitch to suggestion modeu
☑ 联想zSuggestion enabled)zSuggestionMode.DisabledzSuggestionMode.Enabled�SuggestionModezSuggestion modezSwitch suggestion mode�toggle_suggestion_modeu☐ 1z
phrase.svgzMultiple character matchz.Switch to matching multiple characters at onceu☑ 1zonechar.svgzSingle character matchz)Switch to matching only single characters)zOneCharMode.PhrasezOneCharMode.OneChar�OneCharModezOnechar modezSwitch onechar mode�toggle_onechar_modeu☐ ↑zncommit.svg�Normalz�Switch to normal commit mode (automatic commits go into the preedit instead of into the application. This enables automatic definitions of new shortcuts)u☑ ↑zacommit.svgzQSwitch to direct commit mode (automatic commits go directly into the application))zAutoCommitMode.DirectzAutoCommitMode.Normal�AutoCommitModezAuto commit modezSwitch autocommit mode�toggle_autocommit_modezprocess-key-eventz6********** Initialized and ready for input: **********)��int�str�os�getenv�DEBUG_LEVEL�	TypeError�
ValueError�LOGGER�debug�info�join�map�IBUS_VERSION�hasattrr�Engine�props�super�__init__�get_connection�add_table_by_locale�
_unit_test�_input_purpose�_input_hints�_busrP�
_setup_pidr]�sep�	_icon_dir�basename�filename�replace�_engine_namer�Settings�
_gsettings�connect�on_gsettings_value_changed�
_prop_dict�_sub_props_dict�main_prop_list�chinese_mode_menu�chinese_mode_properties�input_mode_menu�input_mode_properties�letter_width_menu�letter_width_properties�punctuation_width_menu�punctuation_width_properties�pinyin_mode_menu�pinyin_mode_properties�suggestion_mode_menu�suggestion_mode_properties�onechar_mode_menu�onechar_mode_properties�autocommit_mode_menu�autocommit_mode_properties�_setup_property�
_im_clientr-�theme�_keybindings�_hotkeys�ime_properties�get�_ime_pyr!�lower�_ime_sg�_symbol�_valid_input_chars�_pinyin_valid_input_chars�it_util�variant_to_value�	get_value�_debug_level�get_user_value�_dynamic_adjust�_single_wildcard_char�len�_multi_wildcard_char�_auto_wildcard�_max_key_length�_max_key_length_pinyin�_remember_input_mode�_input_mode�_sound_backend�_error_sound_object�_error_sound_file�_error_sound�set_error_sound_file�	_prev_key�
_prev_char�_double_quotation_state�_single_quotation_state�_prefix�_py_mode�_sg_mode�_sg_mode_active�_full_width_letter�_full_width_punct�_auto_commit�_commit_invalid_mode�_auto_select�_always_show_lookup�_chars_valid�_chars_invalid�#_chars_valid_update_candidates_last�%_chars_invalid_update_candidates_last�_candidates�_candidates_previous�_u_chars�_strings�_cursor_precommit�eval�_prompt_characters�_onechar�get_default_chinese_mode�
_chinese_mode�_default_keybindings�get_default_keybindings�get_default_value�
_page_size�range�min�get_orientation�_orientation�set_keybindings�set_dark_theme�get_new_lookup_table�
_lookup_tabler�repr�_is_chinese�_init_properties�_save_user_count�time�_save_user_start�SAVE_USER_COUNT_MAX�_save_user_count_max�SAVE_USER_TIMEOUT�_save_user_timeout�resetr�timeout_add_seconds�
_sync_user_db�sync_timeout_id� _TabEngine__do_process_key_event)�selfrNrOrPrQrkrmrorqr�r�r��chinese_mode�index�user_page_size�orientation�user_keybindings�use_dark_theme�	__class__s                  �rr�zTabEngine.__init__s����	!��c�"�)�)�,D�"E�F�G�K���?��L�L�F��X�x�
)�	���'����#�c�<�2H�)I�J��4�;�;�$�$�n�5��G���-�-�/�$�!�
�
#�
�K�K�9�:��G���-�-�/�$�
�
&�
�K�K�E�F�� � ��&�#���#$���!"�����	�!��
����')�y�y�1F�'G�')�w�w�{�{�G�R�W�W�[�[�J����G�G�,�,��M�M�"�"�$�$+�G�E�2�$6�w�w�s�C�7H�	
����?��L�L�(�$�*;�*;�
=�),���6�9�4�;L�;L�L�)N���	
�����	�4�+J�+J�K�46���9;���35���13���79��$�/1���57��"�13���79��$�68��#�<>��)�02���68��#�46��!�:<��'�13���79��$�46��!�:<��'�8<���!�����
�24���37��
��}�}�3�3�7�7�
�F����<�<����� 2� 2� 4�� ?�@�D�L��K�K�6�
7� �D�L��}�}�3�3�7�7�8I�J����<�<����� 2� 2� 4�� ?�@�D�L��K�K�.�
/�!�D�L��}�}�3�3�7�7��A����<�<��4�<�<�3�#6��=�=�7�7�;�;�O�L�D�L��<�<���D�L��<�<�5� �!�D�L�
�<�<�5� � �D�L��<�<�5� � �D�L�"&�-�-�">�">�"B�"B��#!���)K��&�!(�!9�!9��O�O�%�%�l�3�"5������q� � !�D�����s�"� #�D���'�'��)0�)A�)A��O�O�*�*�?�;�*=���!��}�}�+�+�/�/�0@�A�!%���!=�!=�!A�!A�$�"&�&+�e�g��"9�����G�H����2�3��!�$�5�5����)�)�/�:�<�N�%3���.5�.F�.F��O�O�*�*�+?�@�/B���'��}�}�+�+�/�/�0F�G�'+�}�}�'C�'C�'G�'G�*�(,�$�(/�'?�'?��O�O�-�-�.B�C�(E�$�*>��"��t�)�)�*�Q�.�)-�)C�)C�A�)F�D�&�-4�-E�-E��O�O�*�*�+>�?�.A���&��}�}�+�+�/�/�0E�F�&*�m�m�&B�&B�&F�&F�)�'+�#�'.�&>�&>��O�O�-�-�.A�B�'D�#�)<��!��t�(�(�)�A�-�(,�(A�(A�!�(D�D�%�(/�(@�(@��O�O�*�*�>�:�)<�
�� ��}�}�+�+�/�/��@� $�
�
� <� <� @� @�#�!%�%*�U�W��!8�
����F�G� '� 8� 8��O�O�-�-�n�=�!?�
�$1���"��M�M�(�(�,�,�-=�>� @���&'��#�*1�*B�*B��O�O�%�%�&9�:�+<��!�!"����$�$�&�7�7����)�)�+�6� 8�D��$+�#;�#;��O�O�%�%�n�5�$7���CG�� �&(���")�":�":��O�O�%�%�l�3�#5����!�!��$�$����)�)�*:�;�
=�"�	"�	$�6:���)-���',��$�',��$������
���
�$���9=�t�����$�$����)�)�*@�A�
C��$�$����.�.�/F�G�
I�#����"�"�1�%�-��}�}�+�+�/�/�0G�H�-1�]�]�-I�-I�-M�-M�+�.-�-2�U�W��.@��'�'��*��"�"�1�%�-�)0�)A�)A����)�)�*A�B�*D�D�#�#�A�&�9=�d�|����$�$����)�)�*?�@�
B��$�$����.�.�/E�F�
H�"����!�!�!�$�,��}�}�+�+�/�/�0F�G�,0�M�M�,H�,H�,L�,L�*�-,�,1�E�G�w�-?��&�&�q�)��!�!�!�$�,�(/�(@�(@����)�)�*@�A�)C�D�"�"�1�%�'.�&>�&>��O�O�*�*�<�8�':�����}�}�+�+�/�/�
�>�"�m�m�:�:�>�>�!�#�#(�5�7�g�6��&�6�6��O�O�-�-�l�;�=��"-���*1�)A�)A��O�O�%�%�&9�:�*<��!�'.�&>�&>��O�O�*�*�<�8�':�����}�}�+�+�/�/�
�>�"�m�m�:�:�>�>�!�#�#(�5�7�g�6�����D�E�%�6�6��O�O�-�-�l�;�=��"-���-4�-E�-E��O�O�*�*�+=�>�.@���%��}�}�+�+�/�/�0D�E�%)�]�]�%A�%A�%E�%E�(�&*�*/�%�'�W�&=�"����K�L�%,�%=�%=��O�O�-�-�.@�A�&C�"�);�� � ���!���36��0�58��2�=?���EG��!�
$&��
�4$&��
�"#���"&��M�M�(�(�,�,�^�<�#>���&�6�6��O�O�%�%�i�0�2��
�'.�&>�&>��O�O�*�*�=�9�';����"�;�;��
�
��L�
�1�_��L�L�:�L�
J�".���
$�4�4��O�O�*�*�<�8�:������$��}�}�+�+�/�/�
�>�J�$(�M�M�$@�$@�$D�$D�!�%#�#(�5�7�g�%6��!����$� '� 8� 8����)�)�,�7�!9�D��;=��!�$+�$C�$C��O�O�T�]�]�%,��!� '�7�7��O�O�-�-�.C�D� F����1�b�\�	�E��,�,�)�U�Q�Y�7�9�"%�e�T�_�_�"=����		�
)0�(@�(@��O�O�*�*�+@�A�)C���%�,�D�O�%,�%=�%=��O�O�*�*�+C�D�&F�����-�-�7�7�9�K�!,���"�3�3��O�O�*�*�=�9�;���!�����-���F� �1�1��O�O�*�*�;�7�9�������u��=�!�6�6�8�����%��/�0��<�=�'?���%��0�1��=�>�(@��#�&��5�6��J�K�,M��#�&��6�7��J�K�-M���%��3�4��F�G�
 I�W6(
��$�p!��~�&��.�/�!��!�!�"?�@�B�"�:�:�
"
����=�=�$�$� �#�)��y�\� �!:�;�%=� �#�$)�%-�)��y�\� �!:�;�$=�*�D�&�& �#�d�l�l�2�)��x�[� �!9�:�%<� �#�d�l�l�2�,��w�Z� �!8�9�$;�
*�D�&�&��|�_��,�-�!��!�!�"<�=�?�"�8�8�
 
�����)��6���:�;�!=���)��6���:�;�!=�
(
��$�!��~�&��.�/�!��!�!�"7�8�:�"�:�:�
"
�����(��6���>�?�&A��"�(��6���>�?�&A�
-
��)�&��*�+��3�4�!��!�!�"<�=�?�"�?�?�
'
��#��&�&��7���3�4�!6��&�%��8���4�5�"7�
'
��#� ��}�%��-�.�!��!�!�"6�7�9�"�9�9�
!
����&�&��0�1��8�9�(;��&�&��/�0��8�9�';�
+
��'�$��(�)��1�2�!��!�!�":�;�=�"�=�=�
%
��!��!�$��5�6��B�C�
#E��!�%��3�4��=�>�
$@�(
��$�"!��~�&��.�/�!��!�!�"7�8�:�"�:�:�
"
����#�%��8���K�L�
	&M��#�%��8���K�L�
&M�+
��'�*$��)�*��1�2�!��!�!�":�;�=�"�=�=�
%
��!�	
���� !��� $�	�	����$7��!�"3����
�
��&�:�:�
�t�!�!� #���	
���(�$�*E�*E�F����D�	F��w�:�&�	!��a�&�K�	!�s�'Ac�cAc)�c(Ac)c�n�tj�}|j�|j|j�|j|j�|jd�|jd�tdd�D]�}d}|jd|dzzrb|jd|dzzd}tj|�}|}|jr'|jjd�s|j}|j!tj"j%|����|S)z(
        Get a new lookup table
        Trr�rZr�r0�KP_)r�LookupTable�clear�
set_page_sizer)�set_orientationr-�set_cursor_visible�	set_roundr*r�r��keybinding_to_keyevent�unicode�name�
startswith�append_label�Text�new_from_string)rA�lookup_tablerCr��
keybindingr�s      rr0zTabEngine.get_new_lookup_table�s���'�'�)�������"�"�4�?�?�3��$�$�T�%6�%6�7��'�'��-����t�$��1�b�\�		H�E��E�� � �!6�%�!�)�!D�E�!�.�.�)�U�Q�Y�7�9�9:�<�
��4�4�Z�@��"���;�;�s�x�x�':�':�5�'A��K�K�E��%�%�d�i�i�&?�&?��&F�G�		H��rc���tdkDrtjd�|j�g|_g|_d|_d|_d|_|j�y)uH
        Clear all input, whether committed to preëdit or not.
        r0zclear_all_input_and_preedit()rrZFN)
r�r�r��$clear_input_not_committed_to_preeditrrr rr�update_candidates�rAs r�clear_all_input_and_preeditz%TabEngine.clear_all_input_and_preedit�sU����?��L�L�8�9��1�1�3���
���
�!"������$������ rc�:�|j|jzdk(S)ukChecks whether the preëdit is empty

        Returns True if the preëdit is empty, False if not.
        rZ�rrr]s r�is_emptyzTabEngine.is_empty�s ��
� � �4�#6�#6�6�#�=�=rc��tdkDrtjd�d|_d|_d|_d|_|jj�|jjd�g|_
g|_y)uO
        Clear the input which has not yet been committed to preëdit.
        r0z&clear_input_not_committed_to_preedit()rZTN)r�r�r�rrrrr1rLrOrrr]s rr[z.TabEngine.clear_input_not_committed_to_preedit�sn����?��L�L�A�B����!���36��0�58��2���� � �"����-�-�d�3����$&��!rr?c�d�|jsh|js(||j|jz|jzvs4|jr>||j
|jz|jzvr|xj|z
c_n|xj|z
c_|j�}|S)u�
        Add input character and update candidates.

        Returns “True” if candidates were found, “False” if not.
        )rrr�r�r�r�rr\)rAr?�ress   r�	add_inputzTabEngine.add_input�s���
����
�
���0�0��5�5�6��4�4�5�5��M�M���7�7��5�5�6��4�4�5�5�
���4�'������%���$�$�&���
rc���d}|jr$|jd}|jdd|_n�|jr�|jd}|jdd|_|jsv|jrj|jj|jdz
�|_|j
j|jdz
�|xjdzc_|j
�|S)z'remove and display last input char heldrZ���Nr0)rrr�popr rr\)rA�last_input_chars  r�	pop_inputzTabEngine.pop_inputs��������"�1�1�"�5�O�"&�"5�"5�c�r�":�D��
�
�
�"�/�/��3�O� $� 1� 1�#�2� 6�D���%�%�4�=�=�$(�M�M�$5�$5��*�*�Q�.�%0��!��
�
�!�!�$�"8�"8�1�"<�=��&�&�!�+�&���� ��rc�4�|j|jzS)z&get characters held, valid and invalidr`r]s r�get_input_charszTabEngine.get_input_charss��� � �4�#6�#6�6�6rrC�index_in_phrasec��|j|d|}|j||d}|jj|�|jj|�|jj||jj|��|jj||�|jj|dz|jj|��|jj|dz|�y)Nr0)rrrh�insertrP�parse_phrase)rArCrm�head�tails     r�"split_strings_committed_to_preeditz,TabEngine.split_strings_committed_to_preedits����}�}�U�#�$4�_�5���}�}�U�#�O�$4�5���
�
���%� ��
�
���%� ��
�
���U�D�M�M�$>�$>�t�$D�E��
�
���U�D�)��
�
���U�1�W�d�m�m�&@�&@��&F�G��
�
���U�1�W�d�+rc��|jry|j�r|j�|jsy|jdkry|j
|jd|_|j|jd|_d|_y)uRemove preëdit left of cursorNr)rrl�commit_to_preeditrr rr]s r�remove_preedit_before_cursorz&TabEngine.remove_preedit_before_cursor s{���������!��"�"�$��}�}���!�!�Q�&���
�
�d�&<�&<�&=�>��
��
�
�d�&<�&<�&=�>��
�!"��rc�j�|jry|j�r|j�|jsy|jt|j�k\ry|jd|j|_|jd|j|_t|j�|_y)uRemove preëdit right of cursorN)rrlrurr r�rr]s r�remove_preedit_after_cursorz%TabEngine.remove_preedit_after_cursor.s����������!��"�"�$��}�}���!�!�S����%7�7���
�
�&=�t�'=�'=�>��
��
�
�&=�t�'=�'=�>��
�!$�T�]�]�!3��rc��|jry|j�r|j�|jsy|jdkry|xjdzc_|j
j
|j�|_|jj
|j�|j�y)u>Remove character before cursor in strings comitted to preëditNr0)	rrlrurr rrhrr\r]s r�&remove_preedit_character_before_cursorz0TabEngine.remove_preedit_character_before_cursor<s����������!��"�"�$��}�}���!�!�A�%�����!�#�� �M�M�-�-�d�.D�.D�E����
�
���$�0�0�1���� rc�X�|jry|j�r|j�|jsy|jt|j�dz
kDry|jj|j�|jj|j�y)u>Remove character after cursor in strings committed to preëditNr0)rrlrurr r�rrhr]s r�%remove_preedit_character_after_cursorz/TabEngine.remove_preedit_character_after_cursorKs���������!��"�"�$��}�}���!�!�C��
�
�$6��$:�:���
�
���$�0�0�1��
�
���$�0�0�1r.c��d}d}d}|j�r|j�}|jrDt|jd|j�}t|j|jd�}|||fS)uLReturns the tabkeys which were used to type the parts
        of the preëdit string.

        Such as “(left_of_current_edit, current_edit, right_of_current_edit)”

        “left_of_current_edit” and “right_of_current_edit” are
        strings of tabkeys which have been typed to get the phrases
        which have already been committed to preëdit, but not
        “really” committed yet. “current_edit” is the string of
        tabkeys of the part of the preëdit string which is not
        committed at all.

        For example, the return value could look like:

        (('gggg', 'aahw'), 'adwu', ('ijgl', 'jbus'))

        See also get_preedit_string_parts() which might return something
        like

        (('王', '工具'), '其', ('漫画', '最新'))

        when the wubi-jidian86 table is used.
        rrZN)rlr�tupler �rA�left_of_current_edit�current_edit�right_of_current_edits    r�get_preedit_tabkeys_partsz#TabEngine.get_preedit_tabkeys_partsXs���213����13�����!��/�/�1�L��=�=�#(��
�
�5�t�5�5�6�$8� �$)��
�
�d�4�4�5�6�%8�!�$�l�4I�J�Jrc�v�|j�\}}}dj|�|zdj|�zS)uhReturns the tabkeys which belong to the parts of the preëdit
        string as a single string
        rZ)r�r�)rA�left_tabkeys�current_tabkeys�
right_tabkeyss    r�get_preedit_tabkeys_completez&TabEngine.get_preedit_tabkeys_complete}sG���8�8�:�	��	�	����,�'�"�#��8�8�M�*�+�	,rc�x�d}d}d}|jr4|jt|jj��d}n |j	�r|j	�}|j
rDt
|j
d|j�}t
|j
|jd�}|||fS)u�Returns the phrases which are parts of the preëdit string.

        Such as “(left_of_current_edit, current_edit, right_of_current_edit)”

        “left_of_current_edit” and “right_of_current_edit” are
        tuples of strings which have already been committed to preëdit, but not
        “really” committed yet. “current_edit” is the phrase in the part of the
        preëdit string which is not yet committed at all.

        For example, the return value could look like:

        (('王', '工具'), '其', ('漫画', '最新'))

        See also get_preedit_tabkeys_parts() which might return something
        like

        (('gggg', 'aahw'), 'adwu', ('ijgl', 'jbus'))

        when the wubi-jidian86 table is used.
        rrZr0N)rr�r1�get_cursor_posrlrr~r rs    r�get_preedit_string_partsz"TabEngine.get_preedit_string_parts�s���,13����13������+�+��D�&�&�5�5�7�8�:�:;�=�L�
�
!�
!�
#��/�/�1�L��=�=�#(��
�
�5�t�5�5�6�$8� �$)��
�
�d�4�4�5�6�%8�!�$�l�4I�J�Jrc��|jr@|jr3|jt|jj	��dSy|j�\}}}dj
|�|zdj
|�zS)u_Returns the phrases which are parts of the preëdit string as a
        single string

        rrZ)rrr�r1r�r�r�)rA�left_strings�current_string�
right_stringss    r�get_preedit_string_completez%TabEngine.get_preedit_string_complete�s���
�������'�'���*�*�9�9�;�<�>�>?�A�A���7�7�9�	��	�	�����&� �!��(�(�=�)�*�	+rc�d�d}|jr8|jr,|jd|jD]}|t|�z
}�|jrA|t|jt	|j
j
��d�z
}|S|t|j��z
}|S)u%Get caret position in preëdit stringrNr0)r rr�rr�r1r�rl)rA�caret�parts   r�	get_caretzTabEngine.get_caret�s������!�!�d�m�m��
�
�&=�t�'=�'=�>�
#����T��"��
#�����S�� � ��T�%7�%7�%F�%F�%H�!I�J�1�M�O�
O�E���
�S��-�-�/�0�0�E��rc�r�|jry|j�r|j�|jsy|jdkryt|j|jdz
�dkr|xjdzc_n|j
|jdz
d�|j�y)u(Move cursor left in the preëdit string.Nrr0rg�rrlrurr r�rsr\r]s r�
arrow_leftzTabEngine.arrow_left�s����������!��"�"�$��}�}���!�!�Q�&���t�}�}�T�3�3�A�5�6�7�1�<��"�"�a�'�"��3�3��&�&�q�(�"�
.���� rc��|jry|j�r|j�|jsy|jt|j�k\ry|xjdz
c_t|j|jdz
�dkDr|j
|jdz
d�|j�y)u)Move cursor right in the preëdit string.Nr0r�r]s r�arrow_rightzTabEngine.arrow_right�s����������!��"�"�$��}�}���!�!�S����%7�7�����!�#���t�}�}�T�3�3�A�5�6�7�!�;��3�3��&�&�q�(�!�
-���� rc��|jry|j�r|j�|jsyd|_|j�y)u4Move cursor to the beginning of the preëdit string.Nr)rrlrurr r\r]s r�control_arrow_leftzTabEngine.control_arrow_left�sD���������!��"�"�$��}�}��!"������ rc���|jry|j�r|j�|jsyt	|j�|_|j
�y)u-Move cursor to the end of the preëdit stringN)rrlrurr�r r\r]s r�control_arrow_rightzTabEngine.control_arrow_right�sM���������!��"�"�$��}�}��!$�T�]�]�!3������ r�tabkeys�phrase�freq�	user_freqc	�V�|jdk(sJ�tdkDrtjd||||�|r|sy|j}|j
}|r||jvs|r||jvr|}nR|j}tj|�}tjd|z|�}	|	r||	j�d}n|}tdkDr"tjd||j|�d}
|js1d}|D](}||jvr||j|z
}�$||z
}�*|}|dz|z}
|
r|
dz|
z}
tj�}|jtj |j"d	d
t%|
���|d
kr=|jtj |j"dd
t%|���n~|d
kDr=|jtj |j"dd
t%|���n<|jtj |j"d
d
t%|���td
kDrsdt'|�zdzt'|�z}|
|z
}
|jtj |j"dt%|
�t%|�z
t%|
���tj(j+|
�}d
}|j-|��t|j-|�}|j/|j1�|j3�|j5�|j7��|dz
}|j-|���t|j8j;|�|j8j=d�y)z&append table candidate to lookup tabler0�)tabkeys=%s phrase=%s freq=%s user_freq=%sN�^�3remaining_tabkeys=%s self._chars_valid=%s phrase=%srZr[�   r$rr&r%r'r(T)rr�r�r�r�r�r�re�escape�match�endrr"r�AttrList�append�attr_foreground_newr�r�r�rVrWr��append_attribute�
get_attr_typer��get_start_index�
get_end_indexr1�append_candidaterO)rAr�r�r�r��mwild�swild�remaining_tabkeys�regexpr��
table_code�remaining_tabkeys_newr?r$�attrsr(�text�i�attrs                   r�append_table_candidatez TabEngine.append_table_candidatese�����1�$�$�$���?��L�L�;����y�
2��f���)�)���*�*��
�u�� 1� 1�1��e�t�'8�'8�8� '���&�&�F��Y�Y�v�&�F��H�H�T�F�]�G�4�E��$+�E�I�I�K�L�$9�!�%,�!���?��L�L�1�!�4�#4�#4�f�
>��
��}�}�$'�!�)�
2���4�2�2�2�)�T�-D�-D�T�-J�J�)�)�T�1�)�	
2�
!6���$��):�:���+�f�4�z�A�N��
�
���
���T�-�-��J�J�'�(�!�S��-@�B�	C��!�8��L�L��(�(��J�J�}�-�q�#�f�+�?�
@���]��L�L��1�1��
�
�?�+�Q��F��=�
>�
�L�L��1�1��
�
�1�2�A�s�6�{�D�
E���?���D�	�)�D�0�3�y�>�A�J��j�(�N��L�L��1�1��
�
�<�(��N�#�c�*�o�5��N�#�%�
&��y�y�(�(��8��
���i�i��l�&��9�9�Q�<�D��!�!�$�"4�"4�"6�"&�.�.�"2�"&�"6�"6�"8�"&�"4�"4�"6�
8�
��F�A�
�i�i��l�&�	
���+�+�D�1����-�-�d�3r�asc_table_codesc�^�g}d}d}	tt|��D]�}t|�}||}|dz
}d}|dk\r�||}	t|	�}|dz
}|dkDrh|	|}
|j|
d�rD||dz
k(r|	j|||
ddzf�n ||f|||
ddzfg}|j|�n|dz}|dkDr�h|dkDrn|dz}|dk\r��|dk(s��||f||dfg}|j|���|D�cgc]}|d��	}
}t	|
d�d��}
|
D�
cgc]}
|
d��	}}
|Scc}wcc}
w)Nrgr0rr4c�B�t|d�dzt|d�zS)Nr4rLr0�r�)�ns rrz9TabEngine.get_common_prefix_sorted_list.<locals>.<lambda>�s��S��1��Y��^�c�!�A�$�i�%?�rT)r��reverse)r*r�rTr��sorted)r��prefix_tree�idx�count�code_idx�branch_countrE�
branch_idx�node_idx�
prefix_branch�node�
new_branch�branch�nodes�	idx_arrays               r�get_common_prefix_sorted_listz'TabEngine.get_common_prefix_sorted_list]s���35������	��c�/�2�3�&	/�H��{�+�L�"�8�,�D�%��)�J��H���/� +�J� 7�
�"�=�1��'�!�+����l�(��2�D����t�A�w�/�#�|�a�'7�7�)�0�0�$��$�q�'�A�+�1N�O�,6�x�*@�4��SW�XY�SZ�]^�S^�B_�)`�J�'�.�.�z�:��!�A�
����l�"�a�<���!�O�J�5��/�8�1�}�)�8�4�t�X�q�6I�J�
��"�"�:�.�M&	/�R+6�6�����6��6��u�?�#�%��*/�/��T�!�W�/�	�/����7��0s�4D%�D*�sorted_idx_listc�X�|jdk(r|D]}||d}|dvr�|cS|dS)Nzerbi-qsr)r��u�v)r�)rAr�r�r��
first_chars     r� select_best_idx_from_prefix_listz*TabEngine.select_best_idx_from_prefix_list�sK�����	�)�$�
��,�Q�/��2�
���0���H�
��q�!�!rc	�N�|jdk(sJ�|jsJ�tdkDrtj	d||||�|r|sy|j
}t
j|�}t
jd|z|�}|r||j�d}n|}tdkDr"tj	d||j
|�d}|jjr�|jr�|jdd�jd	d
�jdd�jd
d�jdd�}|jj|�}	|	r(|j|	�}
|j|	|
�}|	|}d}|D](}
|
|j vr||j |
z
}�$||
z
}�*|}|dz|z}|r|dz|z}t#j$�}|j't#j(|j*ddt-|���|j't#j(|j*ddt-|���tdkDrsdt/|�zdzt/|�z}||z
}|j't#j(|j*dt-|�t-|�z
t-|���t"j0j3|�}d}|j5|��t|j5|�}|j7|j9�|j;�|j=�|j?��|dz
}|j5|���t|j@jC|�|j@jEd�y)z'append pinyin candidate to lookup tabler0r�Nr�r�rZ�!u↑1�@u↑2�#u↑3�$u↑4�%u↑5r[r�r$rr%r(T)#rrr�r�r�rr�r�r�r�rPr3r��find_zi_coder�r�r"rr�r�r�r�r�r�rVrWr�r�r�r�r�r�r1r�rO)rAr�r�r�r�r�r�r�r��possible_table_codesr�r��table_code_newr?r$r�r(r�r�r�s                    r�append_pinyin_candidatez!TabEngine.append_pinyin_candidate�sk�����1�$�$�$��}�}��}���?��L�L�;����y�
2��f���"�"�����6�"������f��g�.��� '��	�	��� 5��!(����?��L�L�1�!�4�#4�#4�f�
>�
�
��=�=�$�$���� 1� 9� 9��V�!�$�W���!�!(���V�"%�%,�W���&)�)0�� #�V�*-�	
�$$(�=�=�#=�#=�f�#E� �#� �>�>�?S�T�	��;�;�<P�R[�\��1�#�6�
� �N�"�
+���4�2�2�2�"�d�&=�&=�d�&C�C�N�"�d�*�N�	
+�
(�J��$��):�:���+�f�4�z�A�N��
�
���
���T�-�-��J�J�'�(�!�S��-@�B�	C�	���T�-�-��J�J��'��C��K�9�	:���?���D�	�)�D�0�3�y�>�A�J��j�(�N��L�L��1�1��
�
�<�(��N�#�c�*�o�5��N�#�%�
&��y�y�(�(��8��
���i�i��l�&��9�9�Q�<�D��!�!�$�"4�"4�"6�"&�.�.�"2�"&�"6�"6�"8�"&�"4�"4�"6�
8�
��F�A�
�i�i��l�&�	
���+�+�D�1����-�-�d�3r�prefixc	��|jdk(sJ�|jsJ�tdkDrtj	d||||�|r|sy|j|�sy|}t
j�}|jt
j|jddt|���|jt
j|jddt|���tdkDrsdt|�zdzt|�z}||z
}|jt
j|jdt|�t|�z
t|���tjj|�}d}	|j|	��t|j|	�}
|j!|
j#�|
j%�|
j'�|
j)��|	dz
}	|j|	���t|j*j-|�|j*j/d	�y)
z+append suggestion candidate to lookup tabler0r�Nr$rr%r[r(T)rrr�r�r�rTrr�r�r�r�r�r�rVrWr�r�r�r�r�r�r1r�rO)rAr�r�r�r�r$r�r(r�r�r�s           r�append_suggestion_candidatez%TabEngine.append_suggestion_candidates������1�$�$�$��}�}��}���?��L�L�;����i�
1��V��� � ��(�����
�
���
���T�-�-��J�J�'�(�!�S��-@�B�	C�	���T�-�-��J�J��'��C��K�9�	:���?���D�	�)�D�0�3�y�>�A�J��j�(�N��L�L��1�1��
�
�<�(��N�#�c�*�o�5��N�#�%�
&��y�y�(�(��8��
���i�i��l�&��9�9�Q�<�D��!�!�$�"4�"4�"6�"&�.�.�"2�"&�"6�"6�"8�"&�"4�"4�"6�
8�
��F�A�
�i�i��l�&�	
���+�+�D�1����-�-�d�3r�forcec
���tdkDrltjd|j|j|j
|j|j|jj|j�|sS|jsG|j|j
k(r.|j|jk(rt|j�S|j|_|j|_|jj�|jjd�|js1|js|jsg|_|j|_y|jso|j"rc|jj$rM|jj'|j|j(|j*|j,��|_n�|jsn|jj/|j|j0|j(|j*|j,|j2|j4��|_nE|jr7|j6r+|jj9|j:�|_nJ�|js�|j|j*|j,fvr�|j}|j}t=|�r'|j>drtA|�}n2tC|�}n&|jDdrtA|�}ntC|�}|jjGd||ddf�|jr"|jI�|j|_y|jrX|xj|jd	z
c_|jd
d	|_|j|_|j|_y)u�
        Searches for candidates and updates the lookuptable.

        :param force: Force update candidates even if no change to input

        Returns “True” if candidates were found and “False” if not.
        r0z�self._chars_valid=%s self._chars_invalid=%s self._chars_valid_update_candidates_last=%s self._chars_invalid_update_candidates_last=%s self._candidates=%s self.database.startchars=%s self._strings=%sTF)r�rBrmro)r�r�rBrmrorqrkriʚ;rgN)%r�r�r�rrrrrrP�
startcharsrrr!r1rLrOrrr3�#select_chinese_characters_by_pinyinr%r�r��select_wordsr#rr�r�select_suggestion_candidaterr"rrIrKrro�fill_lookup_table)rAr��wildcard_key�wildcard_phrases    rr\zTabEngine.update_candidatesAsL����?��L�L�#��!�!��#�#��8�8��:�:�� � ��
�
�(�(��
�
�
��d�2�2�����!I�!I�I����4�#M�#M�M���(�(�)�)�37�3D�3D��0�59�5H�5H��2���� � �"����-�-�d�3��#�#��"�"�$�*;�*;�#%�� �,0�,<�,<��)���$�$��
�
��
�
�)�)��
�
�A�A� �-�-�!%�!3�!3�)-�)C�)C�(,�(A�(A�	B�C�
���%�%�#�}�}�9�9��)�)��
�
�!�/�/�%)�%?�%?�$(�$=�$=�"�1�1�#�3�3� :� 5�D���
!�
!�d�m�m�#�}�}�H�H���� �D��
�5��#�#��!�!��.�.��0I�0I�J�K�#�0�0��"&�"3�"3�� ��.��-�-�a�0�*>��*O��*>��*O���.�.�q�1�*>��*O��*>��*O��� � �'�'���o�q�*�E�G�����"�"�$�(,�(8�(8�D�%��������4�#4�#4�R�#8�8�� $� 1� 1�#�2� 6�D��7;�7H�7H�D�4�9=�9L�9L�D�6�rc�8�|js
|jsy|j�rT|js�|j|j�d}|jj|j|j|j�d�|jj|j|�||_n�|jr�|j|j�d}|t|j�d}|jj|jd�|jj|j|�d|_d|_nJ�|xjdz
c_|j�|j�y)u6Add selected phrase in lookup table to preëdit stringFr0rNrZT)rrrr�rror rrr�r[r\)rAr�s  rruzTabEngine.commit_to_preedit�s\���#�#��$�$������'�'��)�)�$�*=�*=�*?�@��C���
�
�$�$��*�*��$�$�T�%8�%8�%:�;�A�>�@��
�
�$�$��*�*�F�4�%����%�%��)�)�$�*=�*=�*?�@��C����D�L�L� 1� 2�3���
�
�$�$�T�%;�%;�%(�*��
�
�$�$�T�%;�%;�%+�-�"���',��$��u��"�"�a�'�"��1�1�3���� �rc��|jj�}|jj�}||z
}||z}|t|j�k\ry|jj|�|j
�S)u�
        Commits the candidate at position “index” in the current
        page of the lookup table to the preëdit. Does not yet “really”
        commit the candidate, only to the preëdit.
        F)r1r��get_cursor_in_pager�r�set_cursor_posru)rArC�
cursor_pos�cursor_in_page�current_page_start�
real_indexs      r�commit_to_preedit_current_pagez(TabEngine.commit_to_preedit_current_page�sz���'�'�6�6�8�
��+�+�>�>�@��'�.�8��'�%�/�
���T�-�-�.�.�����)�)�*�5��%�%�'�'rc���|j�}|�r;|}tdkDr�|jr�|j�\}}}|j	�\}}}d}tdt
|��D]}	|d||	zdz||	zdzz
}�||z
}tdt
|��D]}	|d||	zdz||	zdzz
}�|jrT|jdd	�jd
d�jdd
�jdd�jdd�}|Sd}
|D](}||jvr|
|j|z
}
�$|
|z
}
�*|
}|Sd}|jr{|jt
|j�k\r|jdd}n|j|jd}dj|jj|��}dj|j�}|jjr/t
|�dkDr!|d|jj!|�zz
}d}
|D](}||jvr|
|j|z
}
�$|
|z
}
�*|
S)zGet aux stringsrrZ�(r[z) z (�)r��1r��2r��3r��4r��5rgr0z	#: )rlr�rr�r�r*r�rr�r"rr r�rPr��user_can_define_phraserp)
rA�input_chars�
aux_string�tabkeys_left�dummy_tabkeys_current�
tabkeys_right�strings_left�dummy_string_current�
strings_rightr��aux_string_newr?�cstrs
             r�get_aux_stringszTabEngine.get_aux_strings�s����*�*�,���$�J��Q��4�=�=�#'�"@�"@�"B� ��&��#'�"?�"?�"A� ��%�� �
��q�#�l�"3�4�!�A���&�q�/�*�,0�1�2>�q�/�B�� �!�J�!�
�k�)�
��q�#�m�"4�5� �A���'��*�+�+/�0�0=�a�0@�A��� �J� �
�}�}�'�/�/����%�g��S�"�")�'���#&�&-�g� #�S�'*�*1�'�$'��+.�	���"%��&�/�D��t�6�6�6�&�$�*A�*A�$�*G�G��&�$�.��	/�
,�
����
��=�=��%�%��T�]�]�);�;��}�}�R�(��+���}�}�T�%;�%;�<�Q�?�����4�=�=�#=�#=�d�#C�D�J��x�x��
�
�&���=�=�/�/��4�y�1�}��x�$�-�-�*D�*D�T�*J�J�K�
����	'�D��t�.�.�.��$�"9�"9�$�"?�?���$�&��		'�
�rc	��|jj�}|jj�}|jj�|z|k\�r|t	|j
�kr�||z}|j
||}|D]�}|jr:|js.|js"|j|d|d|d|d���I|jr:|jr.|js"|j|d|d|d|d����|jr:|jr.|j|j|dt|d�����J�yyy)z�Fill more entries to self._lookup_table if needed.

        If the cursor in _lookup_table moved beyond current length,
        add more entries from _candidiate[0] to _lookup_table.rr0r4r�)r�r�r�r�)r�r�r�N)r1�get_number_of_candidates�
get_page_sizer�r�rrrrr�r�r�rr�)rA�looklen�psize�endpos�batch�	candidates      rr�zTabEngine.fill_lookup_table%sg���$�$�=�=�?���"�"�0�0�2�����-�-�/�%�7�7�B��#�d�.�.�/�/��u�_�F��$�$�W�V�4�E�"�
!�	��$�$� �M�M�$�2F�2F��/�/� )�!��(��|�&�q�\�"+�A�,�	0�0�
�&�&��-�-��0D�0D��0�0� )�!��(��|�&�q�\�"+�A�,�	1�0�
�%�%�$�*>�*>��4�4�#�|�|�(��|� ��1��.�5�0�
!�5�+
!�0�
Crc��|j�t|jj��}|s
|jry|S)zBProcess Arrow Down Key Event
        Move Lookup Table cursor downT)r�r!r1�cursor_downr�rArds  rrzTabEngine.cursor_downHs<��	
��� ��4�%�%�1�1�3�4���t�'�'���
rc�j�t|jj��}|s
|jry|S)z>Process Arrow Up Key Event
        Move Lookup Table cursor upT)r!r1�	cursor_uprrs  rrzTabEngine.cursor_upRs0���4�%�%�/�/�1�2���t�'�'���
rc��|j�t|jj��}|s
|jry|S)z?Process Page Down Key Event
        Move Lookup Table page downT)r�r!r1�	page_downrrs  rrzTabEngine.page_downZs<��	
��� ��4�%�%�/�/�1�2���t�'�'���
rc�j�t|jj��}|s
|jry|S)z;Process Page Up Key Event
        move Lookup Table page upT)r!r1�page_uprrs  rrzTabEngine.page_upcs0���4�%�%�-�-�/�0���t�'�'���
rc��tdkDrtjd|�|jj	�}|jj�}||z
}||z}t
|j�|kDrR|j|}|jj|d|dd��d|_
d|_|j�yy)u5Remove the candidate shown at index in the lookup table
        from the user database.

        If that candidate is not in the user database at all, nothing
        happens.

        If this is a candidate which is also in the system database,
        removing it from the user database only means that its user
        frequency data is reset. It might still appear in subsequent
        matches but with much lower priority.

        If this is a candidate which is user defined and not in the system
        database, it will not match at all anymore after removing it.

        :param index: The index in the current page of the lookup table.
                      The topmost candidate has the index 0 (and usually the
                      label “1”)
        :return: True if successful, False if not
        r0zindex=%srT)r�r��commitrZF)
r�r�r�r1r�r�r�rrP�
remove_phraserrr\)rArCr�r�r�r�rs       r�#remove_candidate_from_user_databasez-TabEngine.remove_candidate_from_user_databaseks���(��?��L�L��U�+��'�'�6�6�8�
��+�+�>�>�@��'�.�8��'�%�/�
��t��� �:�-��(�(��4�I��M�M�'�'�!�!��Y�q�\�$�
(�
H�8;�D�4�9<�D�6��"�"�$��rc�H�t|jj��S)z get lookup table cursor position)r�r1r�r]s rr�zTabEngine.get_cursor_pos�s���4�%�%�4�4�6�7�7rc��|jS)zGet lookup table)r1r]s r�get_lookup_tablezTabEngine.get_lookup_table�s���!�!�!rc��tdkDrtjd�|j�r|j	�y|j�y)zProcess remove_char Key Eventr0z
remove_char()N)r�r�r�rlrjrzr]s r�remove_charzTabEngine.remove_char�s:����?��L�L��)����!��N�N����3�3�5rc�F�|j�ry|j�y)zProcess delete Key EventN)rlr|r]s r�deletezTabEngine.delete�s�����!���2�2�4rc�(�t|j�}|dkDrx|jj�}|jj	�}t||z�}|dz
}||dz|zk\s||k\r||z}|jj
|�yy)z+Cycle cursor to next candidate in the page.rr0TF)r�rr1rr�r�r��rA�total�	page_size�pos�pages     r�%select_next_candidate_in_current_pagez/TabEngine.select_next_candidate_in_current_page�s����D�$�$�%���1�9��*�*�8�8�:�I��$�$�3�3�5�C��s�9�}�%�D��1�H�C��t�A�v�y�(�(�C�5�L��9�n�����-�-�c�2��rc�B�t|j�}|dkDr�|jj�}|jj	�}t||z�}|dz}|||zks|dkrt
|dz|zdz
|�}|jj|�yy)z/Cycle cursor to previous candidate in the page.rr0TF)r�rr1rr�r�r+r�r)s     r�)select_previous_candidate_in_current_pagez3TabEngine.select_previous_candidate_in_current_page�s����D�$�$�%���1�9��*�*�8�8�:�I��$�$�3�3�5�C��s�9�}�%�D��1�H�C��T�)�^�#�s�Q�w��D�1�H�	�1�Q�6��>�����-�-�c�2��rc�2�t|j�dk(S)z*Return true if there is only one candidater0)r�rr]s r�
one_candidatezTabEngine.one_candidate�s���4�#�#�$��)�)rc�n�|j�d|_d|_d|_|j	�y)u6Clear the preëdit and close the lookup table
        FN)r^rr
r
�
_update_uir]s rr<zTabEngine.reset�s1��	
�(�(�*�',��$�',��$�������rc�,��|jdkDr&tj|j�d|_|j�|j	�|j
dkDr!|jj�d|_t�|�%�y)z3Called when this input engine is destroyed
        rN)
r?r�
source_remover<�do_focus_outr5rP�
sync_usrdbr��destroy)rArHs �r�
do_destroyzTabEngine.do_destroy�st������!�#��!�!�$�"6�"6�7�#$�D� ��
�
������� � �1�$��M�M�$�$�&�$%�D�!�
���r�debug_levelrzc�,�tdkDrtjd||�||jk(ryd|cxkrdkrYny||_|a|j	�|r:|j
j
dtjj|��yyy)a�Sets the debug level

        :param debug_level: The debug level (>= 0 and <= 255)
        :param update_gsettings: Whether to write the change to Gsettings.
                                 Set this to False if this method is
                                 called because the Gsettings key changed
                                 to avoid endless loops when the Gsettings
                                 key is changed twice in a short time.
        r0�(%s, update_gsettings = %s)Nrrirh)
r�r�r�r�r<r��	set_valuer�Variant�	new_int32)rAr;rzs   r�set_debug_levelzTabEngine.set_debug_level�s�����?��L�L�-�{�<L�
N��$�+�+�+����"�s�"� +�D��%�K��J�J�L�����)�)� ��L�L�*�*�;�7�9� �	#rc��|jS)zReturns the current debug level)r�r]s r�get_debug_levelzTabEngine.get_debug_level����� � � rrkc��tdkDrtjd||�||jk(ry||_|jj�|r:|jjdtjj|��yy)aSets whether dynamic adjustment of the candidates is used.

        :param dynamic_adjust: True if dynamic adjustment is used, False if not
        :param update_gsettings: Whether to write the change to Gsettings.
                                 Set this to False if this method is
                                 called because the Gsettings key changed
                                 to avoid endless loops when the Gsettings
                                 key is changed twice in a short time.
        r0r=Nrj)r�r�r�r�rP�reset_phrases_cacher�r>rr?�new_boolean)rArkrzs   r�set_dynamic_adjustzTabEngine.set_dynamic_adjustsz����?��L�L�-�� 0�
2��T�1�1�1��-����
�
�)�)�+���O�O�%�%�����(�(��8�
:�rc��|jS)z=Returns whether dynamic adjustment of the candidates is used.)r�r]s r�get_dynamic_adjustzTabEngine.get_dynamic_adjusts���#�#�#r�error_soundc���tdkDrtjd||�||jk(ry||_|r:|jjdtjj|��yy)a�Sets whether a sound is played on error or not

        :param error_sound: True if a sound is played on error, False if not
        :param update_gsettings: Whether to write the change to Gsettings.
                                 Set this to False if this method is
                                 called because the Gsettings key changed
                                 to avoid endless loops when the Gsettings
                                 key is changed twice in a short time.
        r0r=Nrw)	r�r�r�rr�r>rr?rG)rArKrzs   r�set_error_soundzTabEngine.set_error_soundsh����?��L�L�-�{�<L�
N��$�+�+�+��'�����O�O�%�%�����(�(��5�
7�rc��|jS)z1Returns whether a sound is played on error or not)rr]s r�get_error_soundzTabEngine.get_error_sound3rDrr]c�n�tdkDrtjd||�||jk(ry||_|r9|jjdtjj|��tjtjj|�|j��|_y)aSets the path of the .wav file containing the sound
        to play on error.

        :param path: The path of the .wav file containing the error sound
        :param update_gsettings: Whether to write the change to Gsettings.
                                 Set this to False if this method is
                                 called because the dconf key changed
                                 to avoid endless loops when the dconf
                                 key is changed twice in a short time.
        r0r=Nrx��
audio_backend)r�r�r�rr�r>rr?�
new_string�it_sound�SoundObjectr�r]�
expanduserrr)rAr]rzs   rr	zTabEngine.set_error_sound_file7s�����?��L�L�-�t�5E�
G��4�)�)�)��!%�����O�O�%�%� ����'�'��-�
/�$,�#7�#7��G�G���t�$��-�-�$/�� rc��|jS)zN
        Return the path of the .wav file containing the error sound.
        )rr]s r�get_error_sound_filezTabEngine.get_error_sound_fileQs���%�%�%r�
sound_backendc��tdkDrtjd||�t|t�sy||j
k(ry||_|r9|jjdtjj|��tjtjj|j �|j
��|_y)a�Sets the sound backend to use

        :param sound_backend: The name of sound backend to use
        :param update_gsettings: Whether to write the change to Gsettings.
                                 Set this to False if this method is
                                 called because the dconf key changed
                                 to avoid endless loops when the dconf
                                 key is changed twice in a short time.
        r0r=NrvrQ)r�r�r��
isinstancer�rr�r>rr?rSrTrUr�r]rVrr)rArYrzs   r�set_sound_backendzTabEngine.set_sound_backendWs�����?��L�L�-�}�>N�
P��-��-���D�/�/�/��+�����O�O�%�%�����'�'�
�6�
8�$,�#7�#7��G�G���t�5�5�6��-�-�$/�� rc��|jS)zE
        Return the name of the currently used sound backend
        )rr]s r�get_sound_backendzTabEngine.get_sound_backendts���"�"�"rr�c
��tdkDrtjd||�t|t�sytj|�}tj|j�|_tj|j|�tj|j�|_|j�|_|j�r�|j r%t#|jd�|j d<|j$r%t#|jd�|j$d<|j&r%t#|jd�|j&d<|j(r%t#|jd�|j(d<|j*r%t#|jd	�|j*d<|j,r%t#|jd
�|j,d<|j.r%t#|jd�|j.d<|j0r%t#|jd�|j0d<|j3�|r�t5j6t5j8d
i��}t;|j�D]}t4j8j=t5j>d�|j|D�cgc]!}t4j8jA|���#c}�}|jC||���|jDjGd|jI��yycc}w)a�Set current key bindings

        :param keybindings: The key bindings to use
        :param update_gsettings: Whether to write the change to Gsettings.
                                 Set this to False if this method is
                                 called because the Gsettings key changed
                                 to avoid endless loops when the Gsettings
                                 key is changed twice in a short time.
        r0r=Nr�r�r�r�r�r�r�r�r�za{sv}�sr�)%r�r�r�r[�dict�copy�deepcopyr&r�r��dict_update_existing_keys�HotKeysr�r0r1r�r�r2r�r�r�r�r�r�r�r4r�VariantDictr?r��	new_array�VariantTyperS�insert_valuer�r>r�)rAr�rz�variant_dict�command�x�
variant_arrays       rr.zTabEngine.set_keybindingszs�����?��L�L�-�{�<L�
N��+�t�,���m�m�K�0�� �M�M�$�*C�*C�D����)�)�$�*;�*;�[�I�����(9�(9�:��
�"�6�6�8����?�?��%�%���*�*�+H�I�J��&�&��7��#�#���*�*�+E�F�G��$�$�_�5��%�%���*�*�+@�A�B��&�&��7��*�*���*�*�+E�F�G��+�+�O�<��$�$���*�*�+?�@�A��%�%�o�6��(�(���*�*�+C�D�E��)�)�/�:��%�%���*�*�+@�A�B��&�&��7��(�(���*�*�+C�D�E��)�)�/�:��!�!�#���+�+�D�L�L��"�,E�F�L�!�$�"3�"3�4�
B�� $��� 6� 6��$�$�S�)�"�/�/��8�:���\�\�,�,�Q�/�:�!;�
��)�)�'�=�A�
B�
�O�O�%�%��� � �"�
$���
:s�*&Mc�6�|jj�S)zGet current key bindings)r�rbr]s r�get_keybindingszTabEngine.get_keybindings�s��� � �%�%�'�'r�
input_modec���||jk(ry||_|rC|jjdtjj|j��|j
|j|j�|j
|j|j|j�|j
|j|j|j�|j�y)z�Sets whether direct input or the current table is used.

        :param input_mode: Whether to use direct input.
                           0: Use direct input.
                           1: Use the current table.
        Nru)
rr�r>rr?r@�_init_or_update_property_menur�r�rr�rr<)rArprzs   r�set_input_modezTabEngine.set_input_mode�s�����)�)�)��%�����O�O�%�%�����&�&�t�'7�'7�8�
:�	
�*�*�� � ����	�	
�*�*��"�"��#�#�D�$4�$4�5�	7�	
�*�*��'�'��"�"�4�#3�#3�4�	6�	
�
�
�r�remember_input_modec���tjd||�t|�}||jk(ry||_|r:|jjdtjj|��yy)aiSets whether the input mode (direct or table) is remembered

        :param remember_input_mode: Whether to remember the input mode.
                                    False: Do not remember
                                    True:  Remember.
        :param update_gsettings: Whether to write the change to Gsettings.
                                 Set this to False if this method is
                                 called because the Gsettings key changed
                                 to avoid endless loops when the Gsettings
                                 key is changed twice in a short time.
        r=Nrt)	r�r�r!rr�r>rr?rG)rArtrzs   r�set_remember_input_modez!TabEngine.set_remember_input_mode�so��	���)�+>�@P�	R�"�#6�7���$�";�";�;��$7��!���O�O�%�%�#����(�(�)<�=�
?�rc��|jS)z>
        Return whether the input mode is remembered.
        )rr]s r�get_remember_input_modez!TabEngine.get_remember_input_mode	s���(�(�(rrGc���|rt}nt}||jur||_|j�|r:|jjdtjj|��yy)z"Set theme to dark theme on requestr�N)	r.r-r�r4r�r>rr?rG)rArGrzr�s    rr/zTabEngine.set_dark_theme	s]��
��E��E���
�
�"��D�J��O�O����O�O�%�%�����(�(��8�
:�rc��|jS)zQ
        Return the current input mode, direct input: 0, table input: 1.
        )rr]s r�get_input_modezTabEngine.get_input_mode	s�����r�modec�~�|jsy||jk(ry||_|j|j|�|r#|jdd|jdd<n"|jdd|jdd<|j|j
|j�|j�y)z�Sets whether Pinyin is used.

        :param mode: Whether to use Pinyin.
                     True: Use Pinyin.
                     False: Use the current table.
        :type mode: Boolean
        Nr�r�rbr�)r�rrrr�r�r�rr4�rAr|s  r�set_pinyin_modezTabEngine.set_pinyin_mode 	s����|�|���4�=�=� ����
��*�*��!�!�4�	)���*�*�+<�=�o�N�
�&�&�'8�9�(�C��*�*�+<�=�n�M�
�&�&�'8�9�(�C��*�*�� � ����	�	
���rc��|jS)zReturn the current pinyin mode)rr]s r�get_pinyin_modezTabEngine.get_pinyin_mode;	����}�}�rc���|jsy||jk(ry|j�||_|j|j|�|j�y)z�Sets whether Suggestion is used.

        :param mode: Whether to use Suggestion.
                     True: Use Suggestion.
                     False: Not use Suggestion.
        N)r�rrurrr�r4r~s  r�set_suggestion_modezTabEngine.set_suggestion_mode?	sS���|�|���4�=�=� ����� ���
��*�*��%�%�t�	-����rc��|jS)z"Return the current suggestion mode)rr]s r�get_suggestion_modezTabEngine.get_suggestion_modeP	r�rc��||jk(ry||_|j|j|�|jj	�|r:|j
j
dtjj|��yy)a�Sets whether only single characters should be matched in
        the database.

        :param mode: Whether only single characters should be matched.
                     True: Match only single characters.
                     False: Possibly match multiple characters at once.
        :param update_gsettings: Whether to write the change to Gsettings.
                                 Set this to False if this method is
                                 called because the dconf key changed
                                 to avoid endless loops when the dconf
                                 key is changed twice in a short time.
        Nr�)
r#rrr�rPrFr�r>rr?rG�rAr|rzs   r�set_onechar_modezTabEngine.set_onechar_modeT	sr���4�=�=� ����
��*�*��"�"�D�	*��
�
�)�)�+���O�O�%�%�����(�(��.�
0�rc��|jS)zU
        Returns whether only single characters are matched in the database.
        )r#r]s r�get_onechar_modezTabEngine.get_onechar_modem	s���}�}�rc���||jk(ry||_|j|j|�|r:|jj	dt
jj|��yy)u�Sets whether automatic commits go into the preëdit or into the
        application.

        :param mode: Whether automatic commits  go into the  preëdit
                     or into the application.
                     True: Into the application.
                     False: Into the preëdit.
        :param update_gsettings: Whether to write the change to Gsettings.
                                 Set this to False if this method is
                                 called because the dconf key changed
                                 to avoid endless loops when the dconf
                                 key is changed twice in a short time.
        Nr�)rrrr�r�r>rr?rGr�s   r�set_autocommit_modezTabEngine.set_autocommit_modes	se���4�$�$�$�� ����*�*��%�%�t�	-���O�O�%�%�����(�(��.�
0�rc��|jS)z$Returns the current auto-commit mode)rr]s r�get_autocommit_modezTabEngine.get_autocommit_mode�	rDrc���tdkDrtjd|�||jk(ry||_|r:|jjdtjj|��yy)a�Sets the commit invalid mode

        This selects what is committed when a character which is not
        in the set of valid input characters for the current table is
        typed.

        0 means to commit the current candidate
        1 means to commit the raw characters typed so far

        :param mode:             The mode (0 <= mode <= 1)
        :param update_gsettings: Whether to write the change to Gsettings.
                                 Set this to False if this method is
                                 called because the dconf key changed
                                 to avoid endless loops when the dconf
                                 key is changed twice in a short time.
        r0�mode=%sNr�)	r�r�r�rr�r>rr?r@r�s   r�set_commit_invalid_modez!TabEngine.set_commit_invalid_mode�	sa��$��?��L�L��D�)��4�,�,�,��$(��!���O�O�%�%�#����&�&�t�,�
.�rc��|jS)z&Return the current comimt invalid mode)rr]s r�get_commit_invalid_modez!TabEngine.get_commit_invalid_mode�	s���(�(�(rc��||jk(ry||_|r:|jjdtjj|��yy)aRSets whether the first candidate will be selected
        automatically during typing.

        :param mode: Whether to select the first candidate automatically.
        :type mode: Boolean
        :param update_gsettings: Whether to write the change to Gsettings.
                                 Set this to False if this method is
                                 called because the dconf key changed
                                 to avoid endless loops when the dconf
                                 key is changed twice in a short time.
        :type update_gsettings: Boolean
        Nr�)rr�r>rr?rGr�s   r�set_autoselect_modezTabEngine.set_autoselect_mode�	sL���4�$�$�$�� �����O�O�%�%�����(�(��.�
0�rc��|jS)z$Returns the current auto-select mode)rr]s r�get_autoselect_modezTabEngine.get_autoselect_mode�	rDrc���||jk(ry||_|jj�|r:|jj	dt
jj|��yy)a�Sets whether a wildcard should be automatically appended
        to the input.

        :param mode: Whether to append a wildcard automatically.
        :param update_gsettings: Whether to write the change to Gsettings.
                                 Set this to False if this method is
                                 called because the dconf key changed
                                 to avoid endless loops when the dconf
                                 key is changed twice in a short time.
        Nrp)rrPrFr�r>rr?rGr�s   r�set_autowildcard_modezTabEngine.set_autowildcard_mode�	s\���4�&�&�&��"����
�
�)�)�+���O�O�%�%�����(�(��.�
0�rc��|jS)z,Returns the  current automatic wildcard mode)rr]s r�get_autowildcard_modezTabEngine.get_autowildcard_mode�	s���"�"�"rc���||jk(ry||_|jj�|r:|jj	dt
jj|��yy)a�Sets the single wildchard character.

        :param char: The character to use as a single wildcard
                     (String  of length 1).
        :param update_gsettings: Whether to write the change to Gsettings.
                                 Set this to False if this method is
                                 called because the dconf key changed
                                 to avoid endless loops when the dconf
                                 key is changed twice in a short time.
        Nrl)r�rPrFr�r>rr?rS�rAr?rzs   r�set_single_wildcard_charz"TabEngine.set_single_wildcard_char�	s\���4�-�-�-��%)��"��
�
�)�)�+���O�O�%�%�$����'�'��-�
/�rc��|jS)zj
        Return the character currently used as a single wildcard.

        (String of length 1.)
        )r�r]s r�get_single_wildcard_charz"TabEngine.get_single_wildcard_char�	s���)�)�)rc��t|�dkDr|d}||jk(ry||_|jj�|r:|jjdtjj|��yy)a�Sets the multi wildchard character.

        :param char: The character to use as a multi wildcard.
                     (String  of length 1.)
        :param update_gsettings: Whether to write the change to Gsettings.
                                 Set this to False if this method is
                                 called because the dconf key changed
                                 to avoid endless loops when the dconf
                                 key is changed twice in a short time.
        r0rNrn)	r�r�rPrFr�r>rr?rSr�s   r�set_multi_wildcard_charz!TabEngine.set_multi_wildcard_char
sp���t�9�q�=���7�D��4�,�,�,��$(��!��
�
�)�)�+���O�O�%�%�#����'�'��-�
/�rc��|jS)zh
        Return the character currently used as a multi wildcard.
        (String of length 1.)
        )r�r]s r�get_multi_wildcard_charz!TabEngine.get_multi_wildcard_char
s��
�(�(�(rc��||jk(ry||_|r:|jjdtjj|��yy)a4Sets the whether the lookup table is shown.

        :param mode: Whether to show the lookup table.
                     True: Lookup table is shown
                     False: Lookup table is hidden
        :param update_gsettings: Whether to write the change to Gsettings.
                                 Set this to False if this method is
                                 called because the dconf key changed
                                 to avoid endless loops when the dconf
                                 key is changed twice in a short time.
        Nr�)rr�r>rr?rGr�s   r�set_always_show_lookupz TabEngine.set_always_show_lookup
sL���4�+�+�+��#'�� ���O�O�%�%�"����(�(��.�
0�rc��|jS)z3Returns whether the lookup table is shown or hidden)rr]s r�get_always_show_lookupz TabEngine.get_always_show_lookup3
s���'�'�'rrEc�<�tdkDrtjd|�||jk(ryd|cxkrdkrbny||_|jj|�|r:|jjdtjj|��yyy)a�Sets the orientation of the lookup table

        :param orientation: The orientation of the lookup table
                            0 <= orientation <= 2
                            IBUS_ORIENTATION_HORIZONTAL = 0,
                            IBUS_ORIENTATION_VERTICAL   = 1,
                            IBUS_ORIENTATION_SYSTEM     = 2.
        :param update_gsettings: Whether to write the change to Gsettings.
                                 Set this to False if this method is
                                 called because the dconf key changed
                                 to avoid endless loops when the dconf
                                 key is changed twice in a short time.
        r0zorientation(%s)Nrr4r�)r�r�r�r-r1rNr�r>rr?r@)rArErzs   r�set_lookup_table_orientationz&TabEngine.set_lookup_table_orientation7
s�����?��L�L�*�K�8��$�+�+�+���� �q� � +�D�����.�.�{�;�����)�)�,��L�L�*�*�;�7�9� �!rc��|jS)z3Returns the current orientation of the lookup table)r-r]s r�get_lookup_table_orientationz&TabEngine.get_lookup_table_orientationR
rDrr+c��tdkDrtjd|�||jk(ryt	dd�D]%}|j
d|dzzr�t
||�}n|dkrd}||_|j�|_|j�|r:|jjdtjj|��yy)aSets the page size of the lookup table

        :param page_size: The page size of the lookup table
                          1 <= page size <= number of select keys
        :param update_gsettings: Whether to write the change to Gsettings.
                                 Set this to False if this method is
                                 called because the dconf key changed
                                 to avoid endless loops when the dconf
                                 key is changed twice in a short time.
        r0zpage_size=%sNr�r�r�)r�r�r�r)r*r&r+r0r1r<r�r>rr?r@)rAr+rzrCs    rrMzTabEngine.set_page_sizeV
s�����?��L�L���3�����'���1�b�\�	�E��,�,�)�U�Q�Y�7�9���y�1�	��		�
�q�=��I�#���!�6�6�8����
�
����O�O�%�%�%����&�&�y�1�
3�rc��|jS)z1Returns the current page size of the lookup table)r)r]s rrzTabEngine.get_page_sizev
s�����rc��||j|k(ry||j|<||jk(r|j|j|�|rv|r:|jjdtjj|��y|jjdtjj|��yy)as
        Sets whether full width letters should be used.

        :param mode: Whether to use full width letters
        :param input_mode: The input mode (direct input: 0, table: 1)
                           for which to set the full width letter mode.
        :param update_gsettings: Whether to write the change to Gsettings.
                                 Set this to False if this method is
                                 called because the Gsettings key changed
                                 to avoid endless loops when the Gsettings
                                 key is changed twice in a short time.
        Nr|r{)	rrrrr�r�r>rr?rG�rAr|rprzs    r�set_letter_widthzTabEngine.set_letter_widthz
s���"�4�*�*�:�6�6��.2����
�+���)�)�)��.�.��&�&��
.������)�)�+��L�L�,�,�T�2�4����)�)�*��L�L�,�,�T�2�4�
rc��|jS)z>Return the current full width letter modes: [Boolean, Boolean])rr]s r�get_letter_widthzTabEngine.get_letter_width�
s���&�&�&rc��||j|k(ry||j|<||jk(r|j|j|�|rv|r:|jjdtjj|��y|jjdtjj|��yy)a�
        Sets whether full width punctuation should be used.

        :param mode: Whether to use full width punctuation
        :param input_mode: The input mode (direct input: 0, table: 1)
                           for which to set the full width punctuation mode.
        :param update_gsettings: Whether to write the change to Gsettings.
                                 Set this to False if this method is
                                 called because the Gsettings key changed
                                 to avoid endless loops when the Gsettings
                                 key is changed twice in a short time.
        Nrr~)	rrrrr�r�r>rr?rGr�s    r�set_punctuation_widthzTabEngine.set_punctuation_width�
s���"�4�)�)�*�5�5��-1����z�*���)�)�)��.�.��+�+�T�
3������)�)�*��L�L�,�,�T�2�4����)�)�)��L�L�,�,�T�2�4�
rc��|jS)zLReturn the current full width punctuation modes: [Boolean, Boolean]
        )rr]s r�get_punctuation_widthzTabEngine.get_punctuation_width�
s���%�%�%rc�T�tdkDrtjd|�||jk(ry||_|jj�|j
|j|�|r:|jjdtjj|��yy)a�Sets the candidate filter mode used for Chinese

        0 means to show simplified Chinese only
        1 means to show traditional Chinese only
        2 means to show all characters but show simplified Chinese first
        3 means to show all characters but show traditional Chinese first
        4 means to show all characters

        :param mode: The Chinese filter mode, 0 <= mode <= 4
        :param update_gsettings: Whether to write the change to Gsettings.
                                 Set this to False if this method is
                                 called because the dconf key changed
                                 to avoid endless loops when the dconf
                                 key is changed twice in a short time.
        r0r�Nr�)
r�r�r�r%rPrFrrr�r�r>rr?r@r�s   r�set_chinese_modezTabEngine.set_chinese_mode�
s���"��?��L�L��D�)��4�%�%�%��!����
�
�)�)�+��*�*��"�"�D�	*���O�O�%�%�����&�&�t�,�
.�rc��|jS)aN
        Return the current Chinese mode.

        0 means to show simplified Chinese only
        1 means to show traditional Chinese only
        2 means to show all characters but show simplified Chinese first
        3 means to show all characters but show traditional Chinese first
        4 means to show all characters
        )r%r]s r�get_chinese_modezTabEngine.get_chinese_mode�
s���!�!�!r�menu�current_modec
��tdkDr tjdt|�|�|sd}|d}|d}|D]D}||dt	|�k(s�||d}||d}d	|d
||dd�z}d
|d|dd�z}	�Fd}
|j|||��||jv�rtj|tjjtjj�tjj�tjj|j �tjj	�|
|
tj"j$|j&|��
|j|<|j(j+|j|�y|j|j-tjj��|j|j/tjj��|j|j1tjj|j ��|j|j3tjj	��|j|j5|
�|j|j7|
�|j9|j|�y)z;
        Initialize or update a ibus property menu
        r0zmenu=%s current_mode=%srr�r�r�rbr�z(%(label)s (%(symbol)s) %(shortcut_hint)sr�r�)r�rbr�z%(tooltip)s
%(shortcut_hint)sr�)r�r�T)r�)
r��	prop_typer�rbr�r��	sensitive�visible�state�	sub_propsN)r�r�r�r2r��_init_or_update_sub_propertiesr�r�Property�PropType�MENUrVrWr�r]r�r��	PropState�	UNCHECKEDr�r�r��	set_label�
set_symbol�set_icon�set_tooltip�
set_sensitive�set_visible�update_property)rAr�r��menu_key�sub_properties_dict�proprbr�r�r�r�s           rrrz'TabEngine._init_or_update_property_menu�
s�����?��L�L�)�4��:�|�
E���L���;��"�#3�4��'�
	<�D�"�4�(��2�c�,�6G�G�,�T�2�8�<��*�4�0��8��B�!�'�]�$�%)�/�%:�F<�<��;�#�I��%)�/�%:�><�<��
	<����+�+��)��	,�	F��4�?�?�*�(,�
�
���-�-�,�,��i�i�/�/��6��y�y�0�0��8��W�W�\�\�$�.�.�$�7��	�	�1�1�'�:�!���n�n�.�.��.�.�x�8�
):�D�O�O�H�%�
���&�&�t���x�'@�A��O�O�H�%�/�/��	�	�)�)�%�0�
2��O�O�H�%�0�0��	�	�)�)�&�1�
3��O�O�H�%�.�.������T�^�^�T�2�
4��O�O�H�%�1�1��	�	�)�)�'�2�
4��O�O�H�%�3�3�G�<��O�O�H�%�1�1�'�:�� � �����!:�;rr��modesc����||jvr$d}tj�|j|<nd}d}t��fd���D�]#}�|dt	|�k(rtj
j}ntj
j}�|d}d�|vr	�|d}	nd}	|s�tj|tjjtjj|�tjj�|d	�tjj|	�|||d
��	|j |<|j|j#|j |���6|j |j%tjj|��|j |j'tjj|	��|j |j)|�|j |j+|�|j |j-|�|j/|j |���&y
)zS
        Initialize or update the sub-properties of a property menu entry.
        FTc�&��t�|d�S)Nr�r�)rlr�s �rrz:TabEngine._init_or_update_sub_properties.<locals>.<lambda>3s����U�1�X�h�5G�1H�r)r�r�r�r�rZr�N)	r�r�r�r�r�r�r�r�r�)r�r�PropListr�r�r��CHECKEDr�r�r��RADIOrVrWr�r]r�r�r�r�r�r�r��	set_stater�)
rAr�r�r��updater�r|r�r�r�s
  `       rr�z(TabEngine._init_or_update_sub_properties%s�����4�/�/�/��F�-1�]�]�_�D� � ��*��F����5�&I�J�	<�D��T�{�8�$��L�(9�9����.�.�����0�0���$�K��(�E��E�$�K�'���+�i�0�����(,�
�
��"�m�m�1�1��)�)�3�3�E�:������e�D�k�&�&9�:� �I�I�5�5�g�>�%�#��"�	)$�����%��$�$�X�.�5�5��O�O�D�)�+�����%�/�/��I�I�-�-�e�4�6�����%�1�1��I�I�-�-�g�6�8�����%�3�3�G�<�����%�1�1�'�:�����%�/�/��6��$�$�T�_�_�T�%:�;�?	<rc
��i|_i|_tj�|_|j|j|j�|jjr5|jdk7r&|j|j|j�|jjrf|j|j|j|j�|j|j|j |j�|j"r&|j|j$|j&�|j(r&|j|j*|j,�|jjr&|j|j.|j0�|jj2r<|jj4r&|j|j6|j8�tj:dtj<j?tAd��dtj<j?tAd�d|jBiz�dd��|_"|jjG|jD�|jI|j�y	)
z4
        Initialize the ibus property menus
        rg�setup�Setupzgtk-preferencesu*Configure ibus-table “%(engine-name)s”zengine-nameT)r�r�r�r�r�r�N)%r�r�rr�r�rrr�rrPr3r%r��_is_cjkr�rr�rr�r�rr�r�rr�r#r�rulesr�rr�rVrWrr�r�r��register_propertiesr]s rr4zTabEngine._init_propertiesTs/�����!���"�m�m�o����*�*�� � ����	��=�=�$�$��);�);�r�)A��.�.��&�&��"�"�
$��=�=� � ��.�.��&�&��'�'��(8�(8�9�
;�
�.�.��+�+��&�&�t�'7�'7�8�
:��<�<��.�.��%�%��
�
�
��<�<��.�.��)�)��
�
�
��=�=� � ��.�.��&�&��
�
�
��=�=�/�/�D�M�M�4G�4G��.�.��)�)��!�!�
#� $�}�}���)�)�+�+�A�g�J�7�"��I�I�-�-��>�?� �$�"3�"3�4�5�6��� ���	
���"�"�4�#7�#7�8�� � ��!4�!4�5r�
ibus_property�
prop_statec���tdkDrtjd||�|dk(r|j�y|tj
jk7ry|j|jddz�r"|j|j|d�y|j|jddz�r7|jr+|jt|j|d��y|j|j ddz�r7|j"r+|j%t|j&|d��y|j|j(ddz�rA|j*j,r+|j/t|j0|d��y|j|j2ddz�rW|j*j4rA|j*j6r+|j9t|j:|d��y|j|j<ddz�rM|j*j,r7|j?t|j@|d�|jB��y|j|jDddz�rM|j*j,r7|jGt|jH|d�|jB��y|j|jJddz�rI|j*jLr2|jNd	k7r"|jQ|jR|d�yyyy)
z-
        Handle clicks on properties
        r0zibus_property=%s prop_state=%sr�Nr�rTr��rprg)*r�r�r��_start_setuprr�r�rTr�rsr�r�r�rr!r�r�r�r�r�r�rPr�r�r�r�rr�r�r�r�r�r�rr�r�r�r�r3r%r�r�)rAr�r�s   r�do_property_activatezTabEngine.do_property_activate�s#����?��L�L�0�-��
M��G�#����������/�/�/�
��#�#�D�$8�$8��$?��$C�D�����*�*�=�9�(�C�
E���$�$�T�%:�%:�5�%A�#�%E�F��L�L�� � ��T�0�0��?��I�J�
L���$�$�T�%>�%>�u�%E�c�%I�J��L�L��$�$��T�4�4�]�C�H�M�N�
P���$�$�T�%;�%;�E�%B�3�%F�G��M�M�)�)��!�!��T�1�1�-�@��J�K�
M���$�$�T�%>�%>�u�%E�c�%I�J��M�M�8�8��M�M�'�'��$�$��T�4�4�]�C�H�M�N�
P���$�$�T�%;�%;�E�%B�3�%F�G��M�M�)�)��!�!��T�1�1�-�@��J�K��+�+�
"�
-�
��$�$�T�%@�%@��%G��%K�L��M�M�)�)��&�&��T�6�6�!�#�#+�-�.��+�+�
'�
-�
��$�$�T�%;�%;�E�%B�3�%F�G��M�M�-�-��&�&�"�,��!�!��,�,�]�;�H�E�
G��-�.�
Hrc��|jdk7rHtj|jtj�\}}||jk7ryd|_tjjt
tjd��d�}tjtj|dd|jz�|_y)z@
        Start the setup tool if it is not running yet.
        rN�IBUS_TABLE_LIB_LOCATIONzibus-setup-tablez--engine-name table:%s)
r�r��waitpid�P_NOWAITr]r�r�r��spawnlr�)rA�pid�dummy_state�	setup_cmds    rr�zTabEngine._start_setup�s����?�?�a��!�z�z�$�/�/�2�;�;�G��C���d�o�o�%�
��D�O��G�G�L�L���	�	�3�4�5�� �	��)�)��K�K���$�d�&7�&7�7�	9��rc��|jr)|jr	|jj�yyy#tj	d�YyxYw)z+Play an error sound if enabled and possiblezPlaying error sound failed.N)rr�playr��	exceptionr]s r�_play_error_soundzTabEngine._play_error_sound�sJ������!9�!9�
@��(�(�-�-�/�":���
@�� � �!>�?�s	�7�Ac
���|jr|j�y|j�}dj|d�}|d}dj|d�}|jr=|js1d}|D](}||j
vr||j
|z
}�$||z
}�*|}||z|z}|sYtjj|tjjd�ddtjj�y|jd}|jd}	|jd	}
t
j�}|jt
j |dt#|���|jt
j |	t#|�t#|�zt#|���|j$rv|j'�|jt
j |
t#|�t#|�zt#|j$�z
t#|�t#|�z��|jt
j(tj*j,dt#|���tjj|�}d}
|j/|
��t|j/|
�}|j1|j3�|j5�|j7�|j9��|
dz
}
|j/|
���ttjj|||j;�d
tjj�y)zUpdate Preedit String in UINrZrr0r4Fr)r*r+T)r�hide_preedit_textr�r�rr"rr��update_preedit_text_with_moderVrW�PreeditFocusMode�COMMITr�r�r�r�r�rr��attr_underline_new�
AttrUnderline�SINGLEr�r�r�r�r�r�r�)rA�preedit_string_partsr�r�r��current_edit_newr?�preedit_string_complete�
color_left�color_right�
color_invalidr�r�r�r�s               r�_update_preeditzTabEngine._update_preedit�s������"�"�$��#�<�<�>��"�x�x�(<�Q�(?�@��+�A�.�� #���)=�a�)@� A�����D�$8�$8�"��$�
-���4�2�2�2�$��(?�(?��(E�E�$�$��,�$�	
-�
,�L� �<�/�2G�G�	 �&�
�K�K�5�5���	�	�)�)�"�-�q�%��%�%�,�,�
.�
��Z�Z��/�
��j�j��1���
�
�#4�5�
��
�
���
����$�$����(�)�
+�	,�
	����$�$���(�)�C��,=�=��+�,�
.�	/�
����"�"�$��L�L��(�(�!��,�-��L�0A�A��$�-�-�.�/��,�-��L�0A�A�	�
�	����#�#��"�"�)�)���+�,�
.�	/�
�y�y�(�(�)@�A��
���i�i��l�&��9�9�Q�<�D��!�!�$�"4�"4�"6�"&�.�.�"2�"&�"6�"6�"8�"&�"4�"4�"6�
8�
��F�A�
�i�i��l�&�	
���1�1���$�.�.�"�D�$�*?�*?�*F�*F�	Hrc	�|��|jry|j�}|jr=|d|jj	�dz|jj�fzz
}|�rBtdkDr |jsd|j��}||z
}tj�}|jtj|jddt|���tjj!|�}d}|j#|��t|j#|�}|j%|j'�|j)�|j+�|j-��|dz
}|j#|���td}|r|j.sd}t0�|�e||�y|j5�y)	zUpdate Aux String in UINz
 (%d / %d)r0ru🪟r,TF)rrrr1r�r
r�r�r�rr�r�r�r�r�rVrWr�r�r�r�r�r�rr��update_auxiliary_text�hide_auxiliary_text)	rAr�clientr�r�r�r�r�rHs	        �r�_update_auxzTabEngine._update_aux1s���������)�)�+�
�����-��"�"�1�1�3�Q�6��"�"�;�;�=�+?�?�
?�J���Q��t�������0�1���f�$�
��M�M�O�E��L�L��1�1��
�
�:�&��3�z�?�<�
=��9�9�,�,�Z�8�D��A��)�)�A�,�*��y�y��|���%�%�d�&8�&8�&:�&*�n�n�&6�&*�&:�&:�&<�&*�&8�&8�&:�<��Q���
�)�)�A�,�*��G��T�%=�%=����G�)�$��8��$�$�&rc�*�|js|j�y|jr-|js!|j	�r|j�y|j
s|j�y|j
|j�d�y)zUpdate Lookup Table in UINT)r�hide_lookup_tablerrrar�update_lookup_tabler#r]s r�_update_lookup_tablezTabEngine._update_lookup_tableRsv�����
�"�"�$�����D�$8�$8��}�}���&�&�(���'�'��"�"�$��� � ��!6�!6�!8�$�?rc�d�|j�|j�|j�y)zUpdate User InterfaceN)rrrr]s rr4zTabEngine._update_uihs&���!�!�#��������rc���|r|sy|jj|||j��|jdkrt	j�|_|xjdz
c_y)z3Check the given phrase and update save user db infoN)r�r�rkrr0)rP�check_phraser�r5r6r7)rAr�r�s   r�
_check_phrasezTabEngine._check_phrasens_���f���
�
�"�"����/�/�	#�	1�
� � �A�%�$(�I�I�K�D�!�����"�rc��|jdk\rstj�}||jz
}|j|jkDs||jk\r(|j
j
�d|_||_y)zSave user db to diskrT)r5r6r7r9r;rPr8)rA�now�
time_deltas   rr>zTabEngine._sync_user_db{sp��� � �A�%��)�)�+�C��t�4�4�4�J��%�%��(A�(A�A��$�"9�"9�9��
�
�(�(�*�()��%�(+��%�rc�8��tdkDrtjd|�|j�|j	�||_t�|�tjj|��|r|d|_nd|_|j||��y)u�
        Commit the string “phrase”, update the user database,
        and clear the preëdit.

        :param phrase: The text to commit
        :param tabkeys: The keys typed to produce this text
        r0z	phrase=%srgN)r�r�)
r�r�r�r^r4rr��commit_textrrVrWrr)rAr�r�rHs   �r�
commit_stringzTabEngine.commit_string�s{�����?��L�L��f�-��(�(�*��������
���D�I�I�5�5�f�=�>��$�R�j�D�O�"�D�O����7�6��:rc�^�tdkDr tjd|j�|jry|jr|j
r|j
�|j�s|j
�|j|j�|j���y)u�
        Commits the current input to the preëdit and then
        commits the preëdit to the application unless there are
        invalid input characters.

        Returns “True” if something was committed, “False” if not.
        r0zself._chars_invalid=%sF�r�T)r�r�r�rrrrurarr�r�r]s r� commit_everything_unless_invalidz*TabEngine.commit_everything_unless_invalid�s�����?��L�L�1��,�,�
.��������� 4� 4��"�"�$��}�}���"�"�$����4�;�;�=�#'�#D�#D�#F�	�	H�rc���ddddddddd	d
d�
}||j�vr|dvr||S|jr||S|d
k(r`|jrS|jj�r9|jr-t|jj�|jk(ry
y|dk(r |j|_|jryy|dk(r |j|_|jryyt|�S)z*Convert half width character to full widthu《u》u「u」u『u』u、u……u——u¥)
�<�>�[�]�{�}�\r�rr�)r!r�rr�rTu。�"u“u”�'u‘u’)
�keysrr�isdigitr
rC�valrr
rI)rAr?�special_punct_dicts   r�_convert_to_full_widthz TabEngine._convert_to_full_width�s��%+�$*�$*�$*�$*�$*�%+�$-�$-�$*�
���%�*�*�,�,��0�0�)�$�/�/����)�$�/�/��4�<�������/�/�1�����D�N�N�.�.�/�4�?�?�B����5�=�/3�/K�/K�+K�D�(��+�+����4�<�/3�/K�/K�+K�D�(��+�+���#�D�)�)r�_button�_statec���tdkDrtjd|||�|j|�r0|j	|j�|j
���yy)Nr0zindex=%s _button=%s state=%srTF)r�r�r�r�rr�r�)rArCr)r*s    r�do_candidate_clickedzTabEngine.do_candidate_clicked�s]����?��L�L�7����P��.�.�u�5�����0�0�2��9�9�;�
�
=��rc�$�|j�y)uzHandle hotkey for the command “setup”

        :return: True if the key was completely handled, False if not.
        T)r�r]s r�_command_setupzTabEngine._command_setup�s��
	
����rc��|j�s!|j�}|j|�|jt	|j
��y)u�Handle hotkey for the command “toggle_input_mode_on_off”

        :return: True if the key was completely handled, False if not.
        T)rar�rrsr�r)rArs  r�!_command_toggle_input_mode_on_offz+TabEngine._command_toggle_input_mode_on_off�sH��
�}�}�� �=�=�?�M����}�-����C�D�$4�$4� 4�5�6�rc��|jjsy|j|j|j|j��y)u�Handle hotkey for the command “toggle_letter_width”

        :return: True if the key was completely handled, False if not.
        Fr�T)rPr�r�rrr]s r�_command_toggle_letter_widthz&TabEngine._command_toggle_letter_width
sL��
�}�}�$�$������'�'��(8�(8�9�9��'�'�	�	)�rc��|jjsy|j|j|j|j��y)u�Handle hotkey for the command “toggle_punctuation_width”

        :return: True if the key was completely handled, False if not.
        Fr�T)rPr�r�rrr]s r�!_command_toggle_punctuation_widthz+TabEngine._command_toggle_punctuation_width
sL��
�}�}�$�$���"�"��&�&�t�'7�'7�8�8��'�'�	#�	)�rc�f�|j�ry|j�|j�y)u{Handle hotkey for the command “cancel”

        :return: True if the key was completely handled, False if not.
        FT)rar<r4r]s r�_command_cancelzTabEngine._command_cancel
s&��
�=�=�?���
�
������rc�V�|jsy|j|j�y)u�Handle hotkey for the command “toggle_suggestion_mode”

        :return: True if the key was completely handled, False if not.
        FT)r�r�rr]s r�_command_toggle_suggestion_modez)TabEngine._command_toggle_suggestion_mode&
s&��
�|�|��� � �T�]�]�!2�3�rc�h�|j�ry|j�}|j�|S)u�Handle hotkey for the command “commit_to_preedit”

        :return: True if the key was completely handled, False if not.
        F)rarur4rs  r�_command_commit_to_preeditz$TabEngine._command_commit_to_preedit0
s-��
�=�=�?���$�$�&�������
rc�8�|jsy|j|j�|j�sa|j|j
z}d|_d|_|D]}|j
|��|jd��|j�y)u�Handle hotkey for the command “toggle_pinyin_mode”

        :return: True if the key was completely handled, False if not.
        FrZT)r�)	r�rrrarrrer\r4)rA�charsr?s   r�_command_toggle_pinyin_modez%TabEngine._command_toggle_pinyin_mode;
s���
�|�|��������.�/��}�}���%�%��(;�(;�;�E� "�D��"$�D���
%�����t�$�
%��"�"��"�.��O�O��rc�F�|j�}|j�|S)u�Handle hotkey for the command
        “select_next_candidate_in_current_page”

        :return: True if the key was completely handled, False if not.
        )r.r4rs  r�._command_select_next_candidate_in_current_pagez8TabEngine._command_select_next_candidate_in_current_pageP
s!���8�8�:�������
rc�F�|j�}|j�|S)u�Handle hotkey for the command
        “select_previous_candidate_in_current_page”

        :return: True if the key was completely handled, False if not.
        )r0r4rs  r�2_command_select_previous_candidate_in_current_pagez<TabEngine._command_select_previous_candidate_in_current_pageZ
s!���<�<�>�������
rc���|jjsy|j|j�|j	�s!|jd�|j
�y)u�Handle hotkey for the command “toggle_onechar_mode”

        :return: True if the key was completely handled, False if not.
        FT)rPr�r�r#rar\r4r]s r�_command_toggle_onechar_modez&TabEngine._command_toggle_onechar_moded
sM��
�}�}�$�$�����$�-�-�/�0��}�}���"�"�4�(��O�O��rc��|jjr3|jjr|j|j�yy)u�Handle hotkey for the command “toggle_autocommit_mode”

        :return: True if the key was completely handled, False if not.
        TF)rPrr�r�rr]s r�_command_toggle_autocommit_modez)TabEngine._command_toggle_autocommit_moder
s:��
�=�=�/�/�D�M�M�4G�4G��$�$��):�):�%:�;��rc���|jjsy|j|jdzdz�|j	�s!|jd�|j
�y)u�Handle hotkey for the command “switch_to_next_chinese_mode”

        :return: True if the key was completely handled, False if not.
        Fr0r:T)rPr3r�r%rar\r4r]s r�$_command_switch_to_next_chinese_modez.TabEngine._command_switch_to_next_chinese_mode|
sV��
�}�}�(�(�����t�1�1�!�3�q�8�9��}�}���"�"�4�(��O�O��rc�F�|js|j�r|jry|j�r|jr|jd�|jr|jr|jsd|_|j�|j�yy)u{Handle hotkey for the command “commit”

        :return: True if the key was completely handled, False if not.
        r[TF)
rrarrrrrrr\r4r]s r�_command_commitzTabEngine._command_commit�
s}��

�M�M��=�=�?��#�#��4�4�6��$�$��&�&�t�,��
�
��$�$��,�,�'+��$��"�"�$��O�O���rc�`�|jsy|j�}|j�|S)u�Handle hotkey for the command “lookup_table_page_down”

        :return: True if the key was completely handled, False if not.
        F)rrr4rs  r�_command_lookup_table_page_downz)TabEngine._command_lookup_table_page_down�
s+��
�����n�n��������
rc�`�|jsy|j�}|j�|S)u�Handle hotkey for the command “lookup_table_page_up”

        :return: True if the key was completely handled, False if not.
        F)rrr4rs  r�_command_lookup_table_page_upz'TabEngine._command_lookup_table_page_up�
s*��
�����l�l�n�������
rr�c���|jtjjzrtjd|�y|jsy|dz
}|j|�}|j�|S)u�Execute the hotkey command “commit_candidate_to_preedit_<number>”

        :return: True if the key was completely handled, False if not.
        :param number: The number of the candidate
        z?OSK is visible: do not commit candidate to preedit by number %sFr0)	�client_capabilitiesr��
Capabilite�OSKr�r�rr�r4�rAr�rCrds    r�+_execute_commit_candidate_to_preedit_numberz5TabEngine._execute_commit_candidate_to_preedit_number�
sm���#�#�g�&8�&8�&<�&<�<��K�K�B�CI�
K��������
���1�1�%�8�������
rc�$�|jd�S)u�Handle hotkey for the command “commit_candidate_to_preedit_1”

        :return: True if the key was completely handled, False if not.
        r0�rSr]s r�&_command_commit_candidate_to_preedit_1z0TabEngine._command_commit_candidate_to_preedit_1�
���
�?�?��B�Brc�$�|jd�S)u�Handle hotkey for the command “commit_candidate_to_preedit_2”

        :return: True if the key was completely handled, False if not.
        r4rUr]s r�&_command_commit_candidate_to_preedit_2z0TabEngine._command_commit_candidate_to_preedit_2�
rWrc�$�|jd�S)u�Handle hotkey for the command “commit_candidate_to_preedit_3”

        :return: True if the key was completely handled, False if not.
        r�rUr]s r�&_command_commit_candidate_to_preedit_3z0TabEngine._command_commit_candidate_to_preedit_3�
rWrc�$�|jd�S)u�Handle hotkey for the command “commit_candidate_to_preedit_4”

        :return: True if the key was completely handled, False if not.
        r=rUr]s r�&_command_commit_candidate_to_preedit_4z0TabEngine._command_commit_candidate_to_preedit_4�
rWrc�$�|jd�S)u�Handle hotkey for the command “commit_candidate_to_preedit_5”

        :return: True if the key was completely handled, False if not.
        r:rUr]s r�&_command_commit_candidate_to_preedit_5z0TabEngine._command_commit_candidate_to_preedit_5�
rWrc�$�|jd�S)u�Handle hotkey for the command “commit_candidate_to_preedit_6”

        :return: True if the key was completely handled, False if not.
        r9rUr]s r�&_command_commit_candidate_to_preedit_6z0TabEngine._command_commit_candidate_to_preedit_6�
rWrc�$�|jd�S)u�Handle hotkey for the command “commit_candidate_to_preedit_7”

        :return: True if the key was completely handled, False if not.
        rsrUr]s r�&_command_commit_candidate_to_preedit_7z0TabEngine._command_commit_candidate_to_preedit_7�
rWrc�$�|jd�S)u�Handle hotkey for the command “commit_candidate_to_preedit_8”

        :return: True if the key was completely handled, False if not.
        �rUr]s r�&_command_commit_candidate_to_preedit_8z0TabEngine._command_commit_candidate_to_preedit_8�
rWrc�$�|jd�S)u�Handle hotkey for the command “commit_candidate_to_preedit_9”

        :return: True if the key was completely handled, False if not.
        r<rUr]s r�&_command_commit_candidate_to_preedit_9z0TabEngine._command_commit_candidate_to_preedit_9rWrc�$�|jd�S)u�Handle hotkey for the command “commit_candidate_to_preedit_10”

        :return: True if the key was completely handled, False if not.
        r�rUr]s r�'_command_commit_candidate_to_preedit_10z1TabEngine._command_commit_candidate_to_preedit_10s��
�?�?��C�Crc���|jtjjzrtjd|�y|jsy|dz
}|j|�}|j�|S)u�Execute the hotkey command “remove_candidate_<number>”

        :return: True if the key was completely handled, False if not.
        :param number: The number of the candidate
        z4OSK is visible: do not remove candidate by number %sFr0)	rOr�rPrQr�r�rr r4rRs    r� _execute_remove_candidate_numberz*TabEngine._execute_remove_candidate_numbersg���#�#�g�&8�&8�&<�&<�<��K�K�F��
P��������
���6�6�u�=�������
rc�$�|jd�S)u�Handle hotkey for the command “remove_candidate_1”

        :return: True if the key was completely handled, False if not.
        r0�rlr]s r�_command_remove_candidate_1z%TabEngine._command_remove_candidate_1���
�4�4�Q�7�7rc�$�|jd�S)u�Handle hotkey for the command “remove_candidate_2”

        :return: True if the key was completely handled, False if not.
        r4rnr]s r�_command_remove_candidate_2z%TabEngine._command_remove_candidate_2&rprc�$�|jd�S)u�Handle hotkey for the command “remove_candidate_3”

        :return: True if the key was completely handled, False if not.
        r�rnr]s r�_command_remove_candidate_3z%TabEngine._command_remove_candidate_3-rprc�$�|jd�S)u�Handle hotkey for the command “remove_candidate_4”

        :return: True if the key was completely handled, False if not.
        r=rnr]s r�_command_remove_candidate_4z%TabEngine._command_remove_candidate_44rprc�$�|jd�S)u�Handle hotkey for the command “remove_candidate_5”

        :return: True if the key was completely handled, False if not.
        r:rnr]s r�_command_remove_candidate_5z%TabEngine._command_remove_candidate_5;rprc�$�|jd�S)u�Handle hotkey for the command “remove_candidate_6”

        :return: True if the key was completely handled, False if not.
        r9rnr]s r�_command_remove_candidate_6z%TabEngine._command_remove_candidate_6Brprc�$�|jd�S)u�Handle hotkey for the command “remove_candidate_7”

        :return: True if the key was completely handled, False if not.
        rsrnr]s r�_command_remove_candidate_7z%TabEngine._command_remove_candidate_7Irprc�$�|jd�S)u�Handle hotkey for the command “remove_candidate_8”

        :return: True if the key was completely handled, False if not.
        rernr]s r�_command_remove_candidate_8z%TabEngine._command_remove_candidate_8Prprc�$�|jd�S)u�Handle hotkey for the command “remove_candidate_9”

        :return: True if the key was completely handled, False if not.
        r<rnr]s r�_command_remove_candidate_9z%TabEngine._command_remove_candidate_9Wrprc�$�|jd�S)u�Handle hotkey for the command “remove_candidate_10”

        :return: True if the key was completely handled, False if not.
        r�rnr]s r�_command_remove_candidate_10z&TabEngine._command_remove_candidate_10^s��
�4�4�R�8�8rc��|jtjjzrtjd|�y|jr|t|j�kDry|dz
}d|cxkr|jksyy|j|�r{|j|j�|j���|jr|jr|jsd|_|j!�|j#�yy)u�Execute the hotkey command “commit_candidate_<number>”

        :return: True if the key was completely handled, False if not.
        :param number: The number of the candidate
        z4OSK is visible: do not commit candidate by number %sFr0rrT)rOr�rPrQr�r�rr�r)r�rr�r�rrrr\r4)rAr�rCs   r�(_execute_command_commit_candidate_numberz2TabEngine._execute_command_commit_candidate_numberes����#�#�g�&8�&8�&<�&<�<��K�K�F��
P�����6�C��0@�0@�,A�#A����
���E�+�D�O�O�+��,���.�.�u�5�����0�0�2��9�9�;�
�
=��
�
��$�$��,�,�'+��$��"�"�$��O�O���rc�$�|jd�S)u�Handle hotkey for the command “commit_candidate_1”

        :return: True if the key was completely handled, False if not.
        r0�r�r]s r�_command_commit_candidate_1z%TabEngine._command_commit_candidate_1����
�<�<�Q�?�?rc�$�|jd�S)u�Handle hotkey for the command “commit_candidate_2”

        :return: True if the key was completely handled, False if not.
        r4r�r]s r�_command_commit_candidate_2z%TabEngine._command_commit_candidate_2�r�rc�$�|jd�S)u�Handle hotkey for the command “commit_candidate_3”

        :return: True if the key was completely handled, False if not.
        r�r�r]s r�_command_commit_candidate_3z%TabEngine._command_commit_candidate_3�r�rc�$�|jd�S)u�Handle hotkey for the command “commit_candidate_4”

        :return: True if the key was completely handled, False if not.
        r=r�r]s r�_command_commit_candidate_4z%TabEngine._command_commit_candidate_4�r�rc�$�|jd�S)u�Handle hotkey for the command “commit_candidate_5”

        :return: True if the key was completely handled, False if not.
        r:r�r]s r�_command_commit_candidate_5z%TabEngine._command_commit_candidate_5�r�rc�$�|jd�S)u�Handle hotkey for the command “commit_candidate_6”

        :return: True if the key was completely handled, False if not.
        r9r�r]s r�_command_commit_candidate_6z%TabEngine._command_commit_candidate_6�r�rc�$�|jd�S)u�Handle hotkey for the command “commit_candidate_7”

        :return: True if the key was completely handled, False if not.
        rsr�r]s r�_command_commit_candidate_7z%TabEngine._command_commit_candidate_7�r�rc�$�|jd�S)u�Handle hotkey for the command “commit_candidate_8”

        :return: True if the key was completely handled, False if not.
        rer�r]s r�_command_commit_candidate_8z%TabEngine._command_commit_candidate_8�r�rc�$�|jd�S)u�Handle hotkey for the command “commit_candidate_9”

        :return: True if the key was completely handled, False if not.
        r<r�r]s r�_command_commit_candidate_9z%TabEngine._command_commit_candidate_9�r�rc�$�|jd�S)u�Handle hotkey for the command “commit_candidate_10”

        :return: True if the key was completely handled, False if not.
        r�r�r]s r�_command_commit_candidate_10z&TabEngine._command_commit_candidate_10�s��
�<�<�R�@�@rr��commandsc��tdkDrtjd|�tdkDr)tjdt|j��|s#t|jj��}|D]h}|j||f|jvs�tdkDrtjd|�d|z}	t||�}|�s�X|jd	vry
yy#tf$rtjd|�YywxYw)a(Handle hotkey commands

        :return: True if the key was completely handled, False if not.
        :param key: The typed key. If this is a hotkey,
                    execute the command for this hotkey.
        :param commands: A list of commands to check whether
                         the key matches the keybinding for one of
                         these commands.
                         If the list of commands is empty, check
                         *all* commands in the self._keybindings
                         dictionary.
        r0zKeyEvent object: %s
r:zself._hotkeys=%s
zmatched command=%sz_command_%szThere is no function %s)FF)�Shift_L�Shift_R�	Control_L�	Control_R�Alt_L�Alt_R�Meta_L�Meta_R�Super_L�Super_R�ISO_Level3_Shift)TF�TT)
r�r�r�r�r�r�r�r$r
�getattr�AttributeErrorr�rS)rAr�r�rk�command_function_name�command_functions      r�_handle_hotkeyszTabEngine._handle_hotkeys�s�� ��?��L�L�0�#�6���?��L�L�-�s�4�=�=�/A�B���d�/�/�4�4�6�7�H��	(�G�����W�-����>���?��L�L�!5�w�?�(5��(?�%�*�'.�t�5J�'K�$�
$�%��x�x�$8�8�,�'�'	(�(��'�(�*��$�$�%>�%:�<�)�*�s�=C%�% D	�D	�keyval�keycoder�c�D�|jr|j|||�yy)uPA replacement for “return False” in do_process_key_event()

        do_process_key_event should return “True” if a key event has
        been handled completely. It should return “False” if the key
        event should be passed to the application.

        But just doing “return False” doesn’t work well when trying to
        do the unit tests. The MockEngine class in the unit tests
        cannot get that return value. Therefore, it cannot do the
        necessary updates to the self._mock_committed_text etc. which
        prevents proper testing of the effects of such keys passed to
        the application. Instead of “return False”, one can also use
        self.forward_key_event(keyval, keycode, keystate) to pass the
        key to the application. And this works fine with the unit
        tests because a forward_key_event function is implemented in
        MockEngine as well which then gets the key and can test its
        effects.

        Unfortunately, “forward_key_event()” does not work in Qt5
        applications because the ibus module in Qt5 does not implement
        “forward_key_event()”. Therefore, always using
        “forward_key_event()” instead of “return False” in
        “do_process_key_event()” would break ibus-typing-table
        completely for all Qt5 applictions.

        To work around this problem and make unit testing possible
        without breaking Qt5 applications, we use this helper function
        which uses “forward_key_event()” when unit testing and “return
        False” during normal usage.

        TF)r��forward_key_event)rAr�r�r�s    r�
_return_falsezTabEngine._return_false�s$��@�?�?��"�"�6�7�E�:��r�_objc�(�|j|||�S)z=This function is connected to the 'process-key-event' signal.)�_do_process_key_event)rAr�r�r�r�s     r�__do_process_key_eventz TabEngine.__do_process_key_event s��
�)�)�&�'�5�A�Arc��tj|||�}tdkDrtj	d|�|j
tjjjtjjjfvr1tdkDrtj	d�|j|||�S|j|�}||_|S)ztProcess Key Events
        Key Events include Key Press and Key Release,
        modifier means Key Pressed
        r0zKeyEvent object: %srz0Disable because of input purpose PASSWORD or PIN)
r��KeyEventr�r�r�r��InputPurpose�PASSWORD�value�PINr��_process_key_eventr
)rAr�r�r�r��results      rr�zTabEngine._do_process_key_event's������v�w��6����?��L�L�.��4�����$�$�-�-�3�3��$�$�(�(�.�.�0�
0��Q�����F�H��%�%�f�g�u�=�=��(�(��-������
rc���|j|gd���\}}|r|S|jr)|j|�\}}|r|S|j|�S|j|�S)a
        Internal method to process key event

        Returns True if the key event has been completely handled by
        ibus-table and should not be passed through anymore.
        Returns False if the key event has not been handled completely
        and is passed through.
        )r�r�r�r�)r�)r�r�_table_mode_process_key_event�_english_mode_process_key_event)rAr�r��return_values    rr�zTabEngine._process_key_event=sz��!%� 4� 4��$�!5�!%����
������$(�$8�$8��$=�!�U�L��#�#��5�5�c�:�:��3�3�C�8�8rc��|j|jr'|jjr|j	|�S|S)u�Converts “char” to full width *if* full width letter mode is on for
        the current input mode (direct input or table mode) *and* if
        the current table is for CJK.

        :param char: The character to maybe convert to full width
        )rrrPr�r(�rAr?s  r�cond_letter_translatezTabEngine.cond_letter_translateTs:���"�"�4�#3�#3�4����9N�9N��.�.�t�4�4��rc��|j|jr'|jjr|j	|�S|S)uConverts “char” to full width *if* full width punctuation mode is
        on for the current input mode (direct input or table mode)
        *and* if the current table is for CJK.

        :param char: The character to maybe convert to full width
        )rrrPr�r(r�s  r�cond_punct_translatezTabEngine.cond_punct_translate_s:���!�!�$�"2�"2�3��
�
�8M�8M��.�.�t�4�4��rc�B�|jtjjzr1|j	|j
|j|j�S|j
dk\r1|j	|j
|j|j�S|jtjjtjjzzr1|j	|j
|j|j�Stj|j
�}t|�r|j|�}n|j|�}||k(r1|j	|j
|j|j�S|j|�y)uQ
        Process a key event in “English” (“Direct input”) mode.
        �T)r�r�ModifierType�RELEASE_MASKr�r&rE�CONTROL_MASK�	MOD1_MASK�keyval_to_unicoder"r�r�r)rAr��keychar�
trans_chars    rr�z)TabEngine._english_mode_process_key_eventjs1��
�9�9�t�(�(�5�5�5��%�%�c�g�g�s�x�x����C�C��7�7�c�>��%�%�c�g�g�s�x�x����C�C��I�I��$�$�1�1��%�%�/�/�0�
1��%�%�c�g�g�s�x�x����C�C��(�(����1����!��2�2�7�;�J��3�3�G�<�J��� ��%�%�c�g�g�s�x�x����C�C����:�&�rc��tdkDrtjdt|��|jt
jjzr1|j|j|j|j�Stj|j�}|j��rE|j��s4||j|jz|j zvs.|j"j$r�||j"j$vr�|jt
jj&t
jj(zzs�tdkDrtjd|�t+|�r|j-|�}n|j/|�}||k(r8||_|j|j|j|j�S|j3|�y|jt
j4t
j6fvr�|j�rA|j�s1|j|j|j|j�S|j8rb|j;�|j�}|j3|�|j|j|j|j�S|j=�}|j3|�y|jt
j>t
j@fvrl|j8r`|j;�|j3|j��|j|j|j|j�S|jt
jBt
jDfvrc|j�s1|j|j|j|j�S|jG�}|jI�|S|jt
jJt
jLfvrc|j�s1|j|j|j|j�S|jO�}|jI�|S|jt
jPt
jRfvr�|jt
jj(zrb|j�s1|j|j|j|j�S|jU�|jI�y|jt
jVt
jXfvr�|jt
jj(zrb|j�s1|j|j|j|j�S|j[�|jI�y|jt
jPt
jRfvrb|j�s1|j|j|j|j�S|j]�|jI�y|jt
jVt
jXfvrb|j�s1|j|j|j|j�S|j_�|jI�y|jt
j`k(r�|jt
jj(zrb|j�s1|j|j|j|j�S|jc�|jI�y|jt
j`k(rb|j�s1|j|j|j|j�S|je�|jI�y|jt
jfk(r�|jt
jj(zrb|j�s1|j|j|j|j�S|ji�|jI�y|jt
jfk(rb|j�s1|j|j|j|j�S|jk�|jI�y|jt
jj(t
jj&zzr1|j|j|j|j�S|jt
jj&zr1|j|j|j|j�S|�r�||j|jz|j zvs)|jl�ri|jn�r\||jpv�rMtdkDrtjd|�|jlr#|jrr|ju�d|_9|jlr�|jnrytw|jx�|jzk(s)tw|jx�dkDr�|jxdd	vr�|j|r|j�n�|j;�n�|jlr�|jns{tw|jx�|j�k(s+tw|jx�|j"j�vr0|j|r|j�n|j;�nJ�|j�|�}|sj|j8r=|j�r1|j��|j�|j�|�S|j�|jI�y|j|r?|j��r/|jx|j�ddk(r|j�|jI�y|r�tdkDrtjd
|�|j�r|j�dk(r |j3|j=��n/|j;�|j3|j��t+|�r!|j3|j-|��y|j3|j/|��y|j|j|j|j�S)u�
        Process a key event in “Table” mode, i.e. when the
        table is actually used and not switched off by using
        direct input.
        rzrepr(key)=%sz!leading invalid input: keychar=%sTzvalid input: keychar=%sFr0rgz!@#$%z"trailing invalid input: keychar=%s)Ir�r�r�r2r�rr�r�r�r&rEr�rar�r�r�r�rPr�r�r�r"r�r�rr�
KEY_Return�KEY_KP_Enterrrur��KEY_Tab�
KEY_KP_Tab�KEY_Down�KEY_KP_Downrr4�KEY_Up�	KEY_KP_Upr�KEY_Left�KEY_KP_Leftr��	KEY_Right�KEY_KP_Rightr�r�r��
KEY_BackSpacervr%�
KEY_Deleterxr'rrr�rr^r�rrrrr�possible_tabkeys_lengthsrerrjr�r2rr)rAr�r�r�rrds      rr�z'TabEngine._table_mode_process_key_event�s;
����?��L�L���c��3��9�9�t�(�(�5�5�5��%�%�c�g�g�s�x�x����C�C��(�(����1��
�M�M�O��8�8�:���+�+��0�0�1��/�/�0�1��]�]�-�-� ��
�
�(@�(@�@� �Y�Y��+�+�5�5��+�+�8�8�9�:���?��L�L�%��!�!��)�!%�!:�!:�7�!C�J�!%�!;�!;�G�!D�J���(�&0�D�O��-�-�c�g�g�s�x�x����K�K��"�"�:�.���7�7�t����(9�(9�:�:��
�
�� �<�<�>��)�)�#�'�'�3�8�8�S�Y�Y�G�G�� � ��&�&�(� $� @� @� B�
��"�"�=�1��)�)�#�'�'�3�8�8�S�Y�Y�G�G� �=�=�?�M����}�-���7�7�t�|�|�T�_�_�5�5�$�:K�:K�(
�"�"�$����t�?�?�A�B��%�%�c�g�g�s�x�x����C�C��7�7�t�}�}�d�&6�&6�7�7��3�3�5��)�)�#�'�'�3�8�8�S�Y�Y�G�G��"�"�$�C��O�O���J��7�7�t�{�{�D�N�N�3�3��3�3�5��)�)�#�'�'�3�8�8�S�Y�Y�G�G��.�.�"�C��O�O���J��G�G��
�
�t�'7�'7�8�8��I�I�� 1� 1� >� >�>��3�3�5��)�)�#�'�'�3�8�8�S�Y�Y�G�G��#�#�%��O�O����G�G�����(9�(9�:�:��I�I�� 1� 1� >� >�>��3�3�5��)�)�#�'�'�3�8�8�S�Y�Y�G�G��$�$�&��O�O����7�7�t�}�}�d�&6�&6�7�7��3�3�5��)�)�#�'�'�3�8�8�S�Y�Y�G�G��O�O���O�O����7�7�t�~�~�t�'8�'8�9�9��3�3�5��)�)�#�'�'�3�8�8�S�Y�Y�G�G������O�O����G�G�t�)�)�)��I�I�� 1� 1� >� >�>��3�3�5��)�)�#�'�'�3�8�8�S�Y�Y�G�G��-�-�/��O�O����7�7�d�(�(�(��3�3�5��)�)�#�'�'�3�8�8�S�Y�Y�G�G������O�O����G�G�t���&��I�I�� 1� 1� >� >�>��3�3�5��)�)�#�'�'�3�8�8�S�Y�Y�G�G��,�,�.��O�O����7�7�d�o�o�%��3�3�5��)�)�#�'�'�3�8�8�S�Y�Y�G�G��K�K�M��O�O���
�I�I��$�$�1�1��%�%�/�/�0�
1��%�%�c�g�g�s�x�x����C�C��9�9�t�(�(�2�2�2��%�%�c�g�g�s�x�x����C�C�
���!8�!8�#'�#=�#=�">�#'�#<�#<�"=�>��)�)�d�m�m�$��(F�(F�F��Q�����-�w�8����D�$8�$8��0�0�2�',��$����D�M�M���*�*�+��3�3�4��� 1� 1�2�Q�6� $� 1� 1�"� 5�� @��(�(��=�=�?��.�.�0��!�!�$�-�-���*�*�+��,�,�-��� 1� 1�2�#�}�}�E�E�F��(�(��=�=�?��.�.�0��u��.�.��)�C���$�$��)B�)B�.�N�N�$��9�9�;��=�=�c�B�B��5�5�7����!���!�!�d�&8�&8�&:��&�&��(�(��+�A�.�/��5�5�7��O�O�����Q�����8�'�C��#�#�t�'@�'@�A�'E��"�"�4�#D�#D�#F�G��&�&�(��"�"�4�#C�#C�#E�F��W�%��"�"�4�#<�#<�W�#E�F���"�"�4�#=�#=�g�#F�G���!�!�#�'�'�3�8�8�S�Y�Y�?�?rc�d�tdkDrtjd�|jdd�y)zn
        Called for ibus < 1.5.27 when a window gets focus while
        this input engine is enabled
        r0zentering do_focus_in()
rZN)r�r�r��do_focus_in_idr]s r�do_focus_inzTabEngine.do_focus_in�s(��
��?��L�L�3�4����B��#rrWrc�x�tdkDrtjd||�||_d|jvrZt	j
�\}}|r|xjd|zz
c_tdkDr tjd|j�|j
|j�|j�y)u(Called for ibus >= 1.5.27 when a window gets focus while
        this input engine is enabled

        :param object_path: Example:
                            '/org/freedesktop/IBus/InputContext_23'
        :param client: Possible values and examples where these values occur:
                       '': unknown
                       'fake': focus where input is impossible
                               (e.g. desktop background)
                       'xim': XIM
                             (Gtk3 programs in a Gnome Xorg session
                              when GTK_IM_MODULE is unset also use xim)
                       'gtk-im:<program-name>':  Gtk2 input module
                       'gtk3-im:<program-name>': Gtk3 input module
                       'gtk4-im:<program-name>': Gtk4 input module
                       'gnome-shell': Entries handled by gnome-shell
                                      (like the command line dialog
                                      opened with Alt+F2 or the search
                                      field when pressing the Super
                                      key.) When GTK_IM_MODULE is
                                      unset in a Gnome Wayland session
                                      all programs which would show
                                      'gtk3-im' or 'gtk4-im' with
                                      GTK_IM_MODULE=ibus then show
                                      'gnome-shell' instead.
                       'Qt':      Qt4 input module
                       'QIBusInputContext': Qt5 input module

                       In case of the Gtk input modules, the name of the
                       client is also shown after the “:”, for example
                       like 'gtk3-im:firefox', 'gtk4-im:gnome-text-editor', …
        r0zobject_path=%s client=%s
�:zself._im_client=%s
N)	r�r�r�r��it_active_window�get_active_windowr�r�r4)rArWr�program_name�
_window_titles     rr�zTabEngine.do_focus_in_id�s���B��?��L�L�5�{�F�K� ����d�o�o�%�.�@�@�B�
�\�
�����3��#5�5���Q�����3�T�_�_�E�� � ��!4�!4�5����rc�b�tdkDrtjd�|jd�y)zo
        Called for ibus < 1.5.27 when a window loses focus while
        this input engine is enabled
        r0zentering do_focus_out()
rZN)r�r�r��do_focus_out_idr]s rr7zTabEngine.do_focus_out�s&��
��?��L�L�4�5����R� rc��tdkDrtjd|�d|_|j	�|j�y)zp
        Called for ibus >= 1.5.27 when a window loses focus while
        this input engine is enabled
        r0zobject_path=%s
rZN)r�r�r�r�r^r4)rArWs  rr�zTabEngine.do_focus_out_id�s9��
��?��L�L�+�[�9����
	
�(�(�*����rc�`�tdkDrtjd�|j�y)aNCalled when the mouse pointer is used to move to cursor to a
        different position in the current window.

        Also called when certain keys are pressed:

            Return, KP_Enter, ISO_Enter, Up, Down, (and others?)

        Even some key sequences like space + Left and space + Right
        seem to call this.

        r0zdo_reset()
N)r�r�r�r<r]s r�do_resetzTabEngine.do_reset�s ����?��L�L��(��
�
�r�purpose�hintsc
��tjd|t|d��||_||_t
dkD�r|jt
tj�D�cgc]
}t|���c}vrYt
tj�D]<}|j|k(s�tjd|jt|���>n tjd|j�tjD]E}|j|zs�tjdt|�tt|�d���Gyycc}w)z-Called when the input purpose or hints changezpurpose=%s hints=%s
�016br0zself._input_purpose = %s (%s)z"self._input_purpose = %s (Unknown)zhint: %s %sN)r�r��formatr�r�r��listr�r�r�r��
InputHints)rAr�r�rl�
input_purpose�hints      r�do_set_content_typezTabEngine.do_set_content_type�s�����,�g�v�e�V�7L�M�%���!�����?��#�#�$(��)=�)=�$>�?�q�C��F�?�@�%)�'�*>�*>�%?�E�M��*�*�m�;����;� �/�/��]�1C�E�E����8��'�'�)� �*�*�
>���$�$�t�+��L�L�%��D�	�6�#�d�)�V�#<�>�
>���?s� E	c��tdkDrtjd�|j�|j	�y)z(Called when this input engine is enabledr0zdo_enable()
N)r�r�r��get_surrounding_textr�r]s r�	do_enablezTabEngine.do_enables/����?��L�L��)�	
�!�!�#����rc��tdkDrtjd�|j�|j	�y)z)Called when this input engine is disabledr0z
do_disable()
N)r�r�r�r^r4r]s r�
do_disablezTabEngine.do_disables,����?��L�L�)�*��(�(�*����rc�F�|j�r|j�yy)z^Called when the page up button in the lookup table is clicked with
        the mouse

        TF)rr4r]s r�
do_page_upzTabEngine.do_page_up$s��
�<�<�>��O�O���rc�F�|j�r|j�yy)z`Called when the page down button in the lookup table is clicked with
        the mouse

        TF)rr4r]s r�do_page_downzTabEngine.do_page_down.s��
�>�>���O�O���rc�F�|j�}|j�|S)zdCalled when the mouse wheel is rolled up in the candidate area of
        the lookup table

        )rr4rs  r�do_cursor_upzTabEngine.do_cursor_up8s��
�n�n��������
rc�F�|j�}|j�|S)zfCalled when the mouse wheel is rolled down in the candidate area of
        the lookup table

        )rr4rs  r�do_cursor_downzTabEngine.do_cursor_downAs!��
��� �������
r�	_settingsc
��tj|jj|��}tjd|j||�id|jid��d|jid��d|jid��d|jid��d|jid��d|jid��d	|jid��d
|jid��d|jid��d|j id��d
|j"id��d|j$id��d|j&id��d|j(id��d|j*id��d|j,id��d|j.id��|j0t3d��d�|j4t3d��d�|j0t3d��d�|j4t3d��d�|j6id�|j8id�|j:id�d��}||vr:||d}||d}|dk7r|j=t3d���||fi|��ytjd�y)zG
        Called when a value in the settings has been changed.
        u5Settings changed for engine “%s”: key=%s value=%srh)�set_function�kwargsrjrwrxrvr�r�r�r�r�r�r�r�r�rlrnrprr�r0)r{r~r|rrurtr�rr	ruFryNzUnknown key)r�r�r�r�r�r�r�rArHrMr	r\r.r�r�r�r�r�rMr�r�r�r�r�r�rar�rsrvr/r�)rArr�r��
set_functionsrr	s       rr�z$TabEngine.on_gsettings_value_changedJs���
�(�(����)B�)B�3�)G�H�����L��&�&��U�	4�5
��!�1�1�R�@�5
�
�!�4�4��C�	5
�

�!�1�1�R�@�
5
�
�!�6�6�"�E�5
�
�!�3�3�r�B�5
�
�!�1�1�R�@�5
�
�!�5�5��D�5
�
�!�5�5��D�!5
�"
 �!�9�9�R�H�%5
�&
�!�2�2�b�A�)5
�*
%�!�>�>�"�M�-5
�.
"�!�/�/�2�>�15
�2
�!�2�2�b�A�55
�6
�!�8�8�B�G�95
�:
!�!�:�:�b�I�=5
�>
 �!�9�9�R�H�A5
�B
�!�7�7�2�F�E5
�H"�2�2��q�)�
+�"�7�7��q�)�
+�"�2�2��q�)�
+�"�7�7��q�)�
+�"�0�0�B�?�!�9�9�R�H�!�0�0�B�?�i5
�
�l�-��(��-�n�=�L�"�3�'��1�F��k�!��
�
�d�E�:�;���)�&�)�����]�#�r)F)rN)rZrZrr)T)rZT)r0Tr�)FT)rT)FrT)r)rZrZ)rZ)r)��__name__�
__module__�__qualname__�__doc__r�Busr�rr!r�rKr0r^rar[rerjrlr�rsrvrxrzr|rr�r�r�r�r�r�r�r�r�r��staticmethodrr�r�r�r�r\rur�rr�rrrrr r�r#r%r'r.r0r2r<r:rArCrHrJrMrOr	rXr	r\r^rr.rorsrvrxr/r{rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rMrr�r
r�r�r�r�r�rrr�r4r�r�r�r�r�rrrr4rr>rrr(r,r.r0r2r4r6r8r:r=r?rArCrErGrIrKrMrSrVrYr[r]r_rarcrfrhrjrlrorrrtrvrxrzr|r~r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr�r��EngineSimpler@r�r�r�r�r�r�r�r�r7r�r�r�r�r�r�rrrrr�r��
__classcell__)rHs@rrrs���"�$�e
F����e
F��e
F��	e
F�
�e
F�
)-�e
F�N�d�&6�&6��,!�>�$�>�
'��c��d��.�3��"7��7�	,��	,�/2�	,�7;�	,�#�4�
!�2�#K��5��c��?�C��s�C�x��@�A�#K�J	,�c�	,�#K��5��c��?�C��s�C�x��@�A�#K�J+�S�+�&�3��!�"!� 	!�	!�����W4��W4��W4��	W4�
�W4�
$(�W4�r�B�t�C�y�B�T�#�Y�B��B�H
"��S�	�
"�\`�ad�\e�
"�jm�
"�����a4��a4��a4��	a4�
�a4�
$(�a4�J����.4��.4��.4��	.4�
�.4�
$(�.4�`k�t�k��k�Z�4��<(�C�(�D�(� G��G�R!!�F�T���4���4�����'��'��'�R8��8�"�$�"2�"2�"�6�5�
�t�
�
�4�
�*�t�*���>B�9�"�9�6:�9�FJ�9�4!��!�
BF�:�"&�:�:>�:�JN�:�0$�D�$�
?C�7�#�7�7;�7�GK�7�,!��!�
=A�/��/�59�/�EI�/�4&�c�&�&*�/� ��c��?�/�#�/�/3�/�:#�3�#�26�I$�%*�4��T�#�Y��+?��+D�%E�I$�*.�I$�:>�I$�V(��c�4��9�n�!5�(�*+�04��#&��)-��9=��>=A�9=�?�59�?�26�?�BF�?�2)��)�$)�%)�:� �:�#�:�/3�:�$ �� ��D��T��6��������"�T��
@D�0��0�8<�0�HL�0�2�$��@D�0��0�8<�0�HL�0�2!�T�!�
;?�.��.�37�.�CG�.�8)��)�
@D�0��0�8<�0�HL�0�,!�T�!�
@D�0��0�8<�0�HL�0�*#�t�#�
=A�/��/�59�/�EI�/�**�#�*�=A�/��/�59�/�EI�/�.)��)�@D�0��0�8<�0�HL�0�*(��(�
>B�9�"�9�6:�9�FJ�9�6!�c�!�
<@�3� �3�48�3�DH�3�@�s����%)�	4��4��4�#�	4�/3�	4�B'�$�x��~�"6�'���%)�	4��4��4�#�	4�/3�	4�B&�t�H�T�N�';�&�;?�.��.�37�.�CG�.�<
"�#�
"�45�4<��s�C�x�.�4<� ��T�4��0�4<�:>�4<�t!"�	-<��-<���S��>�-<��	-<�'+�	-<�^76�x*.���)A�)A�<��<����<�GK�<�|9�,@�FH�P'�B@�,�#�S�#��#�d�#�
�t�
�;�C�;�#�;��;�*�$��0.*�3�.*�3�.*�`
��
�'*�
�47�
�<@�
����	�4�	�
�d�
�
�4�
�	��	����	�D�	��T��*����D���d������d�����,	��	�	�t�	��#��$��$C��C�C��C�C��C�C��C�C��C�C��C�C��C�C��C�C��C�D��D��s��t��"8�T�8�8�T�8�8�T�8�8�T�8�8�T�8�8�T�8�8�T�8�8�T�8�8�T�8�9�d�9��s��t��<@�T�@�@�T�@�@�T�@�@�T�@�@�T�@�@�T�@�@�T�@�@�T�@�@�T�@�A�d�A�')�0��!�!�0��s�m�0�.3�4��:�->�0�d#�C�#�#�#�c�#�d�#�JB��#�#�B��B�#&�B�/2�B�7;�B����(+��47��<@��,9�g�&6�&6�9�4�9�.	�#�	�#�	�	��	��	��7�3C�3C����0Z@��1A�1A�Z@�d�Z@�x$�,�#�,�s�,�t�,�\!�
�3�
�4�
�� >�3�>�s�>�t�>�.���D���d���d�����F� �\�\�F�03�F�8<�Frr�__main__)�streamr0)Dr�__all__�typingrrrrrr	r
r�sysr�r�rbr6�logging�IMPORT_SIMPLEAUDIO_SUCCESSFUL�simpleaudio�ImportError�gettextr
rr��__annotations__r�gir�
gi.repositoryrrrrr�r�rT�	getLoggerr�r�r�r!r"�color_string_to_argbr-r.r>rIrKr8r:�
MAJOR_VERSION�
MINOR_VERSION�
MICRO_VERSIONr�rrr�
StreamHandler�stderr�LOG_HANDLER�setLevel�DEBUG�
addHandler�doctest�testmod�FAILED�	ATTEMPTED�exitrrr�<module>r0so��0�����������
�	�	���� %��*��$(�!��=��8�S�E�3�J��=�&��H�c�U�C�Z��&���������u��������!����	��	�	�<�	(���!�f��0F�S�0F�T�0F�f�6�'�6�6�y�A�5��5�5�i�@�3�w�3�3�I�>� <�� <� <�Y� G�2�g�2�2�9�=�4��4�4�Y�?�5��5�5�i�@�7�7�7�7�	�B�0�G�0�0��;�&��t�C��t�S�y�!�!�"���6�'�6�6�y�A�5��5�5�i�@�3�w�3�3�I�>� <�� <� <�Y� G�2�g�2�2�9�=�4��4�4�Y�?�5��5�5�i�@�7�7�7�7�	�B�0�G�0�0��;�+�
�D��e�D�#�I�&�&�'��=1��4��c�3��m�,�-�=�~�s��s��*�s��s��.�����"�"�D�$6�$6��8J�8J�K��KB��!�!�KB�ZD�z��'�'�'�'�s�z�z�:�K�
�O�O�G�M�M�"�
���k�"��)�'�/�/�+��V�Y�
���������������AK	�~�*�$)�!�*�s�L%�%L1�0L1

Zerion Mini Shell 1.0