Coverage for gws-app/gws/base/printer/core.py: 100%

26 statements  

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

1"""Default printer.""" 

2 

3from typing import Optional 

4 

5import gws 

6import gws.base.feature 

7import gws.base.model 

8import gws.base.template 

9import gws.config.util 

10import gws.lib.style 

11 

12 

13@gws.ext.config.printer('default') 

14class Config(gws.ConfigWithAccess): 

15 """Print template offered to users.""" 

16 

17 template: gws.ext.config.template 

18 """Template that renders the print output.""" 

19 title: str = '' 

20 """Printer title shown to users.""" 

21 models: Optional[list[gws.ext.config.model]] 

22 """Models whose fields are shown as input fields in the print dialog.""" 

23 qualityLevels: Optional[list[gws.TemplateQualityLevel]] 

24 """Quality levels users can choose from.""" 

25 

26 

27@gws.ext.props.printer('default') 

28class Props(gws.Props): 

29 template: gws.base.template.Props 

30 model: gws.base.model.Props 

31 qualityLevels: list[gws.TemplateQualityLevel] 

32 title: str 

33 

34 

35@gws.ext.object.printer('default') 

36class Object(gws.Printer): 

37 """Default printer.""" 

38 

39 def configure(self): 

40 gws.config.util.configure_models_for(self) 

41 self.template = self.create_child(gws.ext.object.template, self.cfg('template')) 

42 self.qualityLevels = self.cfg('qualityLevels') or [gws.TemplateQualityLevel(name='default', dpi=0)] 

43 self.title = self.cfg('title') or self.template.title or '' 

44 

45 def props(self, user): 

46 model = self.root.app.modelMgr.find_model(self, user=user, access=gws.Access.write) 

47 return Props( 

48 uid=self.uid, 

49 template=self.template, 

50 model=model, 

51 qualityLevels=self.qualityLevels, 

52 title=self.title, 

53 )