5.2.2. components requirements

5.2.2.1. introduction

To use a component you have to follow these two instructions:

  1. import the name of the package that includes the component you want to use in the <packages> tag of your instanceconfig.xml file (for more information, check the <packages> section)

    Note

    this step is optionally if the component you want to import is a standard component

  2. set in your webpages a requirement: every component has to be called through the correct py_requires webpage variable

    Note

    In every component’s documentation page you fill find the correct syntax for its py_requires and the name of the package you have to import

5.2.2.1.1. py_requires

  • “py_requires” is a webpage variable

  • py_requires syntax:

    py_requires = 'folderName/fileName:componentClassName'
    

    Where:

    • folderName is the name of the folder that includes the file with the component you need.
    • fileName is the name of the file including the component (without its .py suffix)
    • componentClassName is the name of the python class of the component.

Note

You should also know that:

  1. If you need to import all the classes of a component, the syntax becomes:

    py_requires = 'folderName/fileName'
    
  2. You can omit the “folderName” if the component is placed at the first level of a resources folder of an imported package.

    Viceversa, if the component lives in a nested level of a resources folder you have to specify its path.

    Example: if you need the “Public” class of a component called “public.py” that lives at the following path:

    ~/yourRootPathForGenro/genro/.../resources/public.py
    

    then your “py_requires” will be:

    py_requires = 'public:Public'
    

    Example: if you need the “Power” class of a component called “yourcomponent.py” that lives at the following path:

    ~/yourRootPathForGenro/genro/.../resources/power_components/yourcomponent.py
    

    then your “py_requires” will be:

    py_requires = 'power_components/yourcomponent:Power'
    

    Example:

    py_requires = """public:Public, public:TableHandlerMain,
                     gnrcomponents/htablehandler:HTableHandler"""
    

    Here you call the Public class of the public.py file and the hTableHandler class of the htablehandler file of the gnrcomponents folder, a subfolder of the Genro `resources folder

5.2.2.2. standard component

Definition: A standard component is a component that lives in the following path:

GNRHOME/resources

We remind you that to use a standard component you need to import the proper component’s py_requires in the webpage in which you use the component

For the fact that is while you don’t need to import any package: infact the package importation is automatically handled in the environment.xml file, if you have correctly configured it; in the usage of standard components section you can learn how to configure the environment.xml file

However, in every component’s page you will find if the component is standard or not

5.2.2.3. active or passive components

We can distighuish between active and passive components.

Usually, a component is active OR passive, but this is merely a convention. You can create a component that is both active and passive.

Note

in every component’s documentation page you will find if the component is active or passive.

5.2.2.3.1. active component

The active component is a component that overrides the main method.

5.2.2.3.2. passive component

The passive component is a component that doesn’t have its own main method, so you have to define your own main method in your webpage.