Giter Club home page Giter Club logo

Comments (5)

dgelessus avatar dgelessus commented on June 11, 2024

I'm not an expert on the async features of Rubicon, but I think the line app = NSApplication might be the problem - that sets app to the NSApplication class, not a NSApplication instance. You probably need to use app = NSApplication.sharedApplication(), like in the code from the documentation.

from rubicon-objc.

ryan-WORK avatar ryan-WORK commented on June 11, 2024

@dgelessus I have changed the file to:

    # Import the Event Loop Policy and lifecycle
    from rubicon.objc.eventloop import EventLoopPolicy, CocoaLifecycle
    # importing asyncio to set event loop
    import asyncio
    # Asyncio Install the event loop policy
    asyncio.set_event_loop_policy(EventLoopPolicy())
    # Get a handle to the shared NSApplication
    from ctypes import cdll, util
    from rubicon.objc import ObjCClass
    appkit = cdll.LoadLibrary(util.find_library('AppKit'))
    NSApplication = ObjCClass('NSApplication')
    app = NSApplication.sharedApplication()
    # Get an event loop, and run it, using the NSApplication!
    loop = asyncio.get_event_loop()
    loop.run_forever(lifecycle=CocoaLifecycle(app))

Here is the error message:

    Traceback (most recent call last):
        File "aio/r1a.py", line 13, in <module>
            app = NSApplication.sharedApplication()
    TypeError: 'ObjCInstance' object is not callable

Thanks for the help!

from rubicon-objc.

dgelessus avatar dgelessus commented on June 11, 2024

Ah, this is a relatively common problem - it happens when you try to call a method, but it's actually a property. In this case, you need to add NSApplication.declare_class_property('sharedApplication') under the NSApplication = ObjCClass('NSApplication') line, and then remove the parentheses from the sharedApplication call (i. e. replace NSApplication.sharedApplication() with NSApplication.sharedApplication).

from rubicon-objc.

ryan-WORK avatar ryan-WORK commented on June 11, 2024

@dgelessus

Super cool! It works! Thanks so much!

May I set up a PR for editing the documentation representing the correct syntax?

from rubicon-objc.

dgelessus avatar dgelessus commented on June 11, 2024

Merged it. Thank you for all the documentation fixes :)

from rubicon-objc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.