How to write an EPANET plugin

Each plugin should be placed in its own directory which is the plugin’s name. For example Summary. In the directory, the plugin file is __init__.py.

To begin with, the variable plugin_name must be initialized with the plugin’s name. The plugin_create_menu variable will determine if the plugin will display a menu or not. In this case, the plugin’s name is “Summary” and it will show a menu.

plugin_name = "Summary"
plugin_create_menu = True

Next, the menu items are set using the variable __all__. It holds the menu items text and a code which will be returned when the menu item is clicked.

__all__ = {"Title":1, "Nodes":2, "Links":3}
from PyQt4.QtGui import QMessageBox

def run(session=None, choice=None):
    ltopTitle = 'Plugin:Summary'
    explain_text = "This is a sample plug-in illustrating how a single plug-in can add a menu with several functions." \
                   + "\n\nResult: "
    if choice is None:
        choice = 99
    if choice == 1:
        if session and session.project:
            summary = session.project.title.title
        else:
            summary = "Project is not open"
        QMessageBox.information(None, ltopTitle, explain_text + '\n' + summary, QMessageBox.Ok)
        pass
    elif choice == 2:
        QMessageBox.information(None, ltopTitle,  explain_text + '\n' + "summarizeNodes", QMessageBox.Ok)
        pass
    elif choice == 3:
        QMessageBox.information(None, ltopTitle,  explain_text + '\n' + "summarizeConduits", QMessageBox.Ok)
        pass
    elif choice == 99:
        pass
    else:
        QMessageBox.information(None, ltopTitle,  explain_text + '\n' + "Top level summary is done.", QMessageBox.Ok)
        pass