2015-02-06 14 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()方法不在我的子類上,而是在父類上使用。