Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'NoneType' object has no attribute '_impl' #760

Closed
UncleGoogle opened this issue Aug 26, 2019 · 5 comments · Fixed by #2047
Closed

AttributeError: 'NoneType' object has no attribute '_impl' #760

UncleGoogle opened this issue Aug 26, 2019 · 5 comments · Fixed by #2047
Labels
bug A crash or error in behavior. good first issue Is this your first time contributing? This could be a good place to start!

Comments

@UncleGoogle
Copy link
Contributor

toga==0.3.0.dev14 on Windows10 gives me error in title.
Repro:

class MinimalApp(toga.App):

    def button_handler(widget):
        print("hello")

    def startup(self):
        box = toga.Box()

        button = toga.Button('Hello world', on_press=self.button_handler)
        button.style.padding = 50
        button.style.flex = 1
        box.add(button)

        return box


if __name__ == "__main__":

    app = MinimalApp('Name', 'com.hb.er')
    app.main_loop()
         self.interface.main_window._impl.native.Controls.Add(menubar)
AttributeError: 'NoneType' object has no attribute '_impl'
@UncleGoogle
Copy link
Contributor Author

UncleGoogle commented Aug 26, 2019

Ok, after looking into the code https://github.com/beeware/toga/blob/v0.3.0.dev14/src/core/toga/app.py
I see my mistake, I cannot overwrite startup method with the same as toga.App argument startup is. It does more (creates MainWindow). Documentation should warn about ithttps://toga.readthedocs.io/en/latest/reference/api/app.html

@freakboy3742
Copy link
Member

Thanks for the report!

That's a good point - I can see how the difference between providing a startup() method as an argument, and overriding startup() on an instance is potentially confusing - definitely worth at least a clarification in the docs, if not a rethink of the naming of either the method or the argument.

@freakboy3742 freakboy3742 transferred this issue from beeware/briefcase Dec 21, 2019
@freakboy3742 freakboy3742 added bug A crash or error in behavior. up-for-grabs labels Apr 25, 2020
@freakboy3742
Copy link
Member

The solution here is much the same as the OP discovered. Startup needs to create a main window; your main window is created in the say_hello method, which isn't ever invoked.

You've also got the button handler for the Enviar button pointing back to the same method where the button is defined, which... is going to lead to some interesting recursive behavior.

On Toga's side, catching the "no main window" case would be a useful (and relatively straightforward) error to catch here.

@afmaster
Copy link

afmaster commented Nov 5, 2021

Thank you @freakboy3742 . I'm sorry for deletion of my post. I've deleted before refreshing the page and seeing your post. Thank you again.

@freakboy3742 freakboy3742 added the good first issue Is this your first time contributing? This could be a good place to start! label May 19, 2023
@mattip
Copy link
Contributor

mattip commented Jul 22, 2023

Looking at this issue, it seems startup() is called in the platform-specific invocation of self.interface.startup() which does not expect a return value. One way to solve this would be to add a check that self.main_window is valid after the call. As I understand it, this would need to be done on each platform:

git grep "self.interface.startup()"
android/src/toga_android/app.py:        self.interface.startup()
cocoa/src/toga_cocoa/app.py:        self.interface.startup()
gtk/src/toga_gtk/app.py:        self.interface.startup()
iOS/src/toga_iOS/app.py:        self.interface.startup()
web/src/toga_web/app.py:        self.interface.startup()
winforms/src/toga_winforms/app.py:        self.interface.startup()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A crash or error in behavior. good first issue Is this your first time contributing? This could be a good place to start!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants