---------- Forwarded message ----------
From: YunQiang Su <wzss...@gmail.com>
Date: Fri, Feb 10, 2012 at 9:25 PM
Subject: Re: im-config vs. im-switch: switching input method for X
To: ubuntu-devel-discuss@lists.ubuntu.com, os...@debian.org
Cc: david.plane...@ubuntu.com


I port language-selector to fit with im-config, and the patch is attached.

It is based on 0.69 version of language-selector,
and the new source is on
   https://github.com/wzssyqa/language-selector-im-config

On Tue, Jan 24, 2012 at 11:00 PM, Osamu Aoki <os...@debian.org> wrote:
> Hi,
>
> (Excuse me for my slow start... Ubuntu list being closed list was my
> excuse.  I hope my subscription is active by now.  I hope in future,
> Ubuntu accepts signed mail from DD without subscription etc.)
>
> I think Ubuntu is doing very good job to expand user base of FREE OS.
> Thanks.
>
> Since Ubuntu seems to have different support schedule for each release,
> I thought it may be good idea to discuss side effects of my intended
> actions on Debian packages related to Ubuntu main package here, so we
> have least surprises to Ubuntu.
>
> Summary of my wish:
>  Basically im-config is redesigned and cleaned up version of im-switch.
>  Currently, im-switch is Ubuntu main while im-config is Ubuntu universe.
>  I wish to promote im-config to Ubuntu main while at appropriate time to
>  move down im-switch to universe or drop im-switch in Ubuntu.
>
>  If there is something I can do with my skill to help Ubuntu to move to
>  im-config, let me know. (Pointer to the source VCS using im-switch is
>  one thing.)
>
> Main discussion and explanation:
>
> I order to support keyboard input of CJK and many other non-latin
> characters, we have input method (IM) systems.  I maintain both
> im-switch (last 5 years) and im-config (1.5 years as upstream) in
> Debian.  These are input method (IM) configuration helper scripts.
>
> These programs provide very similar functionalities.  Basically,
> im-config is an updated package with a reimplementation and
> simplification of internal structure.  This introduced some
> incompatibilities and caused me to use different package names.  In most
> cases, switching from im-switch to im-config requires no user action
> other than installing and removing these packages.  It works almost
> transparent for users by the default set-up.
>
> For upcoming Debian release, we are doing the followings:
>
>  * make all IM package to Recommends: im-config | im-switch (mostly done)
>   So default install have im-config installed.
>  * README.Debian of im-switch states followings            (done)
>    im-switch is deprecated.
>    Please install im-config package for Wheezy.
>    This package will be dropped completely for Wheezy+1.
>  * probably move im-switch to oldlibs                     (not yet)
>  * probably drop im-switch for Wheezy+1.
>  * im-config is internationalized                         (done)
>  * im-switch is not internationalized and stays so.
>
> But these are some cases you need to watch out.
>
>  * User who understood im-switch's manual configuration features
>   needs to learn new but simpler im-config manual configuration
>   features.  (This is the reason we do not drop in wheezy to enable
>   softer transition in Debian)
>  * Ubuntu provides "Language Support" GUI which uses im-switch.
>   This may needs to be adjusted. (Ubuntu specific, I do not know the
>   source ...)
>
> As I understand, the main frontend of Ubuntu "Language Support" GUI is
> language-selector.  I heard it will be the Region tab from
> gnome-control-center soon. As long as we communicate well, we can change
> the underlying implementation without much hassle.
>
> Let me explain a bit more technical details of what these packages do as
> below:
>
> When X starts, /etc/X11/Xsession runs scripts in /etc/X11/Xsession.d in
> run-parts fashion.  im-switch and im-config drops their hook shell code
> in /etc/X11/Xsession.d.  This hook script will do the followings:
>  * run IM daemon
>  * run GUI panel indication IM status on X
>  * set and export environment variables to X clients
>    export XMODIFIERS
>    export GTK_IM_MODULE
>    export QT_IM_MODULE
>    export QT4_IM_MODULE
>    export CLUTTER_IM_MODULE
>
> This hook script is configured by the im-switch or im-config command and
> there are few notable differences:
>
> The im-switch configuration result is specific to particular locale so
> if user changes his locale setting, previous configuration may become
> invalid.  It stores configuration in a symlink firms.
>
> The im-config configuration result is agnostic about user's locale
> setting (in default setting).  It stores configuration as a plain shell
> code.
>
> Maybe, I should explain the rationale behind these design differences in
> historical context.
>
> There were 2 popular IM packages, SCIM and uim, when im-switch was
> created.  There was a need to make both packages happily installed
> together.  Now there are ibus, uim, fcitx, hime, scim, gcin, ... some
> packages are active but some are about to be dropped.  They all are
> supported by im-config and im-switch for wheezy.
>
> In order to enable all these packages installed together without
> conflicts.  Since some of them comes with many plug-ins, GUI
> configuration with helper dialogue is desirable, too.
>
> The im-switch uses update-alternatives in its extreme by using --altdir
> option,  the im-switch script was started by Muto-san but it has been
> maintained by me.
>  http://packages.qa.debian.org/i/im-switch.html
>  http://anonscm.debian.org/gitweb/?p=collab-maint/im-switch.git
>
> The main problems of the im-switch script were:
>  * over engineered.
>  * very difficult to understand strange usage of update-alternatives
>  * rely on update-alternatives command out put string
>   --> No way for gettext
>  * user customizations require deep understanding of how im-switch
>   works.  I even forget what each variable does.  The only way is to
>   read the whole source.
>  * "im-switch -z en_GB -s scim_xim" is cryptic for average user.
>  * Not too helpful selecting plug-ins.
>  ...
>
> When I looked at FEDORA 2 years ago, it started input method environment
> via pure shell script embedding its guessing logic as simple "if ..." so
> people can move from SCIM to IBUS easily.  (Their new im-chooser is much
> more advanced.)
>
> In order to keep im-switch functionality and but provide cleaner
> framework for people to tweak, I made a simpler script im-config without
> using update-alternatives but pure POSIX SHELL (Well, it still has
> /bin/bash but I think it can be /bin/sh).
>  http://packages.qa.debian.org/i/im-config.html
>  http://anonscm.debian.org/gitweb/?p=collab-maint/im-config.git
>
> The main advantage of im-config is simplicity of its manual
> configuration file:
> ----
> /usr/bin/ibus-daemon --daemonize --xim
> XMODIFIERS=@im=ibus
> GTK_IM_MODULE=ibus
> QT4_IM_MODULE=ibus
> CLUTTER_IM_MODULE=xim
> ----
>
> Its automatic configuration does more guessing/checking of installed
> files.  It looks like:
> ----
> # im-config(8) generated on Sat, 26 Jun 2010 11:41:39 +0900
> run_im default
> # im-config signiture: b4adf8baabbc92cf765f58e30f74c5e5  -
> ----
>
>  * No new variables to remember.
>  * No cryptic symlink firm in your home directory.
>  * Very intuitive and hands free.
>  * "im-config" command guide you properly in localized language what to
>   install to get additional features.
>  * dialogue supports both X(GTK) and non-X.
>  * protection of user configuration.
>
> =======================================================================
> !       Basic design of im-config
> =======================================================================
>
> 1. If an reasonable and single set of input method packages is
>   installed, im-config activates it automatically for all users by
>   default. (recommended situation)
>
> 2. If several reasonable sets of input method packages are installed,
>   im-config activates the most reasonable one automatically for all
>   users by default.
>
> 3. It provides a reasonably simple GUI configuration menu which is off
>   for the system menu by the default.  Menu selected user configuration
>   can override the system default.  Menu should normally show only
>   available input methods on the system.
>
> 4. Its configuration files are intuitive and its contents can be manually
>   overridden easily as a POSIX shell hook script.
>
> 5. Menu configuration system is smart enough to detect manual changes of
>   configuration by editor and honors such changes.
>
> 6. POSIX shell script is internationalized via gettext.sh
>
> Regards,
>
> Osamu
>
>
> --
> Ubuntu-devel-discuss mailing list
> Ubuntu-devel-discuss@lists.ubuntu.com
> Modify settings or unsubscribe at: 
> https://lists.ubuntu.com/mailman/listinfo/ubuntu-devel-discuss



