From 5849f07c74dbc0a19e20adeb28ef6e207c9f4e19 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20Wobst?= Date: Fri, 16 Jan 2004 11:53:57 +0000 Subject: [PATCH] some fixes from tests under various python versions git-svn-id: https://pyx.svn.sourceforge.net/svnroot/pyx/trunk/pyx@1231 069f4177-920e-0410-937b-c2a4a81bcd90 --- examples/graphs/manyaxes.py | 3 +-- manual/palettename.py | 4 ++-- pyx/bbox.py | 17 +++++++++++++---- pyx/box.py | 2 +- pyx/epsfile.py | 6 +++++- pyx/graph.py | 6 +++--- pyx/path.py | 7 ++++++- pyx/tex.py | 7 ++----- 8 files changed, 33 insertions(+), 19 deletions(-) diff --git a/examples/graphs/manyaxes.py b/examples/graphs/manyaxes.py index d75ce0fa..2b959e12 100644 --- a/examples/graphs/manyaxes.py +++ b/examples/graphs/manyaxes.py @@ -8,8 +8,7 @@ g = graph.graphxy(width=8, y=graph.logaxis(), y2=graph.linaxis(), y4=graph.linaxis(min=0, max=2)) # we generate some data and a function with multiple arguments -r = random.Random() -d = [(i, math.exp(0.8*i+r.random())) for i in range(1,10)] +d = [(i, math.exp(0.8*i+random.random())) for i in range(1,10)] f = lambda x, a: x*a g.plot(graph.data(data.data(d), x=0, y=1)) diff --git a/manual/palettename.py b/manual/palettename.py index 52dd5415..b39f5e24 100755 --- a/manual/palettename.py +++ b/manual/palettename.py @@ -24,13 +24,13 @@ skiplevel = None for line in lines: # we yet don't use a file iterator m = p.match(line) if m: - xaxis = graph.linaxis(part=graph.linpart(tickdist=("0.5","0.1"), labeldist="1"), + xaxis = graph.linaxis(parter=graph.linparter(tickdist=("0.5","0.1"), labeldist="1"), painter=graph.axispainter(innerticklengths=None, labelattrs=None)) g = c.insert(graph.graphxy(ypos=y, width=10, height=0.5, x=xaxis, x2=graph.linkaxis(xaxis, painter=graph.linkaxispainter(innerticklengths=None, outerticklengths=graph.axispainter.defaultticklengths)), - y=graph.linaxis(part=None))) + y=graph.linaxis(parter=None))) g.plot(pf, graph.rect(pyx.color.palette.__dict__[m.group("name")])) g.dodata() g.finish() diff --git a/pyx/bbox.py b/pyx/bbox.py index 5404348f..4eeab182 100644 --- a/pyx/bbox.py +++ b/pyx/bbox.py @@ -38,6 +38,15 @@ def _nmin(*args): else: return None +def _nmax(*args): + """maximum of a list of values, where None represents +infinity, not -infinity as + in standard max implementation of python 2.0""" + args = [x for x in args if x is not None] + if len(args): + return max(args) + else: + return None + # # classes representing bounding boxes # @@ -59,12 +68,12 @@ class _bbox: """join two bboxes""" return _bbox(_nmin(self.llx, other.llx), _nmin(self.lly, other.lly), - max(self.urx, other.urx), max(self.ury, other.ury)) + _nmax(self.urx, other.urx), _nmax(self.ury, other.ury)) def __mul__(self, other): """return intersection of two bboxes""" - return _bbox(max(self.llx, other.llx), max(self.lly, other.lly), + return _bbox(_nmax(self.llx, other.llx), _nmax(self.lly, other.lly), _nmin(self.urx, other.urx), _nmin(self.ury, other.ury)) def __str__(self): @@ -110,7 +119,7 @@ class _bbox: # of the new bounding box. return _bbox(_nmin(llx, lrx, urx, ulx), _nmin(lly, lry, ury, uly), - max(llx, lrx, urx, ulx), max(lly, lry, ury, uly)) + _nmax(llx, lrx, urx, ulx), _nmax(lly, lry, ury, uly)) def enlarged(self, all=0, bottom=None, left=None, top=None, right=None): """return bbox enlarged @@ -127,7 +136,7 @@ class _bbox: _top = unit.topt(unit.length(top, default_type="v")) if right is not None: _right = unit.topt(unit.length(right, default_type="v")) - return _bbox(self.llx-_left, self.lly-_bottom, self.urx+_right, self.ury+_top) + return _bbox(self.llx-_left, self.lly-_bottom, self.urx+_right, self.ury+_top) def rect(self): """return rectangle corresponding to bbox""" diff --git a/pyx/box.py b/pyx/box.py index cd6bf33d..2f57e3e9 100644 --- a/pyx/box.py +++ b/pyx/box.py @@ -220,7 +220,7 @@ class polygon_pt: return self def circlealign(self, *args): - self.transform(trafo.translate(*self.circlealignvector(*args))) + self.reltransform(trafo.translate(*self.circlealignvector(*args))) return self def linealign(self, *args): diff --git a/pyx/epsfile.py b/pyx/epsfile.py index ae9f173a..fc6a60d8 100644 --- a/pyx/epsfile.py +++ b/pyx/epsfile.py @@ -65,7 +65,11 @@ def _readbbox(filename): \s+([+-]?\d+) \s+([+-]?\d+)\s*$""" , re.VERBOSE) - for line in file.xreadlines(): + try: + readlinesfunc = file.xreadlines + except: # workaround for Python 2.0 + readlinesfunc = file.readlines + for line in readlinesfunc(): if line=="%%EndComments\n": # XXX: BoundingBox-Deklaration kann auch an Ende von Datei diff --git a/pyx/graph.py b/pyx/graph.py index 20900d31..f3cfecbe 100644 --- a/pyx/graph.py +++ b/pyx/graph.py @@ -853,9 +853,9 @@ class axisrater: considered as ticks for a given level""" maxticklevel = maxlabellevel = 0 for tick in ticks: - if tick.ticklevel >= maxticklevel: + if tick.ticklevel is not None and tick.ticklevel >= maxticklevel: maxticklevel = tick.ticklevel + 1 - if tick.labellevel >= maxlabellevel: + if tick.labellevel is not None and tick.labellevel >= maxlabellevel: maxlabellevel = tick.labellevel + 1 numticks = [0]*maxticklevel numlabels = [0]*maxlabellevel @@ -2342,7 +2342,7 @@ class _axis: if len(self.ticks): self.setrange(float(self.ticks[0])*self.divisor, float(self.ticks[-1])*self.divisor) self.texter.labels(self.ticks) - if painter is not None: + if self.painter is not None: self.axiscanvas = self.painter.paint(axispos, self) else: self.axiscanvas = axiscanvas() diff --git a/pyx/path.py b/pyx/path.py index 278db137..bbe4b898 100755 --- a/pyx/path.py +++ b/pyx/path.py @@ -237,7 +237,12 @@ class _bcurve: tt = [] for length in lengths: # find the last index that is smaller than length - lindex = bisect.bisect_left(cumlengths, length) + try: + lindex = bisect.bisect_left(cumlengths, length) + except: # workaround for python 2.0 + lindex = bisect.bisect(cumlengths, length) + if lindex: + lindex -= 1 if lindex==0: t = 1.0 * length / cumlengths[0] t *= parlengths[0] diff --git a/pyx/tex.py b/pyx/tex.py index eeb87b2d..a4fa45e4 100644 --- a/pyx/tex.py +++ b/pyx/tex.py @@ -797,9 +797,6 @@ class _tex(base.PSCmd, attrlist): except IOError: self.Sizes = [ ] - def _getstack(self): - return traceback.extract_stack(sys._getframe()) - def _execute(self, command): if os.system(command): sys.stderr.write("The exit code of the following command was non-zero:\n" + command + @@ -957,7 +954,7 @@ by yourself.\n""") self.attrcheck(attrs, (), (msghandler,)) self.DefCmds.append(_DefCmd(Cmd, len(self.DefCmds)+ len(self.BoxCmds), - self._getstack(), + traceback.extract_stack(), self.attrgetall(attrs, msghandler, self.defaultmsghandlers))) def _insertcmd(self, Cmd, *attrs): @@ -969,7 +966,7 @@ by yourself.\n""") myvalign = self.attrget(attrs, valign, None) mymsghandlers = self.attrgetall(attrs, msghandler, self.defaultmsghandlers) MyCmd = _BoxCmd(self.DefCmdsStr, Cmd, mystyle, myfontsize, myvalign, - len(self.DefCmds) + len(self.BoxCmds), self._getstack(), mymsghandlers) + len(self.DefCmds) + len(self.BoxCmds), traceback.extract_stack(), mymsghandlers) if MyCmd not in self.BoxCmds: self.BoxCmds.append(MyCmd) for Cmd in self.BoxCmds: -- 2.11.4.GIT