[英]A recursion error I can't figure out
I am trying to make a scatter plane layout behave how I want it to but when I try to zoom out past a certain point I get the error "RuntimeError: maximum recursion depth exceeded while calling a Python object" I can't figure out why the recursion happens, tho by trial and error I have found out where it happens (it is marked in the code)我正在尝试使散射平面布局按照我希望的方式运行,但是当我尝试缩小超过某个点时,出现错误“运行时错误:调用 Python 对象时超出了最大递归深度”我不知道为什么递归发生了,通过反复试验我发现它发生在哪里(它在代码中被标记)
here is the traceback: http://pastebin.com/i2z8SXgc这是回溯: http : //pastebin.com/i2z8SXgc
class Controller(ScatterPlaneLayout):
def __init__(self, **kwargs):
super(Controller, self).__init__(**kwargs)
def on_transform(self, instance, value):
win = self.get_parent_window().size
this = self.bbox[1]
if win[0] > this[0] and win[1] > this[1]:
if self.x < 0:
self.x = 0
if self.y < 0:
self.y = 0
if this[0] + self.x > win[0]:
self.set_right(win[0])
if this[1] + self.y > win[1]:
self.set_top(win[1])
else:
if self.x > 0:
self.x = 0
if self.y > 0:
self.y = 0
#This is the part that causes the error
if this[0] + self.x < win[0]:
self.x = win[0] - this[0]
#end of error
if this[1] + self.y < win[1]:
self.set_top(win[1])
What looks to be causing the error is the code self.x = win[0] - this[0]
calling the function on_transform, passing the first if and calling itself all over again and again.看起来导致错误的是代码
self.x = win[0] - this[0]
调用函数 on_transform,传递第一个 if 并一遍又一遍地调用自己。
You may want to check that.你可能想检查一下。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.