Skip to content
Iury O. G. Figueiredo edited this page Apr 29, 2017 · 6 revisions

It possible to create as many modes as necessary. A mode is like a set of functions, these functions are tied to events. An event may be a keypress, button click or virtual one, when an event happens then the event's function is executed.

Consider the creation of a plugin that implements a mode named TEST that implements a simple keycommand.

Create a file named test_mode.py in your ~/.vy/ folder.

The source code for the plugin:

def say(event):
    event.widget.insert('1.0', 'Hello user!')

def install(area):
    area.add_mode('TEST', opt=True)
    area.install('test-mode', ('ALPHA', '<Key-p>', 
    lambda event: event.widget.chmode('TEST')), 
    ('TEST', '<Control-s>', say))

Install test_mode.py by adding the lines in your vyrc file.

import test_mode
autoload(test_mode)

So, whenever the user presses:

<Key-p>

in ALPHA mode it would switch the AreaVi instance to TEST mode. In TEST mode if one presses:

<Control-s>

Then the function say will get called with the event parameter.

The 'test-mode' argument is the plugin namespace. Whenever AreaVi.install or AreaVi.hook is used it needs to be given its plugin namespace which is usually the plugin file name.

The opt parameter means whether the mode should be equivalent to the INSERT mode, It means whether the default Tk handles for the widget will be called on the events.

Clone this wiki locally