#!/usr/bin/env python
# (C) 2017 OpenEye Scientific Software Inc. All rights reserved.
#
# TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
# provided to current licensees or subscribers of OpenEye products or
# SaaS offerings (each a "Customer").
# Customer is hereby permitted to use, copy, and modify the Sample Code,
# subject to these terms. OpenEye claims no rights to Customer's
# modifications. Modification of Sample Code is at Customer's sole and
# exclusive risk. Sample Code may require Customer to have a then
# current license or subscription to the applicable OpenEye offering.
# THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
# NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall OpenEye be
# liable for any damages or liability in connection with the Sample Code
# or its use.

from openeye import oechem
from openeye import oedepict

###############################################################
# USED TO GENERATE CODE SNIPPETS FOR THE OEDEPICT DOCUMENTATION
###############################################################


def WriteTable(tableoptions, basefilename):

    image = oedepict.OEImage(300, 200)
    table = oedepict.OEImageTable(image, tableoptions)

    for idx, cell in enumerate(table.GetHeaderCells()):
        table.DrawText(cell, "(header %d)" % (idx + 1))

    for idx, cell in enumerate(table.GetStubColumnCells()):
        table.DrawText(cell, "(stub %d)" % (idx + 1))

    onlybody = True
    for row in range(1, table.NumRows(onlybody) + 1):
        for col in range(1, table.NumColumns(onlybody) + 1):
            cell = table.GetBodyCell(row, col)
            table.DrawText(cell, "(body %d, %d)" % (row, col))

    oedepict.OEDrawBorder(image, oedepict.OELightGreyPen)
    oedepict.OEWriteImage(basefilename + ".png", image)
    oedepict.OEWriteImage(basefilename + ".pdf", image)


# @ <SNIPPET-OEIMAGETABLEOPTIONS-DEFAULT>
tableopts = oedepict.OEImageTableOptions(4, 4, oedepict.OEImageTableStyle_MediumBlue)
# @ </SNIPPET-OEIMAGETABLEOPTIONS-DEFAULT>
WriteTable(tableopts, "OEImageTableOptions_Default")

# @ <SNIPPET-OEIMAGETABLEOPTIONS-SETCOLUMNWIDTHS>
tableopts = oedepict.OEImageTableOptions(4, 4, oedepict.OEImageTableStyle_MediumBlue)
tableopts.SetColumnWidths([20, 10, 20, 10])
# @ </SNIPPET-OEIMAGETABLEOPTIONS-SETCOLUMNWIDTHS>
WriteTable(tableopts, "OEImageTableOptions_SetColumnWidths")

# @ <SNIPPET-OEIMAGETABLEOPTIONS-SETROWHEIGHTS>
tableopts = oedepict.OEImageTableOptions(4, 4, oedepict.OEImageTableStyle_MediumBlue)
tableopts.SetRowHeights([10, 20, 30, 40])
# @ </SNIPPET-OEIMAGETABLEOPTIONS-SETROWHEIGHTS>
WriteTable(tableopts, "OEImageTableOptions_SetRowHeights")

# @ <SNIPPET-OEIMAGETABLEOPTIONS-SETBASEFONTSIZE>
tableopts = oedepict.OEImageTableOptions(4, 4, oedepict.OEImageTableStyle_MediumBlue)
tableopts.SetBaseFontSize(6)
# @ </SNIPPET-OEIMAGETABLEOPTIONS-SETBASEFONTSIZE>
WriteTable(tableopts, "OEImageTableOptions_SetBaseFontSize")

# @ <SNIPPET-OEIMAGETABLEOPTIONS-SETCELLBORDERPEN>
tableopts = oedepict.OEImageTableOptions(4, 4, oedepict.OEImageTableStyle_MediumBlue)
pen = oedepict.OEPen(oechem.OEBlack, oechem.OEDarkBlue, oedepict.OEFill_Off, 2.0)
tableopts.SetCellBorderPen(pen)
# @ </SNIPPET-OEIMAGETABLEOPTIONS-SETCELLBORDERPEN>
WriteTable(tableopts, "OEImageTableOptions_SetCellBorderPen")

# @ <SNIPPET-OEIMAGETABLEOPTIONS-SETCELLCOLOR>
tableopts = oedepict.OEImageTableOptions(4, 4, oedepict.OEImageTableStyle_MediumBlue)
evenrow = True
tableopts.SetCellColor(oechem.OELightGrey, not evenrow)
# @ </SNIPPET-OEIMAGETABLEOPTIONS-SETCELLCOLOR>
WriteTable(tableopts, "OEImageTableOptions_SetCellColor")

