2023-08-15 16:20:26 +02:00
|
|
|
# SPDX-FileCopyrightText: 2013-2023 Blender Authors
|
2023-06-15 05:09:04 +02:00
|
|
|
#
|
2022-02-10 23:07:11 +01:00
|
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
2013-02-26 05:48:16 +01:00
|
|
|
|
2018-11-20 01:36:44 +01:00
|
|
|
# simple script to test 'bl_keymap_utils.keymap_hierarchy' contains correct values.
|
2013-02-26 05:48:16 +01:00
|
|
|
|
2018-11-20 01:36:44 +01:00
|
|
|
# Needed for 'bl_keymap_utils.keymap_hierarchy' which inspects tools.
|
|
|
|
import sys
|
|
|
|
import os
|
2023-03-01 11:51:51 +01:00
|
|
|
sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, "scripts", "startup"))
|
2018-11-20 01:36:44 +01:00
|
|
|
del sys, os
|
2013-02-26 05:48:16 +01:00
|
|
|
|
2018-11-20 01:36:44 +01:00
|
|
|
from bl_keymap_utils import keymap_hierarchy
|
2013-02-26 05:48:16 +01:00
|
|
|
|
|
|
|
|
|
|
|
def check_maps():
|
2013-02-26 06:22:04 +01:00
|
|
|
maps = {}
|
2013-02-26 05:48:16 +01:00
|
|
|
|
2018-10-03 07:48:37 +02:00
|
|
|
def fill_maps(seq):
|
|
|
|
for km_name, km_space_type, km_region_type, km_sub in seq:
|
2013-02-26 06:22:04 +01:00
|
|
|
maps[km_name] = (km_space_type, km_region_type)
|
|
|
|
fill_maps(km_sub)
|
2013-02-26 05:48:16 +01:00
|
|
|
|
2018-11-20 01:36:44 +01:00
|
|
|
fill_maps(keymap_hierarchy.generate())
|
2013-02-26 05:48:16 +01:00
|
|
|
|
|
|
|
import bpy
|
2013-02-26 06:22:04 +01:00
|
|
|
keyconf = bpy.context.window_manager.keyconfigs.active
|
|
|
|
maps_bl = set(keyconf.keymaps.keys())
|
|
|
|
maps_py = set(maps.keys())
|
2013-02-26 05:48:16 +01:00
|
|
|
|
|
|
|
err = False
|
|
|
|
# Check keyconfig contains only maps that exist in blender
|
2013-02-26 06:22:04 +01:00
|
|
|
test = maps_py - maps_bl
|
2013-02-26 05:48:16 +01:00
|
|
|
if test:
|
2018-11-20 01:36:44 +01:00
|
|
|
print("Keymaps that are in 'bl_keymap_utils.keymap_hierarchy' but not blender")
|
2019-06-25 16:07:28 +02:00
|
|
|
for km_id in test:
|
|
|
|
if callable(km_id):
|
|
|
|
# Keymap functions of tools are not in blender anyway...
|
|
|
|
continue
|
2013-02-26 05:48:16 +01:00
|
|
|
print("\t%s" % km_id)
|
2023-02-12 04:37:16 +01:00
|
|
|
# TODO #65963, broken keymap hierarchy tests disabled until fixed.
|
2019-06-28 13:42:18 +02:00
|
|
|
# err = True
|
2013-02-26 05:48:16 +01:00
|
|
|
|
2013-02-26 06:22:04 +01:00
|
|
|
test = maps_bl - maps_py
|
2013-02-26 05:48:16 +01:00
|
|
|
if test:
|
2018-11-20 01:36:44 +01:00
|
|
|
print("Keymaps that are in blender but not in 'bl_keymap_utils.keymap_hierarchy'")
|
2019-06-25 16:07:28 +02:00
|
|
|
for km_id in test:
|
2013-02-26 06:22:04 +01:00
|
|
|
km = keyconf.keymaps[km_id]
|
|
|
|
print(" ('%s', '%s', '%s', [])," % (km_id, km.space_type, km.region_type))
|
2023-02-12 04:37:16 +01:00
|
|
|
# TODO #65963, broken keymap hierarchy tests disabled until fixed.
|
2019-06-28 13:42:18 +02:00
|
|
|
# err = True
|
2013-02-26 05:48:16 +01:00
|
|
|
|
2013-02-26 06:22:04 +01:00
|
|
|
# Check space/region's are OK
|
|
|
|
print("Comparing keymap space/region types...")
|
|
|
|
for km_id, km in keyconf.keymaps.items():
|
|
|
|
km_py = maps.get(km_id)
|
|
|
|
if km_py is not None:
|
|
|
|
km_space_type, km_region_type = km_py
|
|
|
|
if km_space_type != km.space_type or km_region_type != km.region_type:
|
|
|
|
print(" Error:")
|
|
|
|
print(" expected -- ('%s', '%s', '%s', [])," % (km_id, km.space_type, km.region_type))
|
|
|
|
print(" got -- ('%s', '%s', '%s', [])," % (km_id, km_space_type, km_region_type))
|
|
|
|
print("done!")
|
|
|
|
|
2013-02-26 05:48:16 +01:00
|
|
|
return err
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
err = check_maps()
|
|
|
|
|
2013-02-26 06:22:04 +01:00
|
|
|
import bpy
|
2013-02-26 05:48:16 +01:00
|
|
|
if err and bpy.app.background:
|
|
|
|
# alert CTest we failed
|
|
|
|
import sys
|
|
|
|
sys.exit(1)
|
|
|
|
|
2017-06-12 05:35:00 +02:00
|
|
|
|
2013-02-26 05:48:16 +01:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|