From a082722b6df2e1158edd858dd5313496a1f6e0ed Mon Sep 17 00:00:00 2001 From: Sergey Vartanov Date: Fri, 8 Apr 2022 01:27:13 +0300 Subject: [PATCH] Refactor icon colors. --- map_machine/scheme.py | 10 +++++++++- map_machine/scheme/default.yml | 1 + tests/test_icons.py | 30 ++++++++++++++++-------------- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/map_machine/scheme.py b/map_machine/scheme.py index 28a3134..7b016ae 100644 --- a/map_machine/scheme.py +++ b/map_machine/scheme.py @@ -410,6 +410,14 @@ class Scheme: logging.debug(f"Unknown color `{color}`.") return Color(self.colors["default"]) + def get_default_color(self) -> Color: + """Get default color for a main icon.""" + return self.get_color("default") + + def get_extra_color(self) -> Color: + """Get default color for an extra icon.""" + return self.get_color("extra") + def get(self, variable_name: str): """ FIXME: colors should be variables. @@ -529,7 +537,7 @@ class Scheme: if matcher.add_shapes: specifications = [ self.get_shape_specification( - x, extractor, color=Color("#888888") + x, extractor, color=self.get_extra_color() ) for x in matcher.add_shapes ] diff --git a/map_machine/scheme/default.yml b/map_machine/scheme/default.yml index d41dd8c..84ff89b 100644 --- a/map_machine/scheme/default.yml +++ b/map_machine/scheme/default.yml @@ -3,6 +3,7 @@ colors: # Entity default: "#444444" + extra: "#888888" direction_view_color: "#C8E8FF" direction_camera_color: "#0088FF" diff --git a/tests/test_icons.py b/tests/test_icons.py index 23cb2df..44b16fa 100644 --- a/tests/test_icons.py +++ b/tests/test_icons.py @@ -15,7 +15,9 @@ __email__ = "me@enzet.ru" COLLECTION: IconCollection = IconCollection.from_scheme(SCHEME, SHAPE_EXTRACTOR) -DEFAULT_COLOR: Color = SCHEME.get_color("default") +DEFAULT_COLOR: Color = SCHEME.get_default_color() +EXTRA_COLOR: Color = SCHEME.get_extra_color() +WHITE: Color = Color("white") def test_grid() -> None: @@ -68,8 +70,8 @@ def test_no_icons_but_color() -> None: def check_icon_set( icon: IconSet, - main_specification: list[tuple[str, Optional[str]]], - extra_specifications: list[list[tuple[str, Optional[str]]]], + main_specification: list[tuple[str, Optional[Color]]], + extra_specifications: list[list[tuple[str, Optional[Color]]]], ) -> None: """Check icon set using simple specification.""" if not main_specification: @@ -101,7 +103,7 @@ def test_icon() -> None: icons. """ icon: IconSet = get_icon({"natural": "tree"}) - check_icon_set(icon, [("tree", "#98AC64")], []) + check_icon_set(icon, [("tree", Color("#98AC64"))], []) def test_icon_1_extra() -> None: @@ -110,7 +112,7 @@ def test_icon_1_extra() -> None: """ icon: IconSet = get_icon({"barrier": "gate", "access": "private"}) check_icon_set( - icon, [("gate", "#444444")], [[("lock_with_keyhole", "#888888")]] + icon, [("gate", DEFAULT_COLOR)], [[("lock_with_keyhole", EXTRA_COLOR)]] ) @@ -123,10 +125,10 @@ def test_icon_2_extra() -> None: ) check_icon_set( icon, - [("gate", "#444444")], + [("gate", DEFAULT_COLOR)], [ - [("bicycle", "#888888")], - [("lock_with_keyhole", "#888888")], + [("bicycle", EXTRA_COLOR)], + [("lock_with_keyhole", EXTRA_COLOR)], ], ) @@ -136,7 +138,7 @@ def test_no_icon_1_extra() -> None: Tags that should be visualized with default main icon and single extra icon. """ icon: IconSet = get_icon({"access": "private"}) - check_icon_set(icon, [], [[("lock_with_keyhole", "#888888")]]) + check_icon_set(icon, [], [[("lock_with_keyhole", EXTRA_COLOR)]]) def test_no_icon_2_extra() -> None: @@ -148,8 +150,8 @@ def test_no_icon_2_extra() -> None: icon, [], [ - [("bicycle", "#888888")], - [("lock_with_keyhole", "#888888")], + [("bicycle", EXTRA_COLOR)], + [("lock_with_keyhole", EXTRA_COLOR)], ], ) @@ -162,9 +164,9 @@ def test_icon_regex() -> None: check_icon_set( icon, [ - ("circle_11", "#444444"), - ("digit_4", "#FFFFFF"), - ("digit_2", "#FFFFFF"), + ("circle_11", DEFAULT_COLOR), + ("digit_4", WHITE), + ("digit_2", WHITE), ], [], )