]> git.lyx.org Git - features.git/blobdiff - development/autotests/keytest.py
Allow to unbind without specifying the lfun
[features.git] / development / autotests / keytest.py
index 404f2c540f0143da1f97e3ef995dd42b8fb0c967..58acd4085b6d696a2e5b0760d4a01e33b1dd438b 100755 (executable)
@@ -481,7 +481,8 @@ class Shortcuts:
     def __init__(self):
         self.shortcut_entry = re.compile(r'^\s*"([^"]+)"\s*\"([^"]+)\"')
         self.bindings = {}
-        self.bind = re.compile(r'^\s*\\bind\s+"([^"]+)"')
+        self.unbindings = {}
+        self.bind = re.compile(r'^\s*\\(un)?bind\s+"([^"]+)"')
         if lyx_userdir_ver is None:
             self.dir = lyx_userdir
         else:
@@ -496,6 +497,15 @@ class Shortcuts:
         else:
             die(1, "cad shortcut spec(" + c + ")")
 
+    def __UnuseShortcut(self, c):
+        m = self.shortcut_entry.match(c)
+        if m:
+            sh = m.group(1)
+            fkt = m.group(2)
+            self.unbindings[sh] = fkt
+        else:
+            die(1, "cad shortcut spec(" + c + ")")
+
     def __PrepareShortcuts(self):
         if not self.dir is None:
             tmp = tempfile.NamedTemporaryFile(suffix='.bind', delete=False)
@@ -511,11 +521,15 @@ class Shortcuts:
                     m = self.bind.match(line)
                     if m:
                         bindfound = True
-                        val = m.group(1)
+                        val = m.group(2)
                         if val in self.bindings:
                             if self.bindings[val] != "":
                                 tmp.write("\\bind \"" + val + "\" \"" + self.bindings[val] + "\"\n")
                                 self.bindings[val] = ""
+                        elif val in self.unbindings:
+                            if self.unbindings[val] != "":
+                                tmp.write("\\unbind \"" + val + "\" \"" + self.unbindings[val] + "\"\n")
+                                self.unbindings[val] = ""
                         else:
                             tmp.write(line + '\n')
                     elif not bindfound:
@@ -527,9 +541,14 @@ class Shortcuts:
                 )
             for val in self.bindings:
                 if not self.bindings[val] is None:
-                    if  self.bindings[val] != "":
+                    if self.bindings[val] != "":
                         tmp.write("\\bind \"" + val + "\" \"" + self.bindings[val] + "\"\n")
                         self.bindings[val] = ""
+            for val in self.unbindings:
+                if not self.unbindings[val] is None:
+                    if self.unbindings[val] != "":
+                        tmp.write("\\unbind \"" + val + "\" \"" + self.unbindings[val] + "\"\n")
+                        self.unbindings[val] = ""
             tmp.close()
             shutil.move(tmp.name, self.dir + '/bind/user.bind')
         else:
@@ -538,6 +557,8 @@ class Shortcuts:
     def dispatch(self, c):
         if c[0:12] == 'UseShortcut ':
             self.__UseShortcut(c[12:])
+        elif c[0:14] == 'UnuseShortcut ':
+            self.__UnuseShortcut(c[14:])
         elif c == 'PrepareShortcuts':
             print('Preparing usefull sortcuts for tests')
             self.__PrepareShortcuts()
@@ -593,7 +614,7 @@ if qt_frontend is None:
     qt_frontend = 'QT4'
 if qt_frontend == 'QT5':
     # Some tests sometimes failed with value 0.01 on Qt5.8
-    controlkey_delay = 0.02
+    controlkey_delay = 0.4
 else:
     controlkey_delay = 0.4