Server IP : 127.0.0.2 / Your IP : 18.119.122.86 Web Server : Apache/2.4.18 (Ubuntu) System : User : www-data ( ) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : disk_free_space,disk_total_space,diskfreespace,dl,exec,fpaththru,getmyuid,getmypid,highlight_file,ignore_user_abord,leak,listen,link,opcache_get_configuration,opcache_get_status,passthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,php_uname,phpinfo,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix,_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,pclose,popen,proc_open,proc_close,proc_get_status,proc_nice,proc_terminate,shell_exec,source,show_source,system,virtual MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /usr/lib/python3/dist-packages/LanguageSelector/ |
Upload File : |
# ImConfig.py (c) 2012-2016 Canonical # Author: Gunnar Hjalmarsson <gunnarhj@ubuntu.com> # # Released under the GPL # import os import subprocess import locale class ImConfig(object): def __init__(self): pass def available(self): return os.path.exists('/usr/bin/im-config') def getAvailableInputMethods(self): inputMethods = sorted(subprocess.check_output(['im-config', '-l']).decode().split()) inputMethods.append('none') return inputMethods def getCurrentInputMethod(self): (systemConfig, userConfig, autoConfig) = \ subprocess.check_output(['im-config', '-m']).decode().split()[:3] if userConfig != 'missing': return userConfig """ no saved user configuration let's ask the system and save the system configuration as the user ditto """ system_conf = '' try: locale.setlocale(locale.LC_ALL, '') except locale.Error: return None desktop = os.environ.get('XDG_CURRENT_DESKTOP') if desktop.split(':')[-1] in ['Unity', 'MATE', 'GNOME'] \ and desktop.split(':')[0] != 'GNOME-Flashback' \ or locale.getlocale(locale.LC_CTYPE)[0][:3] in ['zh_', 'ja_', 'ko_', 'vi_']: system_default = autoConfig else: system_default = 'none' if systemConfig == 'default': system_conf = system_default elif os.path.exists('/etc/X11/xinit/xinputrc'): for line in open('/etc/X11/xinit/xinputrc'): if line.startswith('run_im'): system_conf = line.split()[1] break if not system_conf: system_conf = system_default self.setInputMethod(system_conf) return system_conf def setInputMethod(self, im): subprocess.call(['im-config', '-n', im]) if __name__ == '__main__': im = ImConfig() print('available input methods: %s' % im.getAvailableInputMethods()) print('current method: %s' % im.getCurrentInputMethod()) print("setting method 'fcitx'") im.setInputMethod('fcitx') print('current method: %s' % im.getCurrentInputMethod()) print('removing ~/.xinputrc') im.setInputMethod('REMOVE')