Howdy, Stranger!

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

Supported by

how to use variables collected by a plugin?

edited June 2022 in OpenSesame

Dear opensesame users,


I'm a newbee in the opensesame world. I have a project to complet to I need to develop some plugins to achieve this. Since I have no experience with opensesame I tried first to write a minimal plugin. Here are the info.yaml and to *.py files:


info.yaml

author: author
category: plugin essai
description: un plugin d'essai
controls:
-
   label: essai
   name: line_edit_essai
   type: line_edit
   var: essai


*.py

from libopensesame.py3compat import *
from libopensesame.oslogging import oslogger
from libopensesame.item import item
from libqtopensesame.items.qtautoplugin import qtautoplugin

class plugin_essai(item):
   def reset(self):
       self.var.essai = u'un texte par défaut'
       oslogger.debug('plugin_essai has been initialized')

   def prepare(self):
       item.prepare(self)

   def run(self):
       self.set_item_onset()



class qtplugin_essai(plugin_essai, qtautoplugin):
   def __init__(self, name, experiment, script = None):
       plugin_essai.__init__(self, name, experiment, script)
       qtautoplugin.__init__(self, __file__)

Very simple as you can see. Here is my question: A essai variable is declared in the yaml file to capture the line_edit data and is passed to var in the class plugin_essai. Up to this, it seems in line with what I understand of opensesame. However, this var.essai variable is not registered in the var inspector and, accordingly, a script that would try to use it crash with the error message No essai variable exists. Could you help me to figure how to use informations captured in a plugin?


Thanks so much for your help.

Best regards,

Hugues

Comments

  • Hi @HuguesJ ,

    Each item (or plugin) has its own var object, which is used to store item-specific information, but is not (easily) accessible from outside the item. The var object that you see in an inline_script item is actually part of the experiment object. Practically speaking, this means that if you want your item to expose experimental variables you would do it like this:

    self.experiment.var.my_item_variable = 'some value'
    

    Hope this helps!

    — Sebastiaan

  • Hi sebastiaan,


    Thanks so much for this kind and nice answer. I did not figure that the var object was part of experiment object. I thought it was an independant opensesame object overseeing all var variables and making them public for the whole experiment. Your explanation helps a lot.

    I figured an other way to manipulate the variables/attributes of a plugin. Actually, the plugin is an item and it can be manipulate like other items of opensesame using the 'items' command. Thus it is possible to reach attributes and likely methods using this synthax:

    items['plugin name'].var.'variable_name'

    This is not very intuitive when you are coding in pure python, but fairly logical considering opensesame philosophy. Besides this, it is not that bad at the end since it recalls in the code where the variable is comming from.

    Anyway, thanks again for your help and I hope my question and answers will help other new opensesame users to make their way in this software philosophy.

    Best regards,

    Hugues

  • Thanks so much for this kind and nice answer. I did not figure that the var object was part of experiment object. I thought it was an independant opensesame object overseeing all var variables and making them public for the whole experiment. Your explanation helps a lot.

    I figured an other way to manipulate the variables/attributes of a plugin. Actually, the plugin is an item and it can be manipulate like other items of opensesame using the 'items' command. Thus it is possible to reach attributes and likely methods using this synthax:

    items['plugin name'].var.'variable_name'

    This is not very intuitive when you are coding in pure python, but fairly logical considering opensesame philosophy. Besides this, it is not that bad at the end since it recalls in the code where the variable is comming from.

    Anyway, thanks again for your help and I hope my question and answers will help other new opensesame users to make their way in this software philosophy.

    Best regards,

    Hugues

     

Sign In or Register to comment.