Re: dogtail-devel PROPOSAL: new options in config module for customized environments.



Zack Cerza wrote:
Alexander Todorov wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

Hi all,
I'm proposing two new options in the config module and I have already written
some of the code. Both options will help script development (or dogtail
integration) in customized environments.

Hi Alexander,

1) checkForA11y (boolean), default True. If False don't use GConf to check if
a11y is enabled or not.

This looks fine.

I just committed a patch (again attached).

+
1) -- get rid of gconf modules and related in customized environment. Such an environment at present is Anaconda (Fedora installer) which needed ~2MB of GConf
libs only because of that. It also needed a customized XML file with the
necessary settings.

The attached patch should allow you to leave out gconf without problems.

- -
1) Ugly code. Looks like:

def isA11yEnabled():
    if config.checkForA11y:
        import gconf
        gconfClient = gconf.client_get_default()

        gconfEnabled = gconfClient.get_bool(a11yGConfKey)
if os.environ.get('GTK_MODULES','').find('gail:atk-bridge') == -1:
            envEnabled = False
        else: envEnabled = True
        return (gconfEnabled or envEnabled)
    else:
        return True

and then pretty much the same for enableA11y()
I can't figure out how to "nicely" import the gconf module if needed.

I think I would rather not even execute those functions if config.checkForA11y is False, but I haven't looked into it yet.

... and that's how I implemented it. So let me know what you think :)

Zack
Index: dogtail/tree.py
===================================================================
--- dogtail/tree.py	(revision 388)
+++ dogtail/tree.py	(working copy)
@@ -60,14 +60,15 @@
 David Malcolm <dmalcolm redhat com>
 """
 
-from utils import checkForA11y
-checkForA11y()
+from config import config
+if config.checkForA11y:
+    from utils import checkForA11y
+    checkForA11y()
 
 import re
 import predicate
 from datetime import datetime
 from time import sleep
-from config import config
 from utils import doDelay
 from utils import Blinker
 import rawinput
Index: dogtail/utils.py
===================================================================
--- dogtail/utils.py	(revision 387)
+++ dogtail/utils.py	(working copy)
@@ -11,6 +11,7 @@
 """
 
 import os
+import sys
 import subprocess
 import re
 from config import config
@@ -148,16 +149,14 @@
         return True
 
 
-import sys
-import gconf
-gconfClient = gconf.client_get_default()
 a11yGConfKey = '/desktop/gnome/interface/accessibility'
 
 def isA11yEnabled():
     """
     Checks if accessibility is enabled via gconf.
     """
-    gconfEnabled = gconfClient.get_bool(a11yGConfKey)
+    import gconf
+    gconfEnabled = gconf.client_get_default().get_bool(a11yGConfKey)
     if os.environ.get('GTK_MODULES','').find('gail:atk-bridge') == -1:
         envEnabled = False
     else: envEnabled = True
@@ -171,7 +170,8 @@
     """
     Enables accessibility via gconf.
     """
-    return gconfClient.set_bool(a11yGConfKey, True)
+    import gconf
+    return gconf.client_get_default().set_bool(a11yGConfKey, True)
 
 def checkForA11y():
     """
Index: dogtail/config.py
===================================================================
--- dogtail/config.py	(revision 363)
+++ dogtail/config.py	(working copy)
@@ -89,6 +89,10 @@
     fatal. If True, exceptions will be raised. If False, warnings will be 
     passed to the debug logger.
 
+    checkForA11y (boolean):
+    Whether to check if accessibility is enabled. If not, just assume it is 
+    (default True).
+
     logDebugToFile (boolean):
     Whether to write debug output to a log file.
 
@@ -134,6 +138,7 @@
             'debugTranslation' : False,
             'blinkOnActions' : False,
             'fatalErrors' : False,
+            'checkForA11y' : True,
 
             # Logging
             'logDebugToFile' : True
Index: sniff/sniff
===================================================================
--- sniff/sniff	(revision 373)
+++ sniff/sniff	(working copy)
@@ -9,9 +9,11 @@
 There is no SniffView class; we just use a GtkTreeView.
 Data display is handled by the SniffController class.
 """
-from dogtail.utils import checkForA11yInteractively
-checkForA11yInteractively()
 from dogtail.config import config
+if config.checkForA11y:
+    from dogtail.utils import checkForA11yInteractively
+    checkForA11yInteractively()
+
 config.logDebugToFile = False
 config.childrenLimit = 100000
 from dogtail import tree


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]