def testUnderfullVboxWarning(self, l): text.text(0, 0, r"\parindent=0pt\vbox to 1cm {hello, world, hello, world}", textattrs=[text.parbox(1.9)]) l.check(("pyx", "WARNING", r"""ignoring overfull/underfull box: Underfull \vbox (badness 10000) detected at line 0"""))
def testBadTeX(self, l): text.text(0, 0, r"\some \badly \broken \TeX", texmessages=[text.texmessage.warn]) l.check( ( "pyx", "WARNING", r"""ignoring TeX warnings: * *! Undefined control sequence. <argument> \some \badly \broken \TeX <*> }{1} % ! Undefined control sequence. <argument> \some \badly \broken \TeX <*> }{1} % ! Undefined control sequence. <argument> \some \badly \broken \TeX <*> }{1} % *""", ) )
def testBadTeX(self, l): text.text(0, 0, r"\some \badly \broken \TeX", texmessages=[text.texmessage.warn]) l.check(("pyx", "WARNING", r"""ignoring TeX warnings: * *! Undefined control sequence. <argument> \some \badly \broken \TeX <*> }{1} % ! Undefined control sequence. <argument> \some \badly \broken \TeX <*> }{1} % ! Undefined control sequence. <argument> \some \badly \broken \TeX <*> }{1} % *"""))
def testOverfullHboxWarning(self, l): text.text(0, 0, r"hello, world", textattrs=[text.parbox(30 * unit.u_pt)]) l.check(("pyx", "WARNING", r"""ignoring overfull/underfull box: Overfull \hbox (8.22089pt too wide) detected at line 0 []\OT1/cmr/m/n/10 hello,"""))
def testUnderfullHboxWarning(self, l): text.text(0, 0, r"\hbadness=0hello, world, hello", textattrs=[text.parbox(2.5)]) l.check(("pyx", "WARNING", r"""ignoring overfull/underfull box: Underfull \hbox (badness 171) detected at line 0 []\OT1/cmr/m/n/10 hello, world,"""))
def testLoadLongFileNames(self): testfilename = "x" * 100 with open(testfilename + ".tex", "w") as f: f.write("\message{ignore this}") text.text(0, 0, "\\input %s\n" % testfilename, texmessages=[text.texmessage.load]) os.remove(testfilename + ".tex") with open(testfilename + ".eps", "w") as f: f.write("%%BoundingBox: 0 0 10 10") text.text(0, 0, r"\includegraphics{%s}" % testfilename) os.remove(testfilename + ".eps")
def testUnderfullVboxWarning(self, l): text.text(0, 0, r"\parindent=0pt\vbox to 1cm {hello, world, hello, world}", textattrs=[text.parbox(1.9)]) l.check( ( "pyx", "WARNING", r"""ignoring overfull/underfull box: Underfull \vbox (badness 10000) detected at line 0""", ) )
def testUnderfullHboxWarning(self, l): text.text(0, 0, r"\hbadness=0hello, world, hello", textattrs=[text.parbox(2.5)]) l.check( ( "pyx", "WARNING", r"""ignoring overfull/underfull box: Underfull \hbox (badness 171) detected at line 0 []\OT1/cmr/m/n/10 hello, world,""", ) )
def testOverfullHboxWarning(self, l): text.text(0, 0, r"hello, world", textattrs=[text.parbox(30 * unit.u_pt)]) l.check( ( "pyx", "WARNING", r"""ignoring overfull/underfull box: Overfull \hbox (8.22089pt too wide) detected at line 0 []\OT1/cmr/m/n/10 hello,""", ) )
def testFontWarning(self, l): text.text(0, 0, r"\fontseries{invalid}\selectfont{}hello, world", texmessages=[text.texmessage.font_warning]) text.defaulttextengine.instance.do_finish() l.check(("pyx", "WARNING", r"""ignoring font substitutions of NFSS: LaTeX Font Warning: Font shape `OT1/cmr/invalid/n' undefined (Font) using `OT1/cmr/m/n' instead on input line 0."""), ("pyx", "WARNING", r"""ignoring font substitutions of NFSS: LaTeX Font Warning: Some font shapes were not available, defaults substituted.""" ))
def testFontWarning(self, l): text.text(0, 0, r"\fontseries{invalid}\selectfont{}hello, world", texmessages=[text.texmessage.font_warning]) text.default_runner.instance.do_finish() l.check( ( "pyx", "WARNING", r"""ignoring font substitutions of NFSS: LaTeX Font Warning: Font shape `OT1/cmr/invalid/n' undefined (Font) using `OT1/cmr/m/n' instead on input line 0.""", ), ( "pyx", "WARNING", r"""ignoring font substitutions of NFSS: LaTeX Font Warning: Some font shapes were not available, defaults substituted.""", ), )
def repo(label, colorfg, colorbg): crepo = canvas.canvas() labeltext = text.text(0, 0, r'\textsf{{{}}}'.format(label), [colorfg]) extrawd = 0.15 labelbox = labeltext.bbox().enlarged(extrawd) crepo.fill(labelbox.path(), [colorbg, deformer.smoothed(0.05), deco.stroked([colorfg])]) crepo.insert(labeltext) return crepo
myattrs = [text.valign.top, text.parbox(parwidth)] textblockdist = 0.5 ytop = ncols*boxsize for s in ((inputtemplate.format('1', 'a[(0,1,2,3,4), (1,2,3,4,5)]') + r'\\[0.1\baselineskip]' + resulttemplate.format('1', r'array([1, 12, 23, 34, 45])') ), (inputtemplate.format('2', 'a[3:, [0,2,5]]') + r'\\[0.1\baselineskip]' + resulttemplate.format('2', 'array([[30, 32, 35],') + r'\\' + resulttemplate.format('2', r'\hphantom{array([}[40, 42, 45],') + r'\\' + resulttemplate.format('2', r'\hphantom{array([}[50, 52, 55]])') ), (inputtemplate.format('3', 'mask = np.array([1,0,1,0,0,1], dtype=bool)') + r'\\' + inputtemplate.format('3', 'a[mask, 2]') + r'\\[0.1\baselineskip]' + resulttemplate.format('3', 'array([2, 22, 52])') )): t = text.text(-parwidth-0.5, ytop, s, myattrs) c.insert(t) ytop = ytop-t.bbox().height()-textblockdist basename = os.path.splitext(sys.argv[0])[0] c.writeGSfile(basename+'.png', resolution=150) c.writePDFfile(basename)
text.preamble(r'''\usepackage[scaled=0.85,lining]{FiraMono} \usepackage[utf8]{inputenc}''') unit.set(xscale=1.2) c = canvas.canvas() dx = 0.3 h = 4 w = 6.5 p = path.rect(-dx, -dx, w + 2 * dx, h + 2 * dx) p = deformer.smoothed(0.5).deform(p) c.fill(p, [color.grey(0.5), trafo.translate(0.05, -0.05)]) c.fill(p, [color.grey(0.9)]) c2 = canvas.canvas([canvas.clip(p)]) primetimes = [p for p in prime_list(2359) if is_time(p)] s = text.text(0, 0, formattime(primetimes[0])) textwidth, textheight = s.width, s.height nx = int(w / unit.tocm(textwidth)) xoff = 0.5 * (w - 1.2 * textwidth * nx + 0.2 * textwidth) for n, p in enumerate(primetimes): s = formattime(p) x = xoff + (n % nx) * 1.2 * textwidth y = 1.03 * h - (n // nx) * textheight * 1.4 c2.text(x, y, s, [color.hsb(0.67, 0.4, 0.8)]) c.insert(c2) r1 = 0.95 * h / 2 r2 = 0.8 * h / 2 for n in range(12): x = sin(radians(n * 30)) y = cos(radians(n * 30))
('staging area', color.hsb(0.2, 1, 0.6), color.rgb(0, 0.5, 0), 'staged'), ('repository (.git)', color.hsb(0.53, 1, 0.6), color.grey(0.3), 'committed'))): xmid = nr * (wd + hdist) + 0.5 * wd c.stroke(path.rect(nr * (wd + hdist), 0, wd, ht), [deformer.smoothed(0.3), boxcolor, style.linewidth.Thick]) c.fill(path.rect(nr * (wd + hdist), ht + vdist, wd, htlabel), [deformer.smoothed(0.3), boxcolor]) c.text(xmid, ht + vdist + 0.5 * htlabel, label, [text.halign.center, text.valign.middle, color.grey(1)]) c.insert(filesymbol(size, symbolcolor), [trafo.translate(xmid, 0.5 * ht)]) c.text(xmid, 0.2 * ht, status, [text.halign.center, symbolcolor]) for nr, operation in enumerate(('git add', 'git commit')): xmid = nr * (wd + hdist) + 0.5 * wd c.stroke( path.line(xmid + 0.5 * size + 0.1, 0.5 * ht, xmid + wd + hdist - 0.5 * size - 0.1, 0.5 * ht), [deco.earrow.large, style.linewidth.Thick]) cop = canvas.canvas() optext = text.text(0, 0, operation, [text.halign.center, text.valign.middle]) tblarge = optext.bbox().enlarged(0.1) cop.fill(tblarge.path(), [deco.stroked([color.grey(0)]), color.grey(0.9)]) cop.insert(optext) c.insert( cop, [trafo.translate((nr + 1) * (wd + hdist) - 0.5 * hdist, 0.5 * ht)]) c.writePDFfile()
from pyx import canvas, color, text text.set(text.LatexRunner) c = canvas.canvas() t = text.text(0, 0, r"\sffamily\bfseries ?") tblarge = t.bbox().enlarged(0.1) c.fill(tblarge.path(), [color.rgb(0.8, 0.5, 0)]) c.insert(t, [color.grey(1)]) c.writePDFfile() c.writeGSfile(device="png16m", resolution=600)
text.preamble(r'\usepackage{arev}\usepackage[T1]{fontenc}') c = canvas.canvas() wd = 6.9 ht = 3.5 gitlabfgcolor = color.grey(0.4) gitlabbgcolor = color.grey(0.97) maintainercolor = color.hsb(0.7, 1, 0.5) usercolor = color.hsb(0.05, 1, 0.5) c.stroke(path.rect(0, 0, wd, ht), [ deformer.smoothed(0.1), gitlabfgcolor, style.linewidth.Thick, deco.filled([gitlabbgcolor]) ]) clabel = canvas.canvas() labeltext = text.text(0, 0, r'\textsf{\bfseries Gitlab}', [color.grey(1)]) extrawd = 0.15 labelbox = labeltext.bbox().enlarged(extrawd) clabel.fill(labelbox.path(), [gitlabfgcolor, deformer.smoothed(0.1)]) clabel.insert(labeltext) c.insert(clabel, [trafo.translate(extrawd, ht + extrawd)]) c.text(wd + 0.4, ht - 0.5, r'\footnotesize\textsf{read/write permissions}') c.insert(read(1, usercolor), [trafo.translate(wd + 0.7, ht - 0.9)]) c.insert(write(1, usercolor), [trafo.translate(wd + 1.05, ht - 0.9)]) c.text(wd + 1.5, ht - 1.0, r'\footnotesize\textsf{user}', [usercolor]) c.insert(write(1, maintainercolor), [trafo.translate(wd + 1.05, ht - 1.3)]) c.insert(read(1, maintainercolor), [trafo.translate(wd + 0.7, ht - 1.3)]) c.text(wd + 1.5, ht - 1.4, r'\footnotesize\textsf{maintainer}', [maintainercolor])
for ny in range(nrows): y = (ncols - ny - 0.5) * boxsize c.text(x, y, r'\textbf{{{}}}'.format(ny * 10 + nx), [text.halign.center, text.valign.middle]) parwidth = 6 inputtemplate = r'\noindent\textcolor{{ex{}color}}{{\bfseries>{{}}>{{}}> {}}}' resulttemplate = r'\textcolor{{ex{}color}}{{{}}}' myattrs = [text.valign.top, text.parbox(parwidth)] textblockdist = 0.5 ytop = ncols * boxsize + 0.4 for s in ((inputtemplate.format('1', 'a[0, 3:5]') + r'\\[0.1\baselineskip]' + resulttemplate.format('1', 'array([3, 4])')), (inputtemplate.format('2', 'a[4:, 4:]') + r'\\[0.1\baselineskip]' + resulttemplate.format('2', 'array([[44, 55],') + r'\\' + resulttemplate.format('2', r'\hphantom{array([}[54, 55]])')), (inputtemplate.format('3', 'a[:, 2]') + r'\\[0.1\baselineskip]' + resulttemplate.format('3', 'a([2, 12, 22, 32, 42, 52])')), (inputtemplate.format('4', 'a[2::2, ::2]') + r'\\[0.1\baselineskip]' + resulttemplate.format('4', r'array([[20, 22, 24],') + r'\\' + resulttemplate.format('4', r'\hphantom{array([}[40, 42, 44]])'))): t = text.text(-parwidth - 0.5, ytop, s, myattrs) c.insert(t) ytop = ytop - t.bbox().height() - textblockdist basename = os.path.splitext(sys.argv[0])[0] c.writeGSfile(basename + '.png', resolution=150) c.writePDFfile(basename)