--
YunQiang Su


-- 
YunQiang Su
diff --git a/LanguageSelector/ImSwitch.py b/LanguageSelector/ImSwitch.py
index abd998c..1121cc8 100644
--- a/LanguageSelector/ImSwitch.py
+++ b/LanguageSelector/ImSwitch.py
@@ -11,74 +11,56 @@ class ImSwitch(object):
     
     # some global data
     global_confdir = "/etc/X11/xinit/xinput.d/"
-    local_confdir = os.path.expanduser("~/.xinput.d/")
-    bin = "/usr/bin/im-switch"
+    local_conffile = os.path.expanduser("~/.xinputrc")
+    bin = "/usr/bin/im-config"
     default_method = "ibus"
-    blacklist_file = "/usr/share/language-selector/data/im-switch.blacklist"
+    blacklist_file = "/usr/share/language-selector/data/im-config.blacklist"
 
     def __init__(self):
         pass
 
     def available(self):
-        " return True if im-switch is available at all "
+        " return True if im-config is available at all "
         return os.path.exists(self.bin)
 
     def removeDanglingSymlinks(self):
-        for dir in (self.local_confdir, self.global_confdir):
-            if os.path.exists(dir):
-                for dentry in os.listdir(dir):
-                    if not os.path.exists("%s/%s" % (dir, dentry)):
-                        os.unlink("%s/%s" % (dir, dentry))
+        return True
     
     def enabledForLocale(self, locale):
         " check if we have a config for this specifc locale (e.g. ja_JP) "
