mirror of
https://github.com/Julow/Unexpected-Keyboard.git
synced 2025-06-24 03:31:26 +02:00
check_layout: Check for unknown keys
This can spot mispelled special keys.
This commit is contained in:
parent
b670fe0da2
commit
ff9d2e7d31
@ -26,6 +26,7 @@ latn_bone: Missing important key, missing: loc capslock
|
||||
latn_colemak: Some keys contain whitespaces, unexpected: ́
|
||||
latn_dvorak: Missing important key, missing: loc capslock
|
||||
latn_neo2: Layout redefines the bottom row but some important keys are missing, missing: loc switch_clipboard
|
||||
latn_qwerty_jp: Layout contains unknown keys: accent-macron
|
||||
latn_qwerty_se: Duplicate keys: !, ', ,, -, ., ?
|
||||
latn_qwerty_tly: Duplicate keys: a, c, j, q
|
||||
latn_qwerty_tly: Missing programming keys, missing: loc esc, loc tab
|
||||
|
@ -1,5 +1,5 @@
|
||||
import xml.etree.ElementTree as ET
|
||||
import sys, os, glob
|
||||
import sys, os, glob, re
|
||||
|
||||
layout_file_name = 0
|
||||
warnings = []
|
||||
@ -15,6 +15,9 @@ KEY_ATTRIBUTES = set([
|
||||
"c", "nw", "ne", "sw", "se", "w", "e", "n", "s"
|
||||
])
|
||||
|
||||
# Keys defined in KeyValue.java
|
||||
known_keys = set()
|
||||
|
||||
def warn(msg):
|
||||
global warnings
|
||||
warnings.append("%s: %s" % (layout_file_name, msg))
|
||||
@ -103,6 +106,23 @@ def check_layout(layout):
|
||||
if root.get("script") == None:
|
||||
warn("Layout doesn't specify a script.")
|
||||
|
||||
keys_without_loc = set(( k.removeprefix("loc ") for k in keys ))
|
||||
# Keys with a len under 3 are often composed characters
|
||||
special_keys = set(( k for k in keys_without_loc if len(k) > 3 and ":" not in k ))
|
||||
unknown = special_keys.difference(known_keys)
|
||||
if len(unknown) > 0:
|
||||
warn("Layout contains unknown keys: %s" % key_list_str(unknown))
|
||||
|
||||
# Fill 'known_keys', which is used for some checks
|
||||
def parse_known_keys():
|
||||
global known_keys
|
||||
with open("srcs/juloo.keyboard2/KeyValue.java", "r") as f:
|
||||
known_keys = set(
|
||||
( m.group(1) for m in re.finditer('case "([^"]+)":', f.read()) )
|
||||
)
|
||||
|
||||
parse_known_keys()
|
||||
|
||||
for fname in sorted(glob.glob("srcs/layouts/*.xml")):
|
||||
layout_id, _ = os.path.splitext(os.path.basename(fname))
|
||||
if layout_id in KNOWN_NOT_LAYOUT:
|
||||
|
Loading…
x
Reference in New Issue
Block a user