Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

Problem executing an event in a created extension

I have created an extension as described in the official documentation but I can't figure out how to execute an event inside the extension.

Comments

  • Hi Chris,

    You can fire events from within an extension like so:

    self.extension_manager.fire('some_event', argument1=value1, argument2=value2)
    

    This will then result in the following event-handler functions being called:

    def event_some_event(self, argument1, argument2):
    

    The event name can be anything, so extensions can also make up their own events if they need to, for example to communicate with each other. If no-one is listening to the event, it will simply be ignored. And the arguments have to be passed as keywords, i.e. not by order. I hope this clears things up! (And thanks for pointing out that this information is missing in the docs.)

    Cheers,

    Sebastiaan

  • Hello Sebastian and thank you for your quick response,

    I am a bit confused with the answer you gave me. So I have added the

    example extension given at the documentation to my OpenSesame extensions directory and it recognizes it.

    How can I now make that extension start when I run an experiment ?

    I understand that some extensions start when the OpenSesame software starts. But I would like the experiment to trigger some of the extension's events while running and not just when it starts.

    Thank you,

    Chris

  • Hi Chris,

    Most likely an error occurs while loading the extension. To develop an extension, it's useful to enable a console with an inprocess kernel (Menu → Tools → Preferences), because this allows you to access the OpenSesame internals. (Normally, the console will have its own kernel.) This requires OpenSesame 3.3. Once you've enabled that, and restarted OpenSesame, the console labeled 'Python (1)' will have an opensesame object in it, which corresponds to the application itself. And with this you can test whether your extension loads, like so (but of course change the name of the extension from after_experiment to your extension):

    You'll probably see some errors when you try this, and then you can start debugging from there!

    Sebastiaan

  • Thank you Sebastian for the quick reply once again.

    I managed to make the extension load when the OpenSesame software runs just by changing the disabled: true setting from the .yaml file.

    I also tried the commands you suggested and I get this error:

    Moreover, the problem I have and I want to figure out is, how to execute a specific event of an extension while running a certain experiment ? For example should that be coded in an inline_script ? Can also be executed for example in a sequence ? And if yes, how ?


    Thank you very much for your time and help,

    Christos

  • I also tried the commands you suggested and I get this error:

    You have to enable the inprocess console, as I explained in my previous post.

    Moreover, the problem I have and I want to figure out is, how to execute a specific event of an extension while running a certain experiment ? For example should that be coded in an inline_script ? Can also be executed for example in a sequence ? And if yes, how ?

    There's a distinction between plugins and extensions.

    • An extension lives in the user interface; for example, the console is an extension. You'll also see that all the events, which extensions can fire and listen to, are related to the user interface.
    • A plugin is an additional item that you can use in your experiment; for example, the pygaze items are plugins.

    From your question, it seems like you actually want to create a plugin. Is that correct? If so, then the next step would be to define exactly what you want to do (which is not clear from your question) and only then how to do it!

Sign In or Register to comment.