-        for dir in (self.local_confdir, self.global_confdir):
-            for name in (locale, "all_ALL"):
-                target = os.path.join(dir,name)
-                #print "checking im-switch config: ", target, os.path.basename(os.path.realpath(target))
-                if os.path.exists(target):
-                    im_name = os.path.basename(os.path.realpath(target))
-                    if im_name in ("none", "default"):
-                        #print "points to none or default"
-                        return False
-                    #print "points to real config"
-                    return True
-        return False
+        if os.path.exists(self.local_conffile):
+        	os.unlink(self.local_conffile)
+        return True
 
     def enable(self, locale):
         " enable input methods for locale"
-        # try auto first
-        subprocess.call(["im-switch","-z",locale,"-a"])
-        # if no config is set, force the default
-        if not self.enabledForLocale(locale):
-            subprocess.call(["im-switch","-z",locale,
-                             "-s", self.default_method])
+        if os.path.exists(self.local_conffile):
+        	os.unlink(self.local_conffile)
+        return True
 
     def disable(self, locale):
         " disable input method for locale "
-        # remove local config first
-        if os.path.exists(os.path.join(self.local_confdir, locale)):
-            os.unlink(os.path.join(self.local_confdir, locale))
-        # see if we still have a input method and if so, force "none"
-        if self.enabledForLocale(locale):
-            subprocess.call(["im-switch","-z",locale,"-s","none"])
+        f=open(self.local_conffile,'w')
+        f.write('# Generate by Language-Selector, See im-config(8) for more information.\n')
 
     def getInputMethodForLocale(self, locale):
