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

Method __add__

Lib/pagebot/contexts/basecontext/babelstring.py:794–822  ·  view source on GitHub ↗

If pbs is a plain string, just adds it to the last run. Otherwise creates a new BabelString and copy all runs there. >>> from pagebot.toolbox.units import pt >>> from pagebot.contexts import getContext >>> context = getContext() >>> bs1 = context.newString('A

(self, bs)

Source from the content-addressed store, hash-verified

792 return len(self.s)
793
794 def __add__(self, bs):
795 """If pbs is a plain string, just adds it to the last run. Otherwise
796 creates a new BabelString and copy all runs there.
797
798 >>> from pagebot.toolbox.units import pt
799 >>> from pagebot.contexts import getContext
800 >>> context = getContext()
801 >>> bs1 = context.newString('ABCD', dict(fontSize=pt(18)))
802 >>> bs2 = context.newString('EFGH', dict(fontSize=pt(24)))
803 >>> bs3 = bs1 + bs2 # Create new instance, concatenated from both
804 >>> bs1 is not bs2 and bs1 is not bs3 and bs2 is not bs3
805 True
806 >>> bs3.runs
807 [<BabelRun "ABCD">, <BabelRun "EFGH">]
808 """
809 bsResult = BabelString(context=self.context) # Context can be None
810 for run in self.runs:
811 bsResult.runs.append(deepcopy(run))
812 if isinstance(bs, str):
813 bsResult.add(bs) # Add to last run or create new PageBotRun
814 elif isinstance(bs, BabelString):
815 for run in bs.runs:
816 bsResult.runs.append(deepcopy(run))
817 bsResult.w = bs.w
818 bsResult.h = bs.h
819 else:
820 raise ValueError("@bs must be string or other %s" % self.__class__.__name__)
821 bsResult.reset()
822 return bsResult
823
824 def __eq__(self, bs):
825 """Compares @bs with self.

Callers

nothing calls this directly

Calls 4

addMethod · 0.95
resetMethod · 0.95
BabelStringClass · 0.85
appendMethod · 0.45

Tested by

no test coverage detected