0

I want to force the start of a ModalView when the app is loaded, but i can not figure out how to do it.

It's working fine when i push the button, but i cant figure out how to trigger the event from the python file.

How can i from the code trigger the event (button)?

KV file

<Controller>

    <BoxLayout>

        ***a lot of code ***

        Button:
            id: my_id
            text: "text"
            color: txt_color
            size_hint_y: .05
            background_color: btn_color_not_pressed if self.state=='normal' else btn_color_pressed

            on_release:
                Factory.About().open()

<About@ModalView>
    id: about
    auto_dismiss: True

    
    *** some more code ****

How do i call the event from my main.py?


After solution from @john Anderson:

file: main.py

import kivy
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout

from kivy.factory import Factory


kivy.require("1.11.1")


class Controller(BoxLayout):
    def __init__(self):
        super(Controller, self).__init__()

        Factory.About().open()

class mainApp(App):
    def build(self):
        return Controller()


mainApp().run()

file: main.kv

    #:import Factory kivy.factory.Factory


<Controller>
    BoxLayout:
        orientation: "vertical"
        Label:
            text: "THIS IS THE MAIN TEKST"
            color: 1,0,0,1
            size_hint_y:.8
        Button:
            text: "About"
            size_hint_y: .2
            on_release: Factory.About().open()

<About@ModalView>

    size_hint: .8,.5

    BoxLayout
        orientation: "vertical"
        size: self.width, self.height
        pos_hint: {"center_x": .5}
        size_hint: .8,.6


        Label:
            text: "ABOUT MY APP"
            color: 0,1,0,1
        Button:
            text: "Back"
            size_hint_y: .2
            on_release: root.dismiss()

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
thj001
  • 1
  • 3
  • 1
    Try using `Factory.About().open()` in your main.py. – John Anderson May 12 '21 at 13:06
  • @JohnAnderson Thx for the answer :) :) That worked with triggering the code ... but made some new problems. The app and the ModalView seems to be drawn at the same time I have made an examplecode, and made a screenshot after the app has started, where it can be seen. It works ... almost :) – thj001 May 12 '21 at 14:29
  • The new example code is in the original question :) – thj001 May 12 '21 at 14:43

1 Answers1

0

Your About ModalView is being created in the __init__() method of your root Controller widget. That means that it is created before your Controller. An easy fix is to delay the creation of the About widget until after the App is started. You can use the App method on_start() to do that:

class Controller(BoxLayout):
    pass


class mainApp(App):
    def build(self):
        return Controller()

    def on_start(self):
        Factory.About().open()
John Anderson
  • 35,991
  • 4
  • 13
  • 36