Kivy ScreenManager error while using transition ef

2019-08-19 04:10发布

Complete application works fine. But when I change the screen transition effect from slide or NO to FadeTransition(and similar which uses shader effects) I see the following issue.

Transition to new screens happens without any issue. But transition to any previous screens gives an error saying that the screen is not found. To be more clear, suppose I have 3 screens 1, 2 & 3. FadeTransitions works from 1 to 2, or 2 to 3 but never from 2 to 1 or 3 to 1.

I'm posting the error message below.

[INFO   ] [Base        ] Leaving application in progress...
 Traceback (most recent call last):
   File "example.py", line 1229, in <module>
     ShamarApp().run()
   File "/usr/local/lib/python2.7/dist-packages/kivy/app.py", line 855, in run
     runTouchApp()
   File "/usr/local/lib/python2.7/dist-packages/kivy/base.py", line 504, in runTouchApp
     EventLoop.window.mainloop()
   File "/usr/local/lib/python2.7/dist-packages/kivy/core/window/window_egl_rpi.py", line 92, in mainloop
     self._mainloop()
   File "/usr/local/lib/python2.7/dist-packages/kivy/core/window/window_egl_rpi.py", line 87, in _mainloop
     EventLoop.idle()
   File "/usr/local/lib/python2.7/dist-packages/kivy/base.py", line 339, in idle
     Clock.tick()
   File "/usr/local/lib/python2.7/dist-packages/kivy/clock.py", line 591, in tick
     self._process_events()
   File "kivy/_clock.pyx", line 384, in kivy._clock.CyClockBase._process_events
   File "kivy/_clock.pyx", line 414, in kivy._clock.CyClockBase._process_events
   File "kivy/_clock.pyx", line 412, in kivy._clock.CyClockBase._process_events
   File "kivy/_clock.pyx", line 167, in kivy._clock.ClockEvent.tick
   File "shamar.py", line 248, in <lambda>
     event  = Clock.schedule_interval(lambda dt: self.update_time(), 1)
   File "shamar.py", line 315, in update_time
     self.root.current = 'main'
   File "kivy/properties.pyx", line 497, in kivy.properties.Property.__set__
   File "kivy/properties.pyx", line 544, in kivy.properties.Property.set
   File "kivy/properties.pyx", line 599, in kivy.properties.Property.dispatch
   File "kivy/_event.pyx", line 1214, in kivy._event.EventObservers.dispatch
   File "kivy/_event.pyx", line 1120, in kivy._event.EventObservers._dispatch
   File "/usr/local/lib/python2.7/dist-packages/kivy/uix/screenmanager.py", line 1039, in on_current
     screen = self.get_screen(value)
   File "/usr/local/lib/python2.7/dist-packages/kivy/uix/screenmanager.py", line 1065, in get_screen
     raise ScreenManagerException('No Screen with name "%s".' % name)
 kivy.uix.screenmanager.ScreenManagerException: No Screen with name "main".


------------------
(program exited with code: 1)
Press return to continue

Here the screen with name 'main' is there and works well when I remove this transition effect. Please help.

I am adding a sample code below to further explain this scenario.

screenmanager_test.py

import kivy
kivy.require('1.11.0')
import os
os.environ['KIVY_GL_BACKEND'] = 'gl'
from kivy.app import App
from kivy.uix.popup import Popup
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.screenmanager import Screen, ScreenManager, NoTransition,\
                                    FadeTransition
from kivy.clock import Clock

class MainScreen(Screen):
    def setName(self,*args):
        FirstPopup().open()

class SecondScreen(Screen):
    pass

class FirstPopup(Popup):
    pass

class MyScreenManager(ScreenManager):
    pass

class SmTestApp(App):
    def build(self):
        sm = MyScreenManager()
        sm.transition = FadeTransition()
        sm.add_widget(MainScreen(name="main_scr"))
        sm.add_widget(SecondScreen(name="second_scr"))
        return sm


SmTestApp().run()

smtest.kv

#: kivy 1.11.0

