OSDN Git Service

GlobalGestureMap:
authorJames Teh <jamie@jantrid.net>
Fri, 4 Feb 2011 01:53:48 +0000 (11:53 +1000)
committerJames Teh <jamie@jantrid.net>
Fri, 4 Feb 2011 01:53:48 +0000 (11:53 +1000)
* Don't use a variable in globalVars to indicate an error. First, globalVars is evil and should be phased out. Second, the user doesn't need to see a dialog for errors in non-user gesture maps. Instead, add a variable to the instance specifying whether the last update contained an error.
* Previously, this flag was only set if there was a parse error in the file. However, there can also be errors in the way bindings are specified. Set the flag for those errors too.

source/core.py
source/globalVars.py
source/inputCore.py

index fe54e6e..0689af7 100644 (file)
@@ -74,7 +74,8 @@ def doStartupDialogs():
                gui.WelcomeDialog.run()\r
        if globalVars.configFileError:\r
                gui.ConfigFileErrorDialog.run()\r
-       if globalVars.gestureMapFileError:\r
+       import inputCore\r
+       if inputCore.manager.userGestureMap.lastUpdateContainedError:\r
                import wx\r
                gui.scriptUI.MessageDialog(_("Your gesture map file contains errors.\n"\r
                                "More details about the errors can be found in the log file."),\r
index 9ff755b..8293cc6 100644 (file)
@@ -37,4 +37,3 @@ appArgs=None
 settingsRing = None\r
 speechDictionaryProcessing=True\r
 configFileError=None\r
-gestureMapFileError=False\r
index 5aa36c4..5511b24 100644 (file)
@@ -112,6 +112,9 @@ class GlobalGestureMap(object):
                @type entries: mapping of str to mapping\r
                """\r
                self._map = {}\r
+               #: Indicates that the last load or update contained an error.\r
+               #: @type: bool\r
+               self.lastUpdateContainedError = False\r
                if entries:\r
                        self.update(entries)\r
 \r
@@ -119,6 +122,7 @@ class GlobalGestureMap(object):
                """Clear this map.\r
                """\r
                self._map.clear()\r
+               self.lastUpdateContainedError = False\r
 \r
        def add(self, gesture, module, className, script,replace=False):\r
                """Add a gesture mapping.\r
@@ -162,10 +166,9 @@ class GlobalGestureMap(object):
                        conf = configobj.ConfigObj(filename, file_error=True, encoding="UTF-8")\r
                except configobj.ConfigObjError, e:\r
                        log.warning("Error in gesture map '%s': %s"%(filename, e))\r
-                       globalVars.gestureMapFileError=True\r
-               else:\r
-                       self.update(conf)\r
-                       globalVars.gestureMapFileError=False\r
+                       self.lastUpdateContainedError = True\r
+                       return\r
+               self.update(conf)\r
 \r
        def update(self, entries):\r
                """Add multiple map entries.\r
@@ -185,11 +188,13 @@ class GlobalGestureMap(object):
                @param entries: The items to add.\r
                @type entries: mapping of str to mapping\r
                """\r
+               self.lastUpdateContainedError = False\r
                for locationName, location in entries.iteritems():\r
                        try:\r
                                module, className = locationName.rsplit(".", 1)\r
                        except:\r
                                log.error("Invalid module/class specification: %s" % locationName)\r
+                               self.lastUpdateContainedError = True\r
                                continue\r
                        for script, gestures in location.iteritems():\r
                                if script == "None":\r
@@ -203,6 +208,7 @@ class GlobalGestureMap(object):
                                                self.add(gesture, module, className, script)\r
                                        except:\r
                                                log.error("Invalid gesture: %s" % gesture)\r
+                                               self.lastUpdateContainedError = True\r
                                                continue\r
 \r
        def getScriptsForGesture(self, gesture):\r