Coverage for gws-app/gws/plugin/model_widget/select/__init__.py: 0%

34 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2025-10-16 23:09 +0200

1"""Select widget.""" 

2 

3from typing import Optional, Any 

4 

5import gws 

6import gws.base.model.widget 

7 

8gws.ext.new.modelWidget('select') 

9 

10 

11# see also js/ui/select 

12class ListItem(gws.Data): 

13 """Item in the select widget.""" 

14 

15 value: Any 

16 """Value of the item.""" 

17 text: str 

18 """Text to display for the item.""" 

19 extraText: Optional[str] 

20 """Additional text to display for the item.""" 

21 level: Optional[int] 

22 """Optional level for hierarchical items, used for indentation.""" 

23 

24 

25class ListItemConfig(gws.Data): 

26 """Configuration for a list item in the select widget.""" 

27 

28 value: Any 

29 """Value of the item.""" 

30 text: Optional[str] 

31 """Text to display for the item.""" 

32 extraText: Optional[str] 

33 """Additional text to display for the item.""" 

34 level: Optional[int] 

35 """Optional level for hierarchical items, used for indentation.""" 

36 

37 

38class Config(gws.base.model.widget.Config): 

39 """Select widget configuration.""" 

40 

41 items: list[ListItemConfig] 

42 """List of items to select from.""" 

43 withSearch: bool = False 

44 """Whether to show a search input field.""" 

45 

46 

47class Props(gws.base.model.widget.Props): 

48 items: list[ListItem] 

49 withSearch: bool 

50 

51 

52class Object(gws.base.model.widget.Object): 

53 def props(self, user): 

54 # fmt: off 

55 items = [ 

56 ListItem(value=it.value, text=it.text or str(it.value)) 

57 for it in self.cfg('items', default=[]) 

58 ] 

59 # fmt: on 

60 return gws.u.merge( 

61 super().props(user), 

62 items=items, 

63 withSearch=bool(self.cfg('withSearch')), 

64 )