<MainScreen>:
    name: 'main_scr'
    BoxLayout:
        orientation: 'vertical'
        padding: 100,100
        spacing: 50

        Label:
            text: 'Welcome to Main Screen'
            font_size: 35

        Button:
            text: 'Options'
            font_size: 15
            on_release: root.setName(*args)

        Button:
            text: 'Next Screen'
            font_size: 15
            on_release: app.root.current = 'second_scr'

<SecondScreen>:
    name: 'second_scr'
    BoxLayout:
        orientation:'vertical'
        padding:100,100
        spacing:50

        Label:
            text: 'This is your second screen'
            font_size: 35
        Button:
            text: 'Back'
            font_size: 25
            on_release: app.root.current = 'main_scr'

<FirstPopup>:
    title: 'Options Window'
    size_hint: None, None
    size: 400,370
    BoxLayout:
        orientation : 'vertical'
        Label:
            text : "Checkbox options listed here"
        Button:
            text: "OK"
            on_release: root.dismiss()

And following is the error message while trying to switch back from second screen to first.

[INFO   ] [Base        ] Leaving application in progress...
 Traceback (most recent call last):
   File "screenmanager_test.py", line 34, in <module>
     SmTestApp().run()
   File "/usr/local/lib/python2.7/dist-packages/kivy/app.py", line 855, in run
     runTouchApp()
   File "/usr/local/lib/python2.7/dist-packages/kivy/base.py", line 504, in runTouchApp
     EventLoop.window.mainloop()
   File "/usr/local/lib/python2.7/dist-packages/kivy/core/window/window_egl_rpi.py", line 92, in mainloop
     self._mainloop()
   File "/usr/local/lib/python2.7/dist-packages/kivy/core/window/window_egl_rpi.py", line 87, in _mainloop
     EventLoop.idle()
   File "/usr/local/lib/python2.7/dist-packages/kivy/base.py", line 342, in idle
     self.dispatch_input()
   File "/usr/local/lib/python2.7/dist-packages/kivy/base.py", line 327, in dispatch_input
     post_dispatch_input(*pop(0))
   File "/usr/local/lib/python2.7/dist-packages/kivy/base.py", line 293, in post_dispatch_input
     wid.dispatch('on_touch_up', me)
   File "kivy/_event.pyx", line 707, in kivy._event.EventDispatcher.dispatch
   File "/usr/local/lib/python2.7/dist-packages/kivy/uix/behaviors/button.py", line 179, in on_touch_up
     self.dispatch('on_release')
   File "kivy/_event.pyx", line 703, in kivy._event.EventDispatcher.dispatch
   File "kivy/_event.pyx", line 1214, in kivy._event.EventObservers.dispatch
   File "kivy/_event.pyx", line 1098, in kivy._event.EventObservers._dispatch
   File "/usr/local/lib/python2.7/dist-packages/kivy/lang/builder.py", line 64, in custom_callback
     exec(__kvlang__.co_value, idmap)
   File "/home/pi/Toller_Rpi/training_prgms/smtest.kv", line 37, in <module>
     on_release: app.root.current = 'main_scr'
   File "kivy/properties.pyx", line 497, in kivy.properties.Property.__set__
   File "kivy/properties.pyx", line 544, in kivy.properties.Property.set
   File "kivy/properties.pyx", line 599, in kivy.properties.Property.dispatch
   File "kivy/_event.pyx", line 1214, in kivy._event.EventObservers.dispatch
   File "kivy/_event.pyx", line 1120, in kivy._event.EventObservers._dispatch
   File "/usr/local/lib/python2.7/dist-packages/kivy/uix/screenmanager.py", line 1039, in on_current
     screen = self.get_screen(value)
   File "/usr/local/lib/python2.7/dist-packages/kivy/uix/screenmanager.py", line 1065, in get_screen
     raise ScreenManagerException('No Screen with name "%s".' % name)
 kivy.uix.screenmanager.ScreenManagerException: No Screen with name "main_scr".


------------------
(program exited with code: 1)
Press return to continue

0条回答
登录 后发表回答