Coverage for gws-app/gws/plugin/legend/combined/__init__.py: 0%

22 statements  

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

1"""Combined legend. 

2 

3Renders the legends of several layers, given by ``layerUids``, and combines 

4them into one image. Layers that are not found or have no legend are skipped. 

5 

6Example:: 

7 

8 legend { 

9 type "combined" 

10 layerUids ["layer_1", "layer_2"] 

11 } 

12""" 

13 

14from typing import Optional, cast 

15 

16import gws 

17import gws.lib.image 

18import gws.lib.mime 

19import gws.base.legend 

20 

21 

22@gws.ext.config.legend('combined') 

23class Config(gws.base.legend.Config): 

24 """Legend combining the legends of several layers.""" 

25 

26 layerUids: list[str] 

27 """UIDs of the layers whose legends are combined.""" 

28 

29 

30@gws.ext.object.legend('combined') 

31class Object(gws.base.legend.Object): 

32 """Combined legend.""" 

33 

34 layerUids: list[str] 

35 """UIDs of the layers whose legends are combined.""" 

36 

37 def configure(self): 

38 self.layerUids = self.cfg('layerUids') 

39 

40 def render(self, args=None): 

41 outputs = [] 

42 

43 for uid in self.layerUids: 

44 layer = cast(gws.Layer, self.root.get(uid, gws.ext.object.layer)) 

45 if layer and layer.legend: 

46 lro = layer.legend.render(args) 

47 if lro: 

48 outputs.append(lro) 

49 

50 return gws.base.legend.combine_outputs(outputs, self.options)