Coverage for gws-app/gws/plugin/annotate_tool/action.py: 0%

25 statements  

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

1"""The ``annotate`` action.""" 

2 

3from typing import Optional 

4 

5import gws 

6import gws.base.action 

7import gws.base.web 

8import gws.base.storage 

9 

10 

11@gws.ext.config.action('annotate') 

12class Config(gws.base.action.Config): 

13 """Map annotations with measurement labels.""" 

14 

15 storage: Optional[gws.base.storage.Config] 

16 """Storage for saved annotations.""" 

17 labels: Optional[dict] 

18 """Label templates per shape type.""" 

19 

20 

21@gws.ext.props.action('annotate') 

22class Props(gws.base.action.Props): 

23 storage: gws.base.storage.Props 

24 labels: dict 

25 

26 

27@gws.ext.object.action('annotate') 

28class Object(gws.base.action.Object): 

29 """Annotate action.""" 

30 

31 storage: Optional[gws.base.storage.Object] 

32 """Storage for saved annotations, or ``None`` if not configured.""" 

33 labels: Optional[dict] 

34 """Label templates per shape type, passed to the client.""" 

35 

36 def configure(self): 

37 self.storage = self.create_child_if_configured( 

38 gws.base.storage.Object, 

39 self.cfg('storage'), 

40 categoryName='Annotate', 

41 ) 

42 self.labels = self.cfg('labels') 

43 

44 def props(self, user): 

45 return gws.u.merge( 

46 super().props(user), 

47 storage=self.storage, 

48 labels=self.labels, 

49 ) 

50 

51 @gws.ext.command.api('annotateStorage') 

52 def handle_storage(self, req: gws.WebRequester, p: gws.base.storage.Request) -> gws.base.storage.Response: 

53 """Read or write saved annotations.""" 

54 if not self.storage: 

55 raise gws.NotFoundError('no storage configured') 

56 return self.storage.handle_request(req, p)