-        for dir in (self.local_confdir, self.global_confdir):
-            if os.path.exists(dir):
-                for name in (locale, "all_ALL"):
-                    target = os.path.join(dir,name)
-                    if os.path.exists(target):
-                        return os.path.basename(os.path.realpath(target))
+        """ im-config doesn't support it. """
+        if os.path.exists(self.local_conffile):
+        	progress=os.popen("grep 'run_im' ~/.xinputrc | awk -F ' ' '{print $2}'")
+        	return progress.read().rstrip()
+        else:
+        	return os.path.basename(os.path.realpath(self.global_confdir+locale))
         return None
         
     def setInputMethodForLocale(self, im, locale):
-        if not os.path.exists(self.local_confdir):
-            os.mkdir(self.local_confdir)
-        subprocess.call(["im-switch","-z",locale,"-s",im])
+        """ im-config doesn't support it. """
+        f=open(self.local_conffile,'w')
+        f.write('# Generate by Language-Selector, See im-config(8) for more information.\n')
+        f.write('run_im '+im+'\n')
+        return True
     
     def getAvailableInputMethods(self):
-        """ return the input methods available via im-switch """
+        """ return the input methods available via im-config """
         # load blacklist
         blacklist = []
         for l in open(self.blacklist_file):
@@ -94,31 +76,29 @@ class ImSwitch(object):
         return ['none']+sorted(inputMethods)
 
     def setDefaultInputMethod(self, method, locale="all_ALL"):
-        """ sets the default input method for the given locale
-            (in ll_CC form)
+        """ sets the default input method, the locale is deprecated
         """
-        l = self.confdir+locale
-        if os.path.islink(l):
-            os.unlink(l)
-        os.symlink(self.confdir+method, l)
-        return True
+        f=open(self.local_conffile,'w')
+        f.write('# Generate by Language-Selector, See im-config(8) for more information.\n')
+        f.write('run_im '+method+'\n')
 
     def resetDefaultInputMethod(self, locale="all_ALL"):
         """ reset the default input method to auto (controlled by
-            im-switch
+            im-config
         """
-        d = "/etc/alternatives/xinput-%s" % locale
-        l = self.confdir+locale
-        if os.path.islink(l):
-            os.unlink(l)
-        os.symlink(d, self.confdir+locale)
+        if os.path.exists(self.local_conffile):
+        	os.unlink(self.local_conffile)
         return True
         
     def getCurrentInputMethod(self, locale="all_ALL"):
         """ get the current default input method for the selected
             locale (in ll_CC form)
         """
-        return os.path.basename(os.path.realpath(self.local_confdir+locale))
+        if os.path.exists(self.local_conffile):
+        	progress=os.popen("grep 'run_im' ~/.xinputrc | awk -F ' ' '{print $2}'")
+        	return progress.read().rstrip()
+        else:
+        	return os.path.basename(os.path.realpath(self.global_confdir+locale))
         
 if __name__ == "__main__":
     im = ImSwitch()
@@ -126,8 +106,8 @@ if __name__ == "__main__":
 #    print im.enabledForLocale("all_ALL")
     print "available input methods: "
     print im.getAvailableInputMethods()
-    print "current method: ",
-    print im.getCurrentInputMethod()
+    print "current method: %s" % im.getCurrentInputMethod()
+#    print im.getCurrentInputMethod()
     sys.exit(1)
     print "switching to 'th-xim': ",
     print im.setDefaultInputMethod("th-xim")
diff --git a/data/im-config.blacklist b/data/im-config.blacklist
new file mode 100644
index 0000000..adbe502
--- /dev/null
+++ b/data/im-config.blacklist
@@ -0,0 +1,6 @@
+none
+default
+default-xim
+th-xim
+scim-chewing
+scim-pinyin
diff --git a/data/im-switch.blacklist b/data/im-switch.blacklist
deleted file mode 100644
index adbe502..0000000
--- a/data/im-switch.blacklist
+++ /dev/null
@@ -1,6 +0,0 @@
-none
-default
-default-xim
-th-xim
-scim-chewing
-scim-pinyin
-- 
Ubuntu-devel-discuss mailing list
Ubuntu-devel-discuss@lists.ubuntu.com
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/ubuntu-devel-discuss

Reply via email to