Sreeram TP
Sreeram TP

Reputation: 11917

Launch main App after Splash Screen timedout in Kivy

I want to make a GUI based application in python. I am using FileBrowser from Kivy as the main application.

I want to show a Splash Screen for say 5 seconds or so and after that I want to start the main application i.e the FileBrowser

I am providing the code for File Browser and Splash Screen that I am using below.

# FileBrowser
class TestApp(App):

    def build(self):

        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)
        return 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]

TestApp().run()

# Splash Screen..!!

class timer():
    def work1(self):
        print('Hello')


class arge(App):
    def build(self):
        wing = Image(source='grey.png', pos=(800, 800))
        animation = Animation(x=0, y=0, d=2, t='out_bounce')
        animation.start(wing)

        Clock.schedule_once(timer.work1, 5)
        return wing

arge().run()

I want to run this Splash Screen app for say 5 seconds and then start the main application i.e the FileBrowser defined by TestApp class.

How can I do it.?

Upvotes: 0

Views: 1069

Answers (1)

M. Yasin
M. Yasin

Reputation: 66

You are creating separate apps for each screen. Instead, all you need is ScreenManager. Here is a simple example for you to see how ScreenManager works:

class PgBrowser(Screen):
    # Builder.load_file("browser.kv")

    def on_pre_enter(self, *args):
        filechooser = FileChooserIconView(path=os.path.expanduser('~'),
                                          size=(self.width, self.height),
                                          pos_hint={"center_x": .5, "center_y": .5})
        filechooser.bind(on_submit=self.on_selected)
        self.add_widget(filechooser)

    def on_selected(self, widget_name, file_path, mouse_pos):
        print "Selected: %s" % file_path[0]

class PgSplash(Screen):
    # Builder.load_file("splash.kv")

    def skip(self, dt):
        screen.switch_to(pages[1])

    def on_enter(self, *args):
        Clock.schedule_once(self.skip, 2)

        print "Wait..."

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()

Upvotes: 2

Related Questions