id int32 0 252k | repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1 value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 |
|---|---|---|---|---|---|---|---|---|---|---|---|
229,000 | pymupdf/PyMuPDF | fitz/fitz.py | Document.layout | def layout(self, rect=None, width=0, height=0, fontsize=11):
"""Re-layout a reflowable document."""
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
val = _fitz.Document_layout(self, rect, width, height, fontsize)
self._reset_page_refs()
self.initData()
return val | python | def layout(self, rect=None, width=0, height=0, fontsize=11):
"""Re-layout a reflowable document."""
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
val = _fitz.Document_layout(self, rect, width, height, fontsize)
self._reset_page_refs()
self.initData()
return val | [
"def",
"layout",
"(",
"self",
",",
"rect",
"=",
"None",
",",
"width",
"=",
"0",
",",
"height",
"=",
"0",
",",
"fontsize",
"=",
"11",
")",
":",
"if",
"self",
".",
"isClosed",
"or",
"self",
".",
"isEncrypted",
":",
"raise",
"ValueError",
"(",
"\"operation illegal for closed / encrypted doc\"",
")",
"val",
"=",
"_fitz",
".",
"Document_layout",
"(",
"self",
",",
"rect",
",",
"width",
",",
"height",
",",
"fontsize",
")",
"self",
".",
"_reset_page_refs",
"(",
")",
"self",
".",
"initData",
"(",
")",
"return",
"val"
] | Re-layout a reflowable document. | [
"Re",
"-",
"layout",
"a",
"reflowable",
"document",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L1997-L2007 |
229,001 | pymupdf/PyMuPDF | fitz/fitz.py | Document.makeBookmark | def makeBookmark(self, pno=0):
"""Make page bookmark in a reflowable document."""
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
return _fitz.Document_makeBookmark(self, pno) | python | def makeBookmark(self, pno=0):
"""Make page bookmark in a reflowable document."""
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
return _fitz.Document_makeBookmark(self, pno) | [
"def",
"makeBookmark",
"(",
"self",
",",
"pno",
"=",
"0",
")",
":",
"if",
"self",
".",
"isClosed",
"or",
"self",
".",
"isEncrypted",
":",
"raise",
"ValueError",
"(",
"\"operation illegal for closed / encrypted doc\"",
")",
"return",
"_fitz",
".",
"Document_makeBookmark",
"(",
"self",
",",
"pno",
")"
] | Make page bookmark in a reflowable document. | [
"Make",
"page",
"bookmark",
"in",
"a",
"reflowable",
"document",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2010-L2015 |
229,002 | pymupdf/PyMuPDF | fitz/fitz.py | Document.findBookmark | def findBookmark(self, bookmark):
"""Find page number after layouting a document."""
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
return _fitz.Document_findBookmark(self, bookmark) | python | def findBookmark(self, bookmark):
"""Find page number after layouting a document."""
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
return _fitz.Document_findBookmark(self, bookmark) | [
"def",
"findBookmark",
"(",
"self",
",",
"bookmark",
")",
":",
"if",
"self",
".",
"isClosed",
"or",
"self",
".",
"isEncrypted",
":",
"raise",
"ValueError",
"(",
"\"operation illegal for closed / encrypted doc\"",
")",
"return",
"_fitz",
".",
"Document_findBookmark",
"(",
"self",
",",
"bookmark",
")"
] | Find page number after layouting a document. | [
"Find",
"page",
"number",
"after",
"layouting",
"a",
"document",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2018-L2023 |
229,003 | pymupdf/PyMuPDF | fitz/fitz.py | Document._deleteObject | def _deleteObject(self, xref):
"""Delete an object given its xref."""
if self.isClosed:
raise ValueError("operation illegal for closed doc")
return _fitz.Document__deleteObject(self, xref) | python | def _deleteObject(self, xref):
"""Delete an object given its xref."""
if self.isClosed:
raise ValueError("operation illegal for closed doc")
return _fitz.Document__deleteObject(self, xref) | [
"def",
"_deleteObject",
"(",
"self",
",",
"xref",
")",
":",
"if",
"self",
".",
"isClosed",
":",
"raise",
"ValueError",
"(",
"\"operation illegal for closed doc\"",
")",
"return",
"_fitz",
".",
"Document__deleteObject",
"(",
"self",
",",
"xref",
")"
] | Delete an object given its xref. | [
"Delete",
"an",
"object",
"given",
"its",
"xref",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2035-L2040 |
229,004 | pymupdf/PyMuPDF | fitz/fitz.py | Document.authenticate | def authenticate(self, password):
"""Decrypt document with a password."""
if self.isClosed:
raise ValueError("operation illegal for closed doc")
val = _fitz.Document_authenticate(self, password)
if val: # the doc is decrypted successfully and we init the outline
self.isEncrypted = 0
self.initData()
self.thisown = True
return val | python | def authenticate(self, password):
"""Decrypt document with a password."""
if self.isClosed:
raise ValueError("operation illegal for closed doc")
val = _fitz.Document_authenticate(self, password)
if val: # the doc is decrypted successfully and we init the outline
self.isEncrypted = 0
self.initData()
self.thisown = True
return val | [
"def",
"authenticate",
"(",
"self",
",",
"password",
")",
":",
"if",
"self",
".",
"isClosed",
":",
"raise",
"ValueError",
"(",
"\"operation illegal for closed doc\"",
")",
"val",
"=",
"_fitz",
".",
"Document_authenticate",
"(",
"self",
",",
"password",
")",
"if",
"val",
":",
"# the doc is decrypted successfully and we init the outline",
"self",
".",
"isEncrypted",
"=",
"0",
"self",
".",
"initData",
"(",
")",
"self",
".",
"thisown",
"=",
"True",
"return",
"val"
] | Decrypt document with a password. | [
"Decrypt",
"document",
"with",
"a",
"password",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2105-L2118 |
229,005 | pymupdf/PyMuPDF | fitz/fitz.py | Document.write | def write(self, garbage=0, clean=0, deflate=0, ascii=0, expand=0, linear=0, pretty=0, decrypt=1):
"""Write document to a bytes object."""
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
if self.pageCount < 1:
raise ValueError("cannot write with zero pages")
return _fitz.Document_write(self, garbage, clean, deflate, ascii, expand, linear, pretty, decrypt) | python | def write(self, garbage=0, clean=0, deflate=0, ascii=0, expand=0, linear=0, pretty=0, decrypt=1):
"""Write document to a bytes object."""
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
if self.pageCount < 1:
raise ValueError("cannot write with zero pages")
return _fitz.Document_write(self, garbage, clean, deflate, ascii, expand, linear, pretty, decrypt) | [
"def",
"write",
"(",
"self",
",",
"garbage",
"=",
"0",
",",
"clean",
"=",
"0",
",",
"deflate",
"=",
"0",
",",
"ascii",
"=",
"0",
",",
"expand",
"=",
"0",
",",
"linear",
"=",
"0",
",",
"pretty",
"=",
"0",
",",
"decrypt",
"=",
"1",
")",
":",
"if",
"self",
".",
"isClosed",
"or",
"self",
".",
"isEncrypted",
":",
"raise",
"ValueError",
"(",
"\"operation illegal for closed / encrypted doc\"",
")",
"if",
"self",
".",
"pageCount",
"<",
"1",
":",
"raise",
"ValueError",
"(",
"\"cannot write with zero pages\"",
")",
"return",
"_fitz",
".",
"Document_write",
"(",
"self",
",",
"garbage",
",",
"clean",
",",
"deflate",
",",
"ascii",
",",
"expand",
",",
"linear",
",",
"pretty",
",",
"decrypt",
")"
] | Write document to a bytes object. | [
"Write",
"document",
"to",
"a",
"bytes",
"object",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2144-L2153 |
229,006 | pymupdf/PyMuPDF | fitz/fitz.py | Document.select | def select(self, pyliste):
"""Build sub-pdf with page numbers in 'list'."""
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
val = _fitz.Document_select(self, pyliste)
self._reset_page_refs()
self.initData()
return val | python | def select(self, pyliste):
"""Build sub-pdf with page numbers in 'list'."""
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
val = _fitz.Document_select(self, pyliste)
self._reset_page_refs()
self.initData()
return val | [
"def",
"select",
"(",
"self",
",",
"pyliste",
")",
":",
"if",
"self",
".",
"isClosed",
"or",
"self",
".",
"isEncrypted",
":",
"raise",
"ValueError",
"(",
"\"operation illegal for closed / encrypted doc\"",
")",
"val",
"=",
"_fitz",
".",
"Document_select",
"(",
"self",
",",
"pyliste",
")",
"self",
".",
"_reset_page_refs",
"(",
")",
"self",
".",
"initData",
"(",
")",
"return",
"val"
] | Build sub-pdf with page numbers in 'list'. | [
"Build",
"sub",
"-",
"pdf",
"with",
"page",
"numbers",
"in",
"list",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2186-L2196 |
229,007 | pymupdf/PyMuPDF | fitz/fitz.py | Document._getCharWidths | def _getCharWidths(self, xref, bfname, ext, ordering, limit, idx=0):
"""Return list of glyphs and glyph widths of a font."""
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
return _fitz.Document__getCharWidths(self, xref, bfname, ext, ordering, limit, idx) | python | def _getCharWidths(self, xref, bfname, ext, ordering, limit, idx=0):
"""Return list of glyphs and glyph widths of a font."""
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
return _fitz.Document__getCharWidths(self, xref, bfname, ext, ordering, limit, idx) | [
"def",
"_getCharWidths",
"(",
"self",
",",
"xref",
",",
"bfname",
",",
"ext",
",",
"ordering",
",",
"limit",
",",
"idx",
"=",
"0",
")",
":",
"if",
"self",
".",
"isClosed",
"or",
"self",
".",
"isEncrypted",
":",
"raise",
"ValueError",
"(",
"\"operation illegal for closed / encrypted doc\"",
")",
"return",
"_fitz",
".",
"Document__getCharWidths",
"(",
"self",
",",
"xref",
",",
"bfname",
",",
"ext",
",",
"ordering",
",",
"limit",
",",
"idx",
")"
] | Return list of glyphs and glyph widths of a font. | [
"Return",
"list",
"of",
"glyphs",
"and",
"glyph",
"widths",
"of",
"a",
"font",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2208-L2213 |
229,008 | pymupdf/PyMuPDF | fitz/fitz.py | Document._getPageInfo | def _getPageInfo(self, pno, what):
"""Show fonts or images used on a page."""
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
val = _fitz.Document__getPageInfo(self, pno, what)
x = []
for v in val:
if v not in x:
x.append(v)
val = x
return val | python | def _getPageInfo(self, pno, what):
"""Show fonts or images used on a page."""
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
val = _fitz.Document__getPageInfo(self, pno, what)
x = []
for v in val:
if v not in x:
x.append(v)
val = x
return val | [
"def",
"_getPageInfo",
"(",
"self",
",",
"pno",
",",
"what",
")",
":",
"if",
"self",
".",
"isClosed",
"or",
"self",
".",
"isEncrypted",
":",
"raise",
"ValueError",
"(",
"\"operation illegal for closed / encrypted doc\"",
")",
"val",
"=",
"_fitz",
".",
"Document__getPageInfo",
"(",
"self",
",",
"pno",
",",
"what",
")",
"x",
"=",
"[",
"]",
"for",
"v",
"in",
"val",
":",
"if",
"v",
"not",
"in",
"x",
":",
"x",
".",
"append",
"(",
"v",
")",
"val",
"=",
"x",
"return",
"val"
] | Show fonts or images used on a page. | [
"Show",
"fonts",
"or",
"images",
"used",
"on",
"a",
"page",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2224-L2237 |
229,009 | pymupdf/PyMuPDF | fitz/fitz.py | Document.extractImage | def extractImage(self, xref=0):
"""Extract image which 'xref' is pointing to."""
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
return _fitz.Document_extractImage(self, xref) | python | def extractImage(self, xref=0):
"""Extract image which 'xref' is pointing to."""
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
return _fitz.Document_extractImage(self, xref) | [
"def",
"extractImage",
"(",
"self",
",",
"xref",
"=",
"0",
")",
":",
"if",
"self",
".",
"isClosed",
"or",
"self",
".",
"isEncrypted",
":",
"raise",
"ValueError",
"(",
"\"operation illegal for closed / encrypted doc\"",
")",
"return",
"_fitz",
".",
"Document_extractImage",
"(",
"self",
",",
"xref",
")"
] | Extract image which 'xref' is pointing to. | [
"Extract",
"image",
"which",
"xref",
"is",
"pointing",
"to",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2248-L2253 |
229,010 | pymupdf/PyMuPDF | fitz/fitz.py | Document.getPageFontList | def getPageFontList(self, pno):
"""Retrieve a list of fonts used on a page.
"""
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
if self.isPDF:
return self._getPageInfo(pno, 1)
return [] | python | def getPageFontList(self, pno):
"""Retrieve a list of fonts used on a page.
"""
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
if self.isPDF:
return self._getPageInfo(pno, 1)
return [] | [
"def",
"getPageFontList",
"(",
"self",
",",
"pno",
")",
":",
"if",
"self",
".",
"isClosed",
"or",
"self",
".",
"isEncrypted",
":",
"raise",
"ValueError",
"(",
"\"operation illegal for closed / encrypted doc\"",
")",
"if",
"self",
".",
"isPDF",
":",
"return",
"self",
".",
"_getPageInfo",
"(",
"pno",
",",
"1",
")",
"return",
"[",
"]"
] | Retrieve a list of fonts used on a page. | [
"Retrieve",
"a",
"list",
"of",
"fonts",
"used",
"on",
"a",
"page",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2391-L2398 |
229,011 | pymupdf/PyMuPDF | fitz/fitz.py | Document.getPageImageList | def getPageImageList(self, pno):
"""Retrieve a list of images used on a page.
"""
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
if self.isPDF:
return self._getPageInfo(pno, 2)
return [] | python | def getPageImageList(self, pno):
"""Retrieve a list of images used on a page.
"""
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
if self.isPDF:
return self._getPageInfo(pno, 2)
return [] | [
"def",
"getPageImageList",
"(",
"self",
",",
"pno",
")",
":",
"if",
"self",
".",
"isClosed",
"or",
"self",
".",
"isEncrypted",
":",
"raise",
"ValueError",
"(",
"\"operation illegal for closed / encrypted doc\"",
")",
"if",
"self",
".",
"isPDF",
":",
"return",
"self",
".",
"_getPageInfo",
"(",
"pno",
",",
"2",
")",
"return",
"[",
"]"
] | Retrieve a list of images used on a page. | [
"Retrieve",
"a",
"list",
"of",
"images",
"used",
"on",
"a",
"page",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2400-L2407 |
229,012 | pymupdf/PyMuPDF | fitz/fitz.py | Document.copyPage | def copyPage(self, pno, to=-1):
"""Copy a page to before some other page of the document. Specify 'to = -1' to copy after last page.
"""
pl = list(range(len(self)))
if pno < 0 or pno > pl[-1]:
raise ValueError("'from' page number out of range")
if to < -1 or to > pl[-1]:
raise ValueError("'to' page number out of range")
if to == -1:
pl.append(pno)
else:
pl.insert(to, pno)
return self.select(pl) | python | def copyPage(self, pno, to=-1):
"""Copy a page to before some other page of the document. Specify 'to = -1' to copy after last page.
"""
pl = list(range(len(self)))
if pno < 0 or pno > pl[-1]:
raise ValueError("'from' page number out of range")
if to < -1 or to > pl[-1]:
raise ValueError("'to' page number out of range")
if to == -1:
pl.append(pno)
else:
pl.insert(to, pno)
return self.select(pl) | [
"def",
"copyPage",
"(",
"self",
",",
"pno",
",",
"to",
"=",
"-",
"1",
")",
":",
"pl",
"=",
"list",
"(",
"range",
"(",
"len",
"(",
"self",
")",
")",
")",
"if",
"pno",
"<",
"0",
"or",
"pno",
">",
"pl",
"[",
"-",
"1",
"]",
":",
"raise",
"ValueError",
"(",
"\"'from' page number out of range\"",
")",
"if",
"to",
"<",
"-",
"1",
"or",
"to",
">",
"pl",
"[",
"-",
"1",
"]",
":",
"raise",
"ValueError",
"(",
"\"'to' page number out of range\"",
")",
"if",
"to",
"==",
"-",
"1",
":",
"pl",
".",
"append",
"(",
"pno",
")",
"else",
":",
"pl",
".",
"insert",
"(",
"to",
",",
"pno",
")",
"return",
"self",
".",
"select",
"(",
"pl",
")"
] | Copy a page to before some other page of the document. Specify 'to = -1' to copy after last page. | [
"Copy",
"a",
"page",
"to",
"before",
"some",
"other",
"page",
"of",
"the",
"document",
".",
"Specify",
"to",
"=",
"-",
"1",
"to",
"copy",
"after",
"last",
"page",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2409-L2421 |
229,013 | pymupdf/PyMuPDF | fitz/fitz.py | Document.movePage | def movePage(self, pno, to = -1):
"""Move a page to before some other page of the document. Specify 'to = -1' to move after last page.
"""
pl = list(range(len(self)))
if pno < 0 or pno > pl[-1]:
raise ValueError("'from' page number out of range")
if to < -1 or to > pl[-1]:
raise ValueError("'to' page number out of range")
pl.remove(pno)
if to == -1:
pl.append(pno)
else:
pl.insert(to-1, pno)
return self.select(pl) | python | def movePage(self, pno, to = -1):
"""Move a page to before some other page of the document. Specify 'to = -1' to move after last page.
"""
pl = list(range(len(self)))
if pno < 0 or pno > pl[-1]:
raise ValueError("'from' page number out of range")
if to < -1 or to > pl[-1]:
raise ValueError("'to' page number out of range")
pl.remove(pno)
if to == -1:
pl.append(pno)
else:
pl.insert(to-1, pno)
return self.select(pl) | [
"def",
"movePage",
"(",
"self",
",",
"pno",
",",
"to",
"=",
"-",
"1",
")",
":",
"pl",
"=",
"list",
"(",
"range",
"(",
"len",
"(",
"self",
")",
")",
")",
"if",
"pno",
"<",
"0",
"or",
"pno",
">",
"pl",
"[",
"-",
"1",
"]",
":",
"raise",
"ValueError",
"(",
"\"'from' page number out of range\"",
")",
"if",
"to",
"<",
"-",
"1",
"or",
"to",
">",
"pl",
"[",
"-",
"1",
"]",
":",
"raise",
"ValueError",
"(",
"\"'to' page number out of range\"",
")",
"pl",
".",
"remove",
"(",
"pno",
")",
"if",
"to",
"==",
"-",
"1",
":",
"pl",
".",
"append",
"(",
"pno",
")",
"else",
":",
"pl",
".",
"insert",
"(",
"to",
"-",
"1",
",",
"pno",
")",
"return",
"self",
".",
"select",
"(",
"pl",
")"
] | Move a page to before some other page of the document. Specify 'to = -1' to move after last page. | [
"Move",
"a",
"page",
"to",
"before",
"some",
"other",
"page",
"of",
"the",
"document",
".",
"Specify",
"to",
"=",
"-",
"1",
"to",
"move",
"after",
"last",
"page",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2423-L2436 |
229,014 | pymupdf/PyMuPDF | fitz/fitz.py | Document.deletePage | def deletePage(self, pno = -1):
"""Delete a page from the document. First page is '0', last page is '-1'.
"""
pl = list(range(len(self)))
if pno < -1 or pno > pl[-1]:
raise ValueError("page number out of range")
if pno >= 0:
pl.remove(pno)
else:
pl.remove(pl[-1])
return self.select(pl) | python | def deletePage(self, pno = -1):
"""Delete a page from the document. First page is '0', last page is '-1'.
"""
pl = list(range(len(self)))
if pno < -1 or pno > pl[-1]:
raise ValueError("page number out of range")
if pno >= 0:
pl.remove(pno)
else:
pl.remove(pl[-1])
return self.select(pl) | [
"def",
"deletePage",
"(",
"self",
",",
"pno",
"=",
"-",
"1",
")",
":",
"pl",
"=",
"list",
"(",
"range",
"(",
"len",
"(",
"self",
")",
")",
")",
"if",
"pno",
"<",
"-",
"1",
"or",
"pno",
">",
"pl",
"[",
"-",
"1",
"]",
":",
"raise",
"ValueError",
"(",
"\"page number out of range\"",
")",
"if",
"pno",
">=",
"0",
":",
"pl",
".",
"remove",
"(",
"pno",
")",
"else",
":",
"pl",
".",
"remove",
"(",
"pl",
"[",
"-",
"1",
"]",
")",
"return",
"self",
".",
"select",
"(",
"pl",
")"
] | Delete a page from the document. First page is '0', last page is '-1'. | [
"Delete",
"a",
"page",
"from",
"the",
"document",
".",
"First",
"page",
"is",
"0",
"last",
"page",
"is",
"-",
"1",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2438-L2448 |
229,015 | pymupdf/PyMuPDF | fitz/fitz.py | Document.deletePageRange | def deletePageRange(self, from_page = -1, to_page = -1):
"""Delete pages from the document. First page is '0', last page is '-1'.
"""
pl = list(range(len(self)))
f = from_page
t = to_page
if f == -1:
f = pl[-1]
if t == -1:
t = pl[-1]
if not 0 <= f <= t <= pl[-1]:
raise ValueError("page number(s) out of range")
for i in range(f, t+1):
pl.remove(i)
return self.select(pl) | python | def deletePageRange(self, from_page = -1, to_page = -1):
"""Delete pages from the document. First page is '0', last page is '-1'.
"""
pl = list(range(len(self)))
f = from_page
t = to_page
if f == -1:
f = pl[-1]
if t == -1:
t = pl[-1]
if not 0 <= f <= t <= pl[-1]:
raise ValueError("page number(s) out of range")
for i in range(f, t+1):
pl.remove(i)
return self.select(pl) | [
"def",
"deletePageRange",
"(",
"self",
",",
"from_page",
"=",
"-",
"1",
",",
"to_page",
"=",
"-",
"1",
")",
":",
"pl",
"=",
"list",
"(",
"range",
"(",
"len",
"(",
"self",
")",
")",
")",
"f",
"=",
"from_page",
"t",
"=",
"to_page",
"if",
"f",
"==",
"-",
"1",
":",
"f",
"=",
"pl",
"[",
"-",
"1",
"]",
"if",
"t",
"==",
"-",
"1",
":",
"t",
"=",
"pl",
"[",
"-",
"1",
"]",
"if",
"not",
"0",
"<=",
"f",
"<=",
"t",
"<=",
"pl",
"[",
"-",
"1",
"]",
":",
"raise",
"ValueError",
"(",
"\"page number(s) out of range\"",
")",
"for",
"i",
"in",
"range",
"(",
"f",
",",
"t",
"+",
"1",
")",
":",
"pl",
".",
"remove",
"(",
"i",
")",
"return",
"self",
".",
"select",
"(",
"pl",
")"
] | Delete pages from the document. First page is '0', last page is '-1'. | [
"Delete",
"pages",
"from",
"the",
"document",
".",
"First",
"page",
"is",
"0",
"last",
"page",
"is",
"-",
"1",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2450-L2464 |
229,016 | pymupdf/PyMuPDF | fitz/fitz.py | Document._forget_page | def _forget_page(self, page):
"""Remove a page from document page dict."""
pid = id(page)
if pid in self._page_refs:
self._page_refs[pid] = None | python | def _forget_page(self, page):
"""Remove a page from document page dict."""
pid = id(page)
if pid in self._page_refs:
self._page_refs[pid] = None | [
"def",
"_forget_page",
"(",
"self",
",",
"page",
")",
":",
"pid",
"=",
"id",
"(",
"page",
")",
"if",
"pid",
"in",
"self",
".",
"_page_refs",
":",
"self",
".",
"_page_refs",
"[",
"pid",
"]",
"=",
"None"
] | Remove a page from document page dict. | [
"Remove",
"a",
"page",
"from",
"document",
"page",
"dict",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2488-L2492 |
229,017 | pymupdf/PyMuPDF | fitz/fitz.py | Document._reset_page_refs | def _reset_page_refs(self):
"""Invalidate all pages in document dictionary."""
if self.isClosed:
return
for page in self._page_refs.values():
if page:
page._erase()
page = None
self._page_refs.clear() | python | def _reset_page_refs(self):
"""Invalidate all pages in document dictionary."""
if self.isClosed:
return
for page in self._page_refs.values():
if page:
page._erase()
page = None
self._page_refs.clear() | [
"def",
"_reset_page_refs",
"(",
"self",
")",
":",
"if",
"self",
".",
"isClosed",
":",
"return",
"for",
"page",
"in",
"self",
".",
"_page_refs",
".",
"values",
"(",
")",
":",
"if",
"page",
":",
"page",
".",
"_erase",
"(",
")",
"page",
"=",
"None",
"self",
".",
"_page_refs",
".",
"clear",
"(",
")"
] | Invalidate all pages in document dictionary. | [
"Invalidate",
"all",
"pages",
"in",
"document",
"dictionary",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2494-L2502 |
229,018 | pymupdf/PyMuPDF | fitz/fitz.py | Page.addLineAnnot | def addLineAnnot(self, p1, p2):
"""Add 'Line' annot for points p1 and p2."""
CheckParent(self)
val = _fitz.Page_addLineAnnot(self, p1, p2)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | python | def addLineAnnot(self, p1, p2):
"""Add 'Line' annot for points p1 and p2."""
CheckParent(self)
val = _fitz.Page_addLineAnnot(self, p1, p2)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | [
"def",
"addLineAnnot",
"(",
"self",
",",
"p1",
",",
"p2",
")",
":",
"CheckParent",
"(",
"self",
")",
"val",
"=",
"_fitz",
".",
"Page_addLineAnnot",
"(",
"self",
",",
"p1",
",",
"p2",
")",
"if",
"not",
"val",
":",
"return",
"val",
".",
"thisown",
"=",
"True",
"val",
".",
"parent",
"=",
"weakref",
".",
"proxy",
"(",
"self",
")",
"self",
".",
"_annot_refs",
"[",
"id",
"(",
"val",
")",
"]",
"=",
"val",
"return",
"val"
] | Add 'Line' annot for points p1 and p2. | [
"Add",
"Line",
"annot",
"for",
"points",
"p1",
"and",
"p2",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2563-L2574 |
229,019 | pymupdf/PyMuPDF | fitz/fitz.py | Page.addTextAnnot | def addTextAnnot(self, point, text):
"""Add a 'sticky note' at position 'point'."""
CheckParent(self)
val = _fitz.Page_addTextAnnot(self, point, text)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | python | def addTextAnnot(self, point, text):
"""Add a 'sticky note' at position 'point'."""
CheckParent(self)
val = _fitz.Page_addTextAnnot(self, point, text)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | [
"def",
"addTextAnnot",
"(",
"self",
",",
"point",
",",
"text",
")",
":",
"CheckParent",
"(",
"self",
")",
"val",
"=",
"_fitz",
".",
"Page_addTextAnnot",
"(",
"self",
",",
"point",
",",
"text",
")",
"if",
"not",
"val",
":",
"return",
"val",
".",
"thisown",
"=",
"True",
"val",
".",
"parent",
"=",
"weakref",
".",
"proxy",
"(",
"self",
")",
"self",
".",
"_annot_refs",
"[",
"id",
"(",
"val",
")",
"]",
"=",
"val",
"return",
"val"
] | Add a 'sticky note' at position 'point'. | [
"Add",
"a",
"sticky",
"note",
"at",
"position",
"point",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2577-L2588 |
229,020 | pymupdf/PyMuPDF | fitz/fitz.py | Page.addInkAnnot | def addInkAnnot(self, list):
"""Add a 'handwriting' as a list of list of point-likes. Each sublist forms an independent stroke."""
CheckParent(self)
val = _fitz.Page_addInkAnnot(self, list)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | python | def addInkAnnot(self, list):
"""Add a 'handwriting' as a list of list of point-likes. Each sublist forms an independent stroke."""
CheckParent(self)
val = _fitz.Page_addInkAnnot(self, list)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | [
"def",
"addInkAnnot",
"(",
"self",
",",
"list",
")",
":",
"CheckParent",
"(",
"self",
")",
"val",
"=",
"_fitz",
".",
"Page_addInkAnnot",
"(",
"self",
",",
"list",
")",
"if",
"not",
"val",
":",
"return",
"val",
".",
"thisown",
"=",
"True",
"val",
".",
"parent",
"=",
"weakref",
".",
"proxy",
"(",
"self",
")",
"self",
".",
"_annot_refs",
"[",
"id",
"(",
"val",
")",
"]",
"=",
"val",
"return",
"val"
] | Add a 'handwriting' as a list of list of point-likes. Each sublist forms an independent stroke. | [
"Add",
"a",
"handwriting",
"as",
"a",
"list",
"of",
"list",
"of",
"point",
"-",
"likes",
".",
"Each",
"sublist",
"forms",
"an",
"independent",
"stroke",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2591-L2602 |
229,021 | pymupdf/PyMuPDF | fitz/fitz.py | Page.addStampAnnot | def addStampAnnot(self, rect, stamp=0):
"""Add a 'rubber stamp' in a rectangle."""
CheckParent(self)
val = _fitz.Page_addStampAnnot(self, rect, stamp)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | python | def addStampAnnot(self, rect, stamp=0):
"""Add a 'rubber stamp' in a rectangle."""
CheckParent(self)
val = _fitz.Page_addStampAnnot(self, rect, stamp)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | [
"def",
"addStampAnnot",
"(",
"self",
",",
"rect",
",",
"stamp",
"=",
"0",
")",
":",
"CheckParent",
"(",
"self",
")",
"val",
"=",
"_fitz",
".",
"Page_addStampAnnot",
"(",
"self",
",",
"rect",
",",
"stamp",
")",
"if",
"not",
"val",
":",
"return",
"val",
".",
"thisown",
"=",
"True",
"val",
".",
"parent",
"=",
"weakref",
".",
"proxy",
"(",
"self",
")",
"self",
".",
"_annot_refs",
"[",
"id",
"(",
"val",
")",
"]",
"=",
"val",
"return",
"val"
] | Add a 'rubber stamp' in a rectangle. | [
"Add",
"a",
"rubber",
"stamp",
"in",
"a",
"rectangle",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2605-L2616 |
229,022 | pymupdf/PyMuPDF | fitz/fitz.py | Page.addFileAnnot | def addFileAnnot(self, point, buffer, filename, ufilename=None, desc=None):
"""Add a 'FileAttachment' annotation at location 'point'."""
CheckParent(self)
val = _fitz.Page_addFileAnnot(self, point, buffer, filename, ufilename, desc)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | python | def addFileAnnot(self, point, buffer, filename, ufilename=None, desc=None):
"""Add a 'FileAttachment' annotation at location 'point'."""
CheckParent(self)
val = _fitz.Page_addFileAnnot(self, point, buffer, filename, ufilename, desc)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | [
"def",
"addFileAnnot",
"(",
"self",
",",
"point",
",",
"buffer",
",",
"filename",
",",
"ufilename",
"=",
"None",
",",
"desc",
"=",
"None",
")",
":",
"CheckParent",
"(",
"self",
")",
"val",
"=",
"_fitz",
".",
"Page_addFileAnnot",
"(",
"self",
",",
"point",
",",
"buffer",
",",
"filename",
",",
"ufilename",
",",
"desc",
")",
"if",
"not",
"val",
":",
"return",
"val",
".",
"thisown",
"=",
"True",
"val",
".",
"parent",
"=",
"weakref",
".",
"proxy",
"(",
"self",
")",
"self",
".",
"_annot_refs",
"[",
"id",
"(",
"val",
")",
"]",
"=",
"val",
"return",
"val"
] | Add a 'FileAttachment' annotation at location 'point'. | [
"Add",
"a",
"FileAttachment",
"annotation",
"at",
"location",
"point",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2619-L2630 |
229,023 | pymupdf/PyMuPDF | fitz/fitz.py | Page.addStrikeoutAnnot | def addStrikeoutAnnot(self, rect):
"""Strike out content in a rectangle or quadrilateral."""
CheckParent(self)
val = _fitz.Page_addStrikeoutAnnot(self, rect)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | python | def addStrikeoutAnnot(self, rect):
"""Strike out content in a rectangle or quadrilateral."""
CheckParent(self)
val = _fitz.Page_addStrikeoutAnnot(self, rect)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | [
"def",
"addStrikeoutAnnot",
"(",
"self",
",",
"rect",
")",
":",
"CheckParent",
"(",
"self",
")",
"val",
"=",
"_fitz",
".",
"Page_addStrikeoutAnnot",
"(",
"self",
",",
"rect",
")",
"if",
"not",
"val",
":",
"return",
"val",
".",
"thisown",
"=",
"True",
"val",
".",
"parent",
"=",
"weakref",
".",
"proxy",
"(",
"self",
")",
"self",
".",
"_annot_refs",
"[",
"id",
"(",
"val",
")",
"]",
"=",
"val",
"return",
"val"
] | Strike out content in a rectangle or quadrilateral. | [
"Strike",
"out",
"content",
"in",
"a",
"rectangle",
"or",
"quadrilateral",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2633-L2644 |
229,024 | pymupdf/PyMuPDF | fitz/fitz.py | Page.addUnderlineAnnot | def addUnderlineAnnot(self, rect):
"""Underline content in a rectangle or quadrilateral."""
CheckParent(self)
val = _fitz.Page_addUnderlineAnnot(self, rect)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | python | def addUnderlineAnnot(self, rect):
"""Underline content in a rectangle or quadrilateral."""
CheckParent(self)
val = _fitz.Page_addUnderlineAnnot(self, rect)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | [
"def",
"addUnderlineAnnot",
"(",
"self",
",",
"rect",
")",
":",
"CheckParent",
"(",
"self",
")",
"val",
"=",
"_fitz",
".",
"Page_addUnderlineAnnot",
"(",
"self",
",",
"rect",
")",
"if",
"not",
"val",
":",
"return",
"val",
".",
"thisown",
"=",
"True",
"val",
".",
"parent",
"=",
"weakref",
".",
"proxy",
"(",
"self",
")",
"self",
".",
"_annot_refs",
"[",
"id",
"(",
"val",
")",
"]",
"=",
"val",
"return",
"val"
] | Underline content in a rectangle or quadrilateral. | [
"Underline",
"content",
"in",
"a",
"rectangle",
"or",
"quadrilateral",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2647-L2658 |
229,025 | pymupdf/PyMuPDF | fitz/fitz.py | Page.addSquigglyAnnot | def addSquigglyAnnot(self, rect):
"""Wavy underline content in a rectangle or quadrilateral."""
CheckParent(self)
val = _fitz.Page_addSquigglyAnnot(self, rect)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | python | def addSquigglyAnnot(self, rect):
"""Wavy underline content in a rectangle or quadrilateral."""
CheckParent(self)
val = _fitz.Page_addSquigglyAnnot(self, rect)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | [
"def",
"addSquigglyAnnot",
"(",
"self",
",",
"rect",
")",
":",
"CheckParent",
"(",
"self",
")",
"val",
"=",
"_fitz",
".",
"Page_addSquigglyAnnot",
"(",
"self",
",",
"rect",
")",
"if",
"not",
"val",
":",
"return",
"val",
".",
"thisown",
"=",
"True",
"val",
".",
"parent",
"=",
"weakref",
".",
"proxy",
"(",
"self",
")",
"self",
".",
"_annot_refs",
"[",
"id",
"(",
"val",
")",
"]",
"=",
"val",
"return",
"val"
] | Wavy underline content in a rectangle or quadrilateral. | [
"Wavy",
"underline",
"content",
"in",
"a",
"rectangle",
"or",
"quadrilateral",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2661-L2672 |
229,026 | pymupdf/PyMuPDF | fitz/fitz.py | Page.addHighlightAnnot | def addHighlightAnnot(self, rect):
"""Highlight content in a rectangle or quadrilateral."""
CheckParent(self)
val = _fitz.Page_addHighlightAnnot(self, rect)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | python | def addHighlightAnnot(self, rect):
"""Highlight content in a rectangle or quadrilateral."""
CheckParent(self)
val = _fitz.Page_addHighlightAnnot(self, rect)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | [
"def",
"addHighlightAnnot",
"(",
"self",
",",
"rect",
")",
":",
"CheckParent",
"(",
"self",
")",
"val",
"=",
"_fitz",
".",
"Page_addHighlightAnnot",
"(",
"self",
",",
"rect",
")",
"if",
"not",
"val",
":",
"return",
"val",
".",
"thisown",
"=",
"True",
"val",
".",
"parent",
"=",
"weakref",
".",
"proxy",
"(",
"self",
")",
"self",
".",
"_annot_refs",
"[",
"id",
"(",
"val",
")",
"]",
"=",
"val",
"return",
"val"
] | Highlight content in a rectangle or quadrilateral. | [
"Highlight",
"content",
"in",
"a",
"rectangle",
"or",
"quadrilateral",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2675-L2686 |
229,027 | pymupdf/PyMuPDF | fitz/fitz.py | Page.addRectAnnot | def addRectAnnot(self, rect):
"""Add a 'Rectangle' annotation."""
CheckParent(self)
val = _fitz.Page_addRectAnnot(self, rect)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | python | def addRectAnnot(self, rect):
"""Add a 'Rectangle' annotation."""
CheckParent(self)
val = _fitz.Page_addRectAnnot(self, rect)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | [
"def",
"addRectAnnot",
"(",
"self",
",",
"rect",
")",
":",
"CheckParent",
"(",
"self",
")",
"val",
"=",
"_fitz",
".",
"Page_addRectAnnot",
"(",
"self",
",",
"rect",
")",
"if",
"not",
"val",
":",
"return",
"val",
".",
"thisown",
"=",
"True",
"val",
".",
"parent",
"=",
"weakref",
".",
"proxy",
"(",
"self",
")",
"self",
".",
"_annot_refs",
"[",
"id",
"(",
"val",
")",
"]",
"=",
"val",
"return",
"val"
] | Add a 'Rectangle' annotation. | [
"Add",
"a",
"Rectangle",
"annotation",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2689-L2700 |
229,028 | pymupdf/PyMuPDF | fitz/fitz.py | Page.addCircleAnnot | def addCircleAnnot(self, rect):
"""Add a 'Circle' annotation."""
CheckParent(self)
val = _fitz.Page_addCircleAnnot(self, rect)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | python | def addCircleAnnot(self, rect):
"""Add a 'Circle' annotation."""
CheckParent(self)
val = _fitz.Page_addCircleAnnot(self, rect)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | [
"def",
"addCircleAnnot",
"(",
"self",
",",
"rect",
")",
":",
"CheckParent",
"(",
"self",
")",
"val",
"=",
"_fitz",
".",
"Page_addCircleAnnot",
"(",
"self",
",",
"rect",
")",
"if",
"not",
"val",
":",
"return",
"val",
".",
"thisown",
"=",
"True",
"val",
".",
"parent",
"=",
"weakref",
".",
"proxy",
"(",
"self",
")",
"self",
".",
"_annot_refs",
"[",
"id",
"(",
"val",
")",
"]",
"=",
"val",
"return",
"val"
] | Add a 'Circle' annotation. | [
"Add",
"a",
"Circle",
"annotation",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2703-L2714 |
229,029 | pymupdf/PyMuPDF | fitz/fitz.py | Page.addPolylineAnnot | def addPolylineAnnot(self, points):
"""Add a 'Polyline' annotation for a sequence of points."""
CheckParent(self)
val = _fitz.Page_addPolylineAnnot(self, points)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | python | def addPolylineAnnot(self, points):
"""Add a 'Polyline' annotation for a sequence of points."""
CheckParent(self)
val = _fitz.Page_addPolylineAnnot(self, points)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | [
"def",
"addPolylineAnnot",
"(",
"self",
",",
"points",
")",
":",
"CheckParent",
"(",
"self",
")",
"val",
"=",
"_fitz",
".",
"Page_addPolylineAnnot",
"(",
"self",
",",
"points",
")",
"if",
"not",
"val",
":",
"return",
"val",
".",
"thisown",
"=",
"True",
"val",
".",
"parent",
"=",
"weakref",
".",
"proxy",
"(",
"self",
")",
"self",
".",
"_annot_refs",
"[",
"id",
"(",
"val",
")",
"]",
"=",
"val",
"return",
"val"
] | Add a 'Polyline' annotation for a sequence of points. | [
"Add",
"a",
"Polyline",
"annotation",
"for",
"a",
"sequence",
"of",
"points",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2717-L2728 |
229,030 | pymupdf/PyMuPDF | fitz/fitz.py | Page.addPolygonAnnot | def addPolygonAnnot(self, points):
"""Add a 'Polygon' annotation for a sequence of points."""
CheckParent(self)
val = _fitz.Page_addPolygonAnnot(self, points)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | python | def addPolygonAnnot(self, points):
"""Add a 'Polygon' annotation for a sequence of points."""
CheckParent(self)
val = _fitz.Page_addPolygonAnnot(self, points)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | [
"def",
"addPolygonAnnot",
"(",
"self",
",",
"points",
")",
":",
"CheckParent",
"(",
"self",
")",
"val",
"=",
"_fitz",
".",
"Page_addPolygonAnnot",
"(",
"self",
",",
"points",
")",
"if",
"not",
"val",
":",
"return",
"val",
".",
"thisown",
"=",
"True",
"val",
".",
"parent",
"=",
"weakref",
".",
"proxy",
"(",
"self",
")",
"self",
".",
"_annot_refs",
"[",
"id",
"(",
"val",
")",
"]",
"=",
"val",
"return",
"val"
] | Add a 'Polygon' annotation for a sequence of points. | [
"Add",
"a",
"Polygon",
"annotation",
"for",
"a",
"sequence",
"of",
"points",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2731-L2742 |
229,031 | pymupdf/PyMuPDF | fitz/fitz.py | Page.addFreetextAnnot | def addFreetextAnnot(self, rect, text, fontsize=12, fontname=None, color=None, rotate=0):
"""Add a 'FreeText' annotation in rectangle 'rect'."""
CheckParent(self)
val = _fitz.Page_addFreetextAnnot(self, rect, text, fontsize, fontname, color, rotate)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | python | def addFreetextAnnot(self, rect, text, fontsize=12, fontname=None, color=None, rotate=0):
"""Add a 'FreeText' annotation in rectangle 'rect'."""
CheckParent(self)
val = _fitz.Page_addFreetextAnnot(self, rect, text, fontsize, fontname, color, rotate)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | [
"def",
"addFreetextAnnot",
"(",
"self",
",",
"rect",
",",
"text",
",",
"fontsize",
"=",
"12",
",",
"fontname",
"=",
"None",
",",
"color",
"=",
"None",
",",
"rotate",
"=",
"0",
")",
":",
"CheckParent",
"(",
"self",
")",
"val",
"=",
"_fitz",
".",
"Page_addFreetextAnnot",
"(",
"self",
",",
"rect",
",",
"text",
",",
"fontsize",
",",
"fontname",
",",
"color",
",",
"rotate",
")",
"if",
"not",
"val",
":",
"return",
"val",
".",
"thisown",
"=",
"True",
"val",
".",
"parent",
"=",
"weakref",
".",
"proxy",
"(",
"self",
")",
"self",
".",
"_annot_refs",
"[",
"id",
"(",
"val",
")",
"]",
"=",
"val",
"return",
"val"
] | Add a 'FreeText' annotation in rectangle 'rect'. | [
"Add",
"a",
"FreeText",
"annotation",
"in",
"rectangle",
"rect",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2745-L2756 |
229,032 | pymupdf/PyMuPDF | fitz/fitz.py | Page.addWidget | def addWidget(self, widget):
"""Add a form field.
"""
CheckParent(self)
doc = self.parent
if not doc.isPDF:
raise ValueError("not a PDF")
widget._validate()
# Check if PDF already has our fonts.
# If none insert all of them in a new object and store the xref.
# Else only add any missing fonts.
# To determine the situation, /DR object is checked.
xref = 0
ff = doc.FormFonts # /DR object: existing fonts
if not widget.text_font: # ensure default
widget.text_font = "Helv"
if not widget.text_font in ff: # if no existent font ...
if not doc.isFormPDF or not ff: # a fresh /AcroForm PDF!
xref = doc._getNewXref() # insert all our fonts
doc._updateObject(xref, Widget_fontobjects)
else: # add any missing fonts
for k in Widget_fontdict.keys():
if not k in ff: # add our font if missing
doc._addFormFont(k, Widget_fontdict[k])
widget._adjust_font() # ensure correct font spelling
widget._dr_xref = xref # non-zero causes /DR creation
# now create the /DA string
if len(widget.text_color) == 3:
fmt = "{:g} {:g} {:g} rg /{f:s} {s:g} Tf " + widget._text_da
elif len(widget.text_color) == 1:
fmt = "{:g} g /{f:s} {s:g} Tf " + widget._text_da
elif len(widget.text_color) == 4:
fmt = "{:g} {:g} {:g} {:g} k /{f:s} {s:g} Tf " + widget._text_da
widget._text_da = fmt.format(*widget.text_color, f=widget.text_font,
s=widget.text_fontsize)
# create the widget at last
annot = self._addWidget(widget)
if annot:
annot.thisown = True
annot.parent = weakref.proxy(self) # owning page object
self._annot_refs[id(annot)] = annot
return annot | python | def addWidget(self, widget):
"""Add a form field.
"""
CheckParent(self)
doc = self.parent
if not doc.isPDF:
raise ValueError("not a PDF")
widget._validate()
# Check if PDF already has our fonts.
# If none insert all of them in a new object and store the xref.
# Else only add any missing fonts.
# To determine the situation, /DR object is checked.
xref = 0
ff = doc.FormFonts # /DR object: existing fonts
if not widget.text_font: # ensure default
widget.text_font = "Helv"
if not widget.text_font in ff: # if no existent font ...
if not doc.isFormPDF or not ff: # a fresh /AcroForm PDF!
xref = doc._getNewXref() # insert all our fonts
doc._updateObject(xref, Widget_fontobjects)
else: # add any missing fonts
for k in Widget_fontdict.keys():
if not k in ff: # add our font if missing
doc._addFormFont(k, Widget_fontdict[k])
widget._adjust_font() # ensure correct font spelling
widget._dr_xref = xref # non-zero causes /DR creation
# now create the /DA string
if len(widget.text_color) == 3:
fmt = "{:g} {:g} {:g} rg /{f:s} {s:g} Tf " + widget._text_da
elif len(widget.text_color) == 1:
fmt = "{:g} g /{f:s} {s:g} Tf " + widget._text_da
elif len(widget.text_color) == 4:
fmt = "{:g} {:g} {:g} {:g} k /{f:s} {s:g} Tf " + widget._text_da
widget._text_da = fmt.format(*widget.text_color, f=widget.text_font,
s=widget.text_fontsize)
# create the widget at last
annot = self._addWidget(widget)
if annot:
annot.thisown = True
annot.parent = weakref.proxy(self) # owning page object
self._annot_refs[id(annot)] = annot
return annot | [
"def",
"addWidget",
"(",
"self",
",",
"widget",
")",
":",
"CheckParent",
"(",
"self",
")",
"doc",
"=",
"self",
".",
"parent",
"if",
"not",
"doc",
".",
"isPDF",
":",
"raise",
"ValueError",
"(",
"\"not a PDF\"",
")",
"widget",
".",
"_validate",
"(",
")",
"# Check if PDF already has our fonts.",
"# If none insert all of them in a new object and store the xref.",
"# Else only add any missing fonts.",
"# To determine the situation, /DR object is checked.",
"xref",
"=",
"0",
"ff",
"=",
"doc",
".",
"FormFonts",
"# /DR object: existing fonts",
"if",
"not",
"widget",
".",
"text_font",
":",
"# ensure default",
"widget",
".",
"text_font",
"=",
"\"Helv\"",
"if",
"not",
"widget",
".",
"text_font",
"in",
"ff",
":",
"# if no existent font ...",
"if",
"not",
"doc",
".",
"isFormPDF",
"or",
"not",
"ff",
":",
"# a fresh /AcroForm PDF!",
"xref",
"=",
"doc",
".",
"_getNewXref",
"(",
")",
"# insert all our fonts",
"doc",
".",
"_updateObject",
"(",
"xref",
",",
"Widget_fontobjects",
")",
"else",
":",
"# add any missing fonts",
"for",
"k",
"in",
"Widget_fontdict",
".",
"keys",
"(",
")",
":",
"if",
"not",
"k",
"in",
"ff",
":",
"# add our font if missing",
"doc",
".",
"_addFormFont",
"(",
"k",
",",
"Widget_fontdict",
"[",
"k",
"]",
")",
"widget",
".",
"_adjust_font",
"(",
")",
"# ensure correct font spelling",
"widget",
".",
"_dr_xref",
"=",
"xref",
"# non-zero causes /DR creation",
"# now create the /DA string",
"if",
"len",
"(",
"widget",
".",
"text_color",
")",
"==",
"3",
":",
"fmt",
"=",
"\"{:g} {:g} {:g} rg /{f:s} {s:g} Tf \"",
"+",
"widget",
".",
"_text_da",
"elif",
"len",
"(",
"widget",
".",
"text_color",
")",
"==",
"1",
":",
"fmt",
"=",
"\"{:g} g /{f:s} {s:g} Tf \"",
"+",
"widget",
".",
"_text_da",
"elif",
"len",
"(",
"widget",
".",
"text_color",
")",
"==",
"4",
":",
"fmt",
"=",
"\"{:g} {:g} {:g} {:g} k /{f:s} {s:g} Tf \"",
"+",
"widget",
".",
"_text_da",
"widget",
".",
"_text_da",
"=",
"fmt",
".",
"format",
"(",
"*",
"widget",
".",
"text_color",
",",
"f",
"=",
"widget",
".",
"text_font",
",",
"s",
"=",
"widget",
".",
"text_fontsize",
")",
"# create the widget at last",
"annot",
"=",
"self",
".",
"_addWidget",
"(",
"widget",
")",
"if",
"annot",
":",
"annot",
".",
"thisown",
"=",
"True",
"annot",
".",
"parent",
"=",
"weakref",
".",
"proxy",
"(",
"self",
")",
"# owning page object",
"self",
".",
"_annot_refs",
"[",
"id",
"(",
"annot",
")",
"]",
"=",
"annot",
"return",
"annot"
] | Add a form field. | [
"Add",
"a",
"form",
"field",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2762-L2805 |
229,033 | pymupdf/PyMuPDF | fitz/fitz.py | Page.firstAnnot | def firstAnnot(self):
"""Points to first annotation on page"""
CheckParent(self)
val = _fitz.Page_firstAnnot(self)
if val:
val.thisown = True
val.parent = weakref.proxy(self) # owning page object
self._annot_refs[id(val)] = val
return val | python | def firstAnnot(self):
"""Points to first annotation on page"""
CheckParent(self)
val = _fitz.Page_firstAnnot(self)
if val:
val.thisown = True
val.parent = weakref.proxy(self) # owning page object
self._annot_refs[id(val)] = val
return val | [
"def",
"firstAnnot",
"(",
"self",
")",
":",
"CheckParent",
"(",
"self",
")",
"val",
"=",
"_fitz",
".",
"Page_firstAnnot",
"(",
"self",
")",
"if",
"val",
":",
"val",
".",
"thisown",
"=",
"True",
"val",
".",
"parent",
"=",
"weakref",
".",
"proxy",
"(",
"self",
")",
"# owning page object",
"self",
".",
"_annot_refs",
"[",
"id",
"(",
"val",
")",
"]",
"=",
"val",
"return",
"val"
] | Points to first annotation on page | [
"Points",
"to",
"first",
"annotation",
"on",
"page"
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2848-L2858 |
229,034 | pymupdf/PyMuPDF | fitz/fitz.py | Page.deleteLink | def deleteLink(self, linkdict):
"""Delete link if PDF"""
CheckParent(self)
val = _fitz.Page_deleteLink(self, linkdict)
if linkdict["xref"] == 0: return
linkid = linkdict["id"]
try:
linkobj = self._annot_refs[linkid]
linkobj._erase()
except:
pass
return val | python | def deleteLink(self, linkdict):
"""Delete link if PDF"""
CheckParent(self)
val = _fitz.Page_deleteLink(self, linkdict)
if linkdict["xref"] == 0: return
linkid = linkdict["id"]
try:
linkobj = self._annot_refs[linkid]
linkobj._erase()
except:
pass
return val | [
"def",
"deleteLink",
"(",
"self",
",",
"linkdict",
")",
":",
"CheckParent",
"(",
"self",
")",
"val",
"=",
"_fitz",
".",
"Page_deleteLink",
"(",
"self",
",",
"linkdict",
")",
"if",
"linkdict",
"[",
"\"xref\"",
"]",
"==",
"0",
":",
"return",
"linkid",
"=",
"linkdict",
"[",
"\"id\"",
"]",
"try",
":",
"linkobj",
"=",
"self",
".",
"_annot_refs",
"[",
"linkid",
"]",
"linkobj",
".",
"_erase",
"(",
")",
"except",
":",
"pass",
"return",
"val"
] | Delete link if PDF | [
"Delete",
"link",
"if",
"PDF"
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2861-L2875 |
229,035 | pymupdf/PyMuPDF | fitz/fitz.py | Page.deleteAnnot | def deleteAnnot(self, fannot):
"""Delete annot if PDF and return next one"""
CheckParent(self)
val = _fitz.Page_deleteAnnot(self, fannot)
if val:
val.thisown = True
val.parent = weakref.proxy(self) # owning page object
val.parent._annot_refs[id(val)] = val
fannot._erase()
return val | python | def deleteAnnot(self, fannot):
"""Delete annot if PDF and return next one"""
CheckParent(self)
val = _fitz.Page_deleteAnnot(self, fannot)
if val:
val.thisown = True
val.parent = weakref.proxy(self) # owning page object
val.parent._annot_refs[id(val)] = val
fannot._erase()
return val | [
"def",
"deleteAnnot",
"(",
"self",
",",
"fannot",
")",
":",
"CheckParent",
"(",
"self",
")",
"val",
"=",
"_fitz",
".",
"Page_deleteAnnot",
"(",
"self",
",",
"fannot",
")",
"if",
"val",
":",
"val",
".",
"thisown",
"=",
"True",
"val",
".",
"parent",
"=",
"weakref",
".",
"proxy",
"(",
"self",
")",
"# owning page object",
"val",
".",
"parent",
".",
"_annot_refs",
"[",
"id",
"(",
"val",
")",
"]",
"=",
"val",
"fannot",
".",
"_erase",
"(",
")",
"return",
"val"
] | Delete annot if PDF and return next one | [
"Delete",
"annot",
"if",
"PDF",
"and",
"return",
"next",
"one"
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2878-L2890 |
229,036 | pymupdf/PyMuPDF | fitz/fitz.py | Page._forget_annot | def _forget_annot(self, annot):
"""Remove an annot from reference dictionary."""
aid = id(annot)
if aid in self._annot_refs:
self._annot_refs[aid] = None | python | def _forget_annot(self, annot):
"""Remove an annot from reference dictionary."""
aid = id(annot)
if aid in self._annot_refs:
self._annot_refs[aid] = None | [
"def",
"_forget_annot",
"(",
"self",
",",
"annot",
")",
":",
"aid",
"=",
"id",
"(",
"annot",
")",
"if",
"aid",
"in",
"self",
".",
"_annot_refs",
":",
"self",
".",
"_annot_refs",
"[",
"aid",
"]",
"=",
"None"
] | Remove an annot from reference dictionary. | [
"Remove",
"an",
"annot",
"from",
"reference",
"dictionary",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L3072-L3076 |
229,037 | pymupdf/PyMuPDF | fitz/fitz.py | Annot.rect | def rect(self):
"""Rectangle containing the annot"""
CheckParent(self)
val = _fitz.Annot_rect(self)
val = Rect(val)
return val | python | def rect(self):
"""Rectangle containing the annot"""
CheckParent(self)
val = _fitz.Annot_rect(self)
val = Rect(val)
return val | [
"def",
"rect",
"(",
"self",
")",
":",
"CheckParent",
"(",
"self",
")",
"val",
"=",
"_fitz",
".",
"Annot_rect",
"(",
"self",
")",
"val",
"=",
"Rect",
"(",
"val",
")",
"return",
"val"
] | Rectangle containing the annot | [
"Rectangle",
"containing",
"the",
"annot"
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L3586-L3593 |
229,038 | pymupdf/PyMuPDF | fitz/fitz.py | Annot.fileUpd | def fileUpd(self, buffer=None, filename=None, ufilename=None, desc=None):
"""Update annotation attached file."""
CheckParent(self)
return _fitz.Annot_fileUpd(self, buffer, filename, ufilename, desc) | python | def fileUpd(self, buffer=None, filename=None, ufilename=None, desc=None):
"""Update annotation attached file."""
CheckParent(self)
return _fitz.Annot_fileUpd(self, buffer, filename, ufilename, desc) | [
"def",
"fileUpd",
"(",
"self",
",",
"buffer",
"=",
"None",
",",
"filename",
"=",
"None",
",",
"ufilename",
"=",
"None",
",",
"desc",
"=",
"None",
")",
":",
"CheckParent",
"(",
"self",
")",
"return",
"_fitz",
".",
"Annot_fileUpd",
"(",
"self",
",",
"buffer",
",",
"filename",
",",
"ufilename",
",",
"desc",
")"
] | Update annotation attached file. | [
"Update",
"annotation",
"attached",
"file",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L3888-L3894 |
229,039 | pymupdf/PyMuPDF | fitz/fitz.py | Link.dest | def dest(self):
"""Create link destination details."""
if hasattr(self, "parent") and self.parent is None:
raise ValueError("orphaned object: parent is None")
if self.parent.parent.isClosed or self.parent.parent.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
doc = self.parent.parent
if self.isExternal or self.uri.startswith("#"):
uri = None
else:
uri = doc.resolveLink(self.uri)
return linkDest(self, uri) | python | def dest(self):
"""Create link destination details."""
if hasattr(self, "parent") and self.parent is None:
raise ValueError("orphaned object: parent is None")
if self.parent.parent.isClosed or self.parent.parent.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
doc = self.parent.parent
if self.isExternal or self.uri.startswith("#"):
uri = None
else:
uri = doc.resolveLink(self.uri)
return linkDest(self, uri) | [
"def",
"dest",
"(",
"self",
")",
":",
"if",
"hasattr",
"(",
"self",
",",
"\"parent\"",
")",
"and",
"self",
".",
"parent",
"is",
"None",
":",
"raise",
"ValueError",
"(",
"\"orphaned object: parent is None\"",
")",
"if",
"self",
".",
"parent",
".",
"parent",
".",
"isClosed",
"or",
"self",
".",
"parent",
".",
"parent",
".",
"isEncrypted",
":",
"raise",
"ValueError",
"(",
"\"operation illegal for closed / encrypted doc\"",
")",
"doc",
"=",
"self",
".",
"parent",
".",
"parent",
"if",
"self",
".",
"isExternal",
"or",
"self",
".",
"uri",
".",
"startswith",
"(",
"\"#\"",
")",
":",
"uri",
"=",
"None",
"else",
":",
"uri",
"=",
"doc",
".",
"resolveLink",
"(",
"self",
".",
"uri",
")",
"return",
"linkDest",
"(",
"self",
",",
"uri",
")"
] | Create link destination details. | [
"Create",
"link",
"destination",
"details",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L4130-L4143 |
229,040 | pymupdf/PyMuPDF | fitz/fitz.py | Tools.measure_string | def measure_string(self, text, fontname, fontsize, encoding=0):
"""Measure length of a string for a Base14 font."""
return _fitz.Tools_measure_string(self, text, fontname, fontsize, encoding) | python | def measure_string(self, text, fontname, fontsize, encoding=0):
"""Measure length of a string for a Base14 font."""
return _fitz.Tools_measure_string(self, text, fontname, fontsize, encoding) | [
"def",
"measure_string",
"(",
"self",
",",
"text",
",",
"fontname",
",",
"fontsize",
",",
"encoding",
"=",
"0",
")",
":",
"return",
"_fitz",
".",
"Tools_measure_string",
"(",
"self",
",",
"text",
",",
"fontname",
",",
"fontsize",
",",
"encoding",
")"
] | Measure length of a string for a Base14 font. | [
"Measure",
"length",
"of",
"a",
"string",
"for",
"a",
"Base14",
"font",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L4492-L4494 |
229,041 | pymupdf/PyMuPDF | fitz/fitz.py | Tools._le_annot_parms | def _le_annot_parms(self, annot, p1, p2):
"""Get common parameters for making line end symbols.
"""
w = annot.border["width"] # line width
sc = annot.colors["stroke"] # stroke color
if not sc: sc = (0,0,0)
scol = " ".join(map(str, sc)) + " RG\n"
fc = annot.colors["fill"] # fill color
if not fc: fc = (0,0,0)
fcol = " ".join(map(str, fc)) + " rg\n"
nr = annot.rect
np1 = p1 # point coord relative to annot rect
np2 = p2 # point coord relative to annot rect
m = self._hor_matrix(np1, np2) # matrix makes the line horizontal
im = ~m # inverted matrix
L = np1 * m # converted start (left) point
R = np2 * m # converted end (right) point
if 0 <= annot.opacity < 1:
opacity = "/Alp0 gs\n"
else:
opacity = ""
return m, im, L, R, w, scol, fcol, opacity | python | def _le_annot_parms(self, annot, p1, p2):
"""Get common parameters for making line end symbols.
"""
w = annot.border["width"] # line width
sc = annot.colors["stroke"] # stroke color
if not sc: sc = (0,0,0)
scol = " ".join(map(str, sc)) + " RG\n"
fc = annot.colors["fill"] # fill color
if not fc: fc = (0,0,0)
fcol = " ".join(map(str, fc)) + " rg\n"
nr = annot.rect
np1 = p1 # point coord relative to annot rect
np2 = p2 # point coord relative to annot rect
m = self._hor_matrix(np1, np2) # matrix makes the line horizontal
im = ~m # inverted matrix
L = np1 * m # converted start (left) point
R = np2 * m # converted end (right) point
if 0 <= annot.opacity < 1:
opacity = "/Alp0 gs\n"
else:
opacity = ""
return m, im, L, R, w, scol, fcol, opacity | [
"def",
"_le_annot_parms",
"(",
"self",
",",
"annot",
",",
"p1",
",",
"p2",
")",
":",
"w",
"=",
"annot",
".",
"border",
"[",
"\"width\"",
"]",
"# line width",
"sc",
"=",
"annot",
".",
"colors",
"[",
"\"stroke\"",
"]",
"# stroke color",
"if",
"not",
"sc",
":",
"sc",
"=",
"(",
"0",
",",
"0",
",",
"0",
")",
"scol",
"=",
"\" \"",
".",
"join",
"(",
"map",
"(",
"str",
",",
"sc",
")",
")",
"+",
"\" RG\\n\"",
"fc",
"=",
"annot",
".",
"colors",
"[",
"\"fill\"",
"]",
"# fill color",
"if",
"not",
"fc",
":",
"fc",
"=",
"(",
"0",
",",
"0",
",",
"0",
")",
"fcol",
"=",
"\" \"",
".",
"join",
"(",
"map",
"(",
"str",
",",
"fc",
")",
")",
"+",
"\" rg\\n\"",
"nr",
"=",
"annot",
".",
"rect",
"np1",
"=",
"p1",
"# point coord relative to annot rect",
"np2",
"=",
"p2",
"# point coord relative to annot rect",
"m",
"=",
"self",
".",
"_hor_matrix",
"(",
"np1",
",",
"np2",
")",
"# matrix makes the line horizontal",
"im",
"=",
"~",
"m",
"# inverted matrix",
"L",
"=",
"np1",
"*",
"m",
"# converted start (left) point",
"R",
"=",
"np2",
"*",
"m",
"# converted end (right) point",
"if",
"0",
"<=",
"annot",
".",
"opacity",
"<",
"1",
":",
"opacity",
"=",
"\"/Alp0 gs\\n\"",
"else",
":",
"opacity",
"=",
"\"\"",
"return",
"m",
",",
"im",
",",
"L",
",",
"R",
",",
"w",
",",
"scol",
",",
"fcol",
",",
"opacity"
] | Get common parameters for making line end symbols. | [
"Get",
"common",
"parameters",
"for",
"making",
"line",
"end",
"symbols",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L4504-L4525 |
229,042 | pymupdf/PyMuPDF | demo/caustic.py | pbis | def pbis(a):
"""End point of a reflected sun ray, given an angle a."""
return(math.cos(3*a - math.pi), (math.sin(3*a - math.pi))) | python | def pbis(a):
"""End point of a reflected sun ray, given an angle a."""
return(math.cos(3*a - math.pi), (math.sin(3*a - math.pi))) | [
"def",
"pbis",
"(",
"a",
")",
":",
"return",
"(",
"math",
".",
"cos",
"(",
"3",
"*",
"a",
"-",
"math",
".",
"pi",
")",
",",
"(",
"math",
".",
"sin",
"(",
"3",
"*",
"a",
"-",
"math",
".",
"pi",
")",
")",
")"
] | End point of a reflected sun ray, given an angle a. | [
"End",
"point",
"of",
"a",
"reflected",
"sun",
"ray",
"given",
"an",
"angle",
"a",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/demo/caustic.py#L33-L35 |
229,043 | pymupdf/PyMuPDF | demo/new-annots.py | print_descr | def print_descr(rect, annot):
"""Print a short description to the right of an annot rect."""
annot.parent.insertText(rect.br + (10, 0),
"'%s' annotation" % annot.type[1], color = red) | python | def print_descr(rect, annot):
"""Print a short description to the right of an annot rect."""
annot.parent.insertText(rect.br + (10, 0),
"'%s' annotation" % annot.type[1], color = red) | [
"def",
"print_descr",
"(",
"rect",
",",
"annot",
")",
":",
"annot",
".",
"parent",
".",
"insertText",
"(",
"rect",
".",
"br",
"+",
"(",
"10",
",",
"0",
")",
",",
"\"'%s' annotation\"",
"%",
"annot",
".",
"type",
"[",
"1",
"]",
",",
"color",
"=",
"red",
")"
] | Print a short description to the right of an annot rect. | [
"Print",
"a",
"short",
"description",
"to",
"the",
"right",
"of",
"an",
"annot",
"rect",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/demo/new-annots.py#L41-L44 |
229,044 | pymupdf/PyMuPDF | demo/extract-img2.py | recoverpix | def recoverpix(doc, item):
"""Return pixmap for item, which is a list of 2 xref numbers. Second xref
is that of an smask if > 0.
Return None for any error.
"""
x = item[0] # xref of PDF image
s = item[1] # xref of its /SMask
try:
pix1 = fitz.Pixmap(doc, x) # make pixmap from image
except:
print("xref %i " % x + doc._getGCTXerrmsg())
return None # skip if error
if s == 0: # has no /SMask
return pix1 # no special handling
try:
pix2 = fitz.Pixmap(doc, s) # create pixmap of /SMask entry
except:
print("cannot create mask %i for image xref %i" % (s,x))
return pix1 # return w/ failed transparency
# check that we are safe
if not (pix1.irect == pix2.irect and \
pix1.alpha == pix2.alpha == 0 and \
pix2.n == 1):
print("unexpected /SMask situation: pix1", pix1, "pix2", pix2)
return pix1
pix = fitz.Pixmap(pix1) # copy of pix1, alpha channel added
pix.setAlpha(pix2.samples) # treat pix2.samples as alpha values
pix1 = pix2 = None # free temp pixmaps
return pix | python | def recoverpix(doc, item):
"""Return pixmap for item, which is a list of 2 xref numbers. Second xref
is that of an smask if > 0.
Return None for any error.
"""
x = item[0] # xref of PDF image
s = item[1] # xref of its /SMask
try:
pix1 = fitz.Pixmap(doc, x) # make pixmap from image
except:
print("xref %i " % x + doc._getGCTXerrmsg())
return None # skip if error
if s == 0: # has no /SMask
return pix1 # no special handling
try:
pix2 = fitz.Pixmap(doc, s) # create pixmap of /SMask entry
except:
print("cannot create mask %i for image xref %i" % (s,x))
return pix1 # return w/ failed transparency
# check that we are safe
if not (pix1.irect == pix2.irect and \
pix1.alpha == pix2.alpha == 0 and \
pix2.n == 1):
print("unexpected /SMask situation: pix1", pix1, "pix2", pix2)
return pix1
pix = fitz.Pixmap(pix1) # copy of pix1, alpha channel added
pix.setAlpha(pix2.samples) # treat pix2.samples as alpha values
pix1 = pix2 = None # free temp pixmaps
return pix | [
"def",
"recoverpix",
"(",
"doc",
",",
"item",
")",
":",
"x",
"=",
"item",
"[",
"0",
"]",
"# xref of PDF image",
"s",
"=",
"item",
"[",
"1",
"]",
"# xref of its /SMask",
"try",
":",
"pix1",
"=",
"fitz",
".",
"Pixmap",
"(",
"doc",
",",
"x",
")",
"# make pixmap from image",
"except",
":",
"print",
"(",
"\"xref %i \"",
"%",
"x",
"+",
"doc",
".",
"_getGCTXerrmsg",
"(",
")",
")",
"return",
"None",
"# skip if error",
"if",
"s",
"==",
"0",
":",
"# has no /SMask",
"return",
"pix1",
"# no special handling",
"try",
":",
"pix2",
"=",
"fitz",
".",
"Pixmap",
"(",
"doc",
",",
"s",
")",
"# create pixmap of /SMask entry",
"except",
":",
"print",
"(",
"\"cannot create mask %i for image xref %i\"",
"%",
"(",
"s",
",",
"x",
")",
")",
"return",
"pix1",
"# return w/ failed transparency",
"# check that we are safe",
"if",
"not",
"(",
"pix1",
".",
"irect",
"==",
"pix2",
".",
"irect",
"and",
"pix1",
".",
"alpha",
"==",
"pix2",
".",
"alpha",
"==",
"0",
"and",
"pix2",
".",
"n",
"==",
"1",
")",
":",
"print",
"(",
"\"unexpected /SMask situation: pix1\"",
",",
"pix1",
",",
"\"pix2\"",
",",
"pix2",
")",
"return",
"pix1",
"pix",
"=",
"fitz",
".",
"Pixmap",
"(",
"pix1",
")",
"# copy of pix1, alpha channel added",
"pix",
".",
"setAlpha",
"(",
"pix2",
".",
"samples",
")",
"# treat pix2.samples as alpha values",
"pix1",
"=",
"pix2",
"=",
"None",
"# free temp pixmaps",
"return",
"pix"
] | Return pixmap for item, which is a list of 2 xref numbers. Second xref
is that of an smask if > 0.
Return None for any error. | [
"Return",
"pixmap",
"for",
"item",
"which",
"is",
"a",
"list",
"of",
"2",
"xref",
"numbers",
".",
"Second",
"xref",
"is",
"that",
"of",
"an",
"smask",
"if",
">",
"0",
".",
"Return",
"None",
"for",
"any",
"error",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/demo/extract-img2.py#L39-L71 |
229,045 | pymupdf/PyMuPDF | examples/PDFLinkMaint.py | PDFdisplay.on_update_page_links | def on_update_page_links(self, evt):
""" Perform PDF update of changed links."""
if not self.update_links: # skip if unsupported links
evt.Skip()
return
pg = self.doc[getint(self.TextToPage.Value) -1]
for i in range(len(self.page_links)):
l = self.page_links[i]
if l.get("update", False): # "update" must be True
if l["xref"] == 0: # no xref => new link
pg.insertLink(l)
elif l["kind"] < 1 or l["kind"] > len(self.linkTypeStrings):
pg.deleteLink(l) # delete invalid link
else:
pg.updateLink(l) # else link update
l["update"] = False # reset update indicator
self.page_links[i] = l # update list of page links
self.btn_Update.Disable() # disable update button
self.t_Update.Label = "" # and its message
self.btn_Save.Enable()
self.t_Save.Label = "There are changes. Press to save them to file."
evt.Skip()
return | python | def on_update_page_links(self, evt):
""" Perform PDF update of changed links."""
if not self.update_links: # skip if unsupported links
evt.Skip()
return
pg = self.doc[getint(self.TextToPage.Value) -1]
for i in range(len(self.page_links)):
l = self.page_links[i]
if l.get("update", False): # "update" must be True
if l["xref"] == 0: # no xref => new link
pg.insertLink(l)
elif l["kind"] < 1 or l["kind"] > len(self.linkTypeStrings):
pg.deleteLink(l) # delete invalid link
else:
pg.updateLink(l) # else link update
l["update"] = False # reset update indicator
self.page_links[i] = l # update list of page links
self.btn_Update.Disable() # disable update button
self.t_Update.Label = "" # and its message
self.btn_Save.Enable()
self.t_Save.Label = "There are changes. Press to save them to file."
evt.Skip()
return | [
"def",
"on_update_page_links",
"(",
"self",
",",
"evt",
")",
":",
"if",
"not",
"self",
".",
"update_links",
":",
"# skip if unsupported links",
"evt",
".",
"Skip",
"(",
")",
"return",
"pg",
"=",
"self",
".",
"doc",
"[",
"getint",
"(",
"self",
".",
"TextToPage",
".",
"Value",
")",
"-",
"1",
"]",
"for",
"i",
"in",
"range",
"(",
"len",
"(",
"self",
".",
"page_links",
")",
")",
":",
"l",
"=",
"self",
".",
"page_links",
"[",
"i",
"]",
"if",
"l",
".",
"get",
"(",
"\"update\"",
",",
"False",
")",
":",
"# \"update\" must be True",
"if",
"l",
"[",
"\"xref\"",
"]",
"==",
"0",
":",
"# no xref => new link",
"pg",
".",
"insertLink",
"(",
"l",
")",
"elif",
"l",
"[",
"\"kind\"",
"]",
"<",
"1",
"or",
"l",
"[",
"\"kind\"",
"]",
">",
"len",
"(",
"self",
".",
"linkTypeStrings",
")",
":",
"pg",
".",
"deleteLink",
"(",
"l",
")",
"# delete invalid link",
"else",
":",
"pg",
".",
"updateLink",
"(",
"l",
")",
"# else link update",
"l",
"[",
"\"update\"",
"]",
"=",
"False",
"# reset update indicator",
"self",
".",
"page_links",
"[",
"i",
"]",
"=",
"l",
"# update list of page links",
"self",
".",
"btn_Update",
".",
"Disable",
"(",
")",
"# disable update button",
"self",
".",
"t_Update",
".",
"Label",
"=",
"\"\"",
"# and its message",
"self",
".",
"btn_Save",
".",
"Enable",
"(",
")",
"self",
".",
"t_Save",
".",
"Label",
"=",
"\"There are changes. Press to save them to file.\"",
"evt",
".",
"Skip",
"(",
")",
"return"
] | Perform PDF update of changed links. | [
"Perform",
"PDF",
"update",
"of",
"changed",
"links",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/examples/PDFLinkMaint.py#L464-L486 |
229,046 | pymupdf/PyMuPDF | examples/PDFLinkMaint.py | PDFdisplay.Rect_to_wxRect | def Rect_to_wxRect(self, fr):
""" Return a zoomed wx.Rect for given fitz.Rect."""
r = (fr * self.zoom).irect # zoomed IRect
return wx.Rect(r.x0, r.y0, r.width, r.height) | python | def Rect_to_wxRect(self, fr):
""" Return a zoomed wx.Rect for given fitz.Rect."""
r = (fr * self.zoom).irect # zoomed IRect
return wx.Rect(r.x0, r.y0, r.width, r.height) | [
"def",
"Rect_to_wxRect",
"(",
"self",
",",
"fr",
")",
":",
"r",
"=",
"(",
"fr",
"*",
"self",
".",
"zoom",
")",
".",
"irect",
"# zoomed IRect",
"return",
"wx",
".",
"Rect",
"(",
"r",
".",
"x0",
",",
"r",
".",
"y0",
",",
"r",
".",
"width",
",",
"r",
".",
"height",
")"
] | Return a zoomed wx.Rect for given fitz.Rect. | [
"Return",
"a",
"zoomed",
"wx",
".",
"Rect",
"for",
"given",
"fitz",
".",
"Rect",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/examples/PDFLinkMaint.py#L903-L906 |
229,047 | pymupdf/PyMuPDF | examples/PDFLinkMaint.py | PDFdisplay.wxRect_to_Rect | def wxRect_to_Rect(self, wr):
""" Return a shrunk fitz.Rect for given wx.Rect."""
r = fitz.Rect(wr.x, wr.y, wr.x + wr.width, wr.y + wr.height)
return r * self.shrink | python | def wxRect_to_Rect(self, wr):
""" Return a shrunk fitz.Rect for given wx.Rect."""
r = fitz.Rect(wr.x, wr.y, wr.x + wr.width, wr.y + wr.height)
return r * self.shrink | [
"def",
"wxRect_to_Rect",
"(",
"self",
",",
"wr",
")",
":",
"r",
"=",
"fitz",
".",
"Rect",
"(",
"wr",
".",
"x",
",",
"wr",
".",
"y",
",",
"wr",
".",
"x",
"+",
"wr",
".",
"width",
",",
"wr",
".",
"y",
"+",
"wr",
".",
"height",
")",
"return",
"r",
"*",
"self",
".",
"shrink"
] | Return a shrunk fitz.Rect for given wx.Rect. | [
"Return",
"a",
"shrunk",
"fitz",
".",
"Rect",
"for",
"given",
"wx",
".",
"Rect",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/examples/PDFLinkMaint.py#L908-L911 |
229,048 | pymupdf/PyMuPDF | examples/PDFLinkMaint.py | PDFdisplay.is_in_free_area | def is_in_free_area(self, nr, ok = -1):
""" Determine if rect covers a free area inside the bitmap."""
for i, r in enumerate(self.link_rects):
if r.Intersects(nr) and i != ok:
return False
bmrect = wx.Rect(0,0,dlg.bitmap.Size[0],dlg.bitmap.Size[1])
return bmrect.Contains(nr) | python | def is_in_free_area(self, nr, ok = -1):
""" Determine if rect covers a free area inside the bitmap."""
for i, r in enumerate(self.link_rects):
if r.Intersects(nr) and i != ok:
return False
bmrect = wx.Rect(0,0,dlg.bitmap.Size[0],dlg.bitmap.Size[1])
return bmrect.Contains(nr) | [
"def",
"is_in_free_area",
"(",
"self",
",",
"nr",
",",
"ok",
"=",
"-",
"1",
")",
":",
"for",
"i",
",",
"r",
"in",
"enumerate",
"(",
"self",
".",
"link_rects",
")",
":",
"if",
"r",
".",
"Intersects",
"(",
"nr",
")",
"and",
"i",
"!=",
"ok",
":",
"return",
"False",
"bmrect",
"=",
"wx",
".",
"Rect",
"(",
"0",
",",
"0",
",",
"dlg",
".",
"bitmap",
".",
"Size",
"[",
"0",
"]",
",",
"dlg",
".",
"bitmap",
".",
"Size",
"[",
"1",
"]",
")",
"return",
"bmrect",
".",
"Contains",
"(",
"nr",
")"
] | Determine if rect covers a free area inside the bitmap. | [
"Determine",
"if",
"rect",
"covers",
"a",
"free",
"area",
"inside",
"the",
"bitmap",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/examples/PDFLinkMaint.py#L913-L919 |
229,049 | pymupdf/PyMuPDF | examples/PDFLinkMaint.py | PDFdisplay.get_linkrect_idx | def get_linkrect_idx(self, pos):
""" Determine if cursor is inside one of the link hot spots."""
for i, r in enumerate(self.link_rects):
if r.Contains(pos):
return i
return -1 | python | def get_linkrect_idx(self, pos):
""" Determine if cursor is inside one of the link hot spots."""
for i, r in enumerate(self.link_rects):
if r.Contains(pos):
return i
return -1 | [
"def",
"get_linkrect_idx",
"(",
"self",
",",
"pos",
")",
":",
"for",
"i",
",",
"r",
"in",
"enumerate",
"(",
"self",
".",
"link_rects",
")",
":",
"if",
"r",
".",
"Contains",
"(",
"pos",
")",
":",
"return",
"i",
"return",
"-",
"1"
] | Determine if cursor is inside one of the link hot spots. | [
"Determine",
"if",
"cursor",
"is",
"inside",
"one",
"of",
"the",
"link",
"hot",
"spots",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/examples/PDFLinkMaint.py#L921-L926 |
229,050 | pymupdf/PyMuPDF | examples/PDFLinkMaint.py | PDFdisplay.get_bottomrect_idx | def get_bottomrect_idx(self, pos):
""" Determine if cursor is on bottom right corner of a hot spot."""
for i, r in enumerate(self.link_bottom_rects):
if r.Contains(pos):
return i
return -1 | python | def get_bottomrect_idx(self, pos):
""" Determine if cursor is on bottom right corner of a hot spot."""
for i, r in enumerate(self.link_bottom_rects):
if r.Contains(pos):
return i
return -1 | [
"def",
"get_bottomrect_idx",
"(",
"self",
",",
"pos",
")",
":",
"for",
"i",
",",
"r",
"in",
"enumerate",
"(",
"self",
".",
"link_bottom_rects",
")",
":",
"if",
"r",
".",
"Contains",
"(",
"pos",
")",
":",
"return",
"i",
"return",
"-",
"1"
] | Determine if cursor is on bottom right corner of a hot spot. | [
"Determine",
"if",
"cursor",
"is",
"on",
"bottom",
"right",
"corner",
"of",
"a",
"hot",
"spot",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/examples/PDFLinkMaint.py#L928-L933 |
229,051 | pymupdf/PyMuPDF | fitz/utils.py | getTextWords | def getTextWords(page):
"""Return the text words as a list with the bbox for each word.
"""
CheckParent(page)
dl = page.getDisplayList()
tp = dl.getTextPage()
l = tp._extractTextWords_AsList()
del dl
del tp
return l | python | def getTextWords(page):
"""Return the text words as a list with the bbox for each word.
"""
CheckParent(page)
dl = page.getDisplayList()
tp = dl.getTextPage()
l = tp._extractTextWords_AsList()
del dl
del tp
return l | [
"def",
"getTextWords",
"(",
"page",
")",
":",
"CheckParent",
"(",
"page",
")",
"dl",
"=",
"page",
".",
"getDisplayList",
"(",
")",
"tp",
"=",
"dl",
".",
"getTextPage",
"(",
")",
"l",
"=",
"tp",
".",
"_extractTextWords_AsList",
"(",
")",
"del",
"dl",
"del",
"tp",
"return",
"l"
] | Return the text words as a list with the bbox for each word. | [
"Return",
"the",
"text",
"words",
"as",
"a",
"list",
"with",
"the",
"bbox",
"for",
"each",
"word",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/utils.py#L349-L358 |
229,052 | pymupdf/PyMuPDF | fitz/utils.py | getText | def getText(page, output = "text"):
""" Extract a document page's text.
Args:
output: (str) text, html, dict, json, rawdict, xhtml or xml.
Returns:
the output of TextPage methods extractText, extractHTML, extractDICT, extractJSON, extractRAWDICT, extractXHTML or etractXML respectively. Default and misspelling choice is "text".
"""
CheckParent(page)
dl = page.getDisplayList()
# available output types
formats = ("text", "html", "json", "xml", "xhtml", "dict", "rawdict")
# choose which of them also include images in the TextPage
images = (0, 1, 1, 0, 1, 1, 1) # controls image inclusion in text page
try:
f = formats.index(output.lower())
except:
f = 0
flags = TEXT_PRESERVE_LIGATURES | TEXT_PRESERVE_WHITESPACE
if images[f] :
flags |= TEXT_PRESERVE_IMAGES
tp = dl.getTextPage(flags) # TextPage with / without images
t = tp._extractText(f)
del dl
del tp
return t | python | def getText(page, output = "text"):
""" Extract a document page's text.
Args:
output: (str) text, html, dict, json, rawdict, xhtml or xml.
Returns:
the output of TextPage methods extractText, extractHTML, extractDICT, extractJSON, extractRAWDICT, extractXHTML or etractXML respectively. Default and misspelling choice is "text".
"""
CheckParent(page)
dl = page.getDisplayList()
# available output types
formats = ("text", "html", "json", "xml", "xhtml", "dict", "rawdict")
# choose which of them also include images in the TextPage
images = (0, 1, 1, 0, 1, 1, 1) # controls image inclusion in text page
try:
f = formats.index(output.lower())
except:
f = 0
flags = TEXT_PRESERVE_LIGATURES | TEXT_PRESERVE_WHITESPACE
if images[f] :
flags |= TEXT_PRESERVE_IMAGES
tp = dl.getTextPage(flags) # TextPage with / without images
t = tp._extractText(f)
del dl
del tp
return t | [
"def",
"getText",
"(",
"page",
",",
"output",
"=",
"\"text\"",
")",
":",
"CheckParent",
"(",
"page",
")",
"dl",
"=",
"page",
".",
"getDisplayList",
"(",
")",
"# available output types",
"formats",
"=",
"(",
"\"text\"",
",",
"\"html\"",
",",
"\"json\"",
",",
"\"xml\"",
",",
"\"xhtml\"",
",",
"\"dict\"",
",",
"\"rawdict\"",
")",
"# choose which of them also include images in the TextPage",
"images",
"=",
"(",
"0",
",",
"1",
",",
"1",
",",
"0",
",",
"1",
",",
"1",
",",
"1",
")",
"# controls image inclusion in text page",
"try",
":",
"f",
"=",
"formats",
".",
"index",
"(",
"output",
".",
"lower",
"(",
")",
")",
"except",
":",
"f",
"=",
"0",
"flags",
"=",
"TEXT_PRESERVE_LIGATURES",
"|",
"TEXT_PRESERVE_WHITESPACE",
"if",
"images",
"[",
"f",
"]",
":",
"flags",
"|=",
"TEXT_PRESERVE_IMAGES",
"tp",
"=",
"dl",
".",
"getTextPage",
"(",
"flags",
")",
"# TextPage with / without images",
"t",
"=",
"tp",
".",
"_extractText",
"(",
"f",
")",
"del",
"dl",
"del",
"tp",
"return",
"t"
] | Extract a document page's text.
Args:
output: (str) text, html, dict, json, rawdict, xhtml or xml.
Returns:
the output of TextPage methods extractText, extractHTML, extractDICT, extractJSON, extractRAWDICT, extractXHTML or etractXML respectively. Default and misspelling choice is "text". | [
"Extract",
"a",
"document",
"page",
"s",
"text",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/utils.py#L360-L386 |
229,053 | pymupdf/PyMuPDF | fitz/utils.py | getPagePixmap | def getPagePixmap(doc, pno, matrix = None, colorspace = csRGB,
clip = None, alpha = True):
"""Create pixmap of document page by page number.
Notes:
Convenience function calling page.getPixmap.
Args:
pno: (int) page number
matrix: Matrix for transformation (default: Identity).
colorspace: (str/Colorspace) rgb, rgb, gray - case ignored, default csRGB.
clip: (irect-like) restrict rendering to this area.
alpha: (bool) include alpha channel
"""
return doc[pno].getPixmap(matrix = matrix, colorspace = colorspace,
clip = clip, alpha = alpha) | python | def getPagePixmap(doc, pno, matrix = None, colorspace = csRGB,
clip = None, alpha = True):
"""Create pixmap of document page by page number.
Notes:
Convenience function calling page.getPixmap.
Args:
pno: (int) page number
matrix: Matrix for transformation (default: Identity).
colorspace: (str/Colorspace) rgb, rgb, gray - case ignored, default csRGB.
clip: (irect-like) restrict rendering to this area.
alpha: (bool) include alpha channel
"""
return doc[pno].getPixmap(matrix = matrix, colorspace = colorspace,
clip = clip, alpha = alpha) | [
"def",
"getPagePixmap",
"(",
"doc",
",",
"pno",
",",
"matrix",
"=",
"None",
",",
"colorspace",
"=",
"csRGB",
",",
"clip",
"=",
"None",
",",
"alpha",
"=",
"True",
")",
":",
"return",
"doc",
"[",
"pno",
"]",
".",
"getPixmap",
"(",
"matrix",
"=",
"matrix",
",",
"colorspace",
"=",
"colorspace",
",",
"clip",
"=",
"clip",
",",
"alpha",
"=",
"alpha",
")"
] | Create pixmap of document page by page number.
Notes:
Convenience function calling page.getPixmap.
Args:
pno: (int) page number
matrix: Matrix for transformation (default: Identity).
colorspace: (str/Colorspace) rgb, rgb, gray - case ignored, default csRGB.
clip: (irect-like) restrict rendering to this area.
alpha: (bool) include alpha channel | [
"Create",
"pixmap",
"of",
"document",
"page",
"by",
"page",
"number",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/utils.py#L438-L452 |
229,054 | pymupdf/PyMuPDF | fitz/utils.py | getToC | def getToC(doc, simple = True):
"""Create a table of contents.
Args:
simple: a bool to control output. Returns a list, where each entry consists of outline level, title, page number and link destination (if simple = False). For details see PyMuPDF's documentation.
"""
def recurse(olItem, liste, lvl):
'''Recursively follow the outline item chain and record item information in a list.'''
while olItem:
if olItem.title:
title = olItem.title
else:
title = " "
if not olItem.isExternal:
if olItem.uri:
page = olItem.page + 1
else:
page = -1
else:
page = -1
if not simple:
link = getLinkDict(olItem)
liste.append([lvl, title, page, link])
else:
liste.append([lvl, title, page])
if olItem.down:
liste = recurse(olItem.down, liste, lvl+1)
olItem = olItem.next
return liste
# check if document is open and not encrypted
if doc.isClosed:
raise ValueError("illegal operation on closed document")
olItem = doc.outline
if not olItem: return []
lvl = 1
liste = []
return recurse(olItem, liste, lvl) | python | def getToC(doc, simple = True):
"""Create a table of contents.
Args:
simple: a bool to control output. Returns a list, where each entry consists of outline level, title, page number and link destination (if simple = False). For details see PyMuPDF's documentation.
"""
def recurse(olItem, liste, lvl):
'''Recursively follow the outline item chain and record item information in a list.'''
while olItem:
if olItem.title:
title = olItem.title
else:
title = " "
if not olItem.isExternal:
if olItem.uri:
page = olItem.page + 1
else:
page = -1
else:
page = -1
if not simple:
link = getLinkDict(olItem)
liste.append([lvl, title, page, link])
else:
liste.append([lvl, title, page])
if olItem.down:
liste = recurse(olItem.down, liste, lvl+1)
olItem = olItem.next
return liste
# check if document is open and not encrypted
if doc.isClosed:
raise ValueError("illegal operation on closed document")
olItem = doc.outline
if not olItem: return []
lvl = 1
liste = []
return recurse(olItem, liste, lvl) | [
"def",
"getToC",
"(",
"doc",
",",
"simple",
"=",
"True",
")",
":",
"def",
"recurse",
"(",
"olItem",
",",
"liste",
",",
"lvl",
")",
":",
"'''Recursively follow the outline item chain and record item information in a list.'''",
"while",
"olItem",
":",
"if",
"olItem",
".",
"title",
":",
"title",
"=",
"olItem",
".",
"title",
"else",
":",
"title",
"=",
"\" \"",
"if",
"not",
"olItem",
".",
"isExternal",
":",
"if",
"olItem",
".",
"uri",
":",
"page",
"=",
"olItem",
".",
"page",
"+",
"1",
"else",
":",
"page",
"=",
"-",
"1",
"else",
":",
"page",
"=",
"-",
"1",
"if",
"not",
"simple",
":",
"link",
"=",
"getLinkDict",
"(",
"olItem",
")",
"liste",
".",
"append",
"(",
"[",
"lvl",
",",
"title",
",",
"page",
",",
"link",
"]",
")",
"else",
":",
"liste",
".",
"append",
"(",
"[",
"lvl",
",",
"title",
",",
"page",
"]",
")",
"if",
"olItem",
".",
"down",
":",
"liste",
"=",
"recurse",
"(",
"olItem",
".",
"down",
",",
"liste",
",",
"lvl",
"+",
"1",
")",
"olItem",
"=",
"olItem",
".",
"next",
"return",
"liste",
"# check if document is open and not encrypted",
"if",
"doc",
".",
"isClosed",
":",
"raise",
"ValueError",
"(",
"\"illegal operation on closed document\"",
")",
"olItem",
"=",
"doc",
".",
"outline",
"if",
"not",
"olItem",
":",
"return",
"[",
"]",
"lvl",
"=",
"1",
"liste",
"=",
"[",
"]",
"return",
"recurse",
"(",
"olItem",
",",
"liste",
",",
"lvl",
")"
] | Create a table of contents.
Args:
simple: a bool to control output. Returns a list, where each entry consists of outline level, title, page number and link destination (if simple = False). For details see PyMuPDF's documentation. | [
"Create",
"a",
"table",
"of",
"contents",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/utils.py#L528-L571 |
229,055 | pymupdf/PyMuPDF | fitz/utils.py | updateLink | def updateLink(page, lnk):
""" Update a link on the current page. """
CheckParent(page)
annot = getLinkText(page, lnk)
if annot == "":
raise ValueError("link kind not supported")
page.parent._updateObject(lnk["xref"], annot, page = page)
return | python | def updateLink(page, lnk):
""" Update a link on the current page. """
CheckParent(page)
annot = getLinkText(page, lnk)
if annot == "":
raise ValueError("link kind not supported")
page.parent._updateObject(lnk["xref"], annot, page = page)
return | [
"def",
"updateLink",
"(",
"page",
",",
"lnk",
")",
":",
"CheckParent",
"(",
"page",
")",
"annot",
"=",
"getLinkText",
"(",
"page",
",",
"lnk",
")",
"if",
"annot",
"==",
"\"\"",
":",
"raise",
"ValueError",
"(",
"\"link kind not supported\"",
")",
"page",
".",
"parent",
".",
"_updateObject",
"(",
"lnk",
"[",
"\"xref\"",
"]",
",",
"annot",
",",
"page",
"=",
"page",
")",
"return"
] | Update a link on the current page. | [
"Update",
"a",
"link",
"on",
"the",
"current",
"page",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/utils.py#L990-L998 |
229,056 | pymupdf/PyMuPDF | fitz/utils.py | insertLink | def insertLink(page, lnk, mark = True):
""" Insert a new link for the current page. """
CheckParent(page)
annot = getLinkText(page, lnk)
if annot == "":
raise ValueError("link kind not supported")
page._addAnnot_FromString([annot])
return | python | def insertLink(page, lnk, mark = True):
""" Insert a new link for the current page. """
CheckParent(page)
annot = getLinkText(page, lnk)
if annot == "":
raise ValueError("link kind not supported")
page._addAnnot_FromString([annot])
return | [
"def",
"insertLink",
"(",
"page",
",",
"lnk",
",",
"mark",
"=",
"True",
")",
":",
"CheckParent",
"(",
"page",
")",
"annot",
"=",
"getLinkText",
"(",
"page",
",",
"lnk",
")",
"if",
"annot",
"==",
"\"\"",
":",
"raise",
"ValueError",
"(",
"\"link kind not supported\"",
")",
"page",
".",
"_addAnnot_FromString",
"(",
"[",
"annot",
"]",
")",
"return"
] | Insert a new link for the current page. | [
"Insert",
"a",
"new",
"link",
"for",
"the",
"current",
"page",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/utils.py#L1000-L1008 |
229,057 | pymupdf/PyMuPDF | fitz/utils.py | newPage | def newPage(doc, pno=-1, width=595, height=842):
"""Create and return a new page object.
"""
doc._newPage(pno, width=width, height=height)
return doc[pno] | python | def newPage(doc, pno=-1, width=595, height=842):
"""Create and return a new page object.
"""
doc._newPage(pno, width=width, height=height)
return doc[pno] | [
"def",
"newPage",
"(",
"doc",
",",
"pno",
"=",
"-",
"1",
",",
"width",
"=",
"595",
",",
"height",
"=",
"842",
")",
":",
"doc",
".",
"_newPage",
"(",
"pno",
",",
"width",
"=",
"width",
",",
"height",
"=",
"height",
")",
"return",
"doc",
"[",
"pno",
"]"
] | Create and return a new page object. | [
"Create",
"and",
"return",
"a",
"new",
"page",
"object",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/utils.py#L1094-L1098 |
229,058 | pymupdf/PyMuPDF | fitz/utils.py | insertPage | def insertPage(
doc,
pno,
text=None,
fontsize=11,
width=595,
height=842,
fontname="helv",
fontfile=None,
color=None,
):
""" Create a new PDF page and insert some text.
Notes:
Function combining Document.newPage() and Page.insertText().
For parameter details see these methods.
"""
page = doc.newPage(pno=pno, width=width, height=height)
if not bool(text):
return 0
rc = page.insertText(
(50, 72),
text,
fontsize=fontsize,
fontname=fontname,
fontfile=fontfile,
color=color,
)
return rc | python | def insertPage(
doc,
pno,
text=None,
fontsize=11,
width=595,
height=842,
fontname="helv",
fontfile=None,
color=None,
):
""" Create a new PDF page and insert some text.
Notes:
Function combining Document.newPage() and Page.insertText().
For parameter details see these methods.
"""
page = doc.newPage(pno=pno, width=width, height=height)
if not bool(text):
return 0
rc = page.insertText(
(50, 72),
text,
fontsize=fontsize,
fontname=fontname,
fontfile=fontfile,
color=color,
)
return rc | [
"def",
"insertPage",
"(",
"doc",
",",
"pno",
",",
"text",
"=",
"None",
",",
"fontsize",
"=",
"11",
",",
"width",
"=",
"595",
",",
"height",
"=",
"842",
",",
"fontname",
"=",
"\"helv\"",
",",
"fontfile",
"=",
"None",
",",
"color",
"=",
"None",
",",
")",
":",
"page",
"=",
"doc",
".",
"newPage",
"(",
"pno",
"=",
"pno",
",",
"width",
"=",
"width",
",",
"height",
"=",
"height",
")",
"if",
"not",
"bool",
"(",
"text",
")",
":",
"return",
"0",
"rc",
"=",
"page",
".",
"insertText",
"(",
"(",
"50",
",",
"72",
")",
",",
"text",
",",
"fontsize",
"=",
"fontsize",
",",
"fontname",
"=",
"fontname",
",",
"fontfile",
"=",
"fontfile",
",",
"color",
"=",
"color",
",",
")",
"return",
"rc"
] | Create a new PDF page and insert some text.
Notes:
Function combining Document.newPage() and Page.insertText().
For parameter details see these methods. | [
"Create",
"a",
"new",
"PDF",
"page",
"and",
"insert",
"some",
"text",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/utils.py#L1100-L1128 |
229,059 | pymupdf/PyMuPDF | fitz/utils.py | drawSquiggle | def drawSquiggle(page, p1, p2, breadth = 2, color=None, dashes=None,
width=1, roundCap=False, overlay=True, morph=None):
"""Draw a squiggly line from point p1 to point p2.
"""
img = page.newShape()
p = img.drawSquiggle(Point(p1), Point(p2), breadth = breadth)
img.finish(color=color, dashes=dashes, width=width, closePath=False,
roundCap=roundCap, morph=morph)
img.commit(overlay)
return p | python | def drawSquiggle(page, p1, p2, breadth = 2, color=None, dashes=None,
width=1, roundCap=False, overlay=True, morph=None):
"""Draw a squiggly line from point p1 to point p2.
"""
img = page.newShape()
p = img.drawSquiggle(Point(p1), Point(p2), breadth = breadth)
img.finish(color=color, dashes=dashes, width=width, closePath=False,
roundCap=roundCap, morph=morph)
img.commit(overlay)
return p | [
"def",
"drawSquiggle",
"(",
"page",
",",
"p1",
",",
"p2",
",",
"breadth",
"=",
"2",
",",
"color",
"=",
"None",
",",
"dashes",
"=",
"None",
",",
"width",
"=",
"1",
",",
"roundCap",
"=",
"False",
",",
"overlay",
"=",
"True",
",",
"morph",
"=",
"None",
")",
":",
"img",
"=",
"page",
".",
"newShape",
"(",
")",
"p",
"=",
"img",
".",
"drawSquiggle",
"(",
"Point",
"(",
"p1",
")",
",",
"Point",
"(",
"p2",
")",
",",
"breadth",
"=",
"breadth",
")",
"img",
".",
"finish",
"(",
"color",
"=",
"color",
",",
"dashes",
"=",
"dashes",
",",
"width",
"=",
"width",
",",
"closePath",
"=",
"False",
",",
"roundCap",
"=",
"roundCap",
",",
"morph",
"=",
"morph",
")",
"img",
".",
"commit",
"(",
"overlay",
")",
"return",
"p"
] | Draw a squiggly line from point p1 to point p2. | [
"Draw",
"a",
"squiggly",
"line",
"from",
"point",
"p1",
"to",
"point",
"p2",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/utils.py#L1141-L1151 |
229,060 | pymupdf/PyMuPDF | fitz/utils.py | drawQuad | def drawQuad(page, quad, color=None, fill=None, dashes=None,
width=1, roundCap=False, morph=None, overlay=True):
"""Draw a quadrilateral.
"""
img = page.newShape()
Q = img.drawQuad(Quad(quad))
img.finish(color=color, fill=fill, dashes=dashes, width=width,
roundCap=roundCap, morph=morph)
img.commit(overlay)
return Q | python | def drawQuad(page, quad, color=None, fill=None, dashes=None,
width=1, roundCap=False, morph=None, overlay=True):
"""Draw a quadrilateral.
"""
img = page.newShape()
Q = img.drawQuad(Quad(quad))
img.finish(color=color, fill=fill, dashes=dashes, width=width,
roundCap=roundCap, morph=morph)
img.commit(overlay)
return Q | [
"def",
"drawQuad",
"(",
"page",
",",
"quad",
",",
"color",
"=",
"None",
",",
"fill",
"=",
"None",
",",
"dashes",
"=",
"None",
",",
"width",
"=",
"1",
",",
"roundCap",
"=",
"False",
",",
"morph",
"=",
"None",
",",
"overlay",
"=",
"True",
")",
":",
"img",
"=",
"page",
".",
"newShape",
"(",
")",
"Q",
"=",
"img",
".",
"drawQuad",
"(",
"Quad",
"(",
"quad",
")",
")",
"img",
".",
"finish",
"(",
"color",
"=",
"color",
",",
"fill",
"=",
"fill",
",",
"dashes",
"=",
"dashes",
",",
"width",
"=",
"width",
",",
"roundCap",
"=",
"roundCap",
",",
"morph",
"=",
"morph",
")",
"img",
".",
"commit",
"(",
"overlay",
")",
"return",
"Q"
] | Draw a quadrilateral. | [
"Draw",
"a",
"quadrilateral",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/utils.py#L1177-L1187 |
229,061 | pymupdf/PyMuPDF | fitz/utils.py | drawPolyline | def drawPolyline(page, points, color=None, fill=None, dashes=None,
width=1, morph=None, roundCap=False, overlay=True,
closePath=False):
"""Draw multiple connected line segments.
"""
img = page.newShape()
Q = img.drawPolyline(points)
img.finish(color=color, fill=fill, dashes=dashes, width=width,
roundCap=roundCap, morph=morph, closePath=closePath)
img.commit(overlay)
return Q | python | def drawPolyline(page, points, color=None, fill=None, dashes=None,
width=1, morph=None, roundCap=False, overlay=True,
closePath=False):
"""Draw multiple connected line segments.
"""
img = page.newShape()
Q = img.drawPolyline(points)
img.finish(color=color, fill=fill, dashes=dashes, width=width,
roundCap=roundCap, morph=morph, closePath=closePath)
img.commit(overlay)
return Q | [
"def",
"drawPolyline",
"(",
"page",
",",
"points",
",",
"color",
"=",
"None",
",",
"fill",
"=",
"None",
",",
"dashes",
"=",
"None",
",",
"width",
"=",
"1",
",",
"morph",
"=",
"None",
",",
"roundCap",
"=",
"False",
",",
"overlay",
"=",
"True",
",",
"closePath",
"=",
"False",
")",
":",
"img",
"=",
"page",
".",
"newShape",
"(",
")",
"Q",
"=",
"img",
".",
"drawPolyline",
"(",
"points",
")",
"img",
".",
"finish",
"(",
"color",
"=",
"color",
",",
"fill",
"=",
"fill",
",",
"dashes",
"=",
"dashes",
",",
"width",
"=",
"width",
",",
"roundCap",
"=",
"roundCap",
",",
"morph",
"=",
"morph",
",",
"closePath",
"=",
"closePath",
")",
"img",
".",
"commit",
"(",
"overlay",
")",
"return",
"Q"
] | Draw multiple connected line segments. | [
"Draw",
"multiple",
"connected",
"line",
"segments",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/utils.py#L1189-L1200 |
229,062 | pymupdf/PyMuPDF | fitz/utils.py | drawBezier | def drawBezier(page, p1, p2, p3, p4, color=None, fill=None,
dashes=None, width=1, morph=None,
closePath=False, roundCap=False, overlay=True):
"""Draw a general cubic Bezier curve from p1 to p4 using control points p2 and p3.
"""
img = page.newShape()
Q = img.drawBezier(Point(p1), Point(p2), Point(p3), Point(p4))
img.finish(color=color, fill=fill, dashes=dashes, width=width,
roundCap=roundCap, morph=morph, closePath=closePath)
img.commit(overlay)
return Q | python | def drawBezier(page, p1, p2, p3, p4, color=None, fill=None,
dashes=None, width=1, morph=None,
closePath=False, roundCap=False, overlay=True):
"""Draw a general cubic Bezier curve from p1 to p4 using control points p2 and p3.
"""
img = page.newShape()
Q = img.drawBezier(Point(p1), Point(p2), Point(p3), Point(p4))
img.finish(color=color, fill=fill, dashes=dashes, width=width,
roundCap=roundCap, morph=morph, closePath=closePath)
img.commit(overlay)
return Q | [
"def",
"drawBezier",
"(",
"page",
",",
"p1",
",",
"p2",
",",
"p3",
",",
"p4",
",",
"color",
"=",
"None",
",",
"fill",
"=",
"None",
",",
"dashes",
"=",
"None",
",",
"width",
"=",
"1",
",",
"morph",
"=",
"None",
",",
"closePath",
"=",
"False",
",",
"roundCap",
"=",
"False",
",",
"overlay",
"=",
"True",
")",
":",
"img",
"=",
"page",
".",
"newShape",
"(",
")",
"Q",
"=",
"img",
".",
"drawBezier",
"(",
"Point",
"(",
"p1",
")",
",",
"Point",
"(",
"p2",
")",
",",
"Point",
"(",
"p3",
")",
",",
"Point",
"(",
"p4",
")",
")",
"img",
".",
"finish",
"(",
"color",
"=",
"color",
",",
"fill",
"=",
"fill",
",",
"dashes",
"=",
"dashes",
",",
"width",
"=",
"width",
",",
"roundCap",
"=",
"roundCap",
",",
"morph",
"=",
"morph",
",",
"closePath",
"=",
"closePath",
")",
"img",
".",
"commit",
"(",
"overlay",
")",
"return",
"Q"
] | Draw a general cubic Bezier curve from p1 to p4 using control points p2 and p3. | [
"Draw",
"a",
"general",
"cubic",
"Bezier",
"curve",
"from",
"p1",
"to",
"p4",
"using",
"control",
"points",
"p2",
"and",
"p3",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/utils.py#L1240-L1251 |
229,063 | pymupdf/PyMuPDF | fitz/utils.py | getColor | def getColor(name):
"""Retrieve RGB color in PDF format by name.
Returns:
a triple of floats in range 0 to 1. In case of name-not-found, "white" is returned.
"""
try:
c = getColorInfoList()[getColorList().index(name.upper())]
return (c[1] / 255., c[2] / 255., c[3] / 255.)
except:
return (1, 1, 1) | python | def getColor(name):
"""Retrieve RGB color in PDF format by name.
Returns:
a triple of floats in range 0 to 1. In case of name-not-found, "white" is returned.
"""
try:
c = getColorInfoList()[getColorList().index(name.upper())]
return (c[1] / 255., c[2] / 255., c[3] / 255.)
except:
return (1, 1, 1) | [
"def",
"getColor",
"(",
"name",
")",
":",
"try",
":",
"c",
"=",
"getColorInfoList",
"(",
")",
"[",
"getColorList",
"(",
")",
".",
"index",
"(",
"name",
".",
"upper",
"(",
")",
")",
"]",
"return",
"(",
"c",
"[",
"1",
"]",
"/",
"255.",
",",
"c",
"[",
"2",
"]",
"/",
"255.",
",",
"c",
"[",
"3",
"]",
"/",
"255.",
")",
"except",
":",
"return",
"(",
"1",
",",
"1",
",",
"1",
")"
] | Retrieve RGB color in PDF format by name.
Returns:
a triple of floats in range 0 to 1. In case of name-not-found, "white" is returned. | [
"Retrieve",
"RGB",
"color",
"in",
"PDF",
"format",
"by",
"name",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/utils.py#L1848-L1858 |
229,064 | pymupdf/PyMuPDF | fitz/utils.py | getColorHSV | def getColorHSV(name):
"""Retrieve the hue, saturation, value triple of a color name.
Returns:
a triple (degree, percent, percent). If not found (-1, -1, -1) is returned.
"""
try:
x = getColorInfoList()[getColorList().index(name.upper())]
except:
return (-1, -1, -1)
r = x[1] / 255.
g = x[2] / 255.
b = x[3] / 255.
cmax = max(r, g, b)
V = round(cmax * 100, 1)
cmin = min(r, g, b)
delta = cmax - cmin
if delta == 0:
hue = 0
elif cmax == r:
hue = 60. * (((g - b)/delta) % 6)
elif cmax == g:
hue = 60. * (((b - r)/delta) + 2)
else:
hue = 60. * (((r - g)/delta) + 4)
H = int(round(hue))
if cmax == 0:
sat = 0
else:
sat = delta / cmax
S = int(round(sat * 100))
return (H, S, V) | python | def getColorHSV(name):
"""Retrieve the hue, saturation, value triple of a color name.
Returns:
a triple (degree, percent, percent). If not found (-1, -1, -1) is returned.
"""
try:
x = getColorInfoList()[getColorList().index(name.upper())]
except:
return (-1, -1, -1)
r = x[1] / 255.
g = x[2] / 255.
b = x[3] / 255.
cmax = max(r, g, b)
V = round(cmax * 100, 1)
cmin = min(r, g, b)
delta = cmax - cmin
if delta == 0:
hue = 0
elif cmax == r:
hue = 60. * (((g - b)/delta) % 6)
elif cmax == g:
hue = 60. * (((b - r)/delta) + 2)
else:
hue = 60. * (((r - g)/delta) + 4)
H = int(round(hue))
if cmax == 0:
sat = 0
else:
sat = delta / cmax
S = int(round(sat * 100))
return (H, S, V) | [
"def",
"getColorHSV",
"(",
"name",
")",
":",
"try",
":",
"x",
"=",
"getColorInfoList",
"(",
")",
"[",
"getColorList",
"(",
")",
".",
"index",
"(",
"name",
".",
"upper",
"(",
")",
")",
"]",
"except",
":",
"return",
"(",
"-",
"1",
",",
"-",
"1",
",",
"-",
"1",
")",
"r",
"=",
"x",
"[",
"1",
"]",
"/",
"255.",
"g",
"=",
"x",
"[",
"2",
"]",
"/",
"255.",
"b",
"=",
"x",
"[",
"3",
"]",
"/",
"255.",
"cmax",
"=",
"max",
"(",
"r",
",",
"g",
",",
"b",
")",
"V",
"=",
"round",
"(",
"cmax",
"*",
"100",
",",
"1",
")",
"cmin",
"=",
"min",
"(",
"r",
",",
"g",
",",
"b",
")",
"delta",
"=",
"cmax",
"-",
"cmin",
"if",
"delta",
"==",
"0",
":",
"hue",
"=",
"0",
"elif",
"cmax",
"==",
"r",
":",
"hue",
"=",
"60.",
"*",
"(",
"(",
"(",
"g",
"-",
"b",
")",
"/",
"delta",
")",
"%",
"6",
")",
"elif",
"cmax",
"==",
"g",
":",
"hue",
"=",
"60.",
"*",
"(",
"(",
"(",
"b",
"-",
"r",
")",
"/",
"delta",
")",
"+",
"2",
")",
"else",
":",
"hue",
"=",
"60.",
"*",
"(",
"(",
"(",
"r",
"-",
"g",
")",
"/",
"delta",
")",
"+",
"4",
")",
"H",
"=",
"int",
"(",
"round",
"(",
"hue",
")",
")",
"if",
"cmax",
"==",
"0",
":",
"sat",
"=",
"0",
"else",
":",
"sat",
"=",
"delta",
"/",
"cmax",
"S",
"=",
"int",
"(",
"round",
"(",
"sat",
"*",
"100",
")",
")",
"return",
"(",
"H",
",",
"S",
",",
"V",
")"
] | Retrieve the hue, saturation, value triple of a color name.
Returns:
a triple (degree, percent, percent). If not found (-1, -1, -1) is returned. | [
"Retrieve",
"the",
"hue",
"saturation",
"value",
"triple",
"of",
"a",
"color",
"name",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/utils.py#L1860-L1895 |
229,065 | pymupdf/PyMuPDF | fitz/utils.py | Shape.horizontal_angle | def horizontal_angle(C, P):
"""Return the angle to the horizontal for the connection from C to P.
This uses the arcus sine function and resolves its inherent ambiguity by
looking up in which quadrant vector S = P - C is located.
"""
S = Point(P - C).unit # unit vector 'C' -> 'P'
alfa = math.asin(abs(S.y)) # absolute angle from horizontal
if S.x < 0: # make arcsin result unique
if S.y <= 0: # bottom-left
alfa = -(math.pi - alfa)
else: # top-left
alfa = math.pi - alfa
else:
if S.y >= 0: # top-right
pass
else: # bottom-right
alfa = - alfa
return alfa | python | def horizontal_angle(C, P):
"""Return the angle to the horizontal for the connection from C to P.
This uses the arcus sine function and resolves its inherent ambiguity by
looking up in which quadrant vector S = P - C is located.
"""
S = Point(P - C).unit # unit vector 'C' -> 'P'
alfa = math.asin(abs(S.y)) # absolute angle from horizontal
if S.x < 0: # make arcsin result unique
if S.y <= 0: # bottom-left
alfa = -(math.pi - alfa)
else: # top-left
alfa = math.pi - alfa
else:
if S.y >= 0: # top-right
pass
else: # bottom-right
alfa = - alfa
return alfa | [
"def",
"horizontal_angle",
"(",
"C",
",",
"P",
")",
":",
"S",
"=",
"Point",
"(",
"P",
"-",
"C",
")",
".",
"unit",
"# unit vector 'C' -> 'P'",
"alfa",
"=",
"math",
".",
"asin",
"(",
"abs",
"(",
"S",
".",
"y",
")",
")",
"# absolute angle from horizontal",
"if",
"S",
".",
"x",
"<",
"0",
":",
"# make arcsin result unique",
"if",
"S",
".",
"y",
"<=",
"0",
":",
"# bottom-left",
"alfa",
"=",
"-",
"(",
"math",
".",
"pi",
"-",
"alfa",
")",
"else",
":",
"# top-left",
"alfa",
"=",
"math",
".",
"pi",
"-",
"alfa",
"else",
":",
"if",
"S",
".",
"y",
">=",
"0",
":",
"# top-right",
"pass",
"else",
":",
"# bottom-right",
"alfa",
"=",
"-",
"alfa",
"return",
"alfa"
] | Return the angle to the horizontal for the connection from C to P.
This uses the arcus sine function and resolves its inherent ambiguity by
looking up in which quadrant vector S = P - C is located. | [
"Return",
"the",
"angle",
"to",
"the",
"horizontal",
"for",
"the",
"connection",
"from",
"C",
"to",
"P",
".",
"This",
"uses",
"the",
"arcus",
"sine",
"function",
"and",
"resolves",
"its",
"inherent",
"ambiguity",
"by",
"looking",
"up",
"in",
"which",
"quadrant",
"vector",
"S",
"=",
"P",
"-",
"C",
"is",
"located",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/utils.py#L1986-L2003 |
229,066 | pymupdf/PyMuPDF | fitz/utils.py | Shape.drawLine | def drawLine(self, p1, p2):
"""Draw a line between two points.
"""
p1 = Point(p1)
p2 = Point(p2)
if not (self.lastPoint == p1):
self.draw_cont += "%g %g m\n" % JM_TUPLE(p1 * self.ipctm)
self.lastPoint = p1
self.updateRect(p1)
self.draw_cont += "%g %g l\n" % JM_TUPLE(p2 * self.ipctm)
self.updateRect(p2)
self.lastPoint = p2
return self.lastPoint | python | def drawLine(self, p1, p2):
"""Draw a line between two points.
"""
p1 = Point(p1)
p2 = Point(p2)
if not (self.lastPoint == p1):
self.draw_cont += "%g %g m\n" % JM_TUPLE(p1 * self.ipctm)
self.lastPoint = p1
self.updateRect(p1)
self.draw_cont += "%g %g l\n" % JM_TUPLE(p2 * self.ipctm)
self.updateRect(p2)
self.lastPoint = p2
return self.lastPoint | [
"def",
"drawLine",
"(",
"self",
",",
"p1",
",",
"p2",
")",
":",
"p1",
"=",
"Point",
"(",
"p1",
")",
"p2",
"=",
"Point",
"(",
"p2",
")",
"if",
"not",
"(",
"self",
".",
"lastPoint",
"==",
"p1",
")",
":",
"self",
".",
"draw_cont",
"+=",
"\"%g %g m\\n\"",
"%",
"JM_TUPLE",
"(",
"p1",
"*",
"self",
".",
"ipctm",
")",
"self",
".",
"lastPoint",
"=",
"p1",
"self",
".",
"updateRect",
"(",
"p1",
")",
"self",
".",
"draw_cont",
"+=",
"\"%g %g l\\n\"",
"%",
"JM_TUPLE",
"(",
"p2",
"*",
"self",
".",
"ipctm",
")",
"self",
".",
"updateRect",
"(",
"p2",
")",
"self",
".",
"lastPoint",
"=",
"p2",
"return",
"self",
".",
"lastPoint"
] | Draw a line between two points. | [
"Draw",
"a",
"line",
"between",
"two",
"points",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/utils.py#L2042-L2055 |
229,067 | pymupdf/PyMuPDF | fitz/utils.py | Shape.drawPolyline | def drawPolyline(self, points):
"""Draw several connected line segments.
"""
for i, p in enumerate(points):
if i == 0:
if not (self.lastPoint == Point(p)):
self.draw_cont += "%g %g m\n" % JM_TUPLE(Point(p) * self.ipctm)
self.lastPoint = Point(p)
else:
self.draw_cont += "%g %g l\n" % JM_TUPLE(Point(p) * self.ipctm)
self.updateRect(p)
self.lastPoint = Point(points[-1])
return self.lastPoint | python | def drawPolyline(self, points):
"""Draw several connected line segments.
"""
for i, p in enumerate(points):
if i == 0:
if not (self.lastPoint == Point(p)):
self.draw_cont += "%g %g m\n" % JM_TUPLE(Point(p) * self.ipctm)
self.lastPoint = Point(p)
else:
self.draw_cont += "%g %g l\n" % JM_TUPLE(Point(p) * self.ipctm)
self.updateRect(p)
self.lastPoint = Point(points[-1])
return self.lastPoint | [
"def",
"drawPolyline",
"(",
"self",
",",
"points",
")",
":",
"for",
"i",
",",
"p",
"in",
"enumerate",
"(",
"points",
")",
":",
"if",
"i",
"==",
"0",
":",
"if",
"not",
"(",
"self",
".",
"lastPoint",
"==",
"Point",
"(",
"p",
")",
")",
":",
"self",
".",
"draw_cont",
"+=",
"\"%g %g m\\n\"",
"%",
"JM_TUPLE",
"(",
"Point",
"(",
"p",
")",
"*",
"self",
".",
"ipctm",
")",
"self",
".",
"lastPoint",
"=",
"Point",
"(",
"p",
")",
"else",
":",
"self",
".",
"draw_cont",
"+=",
"\"%g %g l\\n\"",
"%",
"JM_TUPLE",
"(",
"Point",
"(",
"p",
")",
"*",
"self",
".",
"ipctm",
")",
"self",
".",
"updateRect",
"(",
"p",
")",
"self",
".",
"lastPoint",
"=",
"Point",
"(",
"points",
"[",
"-",
"1",
"]",
")",
"return",
"self",
".",
"lastPoint"
] | Draw several connected line segments. | [
"Draw",
"several",
"connected",
"line",
"segments",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/utils.py#L2057-L2070 |
229,068 | pymupdf/PyMuPDF | fitz/utils.py | Shape.drawBezier | def drawBezier(self, p1, p2, p3, p4):
"""Draw a standard cubic Bezier curve.
"""
p1 = Point(p1)
p2 = Point(p2)
p3 = Point(p3)
p4 = Point(p4)
if not (self.lastPoint == p1):
self.draw_cont += "%g %g m\n" % JM_TUPLE(p1 * self.ipctm)
self.draw_cont += "%g %g %g %g %g %g c\n" % JM_TUPLE(list(p2 * self.ipctm) + \
list(p3 * self.ipctm) + \
list(p4 * self.ipctm))
self.updateRect(p1)
self.updateRect(p2)
self.updateRect(p3)
self.updateRect(p4)
self.lastPoint = p4
return self.lastPoint | python | def drawBezier(self, p1, p2, p3, p4):
"""Draw a standard cubic Bezier curve.
"""
p1 = Point(p1)
p2 = Point(p2)
p3 = Point(p3)
p4 = Point(p4)
if not (self.lastPoint == p1):
self.draw_cont += "%g %g m\n" % JM_TUPLE(p1 * self.ipctm)
self.draw_cont += "%g %g %g %g %g %g c\n" % JM_TUPLE(list(p2 * self.ipctm) + \
list(p3 * self.ipctm) + \
list(p4 * self.ipctm))
self.updateRect(p1)
self.updateRect(p2)
self.updateRect(p3)
self.updateRect(p4)
self.lastPoint = p4
return self.lastPoint | [
"def",
"drawBezier",
"(",
"self",
",",
"p1",
",",
"p2",
",",
"p3",
",",
"p4",
")",
":",
"p1",
"=",
"Point",
"(",
"p1",
")",
"p2",
"=",
"Point",
"(",
"p2",
")",
"p3",
"=",
"Point",
"(",
"p3",
")",
"p4",
"=",
"Point",
"(",
"p4",
")",
"if",
"not",
"(",
"self",
".",
"lastPoint",
"==",
"p1",
")",
":",
"self",
".",
"draw_cont",
"+=",
"\"%g %g m\\n\"",
"%",
"JM_TUPLE",
"(",
"p1",
"*",
"self",
".",
"ipctm",
")",
"self",
".",
"draw_cont",
"+=",
"\"%g %g %g %g %g %g c\\n\"",
"%",
"JM_TUPLE",
"(",
"list",
"(",
"p2",
"*",
"self",
".",
"ipctm",
")",
"+",
"list",
"(",
"p3",
"*",
"self",
".",
"ipctm",
")",
"+",
"list",
"(",
"p4",
"*",
"self",
".",
"ipctm",
")",
")",
"self",
".",
"updateRect",
"(",
"p1",
")",
"self",
".",
"updateRect",
"(",
"p2",
")",
"self",
".",
"updateRect",
"(",
"p3",
")",
"self",
".",
"updateRect",
"(",
"p4",
")",
"self",
".",
"lastPoint",
"=",
"p4",
"return",
"self",
".",
"lastPoint"
] | Draw a standard cubic Bezier curve. | [
"Draw",
"a",
"standard",
"cubic",
"Bezier",
"curve",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/utils.py#L2072-L2089 |
229,069 | pymupdf/PyMuPDF | fitz/utils.py | Shape.drawOval | def drawOval(self, tetra):
"""Draw an ellipse inside a tetrapod.
"""
if len(tetra) != 4:
raise ValueError("invalid arg length")
if hasattr(tetra[0], "__float__"):
q = Rect(tetra).quad
else:
q = Quad(tetra)
mt = q.ul + (q.ur - q.ul) * 0.5
mr = q.ur + (q.lr - q.ur) * 0.5
mb = q.ll + (q.lr - q.ll) * 0.5
ml = q.ul + (q.ll - q.ul) * 0.5
if not (self.lastPoint == ml):
self.draw_cont += "%g %g m\n" % JM_TUPLE(ml * self.ipctm)
self.lastPoint = ml
self.drawCurve(ml, q.ll, mb)
self.drawCurve(mb, q.lr, mr)
self.drawCurve(mr, q.ur, mt)
self.drawCurve(mt, q.ul, ml)
self.updateRect(q.rect)
self.lastPoint = ml
return self.lastPoint | python | def drawOval(self, tetra):
"""Draw an ellipse inside a tetrapod.
"""
if len(tetra) != 4:
raise ValueError("invalid arg length")
if hasattr(tetra[0], "__float__"):
q = Rect(tetra).quad
else:
q = Quad(tetra)
mt = q.ul + (q.ur - q.ul) * 0.5
mr = q.ur + (q.lr - q.ur) * 0.5
mb = q.ll + (q.lr - q.ll) * 0.5
ml = q.ul + (q.ll - q.ul) * 0.5
if not (self.lastPoint == ml):
self.draw_cont += "%g %g m\n" % JM_TUPLE(ml * self.ipctm)
self.lastPoint = ml
self.drawCurve(ml, q.ll, mb)
self.drawCurve(mb, q.lr, mr)
self.drawCurve(mr, q.ur, mt)
self.drawCurve(mt, q.ul, ml)
self.updateRect(q.rect)
self.lastPoint = ml
return self.lastPoint | [
"def",
"drawOval",
"(",
"self",
",",
"tetra",
")",
":",
"if",
"len",
"(",
"tetra",
")",
"!=",
"4",
":",
"raise",
"ValueError",
"(",
"\"invalid arg length\"",
")",
"if",
"hasattr",
"(",
"tetra",
"[",
"0",
"]",
",",
"\"__float__\"",
")",
":",
"q",
"=",
"Rect",
"(",
"tetra",
")",
".",
"quad",
"else",
":",
"q",
"=",
"Quad",
"(",
"tetra",
")",
"mt",
"=",
"q",
".",
"ul",
"+",
"(",
"q",
".",
"ur",
"-",
"q",
".",
"ul",
")",
"*",
"0.5",
"mr",
"=",
"q",
".",
"ur",
"+",
"(",
"q",
".",
"lr",
"-",
"q",
".",
"ur",
")",
"*",
"0.5",
"mb",
"=",
"q",
".",
"ll",
"+",
"(",
"q",
".",
"lr",
"-",
"q",
".",
"ll",
")",
"*",
"0.5",
"ml",
"=",
"q",
".",
"ul",
"+",
"(",
"q",
".",
"ll",
"-",
"q",
".",
"ul",
")",
"*",
"0.5",
"if",
"not",
"(",
"self",
".",
"lastPoint",
"==",
"ml",
")",
":",
"self",
".",
"draw_cont",
"+=",
"\"%g %g m\\n\"",
"%",
"JM_TUPLE",
"(",
"ml",
"*",
"self",
".",
"ipctm",
")",
"self",
".",
"lastPoint",
"=",
"ml",
"self",
".",
"drawCurve",
"(",
"ml",
",",
"q",
".",
"ll",
",",
"mb",
")",
"self",
".",
"drawCurve",
"(",
"mb",
",",
"q",
".",
"lr",
",",
"mr",
")",
"self",
".",
"drawCurve",
"(",
"mr",
",",
"q",
".",
"ur",
",",
"mt",
")",
"self",
".",
"drawCurve",
"(",
"mt",
",",
"q",
".",
"ul",
",",
"ml",
")",
"self",
".",
"updateRect",
"(",
"q",
".",
"rect",
")",
"self",
".",
"lastPoint",
"=",
"ml",
"return",
"self",
".",
"lastPoint"
] | Draw an ellipse inside a tetrapod. | [
"Draw",
"an",
"ellipse",
"inside",
"a",
"tetrapod",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/utils.py#L2091-L2114 |
229,070 | pymupdf/PyMuPDF | fitz/utils.py | Shape.drawCurve | def drawCurve(self, p1, p2, p3):
"""Draw a curve between points using one control point.
"""
kappa = 0.55228474983
p1 = Point(p1)
p2 = Point(p2)
p3 = Point(p3)
k1 = p1 + (p2 - p1) * kappa
k2 = p3 + (p2 - p3) * kappa
return self.drawBezier(p1, k1, k2, p3) | python | def drawCurve(self, p1, p2, p3):
"""Draw a curve between points using one control point.
"""
kappa = 0.55228474983
p1 = Point(p1)
p2 = Point(p2)
p3 = Point(p3)
k1 = p1 + (p2 - p1) * kappa
k2 = p3 + (p2 - p3) * kappa
return self.drawBezier(p1, k1, k2, p3) | [
"def",
"drawCurve",
"(",
"self",
",",
"p1",
",",
"p2",
",",
"p3",
")",
":",
"kappa",
"=",
"0.55228474983",
"p1",
"=",
"Point",
"(",
"p1",
")",
"p2",
"=",
"Point",
"(",
"p2",
")",
"p3",
"=",
"Point",
"(",
"p3",
")",
"k1",
"=",
"p1",
"+",
"(",
"p2",
"-",
"p1",
")",
"*",
"kappa",
"k2",
"=",
"p3",
"+",
"(",
"p2",
"-",
"p3",
")",
"*",
"kappa",
"return",
"self",
".",
"drawBezier",
"(",
"p1",
",",
"k1",
",",
"k2",
",",
"p3",
")"
] | Draw a curve between points using one control point. | [
"Draw",
"a",
"curve",
"between",
"points",
"using",
"one",
"control",
"point",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/utils.py#L2125-L2134 |
229,071 | pymupdf/PyMuPDF | fitz/utils.py | Shape.drawQuad | def drawQuad(self, quad):
"""Draw a Quad.
"""
q = Quad(quad)
return self.drawPolyline([q.ul, q.ll, q.lr, q.ur, q.ul]) | python | def drawQuad(self, quad):
"""Draw a Quad.
"""
q = Quad(quad)
return self.drawPolyline([q.ul, q.ll, q.lr, q.ur, q.ul]) | [
"def",
"drawQuad",
"(",
"self",
",",
"quad",
")",
":",
"q",
"=",
"Quad",
"(",
"quad",
")",
"return",
"self",
".",
"drawPolyline",
"(",
"[",
"q",
".",
"ul",
",",
"q",
".",
"ll",
",",
"q",
".",
"lr",
",",
"q",
".",
"ur",
",",
"q",
".",
"ul",
"]",
")"
] | Draw a Quad. | [
"Draw",
"a",
"Quad",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/utils.py#L2215-L2219 |
229,072 | pymupdf/PyMuPDF | fitz/utils.py | Shape.drawZigzag | def drawZigzag(self, p1, p2, breadth = 2):
"""Draw a zig-zagged line from p1 to p2.
"""
p1 = Point(p1)
p2 = Point(p2)
S = p2 - p1 # vector start - end
rad = abs(S) # distance of points
cnt = 4 * int(round(rad / (4 * breadth), 0)) # always take full phases
if cnt < 4:
raise ValueError("points too close")
mb = rad / cnt # revised breadth
matrix = TOOLS._hor_matrix(p1, p2) # normalize line to x-axis
i_mat = ~matrix # get original position
points = [] # stores edges
for i in range (1, cnt):
if i % 4 == 1: # point "above" connection
p = Point(i, -1) * mb
elif i % 4 == 3: # point "below" connection
p = Point(i, 1) * mb
else: # ignore others
continue
points.append(p * i_mat)
self.drawPolyline([p1] + points + [p2]) # add start and end points
return p2 | python | def drawZigzag(self, p1, p2, breadth = 2):
"""Draw a zig-zagged line from p1 to p2.
"""
p1 = Point(p1)
p2 = Point(p2)
S = p2 - p1 # vector start - end
rad = abs(S) # distance of points
cnt = 4 * int(round(rad / (4 * breadth), 0)) # always take full phases
if cnt < 4:
raise ValueError("points too close")
mb = rad / cnt # revised breadth
matrix = TOOLS._hor_matrix(p1, p2) # normalize line to x-axis
i_mat = ~matrix # get original position
points = [] # stores edges
for i in range (1, cnt):
if i % 4 == 1: # point "above" connection
p = Point(i, -1) * mb
elif i % 4 == 3: # point "below" connection
p = Point(i, 1) * mb
else: # ignore others
continue
points.append(p * i_mat)
self.drawPolyline([p1] + points + [p2]) # add start and end points
return p2 | [
"def",
"drawZigzag",
"(",
"self",
",",
"p1",
",",
"p2",
",",
"breadth",
"=",
"2",
")",
":",
"p1",
"=",
"Point",
"(",
"p1",
")",
"p2",
"=",
"Point",
"(",
"p2",
")",
"S",
"=",
"p2",
"-",
"p1",
"# vector start - end",
"rad",
"=",
"abs",
"(",
"S",
")",
"# distance of points",
"cnt",
"=",
"4",
"*",
"int",
"(",
"round",
"(",
"rad",
"/",
"(",
"4",
"*",
"breadth",
")",
",",
"0",
")",
")",
"# always take full phases",
"if",
"cnt",
"<",
"4",
":",
"raise",
"ValueError",
"(",
"\"points too close\"",
")",
"mb",
"=",
"rad",
"/",
"cnt",
"# revised breadth",
"matrix",
"=",
"TOOLS",
".",
"_hor_matrix",
"(",
"p1",
",",
"p2",
")",
"# normalize line to x-axis",
"i_mat",
"=",
"~",
"matrix",
"# get original position",
"points",
"=",
"[",
"]",
"# stores edges",
"for",
"i",
"in",
"range",
"(",
"1",
",",
"cnt",
")",
":",
"if",
"i",
"%",
"4",
"==",
"1",
":",
"# point \"above\" connection",
"p",
"=",
"Point",
"(",
"i",
",",
"-",
"1",
")",
"*",
"mb",
"elif",
"i",
"%",
"4",
"==",
"3",
":",
"# point \"below\" connection",
"p",
"=",
"Point",
"(",
"i",
",",
"1",
")",
"*",
"mb",
"else",
":",
"# ignore others",
"continue",
"points",
".",
"append",
"(",
"p",
"*",
"i_mat",
")",
"self",
".",
"drawPolyline",
"(",
"[",
"p1",
"]",
"+",
"points",
"+",
"[",
"p2",
"]",
")",
"# add start and end points",
"return",
"p2"
] | Draw a zig-zagged line from p1 to p2. | [
"Draw",
"a",
"zig",
"-",
"zagged",
"line",
"from",
"p1",
"to",
"p2",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/utils.py#L2221-L2244 |
229,073 | pymupdf/PyMuPDF | fitz/utils.py | Shape.drawSquiggle | def drawSquiggle(self, p1, p2, breadth = 2):
"""Draw a squiggly line from p1 to p2.
"""
p1 = Point(p1)
p2 = Point(p2)
S = p2 - p1 # vector start - end
rad = abs(S) # distance of points
cnt = 4 * int(round(rad / (4 * breadth), 0)) # always take full phases
if cnt < 4:
raise ValueError("points too close")
mb = rad / cnt # revised breadth
matrix = TOOLS._hor_matrix(p1, p2) # normalize line to x-axis
i_mat = ~matrix # get original position
k = 2.4142135623765633 # y of drawCurve helper point
points = [] # stores edges
for i in range (1, cnt):
if i % 4 == 1: # point "above" connection
p = Point(i, -k) * mb
elif i % 4 == 3: # point "below" connection
p = Point(i, k) * mb
else: # else on connection line
p = Point(i, 0) * mb
points.append(p * i_mat)
points = [p1] + points + [p2]
cnt = len(points)
i = 0
while i + 2 < cnt:
self.drawCurve(points[i], points[i+1], points[i+2])
i += 2
return p2 | python | def drawSquiggle(self, p1, p2, breadth = 2):
"""Draw a squiggly line from p1 to p2.
"""
p1 = Point(p1)
p2 = Point(p2)
S = p2 - p1 # vector start - end
rad = abs(S) # distance of points
cnt = 4 * int(round(rad / (4 * breadth), 0)) # always take full phases
if cnt < 4:
raise ValueError("points too close")
mb = rad / cnt # revised breadth
matrix = TOOLS._hor_matrix(p1, p2) # normalize line to x-axis
i_mat = ~matrix # get original position
k = 2.4142135623765633 # y of drawCurve helper point
points = [] # stores edges
for i in range (1, cnt):
if i % 4 == 1: # point "above" connection
p = Point(i, -k) * mb
elif i % 4 == 3: # point "below" connection
p = Point(i, k) * mb
else: # else on connection line
p = Point(i, 0) * mb
points.append(p * i_mat)
points = [p1] + points + [p2]
cnt = len(points)
i = 0
while i + 2 < cnt:
self.drawCurve(points[i], points[i+1], points[i+2])
i += 2
return p2 | [
"def",
"drawSquiggle",
"(",
"self",
",",
"p1",
",",
"p2",
",",
"breadth",
"=",
"2",
")",
":",
"p1",
"=",
"Point",
"(",
"p1",
")",
"p2",
"=",
"Point",
"(",
"p2",
")",
"S",
"=",
"p2",
"-",
"p1",
"# vector start - end",
"rad",
"=",
"abs",
"(",
"S",
")",
"# distance of points",
"cnt",
"=",
"4",
"*",
"int",
"(",
"round",
"(",
"rad",
"/",
"(",
"4",
"*",
"breadth",
")",
",",
"0",
")",
")",
"# always take full phases",
"if",
"cnt",
"<",
"4",
":",
"raise",
"ValueError",
"(",
"\"points too close\"",
")",
"mb",
"=",
"rad",
"/",
"cnt",
"# revised breadth",
"matrix",
"=",
"TOOLS",
".",
"_hor_matrix",
"(",
"p1",
",",
"p2",
")",
"# normalize line to x-axis",
"i_mat",
"=",
"~",
"matrix",
"# get original position",
"k",
"=",
"2.4142135623765633",
"# y of drawCurve helper point",
"points",
"=",
"[",
"]",
"# stores edges",
"for",
"i",
"in",
"range",
"(",
"1",
",",
"cnt",
")",
":",
"if",
"i",
"%",
"4",
"==",
"1",
":",
"# point \"above\" connection",
"p",
"=",
"Point",
"(",
"i",
",",
"-",
"k",
")",
"*",
"mb",
"elif",
"i",
"%",
"4",
"==",
"3",
":",
"# point \"below\" connection",
"p",
"=",
"Point",
"(",
"i",
",",
"k",
")",
"*",
"mb",
"else",
":",
"# else on connection line",
"p",
"=",
"Point",
"(",
"i",
",",
"0",
")",
"*",
"mb",
"points",
".",
"append",
"(",
"p",
"*",
"i_mat",
")",
"points",
"=",
"[",
"p1",
"]",
"+",
"points",
"+",
"[",
"p2",
"]",
"cnt",
"=",
"len",
"(",
"points",
")",
"i",
"=",
"0",
"while",
"i",
"+",
"2",
"<",
"cnt",
":",
"self",
".",
"drawCurve",
"(",
"points",
"[",
"i",
"]",
",",
"points",
"[",
"i",
"+",
"1",
"]",
",",
"points",
"[",
"i",
"+",
"2",
"]",
")",
"i",
"+=",
"2",
"return",
"p2"
] | Draw a squiggly line from p1 to p2. | [
"Draw",
"a",
"squiggly",
"line",
"from",
"p1",
"to",
"p2",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/utils.py#L2246-L2277 |
229,074 | pymupdf/PyMuPDF | fitz/utils.py | Shape.finish | def finish(
self,
width=1,
color=None,
fill=None,
roundCap=False,
dashes=None,
even_odd=False,
morph=None,
closePath=True
):
"""Finish the current drawing segment.
Notes:
Apply stroke and fill colors, dashes, line style and width, or
morphing. Also determines whether any open path should be closed
by a connecting line to its start point.
"""
if self.draw_cont == "": # treat empty contents as no-op
return
color_str = ColorCode(color, "c") # ensure proper color string
fill_str = ColorCode(fill, "f") # ensure proper fill string
if width != 1:
self.draw_cont += "%g w\n" % width
if roundCap:
self.draw_cont += "%i J %i j\n" % (roundCap, roundCap)
if dashes is not None and len(dashes) > 0:
self.draw_cont += "%s d\n" % dashes
if closePath:
self.draw_cont += "h\n"
self.lastPoint = None
if color is not None:
self.draw_cont += color_str
if fill is not None:
self.draw_cont += fill_str
if not even_odd:
self.draw_cont += "B\n"
else:
self.draw_cont += "B*\n"
else:
self.draw_cont += "S\n"
if CheckMorph(morph):
m1 = Matrix(1, 0, 0, 1, morph[0].x + self.x,
self.height - morph[0].y - self.y)
mat = ~m1 * morph[1] * m1
self.draw_cont = "%g %g %g %g %g %g cm\n" % JM_TUPLE(mat) + self.draw_cont
self.totalcont += "\nq\n" + self.draw_cont + "Q\n"
self.draw_cont = ""
self.lastPoint = None
return | python | def finish(
self,
width=1,
color=None,
fill=None,
roundCap=False,
dashes=None,
even_odd=False,
morph=None,
closePath=True
):
"""Finish the current drawing segment.
Notes:
Apply stroke and fill colors, dashes, line style and width, or
morphing. Also determines whether any open path should be closed
by a connecting line to its start point.
"""
if self.draw_cont == "": # treat empty contents as no-op
return
color_str = ColorCode(color, "c") # ensure proper color string
fill_str = ColorCode(fill, "f") # ensure proper fill string
if width != 1:
self.draw_cont += "%g w\n" % width
if roundCap:
self.draw_cont += "%i J %i j\n" % (roundCap, roundCap)
if dashes is not None and len(dashes) > 0:
self.draw_cont += "%s d\n" % dashes
if closePath:
self.draw_cont += "h\n"
self.lastPoint = None
if color is not None:
self.draw_cont += color_str
if fill is not None:
self.draw_cont += fill_str
if not even_odd:
self.draw_cont += "B\n"
else:
self.draw_cont += "B*\n"
else:
self.draw_cont += "S\n"
if CheckMorph(morph):
m1 = Matrix(1, 0, 0, 1, morph[0].x + self.x,
self.height - morph[0].y - self.y)
mat = ~m1 * morph[1] * m1
self.draw_cont = "%g %g %g %g %g %g cm\n" % JM_TUPLE(mat) + self.draw_cont
self.totalcont += "\nq\n" + self.draw_cont + "Q\n"
self.draw_cont = ""
self.lastPoint = None
return | [
"def",
"finish",
"(",
"self",
",",
"width",
"=",
"1",
",",
"color",
"=",
"None",
",",
"fill",
"=",
"None",
",",
"roundCap",
"=",
"False",
",",
"dashes",
"=",
"None",
",",
"even_odd",
"=",
"False",
",",
"morph",
"=",
"None",
",",
"closePath",
"=",
"True",
")",
":",
"if",
"self",
".",
"draw_cont",
"==",
"\"\"",
":",
"# treat empty contents as no-op",
"return",
"color_str",
"=",
"ColorCode",
"(",
"color",
",",
"\"c\"",
")",
"# ensure proper color string",
"fill_str",
"=",
"ColorCode",
"(",
"fill",
",",
"\"f\"",
")",
"# ensure proper fill string",
"if",
"width",
"!=",
"1",
":",
"self",
".",
"draw_cont",
"+=",
"\"%g w\\n\"",
"%",
"width",
"if",
"roundCap",
":",
"self",
".",
"draw_cont",
"+=",
"\"%i J %i j\\n\"",
"%",
"(",
"roundCap",
",",
"roundCap",
")",
"if",
"dashes",
"is",
"not",
"None",
"and",
"len",
"(",
"dashes",
")",
">",
"0",
":",
"self",
".",
"draw_cont",
"+=",
"\"%s d\\n\"",
"%",
"dashes",
"if",
"closePath",
":",
"self",
".",
"draw_cont",
"+=",
"\"h\\n\"",
"self",
".",
"lastPoint",
"=",
"None",
"if",
"color",
"is",
"not",
"None",
":",
"self",
".",
"draw_cont",
"+=",
"color_str",
"if",
"fill",
"is",
"not",
"None",
":",
"self",
".",
"draw_cont",
"+=",
"fill_str",
"if",
"not",
"even_odd",
":",
"self",
".",
"draw_cont",
"+=",
"\"B\\n\"",
"else",
":",
"self",
".",
"draw_cont",
"+=",
"\"B*\\n\"",
"else",
":",
"self",
".",
"draw_cont",
"+=",
"\"S\\n\"",
"if",
"CheckMorph",
"(",
"morph",
")",
":",
"m1",
"=",
"Matrix",
"(",
"1",
",",
"0",
",",
"0",
",",
"1",
",",
"morph",
"[",
"0",
"]",
".",
"x",
"+",
"self",
".",
"x",
",",
"self",
".",
"height",
"-",
"morph",
"[",
"0",
"]",
".",
"y",
"-",
"self",
".",
"y",
")",
"mat",
"=",
"~",
"m1",
"*",
"morph",
"[",
"1",
"]",
"*",
"m1",
"self",
".",
"draw_cont",
"=",
"\"%g %g %g %g %g %g cm\\n\"",
"%",
"JM_TUPLE",
"(",
"mat",
")",
"+",
"self",
".",
"draw_cont",
"self",
".",
"totalcont",
"+=",
"\"\\nq\\n\"",
"+",
"self",
".",
"draw_cont",
"+",
"\"Q\\n\"",
"self",
".",
"draw_cont",
"=",
"\"\"",
"self",
".",
"lastPoint",
"=",
"None",
"return"
] | Finish the current drawing segment.
Notes:
Apply stroke and fill colors, dashes, line style and width, or
morphing. Also determines whether any open path should be closed
by a connecting line to its start point. | [
"Finish",
"the",
"current",
"drawing",
"segment",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/utils.py#L2709-L2767 |
229,075 | stitchfix/pyxley | pyxley/charts/mg/mg.py | OptionHelper.set_float | def set_float(self, option, value):
"""Set a float option.
Args:
option (str): name of option.
value (float): value of the option.
Raises:
TypeError: Value must be a float.
"""
if not isinstance(value, float):
raise TypeError("Value must be a float")
self.options[option] = value | python | def set_float(self, option, value):
"""Set a float option.
Args:
option (str): name of option.
value (float): value of the option.
Raises:
TypeError: Value must be a float.
"""
if not isinstance(value, float):
raise TypeError("Value must be a float")
self.options[option] = value | [
"def",
"set_float",
"(",
"self",
",",
"option",
",",
"value",
")",
":",
"if",
"not",
"isinstance",
"(",
"value",
",",
"float",
")",
":",
"raise",
"TypeError",
"(",
"\"Value must be a float\"",
")",
"self",
".",
"options",
"[",
"option",
"]",
"=",
"value"
] | Set a float option.
Args:
option (str): name of option.
value (float): value of the option.
Raises:
TypeError: Value must be a float. | [
"Set",
"a",
"float",
"option",
"."
] | 2dab00022d977d986169cd8a629b3a2f91be893f | https://github.com/stitchfix/pyxley/blob/2dab00022d977d986169cd8a629b3a2f91be893f/pyxley/charts/mg/mg.py#L29-L41 |
229,076 | stitchfix/pyxley | pyxley/charts/mg/mg.py | OptionHelper.set_integer | def set_integer(self, option, value):
"""Set an integer option.
Args:
option (str): name of option.
value (int): value of the option.
Raises:
ValueError: Value must be an integer.
"""
try:
int_value = int(value)
except ValueError as err:
print(err.args)
self.options[option] = value | python | def set_integer(self, option, value):
"""Set an integer option.
Args:
option (str): name of option.
value (int): value of the option.
Raises:
ValueError: Value must be an integer.
"""
try:
int_value = int(value)
except ValueError as err:
print(err.args)
self.options[option] = value | [
"def",
"set_integer",
"(",
"self",
",",
"option",
",",
"value",
")",
":",
"try",
":",
"int_value",
"=",
"int",
"(",
"value",
")",
"except",
"ValueError",
"as",
"err",
":",
"print",
"(",
"err",
".",
"args",
")",
"self",
".",
"options",
"[",
"option",
"]",
"=",
"value"
] | Set an integer option.
Args:
option (str): name of option.
value (int): value of the option.
Raises:
ValueError: Value must be an integer. | [
"Set",
"an",
"integer",
"option",
"."
] | 2dab00022d977d986169cd8a629b3a2f91be893f | https://github.com/stitchfix/pyxley/blob/2dab00022d977d986169cd8a629b3a2f91be893f/pyxley/charts/mg/mg.py#L43-L58 |
229,077 | stitchfix/pyxley | pyxley/charts/mg/mg.py | OptionHelper.set_boolean | def set_boolean(self, option, value):
"""Set a boolean option.
Args:
option (str): name of option.
value (bool): value of the option.
Raises:
TypeError: Value must be a boolean.
"""
if not isinstance(value, bool):
raise TypeError("%s must be a boolean" % option)
self.options[option] = str(value).lower() | python | def set_boolean(self, option, value):
"""Set a boolean option.
Args:
option (str): name of option.
value (bool): value of the option.
Raises:
TypeError: Value must be a boolean.
"""
if not isinstance(value, bool):
raise TypeError("%s must be a boolean" % option)
self.options[option] = str(value).lower() | [
"def",
"set_boolean",
"(",
"self",
",",
"option",
",",
"value",
")",
":",
"if",
"not",
"isinstance",
"(",
"value",
",",
"bool",
")",
":",
"raise",
"TypeError",
"(",
"\"%s must be a boolean\"",
"%",
"option",
")",
"self",
".",
"options",
"[",
"option",
"]",
"=",
"str",
"(",
"value",
")",
".",
"lower",
"(",
")"
] | Set a boolean option.
Args:
option (str): name of option.
value (bool): value of the option.
Raises:
TypeError: Value must be a boolean. | [
"Set",
"a",
"boolean",
"option",
"."
] | 2dab00022d977d986169cd8a629b3a2f91be893f | https://github.com/stitchfix/pyxley/blob/2dab00022d977d986169cd8a629b3a2f91be893f/pyxley/charts/mg/mg.py#L60-L73 |
229,078 | stitchfix/pyxley | pyxley/charts/mg/mg.py | OptionHelper.set_string | def set_string(self, option, value):
"""Set a string option.
Args:
option (str): name of option.
value (str): value of the option.
Raises:
TypeError: Value must be a string.
"""
if not isinstance(value, str):
raise TypeError("%s must be a string" % option)
self.options[option] = value | python | def set_string(self, option, value):
"""Set a string option.
Args:
option (str): name of option.
value (str): value of the option.
Raises:
TypeError: Value must be a string.
"""
if not isinstance(value, str):
raise TypeError("%s must be a string" % option)
self.options[option] = value | [
"def",
"set_string",
"(",
"self",
",",
"option",
",",
"value",
")",
":",
"if",
"not",
"isinstance",
"(",
"value",
",",
"str",
")",
":",
"raise",
"TypeError",
"(",
"\"%s must be a string\"",
"%",
"option",
")",
"self",
".",
"options",
"[",
"option",
"]",
"=",
"value"
] | Set a string option.
Args:
option (str): name of option.
value (str): value of the option.
Raises:
TypeError: Value must be a string. | [
"Set",
"a",
"string",
"option",
"."
] | 2dab00022d977d986169cd8a629b3a2f91be893f | https://github.com/stitchfix/pyxley/blob/2dab00022d977d986169cd8a629b3a2f91be893f/pyxley/charts/mg/mg.py#L75-L88 |
229,079 | stitchfix/pyxley | pyxley/charts/mg/graphic.py | Graphic.custom_line_color_map | def custom_line_color_map(self, values):
"""Set the custom line color map.
Args:
values (list): list of colors.
Raises:
TypeError: Custom line color map must be a list.
"""
if not isinstance(values, list):
raise TypeError("custom_line_color_map must be a list")
self.options["custom_line_color_map"] = values | python | def custom_line_color_map(self, values):
"""Set the custom line color map.
Args:
values (list): list of colors.
Raises:
TypeError: Custom line color map must be a list.
"""
if not isinstance(values, list):
raise TypeError("custom_line_color_map must be a list")
self.options["custom_line_color_map"] = values | [
"def",
"custom_line_color_map",
"(",
"self",
",",
"values",
")",
":",
"if",
"not",
"isinstance",
"(",
"values",
",",
"list",
")",
":",
"raise",
"TypeError",
"(",
"\"custom_line_color_map must be a list\"",
")",
"self",
".",
"options",
"[",
"\"custom_line_color_map\"",
"]",
"=",
"values"
] | Set the custom line color map.
Args:
values (list): list of colors.
Raises:
TypeError: Custom line color map must be a list. | [
"Set",
"the",
"custom",
"line",
"color",
"map",
"."
] | 2dab00022d977d986169cd8a629b3a2f91be893f | https://github.com/stitchfix/pyxley/blob/2dab00022d977d986169cd8a629b3a2f91be893f/pyxley/charts/mg/graphic.py#L89-L101 |
229,080 | stitchfix/pyxley | pyxley/charts/mg/graphic.py | Graphic.legend | def legend(self, values):
"""Set the legend labels.
Args:
values (list): list of labels.
Raises:
ValueError: legend must be a list of labels.
"""
if not isinstance(values, list):
raise TypeError("legend must be a list of labels")
self.options["legend"] = values | python | def legend(self, values):
"""Set the legend labels.
Args:
values (list): list of labels.
Raises:
ValueError: legend must be a list of labels.
"""
if not isinstance(values, list):
raise TypeError("legend must be a list of labels")
self.options["legend"] = values | [
"def",
"legend",
"(",
"self",
",",
"values",
")",
":",
"if",
"not",
"isinstance",
"(",
"values",
",",
"list",
")",
":",
"raise",
"TypeError",
"(",
"\"legend must be a list of labels\"",
")",
"self",
".",
"options",
"[",
"\"legend\"",
"]",
"=",
"values"
] | Set the legend labels.
Args:
values (list): list of labels.
Raises:
ValueError: legend must be a list of labels. | [
"Set",
"the",
"legend",
"labels",
"."
] | 2dab00022d977d986169cd8a629b3a2f91be893f | https://github.com/stitchfix/pyxley/blob/2dab00022d977d986169cd8a629b3a2f91be893f/pyxley/charts/mg/graphic.py#L164-L176 |
229,081 | stitchfix/pyxley | pyxley/charts/mg/graphic.py | Graphic.markers | def markers(self, values):
"""Set the markers.
Args:
values (list): list of marker objects.
Raises:
ValueError: Markers must be a list of objects.
"""
if not isinstance(values, list):
raise TypeError("Markers must be a list of objects")
self.options["markers"] = values | python | def markers(self, values):
"""Set the markers.
Args:
values (list): list of marker objects.
Raises:
ValueError: Markers must be a list of objects.
"""
if not isinstance(values, list):
raise TypeError("Markers must be a list of objects")
self.options["markers"] = values | [
"def",
"markers",
"(",
"self",
",",
"values",
")",
":",
"if",
"not",
"isinstance",
"(",
"values",
",",
"list",
")",
":",
"raise",
"TypeError",
"(",
"\"Markers must be a list of objects\"",
")",
"self",
".",
"options",
"[",
"\"markers\"",
"]",
"=",
"values"
] | Set the markers.
Args:
values (list): list of marker objects.
Raises:
ValueError: Markers must be a list of objects. | [
"Set",
"the",
"markers",
"."
] | 2dab00022d977d986169cd8a629b3a2f91be893f | https://github.com/stitchfix/pyxley/blob/2dab00022d977d986169cd8a629b3a2f91be893f/pyxley/charts/mg/graphic.py#L194-L206 |
229,082 | stitchfix/pyxley | pyxley/charts/mg/graphic.py | Graphic.get | def get(self):
"""Get graphics options."""
return {k:v for k,v in list(self.options.items()) if k in self._allowed_graphics} | python | def get(self):
"""Get graphics options."""
return {k:v for k,v in list(self.options.items()) if k in self._allowed_graphics} | [
"def",
"get",
"(",
"self",
")",
":",
"return",
"{",
"k",
":",
"v",
"for",
"k",
",",
"v",
"in",
"list",
"(",
"self",
".",
"options",
".",
"items",
"(",
")",
")",
"if",
"k",
"in",
"self",
".",
"_allowed_graphics",
"}"
] | Get graphics options. | [
"Get",
"graphics",
"options",
"."
] | 2dab00022d977d986169cd8a629b3a2f91be893f | https://github.com/stitchfix/pyxley/blob/2dab00022d977d986169cd8a629b3a2f91be893f/pyxley/charts/mg/graphic.py#L260-L262 |
229,083 | stitchfix/pyxley | pyxley/charts/charts.py | Chart.apply_filters | def apply_filters(df, filters):
"""Basic filtering for a dataframe."""
idx = pd.Series([True]*df.shape[0])
for k, v in list(filters.items()):
if k not in df.columns:
continue
idx &= (df[k] == v)
return df.loc[idx] | python | def apply_filters(df, filters):
"""Basic filtering for a dataframe."""
idx = pd.Series([True]*df.shape[0])
for k, v in list(filters.items()):
if k not in df.columns:
continue
idx &= (df[k] == v)
return df.loc[idx] | [
"def",
"apply_filters",
"(",
"df",
",",
"filters",
")",
":",
"idx",
"=",
"pd",
".",
"Series",
"(",
"[",
"True",
"]",
"*",
"df",
".",
"shape",
"[",
"0",
"]",
")",
"for",
"k",
",",
"v",
"in",
"list",
"(",
"filters",
".",
"items",
"(",
")",
")",
":",
"if",
"k",
"not",
"in",
"df",
".",
"columns",
":",
"continue",
"idx",
"&=",
"(",
"df",
"[",
"k",
"]",
"==",
"v",
")",
"return",
"df",
".",
"loc",
"[",
"idx",
"]"
] | Basic filtering for a dataframe. | [
"Basic",
"filtering",
"for",
"a",
"dataframe",
"."
] | 2dab00022d977d986169cd8a629b3a2f91be893f | https://github.com/stitchfix/pyxley/blob/2dab00022d977d986169cd8a629b3a2f91be893f/pyxley/charts/charts.py#L10-L18 |
229,084 | stitchfix/pyxley | pyxley/charts/datatables/datatable.py | DataTable.format_row | def format_row(row, bounds, columns):
"""Formats a single row of the dataframe"""
for c in columns:
if c not in row:
continue
if "format" in columns[c]:
row[c] = columns[c]["format"] % row[c]
if c in bounds:
b = bounds[c]
row[c] = [b["min"],row[b["lower"]], row[b["upper"]], b["max"]]
return row | python | def format_row(row, bounds, columns):
"""Formats a single row of the dataframe"""
for c in columns:
if c not in row:
continue
if "format" in columns[c]:
row[c] = columns[c]["format"] % row[c]
if c in bounds:
b = bounds[c]
row[c] = [b["min"],row[b["lower"]], row[b["upper"]], b["max"]]
return row | [
"def",
"format_row",
"(",
"row",
",",
"bounds",
",",
"columns",
")",
":",
"for",
"c",
"in",
"columns",
":",
"if",
"c",
"not",
"in",
"row",
":",
"continue",
"if",
"\"format\"",
"in",
"columns",
"[",
"c",
"]",
":",
"row",
"[",
"c",
"]",
"=",
"columns",
"[",
"c",
"]",
"[",
"\"format\"",
"]",
"%",
"row",
"[",
"c",
"]",
"if",
"c",
"in",
"bounds",
":",
"b",
"=",
"bounds",
"[",
"c",
"]",
"row",
"[",
"c",
"]",
"=",
"[",
"b",
"[",
"\"min\"",
"]",
",",
"row",
"[",
"b",
"[",
"\"lower\"",
"]",
"]",
",",
"row",
"[",
"b",
"[",
"\"upper\"",
"]",
"]",
",",
"b",
"[",
"\"max\"",
"]",
"]",
"return",
"row"
] | Formats a single row of the dataframe | [
"Formats",
"a",
"single",
"row",
"of",
"the",
"dataframe"
] | 2dab00022d977d986169cd8a629b3a2f91be893f | https://github.com/stitchfix/pyxley/blob/2dab00022d977d986169cd8a629b3a2f91be893f/pyxley/charts/datatables/datatable.py#L70-L83 |
229,085 | stitchfix/pyxley | pyxley/charts/datatables/datatable.py | DataTable.to_json | def to_json(df, columns, confidence={}):
"""Transforms dataframe to properly formatted json response"""
records = []
display_cols = list(columns.keys())
if not display_cols:
display_cols = list(df.columns)
bounds = {}
for c in confidence:
bounds[c] = {
"min": df[confidence[c]["lower"]].min(),
"max": df[confidence[c]["upper"]].max(),
"lower": confidence[c]["lower"],
"upper": confidence[c]["upper"]
}
labels = {}
for c in display_cols:
if "label" in columns[c]:
labels[c] = columns[c]["label"]
else:
labels[c] = c
for i, row in df.iterrows():
row_ = DataTable.format_row(row, bounds, columns)
records.append({labels[c]: row_[c] for c in display_cols})
return {
"data": records,
"columns": [{"data": labels[c]} for c in display_cols]
} | python | def to_json(df, columns, confidence={}):
"""Transforms dataframe to properly formatted json response"""
records = []
display_cols = list(columns.keys())
if not display_cols:
display_cols = list(df.columns)
bounds = {}
for c in confidence:
bounds[c] = {
"min": df[confidence[c]["lower"]].min(),
"max": df[confidence[c]["upper"]].max(),
"lower": confidence[c]["lower"],
"upper": confidence[c]["upper"]
}
labels = {}
for c in display_cols:
if "label" in columns[c]:
labels[c] = columns[c]["label"]
else:
labels[c] = c
for i, row in df.iterrows():
row_ = DataTable.format_row(row, bounds, columns)
records.append({labels[c]: row_[c] for c in display_cols})
return {
"data": records,
"columns": [{"data": labels[c]} for c in display_cols]
} | [
"def",
"to_json",
"(",
"df",
",",
"columns",
",",
"confidence",
"=",
"{",
"}",
")",
":",
"records",
"=",
"[",
"]",
"display_cols",
"=",
"list",
"(",
"columns",
".",
"keys",
"(",
")",
")",
"if",
"not",
"display_cols",
":",
"display_cols",
"=",
"list",
"(",
"df",
".",
"columns",
")",
"bounds",
"=",
"{",
"}",
"for",
"c",
"in",
"confidence",
":",
"bounds",
"[",
"c",
"]",
"=",
"{",
"\"min\"",
":",
"df",
"[",
"confidence",
"[",
"c",
"]",
"[",
"\"lower\"",
"]",
"]",
".",
"min",
"(",
")",
",",
"\"max\"",
":",
"df",
"[",
"confidence",
"[",
"c",
"]",
"[",
"\"upper\"",
"]",
"]",
".",
"max",
"(",
")",
",",
"\"lower\"",
":",
"confidence",
"[",
"c",
"]",
"[",
"\"lower\"",
"]",
",",
"\"upper\"",
":",
"confidence",
"[",
"c",
"]",
"[",
"\"upper\"",
"]",
"}",
"labels",
"=",
"{",
"}",
"for",
"c",
"in",
"display_cols",
":",
"if",
"\"label\"",
"in",
"columns",
"[",
"c",
"]",
":",
"labels",
"[",
"c",
"]",
"=",
"columns",
"[",
"c",
"]",
"[",
"\"label\"",
"]",
"else",
":",
"labels",
"[",
"c",
"]",
"=",
"c",
"for",
"i",
",",
"row",
"in",
"df",
".",
"iterrows",
"(",
")",
":",
"row_",
"=",
"DataTable",
".",
"format_row",
"(",
"row",
",",
"bounds",
",",
"columns",
")",
"records",
".",
"append",
"(",
"{",
"labels",
"[",
"c",
"]",
":",
"row_",
"[",
"c",
"]",
"for",
"c",
"in",
"display_cols",
"}",
")",
"return",
"{",
"\"data\"",
":",
"records",
",",
"\"columns\"",
":",
"[",
"{",
"\"data\"",
":",
"labels",
"[",
"c",
"]",
"}",
"for",
"c",
"in",
"display_cols",
"]",
"}"
] | Transforms dataframe to properly formatted json response | [
"Transforms",
"dataframe",
"to",
"properly",
"formatted",
"json",
"response"
] | 2dab00022d977d986169cd8a629b3a2f91be893f | https://github.com/stitchfix/pyxley/blob/2dab00022d977d986169cd8a629b3a2f91be893f/pyxley/charts/datatables/datatable.py#L86-L117 |
229,086 | stitchfix/pyxley | pyxley/charts/mg/figure.py | Figure.get | def get(self):
"""Return axes, graphics, and layout options."""
options = {}
for x in [self.axes, self.graphics, self.layout]:
for k, v in list(x.get().items()):
options[k] = v
return options | python | def get(self):
"""Return axes, graphics, and layout options."""
options = {}
for x in [self.axes, self.graphics, self.layout]:
for k, v in list(x.get().items()):
options[k] = v
return options | [
"def",
"get",
"(",
"self",
")",
":",
"options",
"=",
"{",
"}",
"for",
"x",
"in",
"[",
"self",
".",
"axes",
",",
"self",
".",
"graphics",
",",
"self",
".",
"layout",
"]",
":",
"for",
"k",
",",
"v",
"in",
"list",
"(",
"x",
".",
"get",
"(",
")",
".",
"items",
"(",
")",
")",
":",
"options",
"[",
"k",
"]",
"=",
"v",
"return",
"options"
] | Return axes, graphics, and layout options. | [
"Return",
"axes",
"graphics",
"and",
"layout",
"options",
"."
] | 2dab00022d977d986169cd8a629b3a2f91be893f | https://github.com/stitchfix/pyxley/blob/2dab00022d977d986169cd8a629b3a2f91be893f/pyxley/charts/mg/figure.py#L22-L29 |
229,087 | stitchfix/pyxley | pyxley/charts/mg/layout.py | Layout.set_margin | def set_margin(self, top=40, bottom=30, left=50, right=10, buffer_size=8):
"""Set margin of the chart.
Args:
top (int): size of top margin in pixels.
bottom (int): size of bottom margin in pixels.
left (int): size of left margin in pixels.
right (int): size of right margin in pixels.
buffer_size (int): buffer size in pixels between the chart and margins.
"""
self.set_integer("top", top)
self.set_integer("bottom", bottom)
self.set_integer("left", left)
self.set_integer("right", right)
self.set_integer("buffer", buffer_size) | python | def set_margin(self, top=40, bottom=30, left=50, right=10, buffer_size=8):
"""Set margin of the chart.
Args:
top (int): size of top margin in pixels.
bottom (int): size of bottom margin in pixels.
left (int): size of left margin in pixels.
right (int): size of right margin in pixels.
buffer_size (int): buffer size in pixels between the chart and margins.
"""
self.set_integer("top", top)
self.set_integer("bottom", bottom)
self.set_integer("left", left)
self.set_integer("right", right)
self.set_integer("buffer", buffer_size) | [
"def",
"set_margin",
"(",
"self",
",",
"top",
"=",
"40",
",",
"bottom",
"=",
"30",
",",
"left",
"=",
"50",
",",
"right",
"=",
"10",
",",
"buffer_size",
"=",
"8",
")",
":",
"self",
".",
"set_integer",
"(",
"\"top\"",
",",
"top",
")",
"self",
".",
"set_integer",
"(",
"\"bottom\"",
",",
"bottom",
")",
"self",
".",
"set_integer",
"(",
"\"left\"",
",",
"left",
")",
"self",
".",
"set_integer",
"(",
"\"right\"",
",",
"right",
")",
"self",
".",
"set_integer",
"(",
"\"buffer\"",
",",
"buffer_size",
")"
] | Set margin of the chart.
Args:
top (int): size of top margin in pixels.
bottom (int): size of bottom margin in pixels.
left (int): size of left margin in pixels.
right (int): size of right margin in pixels.
buffer_size (int): buffer size in pixels between the chart and margins. | [
"Set",
"margin",
"of",
"the",
"chart",
"."
] | 2dab00022d977d986169cd8a629b3a2f91be893f | https://github.com/stitchfix/pyxley/blob/2dab00022d977d986169cd8a629b3a2f91be893f/pyxley/charts/mg/layout.py#L20-L35 |
229,088 | stitchfix/pyxley | pyxley/charts/mg/layout.py | Layout.set_size | def set_size(self, height=220, width=350,
height_threshold=120,
width_threshold=160):
"""Set the size of the chart.
Args:
height (int): height in pixels.
width (int): width in pixels.
height_threshold (int): height threshold in pixels
width_threshold (int): width threshold in pixesls
"""
self.set_integer("height", height)
self.set_integer("width", width)
self.set_integer("small_height_threshold", height_threshold)
self.set_integer("small_width_threshold", width_threshold) | python | def set_size(self, height=220, width=350,
height_threshold=120,
width_threshold=160):
"""Set the size of the chart.
Args:
height (int): height in pixels.
width (int): width in pixels.
height_threshold (int): height threshold in pixels
width_threshold (int): width threshold in pixesls
"""
self.set_integer("height", height)
self.set_integer("width", width)
self.set_integer("small_height_threshold", height_threshold)
self.set_integer("small_width_threshold", width_threshold) | [
"def",
"set_size",
"(",
"self",
",",
"height",
"=",
"220",
",",
"width",
"=",
"350",
",",
"height_threshold",
"=",
"120",
",",
"width_threshold",
"=",
"160",
")",
":",
"self",
".",
"set_integer",
"(",
"\"height\"",
",",
"height",
")",
"self",
".",
"set_integer",
"(",
"\"width\"",
",",
"width",
")",
"self",
".",
"set_integer",
"(",
"\"small_height_threshold\"",
",",
"height_threshold",
")",
"self",
".",
"set_integer",
"(",
"\"small_width_threshold\"",
",",
"width_threshold",
")"
] | Set the size of the chart.
Args:
height (int): height in pixels.
width (int): width in pixels.
height_threshold (int): height threshold in pixels
width_threshold (int): width threshold in pixesls | [
"Set",
"the",
"size",
"of",
"the",
"chart",
"."
] | 2dab00022d977d986169cd8a629b3a2f91be893f | https://github.com/stitchfix/pyxley/blob/2dab00022d977d986169cd8a629b3a2f91be893f/pyxley/charts/mg/layout.py#L37-L52 |
229,089 | stitchfix/pyxley | pyxley/charts/mg/layout.py | Layout.get | def get(self):
"""Get layout options."""
return {k:v for k,v in list(self.options.items()) if k in self._allowed_layout} | python | def get(self):
"""Get layout options."""
return {k:v for k,v in list(self.options.items()) if k in self._allowed_layout} | [
"def",
"get",
"(",
"self",
")",
":",
"return",
"{",
"k",
":",
"v",
"for",
"k",
",",
"v",
"in",
"list",
"(",
"self",
".",
"options",
".",
"items",
"(",
")",
")",
"if",
"k",
"in",
"self",
".",
"_allowed_layout",
"}"
] | Get layout options. | [
"Get",
"layout",
"options",
"."
] | 2dab00022d977d986169cd8a629b3a2f91be893f | https://github.com/stitchfix/pyxley/blob/2dab00022d977d986169cd8a629b3a2f91be893f/pyxley/charts/mg/layout.py#L54-L56 |
229,090 | stitchfix/pyxley | pyxley/react_template.py | format_props | def format_props(props, prop_template="{{k}} = { {{v}} }", delim="\n"):
""" Formats props for the React template.
Args:
props (dict): properties to be written to the template.
Returns:
Two lists, one containing variable names and the other
containing a list of props to be fed to the React template.
"""
vars_ = []
props_ = []
for k, v in list(props.items()):
vars_.append(Template("var {{k}} = {{v}};").render(k=k,v=json.dumps(v)))
props_.append(Template(prop_template).render(k=k, v=k))
return "\n".join(vars_), delim.join(props_) | python | def format_props(props, prop_template="{{k}} = { {{v}} }", delim="\n"):
""" Formats props for the React template.
Args:
props (dict): properties to be written to the template.
Returns:
Two lists, one containing variable names and the other
containing a list of props to be fed to the React template.
"""
vars_ = []
props_ = []
for k, v in list(props.items()):
vars_.append(Template("var {{k}} = {{v}};").render(k=k,v=json.dumps(v)))
props_.append(Template(prop_template).render(k=k, v=k))
return "\n".join(vars_), delim.join(props_) | [
"def",
"format_props",
"(",
"props",
",",
"prop_template",
"=",
"\"{{k}} = { {{v}} }\"",
",",
"delim",
"=",
"\"\\n\"",
")",
":",
"vars_",
"=",
"[",
"]",
"props_",
"=",
"[",
"]",
"for",
"k",
",",
"v",
"in",
"list",
"(",
"props",
".",
"items",
"(",
")",
")",
":",
"vars_",
".",
"append",
"(",
"Template",
"(",
"\"var {{k}} = {{v}};\"",
")",
".",
"render",
"(",
"k",
"=",
"k",
",",
"v",
"=",
"json",
".",
"dumps",
"(",
"v",
")",
")",
")",
"props_",
".",
"append",
"(",
"Template",
"(",
"prop_template",
")",
".",
"render",
"(",
"k",
"=",
"k",
",",
"v",
"=",
"k",
")",
")",
"return",
"\"\\n\"",
".",
"join",
"(",
"vars_",
")",
",",
"delim",
".",
"join",
"(",
"props_",
")"
] | Formats props for the React template.
Args:
props (dict): properties to be written to the template.
Returns:
Two lists, one containing variable names and the other
containing a list of props to be fed to the React template. | [
"Formats",
"props",
"for",
"the",
"React",
"template",
"."
] | 2dab00022d977d986169cd8a629b3a2f91be893f | https://github.com/stitchfix/pyxley/blob/2dab00022d977d986169cd8a629b3a2f91be893f/pyxley/react_template.py#L35-L51 |
229,091 | stitchfix/pyxley | pyxley/ui.py | register_layouts | def register_layouts(layouts, app, url="/api/props/", brand="Pyxley"):
""" register UILayout with the flask app
create a function that will send props for each UILayout
Args:
layouts (dict): dict of UILayout objects by name
app (object): flask app
url (string): address of props; default is /api/props/
"""
def props(name):
if name not in layouts:
# cast as list for python3
name = list(layouts.keys())[0]
return jsonify({"layouts": layouts[name]["layout"]})
def apps():
paths = []
for i, k in enumerate(layouts.keys()):
if i == 0:
paths.append({
"path": "/",
"label": layouts[k].get("title", k)
})
paths.append({
"path": "/"+k,
"label": layouts[k].get("title", k)
})
return jsonify({"brand": brand, "navlinks": paths})
app.add_url_rule(url+"<string:name>/", view_func=props)
app.add_url_rule(url, view_func=apps) | python | def register_layouts(layouts, app, url="/api/props/", brand="Pyxley"):
""" register UILayout with the flask app
create a function that will send props for each UILayout
Args:
layouts (dict): dict of UILayout objects by name
app (object): flask app
url (string): address of props; default is /api/props/
"""
def props(name):
if name not in layouts:
# cast as list for python3
name = list(layouts.keys())[0]
return jsonify({"layouts": layouts[name]["layout"]})
def apps():
paths = []
for i, k in enumerate(layouts.keys()):
if i == 0:
paths.append({
"path": "/",
"label": layouts[k].get("title", k)
})
paths.append({
"path": "/"+k,
"label": layouts[k].get("title", k)
})
return jsonify({"brand": brand, "navlinks": paths})
app.add_url_rule(url+"<string:name>/", view_func=props)
app.add_url_rule(url, view_func=apps) | [
"def",
"register_layouts",
"(",
"layouts",
",",
"app",
",",
"url",
"=",
"\"/api/props/\"",
",",
"brand",
"=",
"\"Pyxley\"",
")",
":",
"def",
"props",
"(",
"name",
")",
":",
"if",
"name",
"not",
"in",
"layouts",
":",
"# cast as list for python3",
"name",
"=",
"list",
"(",
"layouts",
".",
"keys",
"(",
")",
")",
"[",
"0",
"]",
"return",
"jsonify",
"(",
"{",
"\"layouts\"",
":",
"layouts",
"[",
"name",
"]",
"[",
"\"layout\"",
"]",
"}",
")",
"def",
"apps",
"(",
")",
":",
"paths",
"=",
"[",
"]",
"for",
"i",
",",
"k",
"in",
"enumerate",
"(",
"layouts",
".",
"keys",
"(",
")",
")",
":",
"if",
"i",
"==",
"0",
":",
"paths",
".",
"append",
"(",
"{",
"\"path\"",
":",
"\"/\"",
",",
"\"label\"",
":",
"layouts",
"[",
"k",
"]",
".",
"get",
"(",
"\"title\"",
",",
"k",
")",
"}",
")",
"paths",
".",
"append",
"(",
"{",
"\"path\"",
":",
"\"/\"",
"+",
"k",
",",
"\"label\"",
":",
"layouts",
"[",
"k",
"]",
".",
"get",
"(",
"\"title\"",
",",
"k",
")",
"}",
")",
"return",
"jsonify",
"(",
"{",
"\"brand\"",
":",
"brand",
",",
"\"navlinks\"",
":",
"paths",
"}",
")",
"app",
".",
"add_url_rule",
"(",
"url",
"+",
"\"<string:name>/\"",
",",
"view_func",
"=",
"props",
")",
"app",
".",
"add_url_rule",
"(",
"url",
",",
"view_func",
"=",
"apps",
")"
] | register UILayout with the flask app
create a function that will send props for each UILayout
Args:
layouts (dict): dict of UILayout objects by name
app (object): flask app
url (string): address of props; default is /api/props/ | [
"register",
"UILayout",
"with",
"the",
"flask",
"app"
] | 2dab00022d977d986169cd8a629b3a2f91be893f | https://github.com/stitchfix/pyxley/blob/2dab00022d977d986169cd8a629b3a2f91be893f/pyxley/ui.py#L5-L38 |
229,092 | stitchfix/pyxley | pyxley/ui.py | UIComponent.register_route | def register_route(self, app):
"""Register the api route function with the app."""
if "url" not in self.params["options"]:
raise Exception("Component does not have a URL property")
if not hasattr(self.route_func, "__call__"):
raise Exception("No app route function supplied")
app.add_url_rule(self.params["options"]["url"],
self.params["options"]["url"],
self.route_func) | python | def register_route(self, app):
"""Register the api route function with the app."""
if "url" not in self.params["options"]:
raise Exception("Component does not have a URL property")
if not hasattr(self.route_func, "__call__"):
raise Exception("No app route function supplied")
app.add_url_rule(self.params["options"]["url"],
self.params["options"]["url"],
self.route_func) | [
"def",
"register_route",
"(",
"self",
",",
"app",
")",
":",
"if",
"\"url\"",
"not",
"in",
"self",
".",
"params",
"[",
"\"options\"",
"]",
":",
"raise",
"Exception",
"(",
"\"Component does not have a URL property\"",
")",
"if",
"not",
"hasattr",
"(",
"self",
".",
"route_func",
",",
"\"__call__\"",
")",
":",
"raise",
"Exception",
"(",
"\"No app route function supplied\"",
")",
"app",
".",
"add_url_rule",
"(",
"self",
".",
"params",
"[",
"\"options\"",
"]",
"[",
"\"url\"",
"]",
",",
"self",
".",
"params",
"[",
"\"options\"",
"]",
"[",
"\"url\"",
"]",
",",
"self",
".",
"route_func",
")"
] | Register the api route function with the app. | [
"Register",
"the",
"api",
"route",
"function",
"with",
"the",
"app",
"."
] | 2dab00022d977d986169cd8a629b3a2f91be893f | https://github.com/stitchfix/pyxley/blob/2dab00022d977d986169cd8a629b3a2f91be893f/pyxley/ui.py#L61-L71 |
229,093 | stitchfix/pyxley | pyxley/ui.py | SimpleComponent.render | def render(self, path):
"""Render the component to a javascript file."""
return ReactComponent(
self.layout,
self.src_file,
self.component_id,
props=self.props,
static_path=path) | python | def render(self, path):
"""Render the component to a javascript file."""
return ReactComponent(
self.layout,
self.src_file,
self.component_id,
props=self.props,
static_path=path) | [
"def",
"render",
"(",
"self",
",",
"path",
")",
":",
"return",
"ReactComponent",
"(",
"self",
".",
"layout",
",",
"self",
".",
"src_file",
",",
"self",
".",
"component_id",
",",
"props",
"=",
"self",
".",
"props",
",",
"static_path",
"=",
"path",
")"
] | Render the component to a javascript file. | [
"Render",
"the",
"component",
"to",
"a",
"javascript",
"file",
"."
] | 2dab00022d977d986169cd8a629b3a2f91be893f | https://github.com/stitchfix/pyxley/blob/2dab00022d977d986169cd8a629b3a2f91be893f/pyxley/ui.py#L93-L100 |
229,094 | stitchfix/pyxley | pyxley/ui.py | UILayout.add_filter | def add_filter(self, component, filter_group="pyxley-filter"):
"""Add a filter to the layout."""
if getattr(component, "name") != "Filter":
raise Exception("Component is not an instance of Filter")
if filter_group not in self.filters:
self.filters[filter_group] = []
self.filters[filter_group].append(component) | python | def add_filter(self, component, filter_group="pyxley-filter"):
"""Add a filter to the layout."""
if getattr(component, "name") != "Filter":
raise Exception("Component is not an instance of Filter")
if filter_group not in self.filters:
self.filters[filter_group] = []
self.filters[filter_group].append(component) | [
"def",
"add_filter",
"(",
"self",
",",
"component",
",",
"filter_group",
"=",
"\"pyxley-filter\"",
")",
":",
"if",
"getattr",
"(",
"component",
",",
"\"name\"",
")",
"!=",
"\"Filter\"",
":",
"raise",
"Exception",
"(",
"\"Component is not an instance of Filter\"",
")",
"if",
"filter_group",
"not",
"in",
"self",
".",
"filters",
":",
"self",
".",
"filters",
"[",
"filter_group",
"]",
"=",
"[",
"]",
"self",
".",
"filters",
"[",
"filter_group",
"]",
".",
"append",
"(",
"component",
")"
] | Add a filter to the layout. | [
"Add",
"a",
"filter",
"to",
"the",
"layout",
"."
] | 2dab00022d977d986169cd8a629b3a2f91be893f | https://github.com/stitchfix/pyxley/blob/2dab00022d977d986169cd8a629b3a2f91be893f/pyxley/ui.py#L128-L134 |
229,095 | stitchfix/pyxley | pyxley/ui.py | UILayout.add_chart | def add_chart(self, component):
"""Add a chart to the layout."""
if getattr(component, "name") != "Chart":
raise Exception("Component is not an instance of Chart")
self.charts.append(component) | python | def add_chart(self, component):
"""Add a chart to the layout."""
if getattr(component, "name") != "Chart":
raise Exception("Component is not an instance of Chart")
self.charts.append(component) | [
"def",
"add_chart",
"(",
"self",
",",
"component",
")",
":",
"if",
"getattr",
"(",
"component",
",",
"\"name\"",
")",
"!=",
"\"Chart\"",
":",
"raise",
"Exception",
"(",
"\"Component is not an instance of Chart\"",
")",
"self",
".",
"charts",
".",
"append",
"(",
"component",
")"
] | Add a chart to the layout. | [
"Add",
"a",
"chart",
"to",
"the",
"layout",
"."
] | 2dab00022d977d986169cd8a629b3a2f91be893f | https://github.com/stitchfix/pyxley/blob/2dab00022d977d986169cd8a629b3a2f91be893f/pyxley/ui.py#L136-L140 |
229,096 | stitchfix/pyxley | pyxley/ui.py | UILayout.build_props | def build_props(self):
"""Build the props dictionary."""
props = {}
if self.filters:
props["filters"] = {}
for grp in self.filters:
props["filters"][grp] = [f.params for f in self.filters[grp]]
if self.charts:
props["charts"] = [c.params for c in self.charts]
props["type"] = self.layout
return props | python | def build_props(self):
"""Build the props dictionary."""
props = {}
if self.filters:
props["filters"] = {}
for grp in self.filters:
props["filters"][grp] = [f.params for f in self.filters[grp]]
if self.charts:
props["charts"] = [c.params for c in self.charts]
props["type"] = self.layout
return props | [
"def",
"build_props",
"(",
"self",
")",
":",
"props",
"=",
"{",
"}",
"if",
"self",
".",
"filters",
":",
"props",
"[",
"\"filters\"",
"]",
"=",
"{",
"}",
"for",
"grp",
"in",
"self",
".",
"filters",
":",
"props",
"[",
"\"filters\"",
"]",
"[",
"grp",
"]",
"=",
"[",
"f",
".",
"params",
"for",
"f",
"in",
"self",
".",
"filters",
"[",
"grp",
"]",
"]",
"if",
"self",
".",
"charts",
":",
"props",
"[",
"\"charts\"",
"]",
"=",
"[",
"c",
".",
"params",
"for",
"c",
"in",
"self",
".",
"charts",
"]",
"props",
"[",
"\"type\"",
"]",
"=",
"self",
".",
"layout",
"return",
"props"
] | Build the props dictionary. | [
"Build",
"the",
"props",
"dictionary",
"."
] | 2dab00022d977d986169cd8a629b3a2f91be893f | https://github.com/stitchfix/pyxley/blob/2dab00022d977d986169cd8a629b3a2f91be893f/pyxley/ui.py#L142-L153 |
229,097 | stitchfix/pyxley | pyxley/ui.py | UILayout.assign_routes | def assign_routes(self, app):
"""Register routes with the app."""
for grp in self.filters:
for f in self.filters[grp]:
if f.route_func:
f.register_route(app)
for c in self.charts:
if c.route_func:
c.register_route(app) | python | def assign_routes(self, app):
"""Register routes with the app."""
for grp in self.filters:
for f in self.filters[grp]:
if f.route_func:
f.register_route(app)
for c in self.charts:
if c.route_func:
c.register_route(app) | [
"def",
"assign_routes",
"(",
"self",
",",
"app",
")",
":",
"for",
"grp",
"in",
"self",
".",
"filters",
":",
"for",
"f",
"in",
"self",
".",
"filters",
"[",
"grp",
"]",
":",
"if",
"f",
".",
"route_func",
":",
"f",
".",
"register_route",
"(",
"app",
")",
"for",
"c",
"in",
"self",
".",
"charts",
":",
"if",
"c",
".",
"route_func",
":",
"c",
".",
"register_route",
"(",
"app",
")"
] | Register routes with the app. | [
"Register",
"routes",
"with",
"the",
"app",
"."
] | 2dab00022d977d986169cd8a629b3a2f91be893f | https://github.com/stitchfix/pyxley/blob/2dab00022d977d986169cd8a629b3a2f91be893f/pyxley/ui.py#L155-L164 |
229,098 | stitchfix/pyxley | pyxley/ui.py | UILayout.render_layout | def render_layout(self, app, path, alias=None):
"""Write to javascript."""
self.assign_routes(app)
return ReactComponent(
self.layout,
self.src_file,
self.component_id,
props=self.build_props(),
static_path=path,
alias=alias) | python | def render_layout(self, app, path, alias=None):
"""Write to javascript."""
self.assign_routes(app)
return ReactComponent(
self.layout,
self.src_file,
self.component_id,
props=self.build_props(),
static_path=path,
alias=alias) | [
"def",
"render_layout",
"(",
"self",
",",
"app",
",",
"path",
",",
"alias",
"=",
"None",
")",
":",
"self",
".",
"assign_routes",
"(",
"app",
")",
"return",
"ReactComponent",
"(",
"self",
".",
"layout",
",",
"self",
".",
"src_file",
",",
"self",
".",
"component_id",
",",
"props",
"=",
"self",
".",
"build_props",
"(",
")",
",",
"static_path",
"=",
"path",
",",
"alias",
"=",
"alias",
")"
] | Write to javascript. | [
"Write",
"to",
"javascript",
"."
] | 2dab00022d977d986169cd8a629b3a2f91be893f | https://github.com/stitchfix/pyxley/blob/2dab00022d977d986169cd8a629b3a2f91be893f/pyxley/ui.py#L166-L175 |
229,099 | stitchfix/pyxley | pyxley/utils/flask_helper.py | default_static_path | def default_static_path():
"""
Return the path to the javascript bundle
"""
fdir = os.path.dirname(__file__)
return os.path.abspath(os.path.join(fdir, '../assets/')) | python | def default_static_path():
"""
Return the path to the javascript bundle
"""
fdir = os.path.dirname(__file__)
return os.path.abspath(os.path.join(fdir, '../assets/')) | [
"def",
"default_static_path",
"(",
")",
":",
"fdir",
"=",
"os",
".",
"path",
".",
"dirname",
"(",
"__file__",
")",
"return",
"os",
".",
"path",
".",
"abspath",
"(",
"os",
".",
"path",
".",
"join",
"(",
"fdir",
",",
"'../assets/'",
")",
")"
] | Return the path to the javascript bundle | [
"Return",
"the",
"path",
"to",
"the",
"javascript",
"bundle"
] | 2dab00022d977d986169cd8a629b3a2f91be893f | https://github.com/stitchfix/pyxley/blob/2dab00022d977d986169cd8a629b3a2f91be893f/pyxley/utils/flask_helper.py#L31-L36 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.