# @ <SNIPPET-OEIMAGETABLEOPTIONS-SETCELLFONT>
tableopts = oedepict.OEImageTableOptions(4, 4, oedepict.OEImageTableStyle_MediumBlue)
font = oedepict.OEFont(oedepict.OEFontFamily_Default, oedepict.OEFontStyle_Italic | oedepict.OEFontStyle_Bold, 8,
                       oedepict.OEAlignment_Left, oechem.OEDarkRed)
tableopts.SetCellFont(font)
# @ </SNIPPET-OEIMAGETABLEOPTIONS-SETCELLFONT>
WriteTable(tableopts, "OEImageTableOptions_SetCellFont")

# @ <SNIPPET-OEIMAGETABLEOPTIONS-SETHEADER>
tableopts = oedepict.OEImageTableOptions(4, 4, oedepict.OEImageTableStyle_MediumBlue)
tableopts.SetHeader(False)
# @ </SNIPPET-OEIMAGETABLEOPTIONS-SETHEADER>
WriteTable(tableopts, "OEImageTableOptions_SetHeader")

# @ <SNIPPET-OEIMAGETABLEOPTIONS-SETHEADERCOLOR>
tableopts = oedepict.OEImageTableOptions(4, 4, oedepict.OEImageTableStyle_MediumBlue)
tableopts.SetHeaderColor(oechem.OELightGrey)
# @ </SNIPPET-OEIMAGETABLEOPTIONS-SETHEADERCOLOR>
WriteTable(tableopts, "OEImageTableOptions_SetHeaderColor")

# @ <SNIPPET-OEIMAGETABLEOPTIONS-SETHEADERFONT>
tableopts = oedepict.OEImageTableOptions(4, 4, oedepict.OEImageTableStyle_MediumBlue)
font = oedepict.OEFont(oedepict.OEFontFamily_Default, oedepict.OEFontStyle_Default, 12,
                       oedepict.OEAlignment_Right, oechem.OEPinkTint)
tableopts.SetHeaderFont(font)
# @ </SNIPPET-OEIMAGETABLEOPTIONS-SETHEADERFONT>
WriteTable(tableopts, "OEImageTableOptions_SetHeaderFont")

# @ <SNIPPET-OEIMAGETABLEOPTIONS-SETMARGIN>
tableopts = oedepict.OEImageTableOptions(4, 4, oedepict.OEImageTableStyle_MediumBlue)
tableopts.SetMargin(oedepict.OEMargin_Left, 10.0)
tableopts.SetMargin(oedepict.OEMargin_Right, 10.0)
# @ </SNIPPET-OEIMAGETABLEOPTIONS-SETMARGIN>
WriteTable(tableopts, "OEImageTableOptions_SetMargin")

# @ <SNIPPET-OEIMAGETABLEOPTIONS-SETMARGINS>
tableopts = oedepict.OEImageTableOptions(4, 4, oedepict.OEImageTableStyle_MediumBlue)
tableopts.SetMargins(10.0)
# @ </SNIPPET-OEIMAGETABLEOPTIONS-SETMARGINS>
WriteTable(tableopts, "OEImageTableOptions_SetMargins")

# @ <SNIPPET-OEIMAGETABLEOPTIONS-SETSTUBCOLUMN>
tableopts = oedepict.OEImageTableOptions(4, 4, oedepict.OEImageTableStyle_MediumBlue)
tableopts.SetStubColumn(True)
# @ </SNIPPET-OEIMAGETABLEOPTIONS-SETSTUBCOLUMN>>
WriteTable(tableopts, "OEImageTableOptions_SetStubColumn")

# @ <SNIPPET-OEIMAGETABLEOPTIONS-SETSTUBCOLUMNCOLOR>
tableopts = oedepict.OEImageTableOptions(4, 4, oedepict.OEImageTableStyle_MediumBlue)
tableopts.SetStubColumn(True)
tableopts.SetStubColumnColor(oechem.OELightGrey)
# @ </SNIPPET-OEIMAGETABLEOPTIONS-SETSTUBCOLUMNCOLOR>
WriteTable(tableopts, "OEImageTableOptions_SetStubColumnColor")

# @ <SNIPPET-OEIMAGETABLEOPTIONS-SETSTUBCOLUMNFONT>
tableopts = oedepict.OEImageTableOptions(4, 4, oedepict.OEImageTableStyle_MediumBlue)
tableopts.SetStubColumn(True)
font = oedepict.OEFont(oedepict.OEFontFamily_Default, oedepict.OEFontStyle_Default, 12,
                       oedepict.OEAlignment_Right, oechem.OEPinkTint)
tableopts.SetStubColumnFont(font)
# @ </SNIPPET-OEIMAGETABLEOPTIONS-SETSTUBCOLUMNFONT>
WriteTable(tableopts, "OEImageTableOptions_SetStubColumnFont")
