我无法弄清楚的递归错误
A recursion error I can't figure out
我正在尝试使散点平面布局按我想要的方式运行,但是当我尝试缩小超过某个点时出现错误 "RuntimeError: maximum recursion depth exceeded while calling a Python object" 我无法弄清楚为什么会发生递归,通过反复试验我发现了它发生的地方(它在代码中标记)
这里是回溯: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])
导致错误的原因似乎是代码 self.x = win[0] - this[0]
调用函数 on_transform,传递第一个 if 并一次又一次地调用自身。
您可能想检查一下。
我正在尝试使散点平面布局按我想要的方式运行,但是当我尝试缩小超过某个点时出现错误 "RuntimeError: maximum recursion depth exceeded while calling a Python object" 我无法弄清楚为什么会发生递归,通过反复试验我发现了它发生的地方(它在代码中标记)
这里是回溯: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])
导致错误的原因似乎是代码 self.x = win[0] - this[0]
调用函数 on_transform,传递第一个 if 并一次又一次地调用自身。
您可能想检查一下。