I have written a small code to drag widget horizontally using on_touch_move event. Even my widget moves horizontally. But when I am dragging the widget, following log gets generated."[CRITICAL] [Clock ] Warning, too much iteration done before the next frame. Check your code, or increase the Clock.max_iteration attribute". Please find below my sample code. To reproduce this scenario, just drag the white widget right and left. The above log messages gets printed.
from kivy.app import App
from kivy.graphics import Rectangle
from kivy.uix.scatter import Scatter
from kivy.uix.relativelayout import RelativeLayout
class MyPaintWidget(Scatter):
def __init__(self, **kwargs) :
super(MyPaintWidget, self).__init__(**kwargs)
def on_touch_move(self, touch):
touch_x_hint = touch.x / self.parent.size[0]
self.pos_hint = {'center_x': touch_x_hint }
return super(Scatter, self).on_touch_move(touch)
class MyPaintApp(App):
def build(self):
parent = RelativeLayout()
Wdgt = MyPaintWidget(pos_hint={'center_x':0.5, 'center_y':0.5}, size_hint=(0.2,0.2))
with Wdgt.canvas:
Rectangle(pos_hint = {'center_x':0.5, 'center_y':0.5}, size = (Wdgt.width, Wdgt.height))
parent.add_widget(Wdgt)
return parent
if __name__ == '__main__':
MyPaintApp().run()
I see two problems with your code. The first is that your super()
call in MyPaintWidget.on_touch_move()
should pass MyPaintWidget
, not Scatter
. Second, using pos_hint
causes extra calculations, so I suggest changing your on_touch_move()
to:
def on_touch_move(self, touch):
self.pos_hint = {'center_y':0.5} # eliminates the x pos_hint
self.x = touch.x
return super(MyPaintWidget, self).on_touch_move(touch)