Vizard 8 » The Vizard IDE » Editing tools » Autocomplete
8.1

Autocomplete

Vizard's autocomplete system helps you write code by providing completion options as you type in the editor. Relevant options will appear in a pop-up list based on context. In the image below, all viz functions and variables are initially displayed after typing "viz." then narrowed down to viz.addChild with a few more keystrokes:

The autocomplete system makes programming in Vizard more efficient by:

The following table shows the types of options that autocomplete supports:

Option types

Description

Keywords

All keywords available in the Python language

Modules

Available after an import or from statement

Classes, functions, and variables within modules

Available after typing <module name>.

Methods and data attributes within objects

Available after typing <object name>.

Classes, functions, and variables within the current file

Any relevant location within the file.

The legend below defines the icons that appears in the autocomplete window:

Variable

Python keyword

Module

Function or method

Class

Limitations

Multiple return types

If a function has multiple return types, the autocomplete parser cannot be sure which type to use on the returned object. A common example of this is with the viz.add command:

box = viz.add('box.wrl')

Since the return type of the function above can vary, the parser is not able to determine that box is a <node3D> object. This results in incorrect completion options after typing "box.".

 

To correct for this, use the explicit add commands (e.g. viz.addAvatar,viz.addChild, viz.addTexQuad) which only have one return type rather than viz.add. For example, to get the correct options on a <node3D> object use viz.addChild:

box = viz.addChild('box.wrl')

Type tags in function doc strings

A function doc string is an optional comment enclosed in triple quotes that immediately follows a function definition. It is used for documenting a function and can be accessed at runtime using Python's help command. Many Python editors, including Vizard's, display the doc string as a tooltip when the function name is typed.

 

Additionally, Vizard's autocomplete system recognizes several type tags inserted within the function doc string. These help to provide the user with proper completion options on:

The following table shows the type tags supported:

Type tag

Description

@args <types>

Specifies the type of arguments passed to the function by position (comma separated).

@arg <name> <type>

Specifies the type of an argument passed to the function by name.

@return <type>

Specifies the function's return type.

Example 1

Copy the following code into a new Vizard file. The @args tag specifies that the first argument will be a list and the second a dictionary. The @return tag specifies that the return type is a list.

my_list = [4,5,6]
my_dictionary = {'a':1,'b':2,'c':3}

def func(a,b):
    """
    creates a new list using elements from a list and a dictionary
   
    @args [],{}
    @return []
    """

Type in the following lines of code within the function (same level of indentation). After entering "a." and "b."  you should see all list and dictionary methods, respectively, displayed in the autocomplete window. This demonstrates autocompletion on objects passed to the function as arguments:

    a.extend(b.values())
    return a

Now type in the following code that calls the function and sorts the new list. Notice after entering "my_new_list." that all list methods are displayed in the autocomplete window. This demonstrates autocompletion on the object assigned to the return value of the function:

my_new_list = func(my_list,my_dictionary)
my_new_list.sort()
print(my_new_list)
Example 2

In the previous example the types of the arguments were specified by position. Argument types can also be specified individually by name using the @arg tag. The @arg tag in the following code specifies that argument "c" is a string. Typing this in, you should see all string options appear in the autocomplete window after entering "c." within the function:

def func(a,b,c):
    """
    adds three strings together
   
    @arg c ''
    @return ''
    """
   
    c = c.replace('ccc','cde')
    return a + b + c
   
my_string = func('a','b','ccc')
print(my_string.upper())