OEAddSVGClickEvent

The overloaded versions of the OEAddSVGClickEvent function

Link

Description

OEAddSVGClickEvent(disp, adisp, message)

adding click event to OE2DAtomDisplay

OEAddSVGClickEvent(disp, bdisp, message)

adding click event to OE2DBondDisplay

OEAddSVGClickEvent(svggroup, message)

adding click event to OESVGGroup (low-level function)

bool OEAddSVGClickEvent(OE2DMolDisplay& disp, OE2DAtomDisplay* adisp,
                        const std::string& message);

bool OEAddSVGClickEvent(OE2DMolDisplay& disp, OE2DBondDisplay* bdisp,
                        const std::string& message);

Adds a click event to an atom or bond in an .svg image. When clicking at the position defined by the given atom or bond display, an event is triggered with the given message.

Note

This functionality is only available for .svg image format.

See also

disp

The OE2DMolDisplay object that holds the data necessary to depict the molecule with which it is initialized.

adisp

The OE2DAtomDisplay object that defines the mouse click position.

bdisp

The OE2DBondDisplay object that defines the mouse click position

message

The text that will be emitted when an event is triggered on mouse click.

Example for adding event for atom displays

width, height = 400, 200
image = oedepict.OEImage(width, height)

mol = oechem.OEGraphMol()
smiles = "Cc1cccnc1/C=C/[C@H](C(=O)O)O"
oechem.OESmilesToMol(mol, smiles)
oedepict.OEPrepareDepiction(mol)

opts = oedepict.OE2DMolDisplayOptions(width, height, oedepict.OEScale_AutoScale)
opts.SetMargins(10)
disp = oedepict.OE2DMolDisplay(mol, opts)

for adisp in disp.GetAtomDisplays():
    atom = adisp.GetAtom()
    message = "atom idx=%s" % atom.GetIdx()
    oedepict.OEAddSVGClickEvent(disp, adisp, message)

oedepict.OERenderMolecule("AddAtomClickEvent.svg", disp)

Download code

AddAtomClickEvent.py

Example for adding event for bond displays

width, height = 400, 200
image = oedepict.OEImage(width, height)

mol = oechem.OEGraphMol()
smiles = "Cc1cccnc1/C=C/[C@H](C(=O)O)O"
oechem.OESmilesToMol(mol, smiles)
oedepict.OEPrepareDepiction(mol)

opts = oedepict.OE2DMolDisplayOptions(width, height, oedepict.OEScale_AutoScale)
opts.SetMargins(10)
disp = oedepict.OE2DMolDisplay(mol, opts)

for bdisp in disp.GetBondDisplays():
    bond = bdisp.GetBond()
    message = "bond idx=%s" % bond.GetIdx()
    oedepict.OEAddSVGClickEvent(disp, bdisp, message)

oedepict.OERenderMolecule("AddBondClickEvent.svg", disp)

Download code

AddBondClickEvent.py

See also

bool OEAddSVGClickEvent(OESVGGroup* svggroup, const std::string& message);

Adds a click event to a specific SVG group in .svg image. When clicking at the elements drawn inside the given OESVGGroup object, an event is triggered with the given message

Note

This functionality is only available for .svg image format.

Hint

The OEAddSVGClickEvent function should always be called prior to pushing / popping the OESVGGroup object.

Example:

The following example creates an .svg image with a red rectangle and a blue circle. Both drawing elements are rendered inside OESVGGroup objects that are associated with messages clicked on rectangle and clicked on circle, respectively. When the generated .svg image is displayed in a HTTP server, clicking on the rectangle and the circle triggers events with the corresponding messages.

group_rectangle = image.NewSVGGroup("rectangle")

message = "clicked on rectangle"
oedepict.OEAddSVGClickEvent(group_rectangle, message)

image.PushGroup(group_rectangle)
image.DrawRectangle(oedepict.OE2DPoint(30, 30), oedepict.OE2DPoint(70, 70), oedepict.OERedBoxPen)
image.PopGroup(group_rectangle)

group_circle = image.NewSVGGroup("circle")

message = "clicked on circle"
oedepict.OEAddSVGClickEvent(group_circle, message)

image.PushGroup(group_circle)
image.DrawCircle(oedepict.OE2DPoint(150, 50), 30, oedepict.OEBlueBoxPen)
image.PopGroup(group_circle)

oedepict.OEWriteImage("AddSVGClickEvent.svg", image)

Download code

AddSVGClickEvent.py

See also