Coverage for gws-app/gws/lib/style/__init__.py: 100%

2 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-10-05 13:35 +0200

1"""Feature styles. 

2 

3A style describes how features are drawn: fill, stroke, markers, icons and labels. 

4Styles are written in a subset of CSS, extended with custom properties for markers and labels 

5(e.g. ``--marker``, ``--label-fill``). A leading ``--`` is optional, and dashes in property names 

6are converted to underscores, so ``--label-fill`` becomes the ``label_fill`` value in ``gws.StyleValues``. 

7 

8Submodules: 

9 

10- ``core``: the ``Object`` class implementing ``gws.Style``, its ``Config`` and ``Props``, 

11 and the constructors ``from_dict``, ``from_config`` and ``from_props``. 

12- ``parser``: parses CSS text or a dict of values into a dict of style values, 

13 validating property names and values and filling in defaults. 

14- ``icon``: loads and parses SVG icons from data URLs, files or URLs. 

15 

16Parsing depends on whether the source is trusted. Styles from the configuration are trusted 

17and may load icons from arbitrary files and URLs. Styles from client requests are untrusted: 

18icons are only accepted as data URLs or from the configured image directories. 

19In strict mode, invalid properties and values raise an error, otherwise they are logged and skipped. 

20 

21In style props sent to the client, a parsed icon is returned as a data URL. 

22An icon that has not been parsed is not returned. 

23 

24Example config:: 

25 

26 style { 

27 text "fill: rgba(255,0,0,0.4); stroke: red; stroke-width: 2; --label-fill: black" 

28 } 

29 

30Example:: 

31 

32 import gws.lib.style 

33 

34 st = gws.lib.style.from_dict({'text': 'stroke: blue; stroke-width: 3px'}) 

35 st.values.stroke_width # 3 

36""" 

37 

38from .core import ( 

39 Config, Object, Props, 

40 from_dict, 

41 from_props, 

42 from_config 

43) 

44from . import icon, parser