Reputation: 11917
I am implementing a GUI based application in Python 3 with Kivy. My app needs to have 2 screens. First one is a Splash Screen that stays for 5 seconds and then the second screen must come up. Second screen is Garden FileBrowser by Kivy.
I tried to implement this as shown below..
class PgSplash(Screen):
def skip(self, dt):
screen.switch_to(pages[1])
def on_enter(self, *args):
Clock.schedule_once(self.skip, 5)
class PgBrowser(Screen):
def on_pre_enter(self, *args):
user_path = os.path.join(browser_base.get_home_directory(), 'Documents')
browser = browser_base.FileBrowser(select_string='Select',
favorites=[(user_path, 'Documents')])
browser.bind(on_success=self._fbrowser_success,
on_canceled=self._fbrowser_canceled,
on_submit=self._fbrowser_submit)
self.add_widget(browser)
def _fbrowser_canceled(self, instance):
print('cancelled, Close self.')
self.root_window.hide()
sys.exit(0)
def _fbrowser_success(self, instance): # select pressed
global file
print(instance.selection)
file = instance.selection[0]
def _fbrowser_submit(self, instance): # clicked on the file
global file
print(instance.selection)
file = instance.selection[0]
pages = [PgSplash(name="PgSplash"),
PgBrowser(name="PgBrowser")]
screen = ScreenManager()
screen.add_widget(pages[0])
class myApp(App):
def build(self):
screen.current = "PgSplash"
return screen
myApp().run()
While running this the Splash Screen comes up and the program crashes giving an error as shown below..
Traceback (most recent call last):
File "kivy\properties.pyx", line 836, in kivy.properties.ObservableDict.__getattr__ (kivy\properties.c:12509)
KeyError: 'icon_view'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/Spectre/Desktop/Project/base.py", line 219, in <module>
myApp().run()
File "F:\Anaconda3\lib\site-packages\kivy\app.py", line 828, in run
runTouchApp()
File "F:\Anaconda3\lib\site-packages\kivy\base.py", line 504, in runTouchApp
EventLoop.window.mainloop()
File "F:\Anaconda3\lib\site-packages\kivy\core\window\window_sdl2.py", line 663, in mainloop
self._mainloop()
File "F:\Anaconda3\lib\site-packages\kivy\core\window\window_sdl2.py", line 405, in _mainloop
EventLoop.idle()
File "F:\Anaconda3\lib\site-packages\kivy\base.py", line 339, in idle
Clock.tick()
File "F:\Anaconda3\lib\site-packages\kivy\clock.py", line 581, in tick
self._process_events()
File "kivy\_clock.pyx", line 367, in kivy._clock.CyClockBase._process_events (kivy\_clock.c:7700)
File "kivy\_clock.pyx", line 397, in kivy._clock.CyClockBase._process_events (kivy\_clock.c:7577)
File "kivy\_clock.pyx", line 395, in kivy._clock.CyClockBase._process_events (kivy\_clock.c:7498)
File "kivy\_clock.pyx", line 167, in kivy._clock.ClockEvent.tick (kivy\_clock.c:3490)
File "C:\Users\Spectre\Desktop\Project\browser_base.py", line 320, in _post_init
self.ids.icon_view.bind(selection=partial(self._attr_callback, 'selection'),
File "kivy\properties.pyx", line 839, in kivy.properties.ObservableDict.__getattr__ (kivy\properties.c:12654)
AttributeError: 'super' object has no attribute '__getattr__'
What is the issue.? What is that I am doing wrong.? How to fix this.?
Upvotes: 0
Views: 672
Reputation: 16031
I am able to get the app working by doing the following and removed self.root_window.hide() because "AttributeError: 'PgBrowser' object has no attribute 'root_window'". My environment is Ubuntu 16.04 LTS, Python 3.5, and Kivy 1.10.0
class PgBrowser(Screen):
def on_pre_enter(self, *args):
if sys.platform == 'win':
user_path = dirname(expanduser('~')) + sep + 'Documents'
else:
user_path = expanduser('~') + sep + 'Documents'
browser = FileBrowser(select_string='Select',
favorites=[(user_path, 'Documents')])
import sys
from os.path import sep, expanduser, dirname
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.clock import Clock
from kivy.garden.filebrowser import FileBrowser
file = ""
class PgSplash(Screen):
def skip(self, dt):
self.manager.current = "PgBrowser"
def on_enter(self, *args):
Clock.schedule_once(self.skip, 5)
class PgBrowser(Screen):
def on_pre_enter(self, *args):
if sys.platform == 'win':
user_path = dirname(expanduser('~')) + sep + 'Documents'
else:
user_path = expanduser('~') + sep + 'Documents'
browser = FileBrowser(select_string='Select',
favorites=[(user_path, 'Documents')])
browser.bind(on_success=self._fbrowser_success,
on_canceled=self._fbrowser_canceled,
on_submit=self._fbrowser_submit)
self.add_widget(browser)
def _fbrowser_canceled(self, instance):
print('cancelled, Close self.')
sys.exit(0)
def _fbrowser_success(self, instance): # select pressed
global file
print(instance.selection)
file = instance.selection[0]
def _fbrowser_submit(self, instance): # clicked on the file
global file
print(instance.selection)
file = instance.selection[0]
class MyScreenManager(ScreenManager):
pass
class TestApp(App):
def build(self):
return MyScreenManager()
if __name__ == "__main__":
TestApp().run()
#:kivy 1.10.0
<MyScreenManager>:
PgSplash:
PgBrowser:
<PgSplash>:
name: 'PgSplash'
AnchorLayout:
Image:
source: 'kivyLogo.png'
size_hint: 1,1
<PgBrowser>:
name: 'PgBrowser'
Upvotes: 4