MCPcopy Create free account
hub / github.com/PageBot/PageBot / newPage

Method newPage

Lib/pagebot/document.py:1023–1063  ·  view source on GitHub ↗

Creates a new page with size `(self.w, self.h)` unless defined otherwise. Add the pages in the row of pn, if defined, otherwise create a new row of pages at pn. If `pn` is undefined, add a new page row at the end. If template is undefined, then use self.defaultTemplate to

(self, pn=None, template=None, w=None, h=None, name=None, **kwargs)

Source from the content-addressed store, hash-verified

1021 isRight = isLeft = False
1022
1023 def newPage(self, pn=None, template=None, w=None, h=None, name=None, **kwargs):
1024 """Creates a new page with size `(self.w, self.h)` unless defined
1025 otherwise. Add the pages in the row of pn, if defined, otherwise create
1026 a new row of pages at pn. If `pn` is undefined, add a new page row at
1027 the end. If template is undefined, then use self.defaultTemplate to
1028 initialize the new page.
1029
1030 >>> doc = Document(w=80, h=120)
1031 >>> page = doc[1]
1032 >>> page.size
1033 (80pt, 120pt)
1034 """
1035
1036 if isinstance(template, str):
1037 template = self.templates.get(template)
1038
1039 # Find the template with this name.
1040 if isinstance(template, str):
1041 template = self.getTemplate(template)
1042
1043 # Not defined or template not found, then use default
1044 if template is None:
1045 template = self.defaultTemplate
1046
1047 if not name and template is not None:
1048 name = template.name
1049
1050 # If undefined, copy the new page size from the document preset size.
1051 if w is None:
1052 w = self.w
1053
1054 if h is None:
1055 h = self.h
1056
1057 # Don't set parent to self yet, as this will make the page create a #1.
1058 # Setting of page.parent is done by self.appendPage, for the right page
1059 # number.
1060 page = self.PAGE_CLASS(w=w, h=h, name=name, description='page', **kwargs)
1061 self.appendPage(page, pn) # Add the page to the document, before applying the template.
1062 page.applyTemplate(template)
1063 return page
1064
1065 def removePage(self, pn):
1066 """Remove the page with index pn, keeping the page numbers of the remaining pages unchanged.

Callers 2

makePagesMethod · 0.95
nextPageMethod · 0.95

Calls 4

getTemplateMethod · 0.95
appendPageMethod · 0.95
applyTemplateMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected