2015-02-06 67 views
0

我在我的Kivy应用程序中制作动画,但是所有可用的类都是动画,只有分散才能正确动画。问题是,当我触摸散点图时,我的on_touch_move()事件根本不起作用。我想做出无法选择的分散结果Python Kivy使scatter无法选择

self.do_rotation = False 
self.do_scale = False 
self.do_translation = False 

但这似乎不起作用。如预期的那样,分散没有移动,但仍然可以选择。或者,也许有一个课程适合动画?我试过了Image,AsyncImage,Widget和Layouts。有任何想法吗?

@EDIT:这里是什么我谈论的最简单的例子:

from kivy.app import App 
from kivy.core.window import Window 
from kivy.uix.widget import Widget 
from kivy.uix.scatter import Scatter 
from kivy.animation import Animation 
from kivy.graphics import Color, Rectangle 

class ExampleWidget(Widget): 
    def __init__(self, **kwargs): 
     super(ExampleWidget, self).__init__(**kwargs) 
     self.size = (100,100) 
     self.pos = (100,100) 
     with self.canvas: 
      Color(1,0,0) 
      self.texture = Rectangle(size=self.size, pos=self.pos) 

    def on_pos(self, obj, value): 
     try: self.texture.pos = value 
     except: pass 

class ExampleScatterTexture(Widget): 
    def __init__(self, **kwargs): 
     super(ExampleScatterTexture, self).__init__(**kwargs) 
     with self.canvas: 
      Color(0,1,0) 
      texture = Rectangle(size=self.size, pos=self.pos) 

class ExampleScatter(Scatter): 
    def __init__(self, **kwargs): 
     super(ExampleScatter, self).__init__(**kwargs) 
     self.do_rotation = False 
     self.do_scale = False 
     self.do_translation = False 
     self.size = (100,100) 
     self.pos = (100,300) 
     texture = ExampleScatterTexture(size=self.size) 
     self.add_widget(texture) 

class ExampleScreen(Widget): 
    def __init__(self, **kwargs): 
     super(ExampleScreen, self).__init__(**kwargs) 
     self.size = Window.size 

     example_widget = ExampleWidget() 
     self.add_widget(example_widget) 

     example_scatter = ExampleScatter() 
     self.add_widget(example_scatter) 

     #SCATTER IS GREEN, WIDGET IS RED 
     example_widget_animation = Animation(pos=(300,100), duration=2., t='in_bounce') + Animation(pos=(100,100), duration=2., t='in_bounce') 
     example_scatter_animation = Animation(pos=(300,300), duration=2., t='in_bounce') + Animation(pos=(100,300), duration=2., t='in_bounce') 
     example_widget_animation.repeat = True 
     example_scatter_animation.repeat = True 
     example_widget_animation.start(example_widget) 
     example_scatter_animation.start(example_scatter) 

class BadAnimationExample(App): 
    def build(self): 
     root = ExampleScreen() 
     return root 

if __name__ == "__main__": 
    BadAnimationExample().run()  
+1

如果您正在为该窗口小部件上的某个属性设置动画,则每个窗口小部件都会正常动画。 – 2015-02-06 19:13:06

+0

我正在做什么与小部件是我添加一个图像,并调用on_pos()函数来更改图像的位置,每次部件的位置正在像这样改变:self.image.pos = self.pos。我究竟做错了什么? – Nhor 2015-02-06 19:18:45

+0

发布一些演示该问题的示例代码。我的第一个猜测是小部件pos永远不会改变,也许是因为它的布局是你没有考虑到的,但是没有一个完整的例子就不可能知道。 – inclement 2015-02-06 23:20:41

回答

0

我想通了。诀窍不是让scatters不可选,而是使用on_touch_move()方法不在我的子类上,而是在父类上使用。