#! /usr/bin/env python
# JV website generator
# (c) 2008, Johan Tuitman
# Licentie: GPL
#
# maken van knoppen met Gimp
from gimpfu import *
import cPickle
import os

def knop(bestand):
    f = open(bestand)
    mkPic = cPickle.load(f)
    f.close()

    picDir = mkPic['picDir']
    workDir = mkPic['workDir']
    
    for mk in mkPic['mk']:
        outfile = os.path.join(workDir,mk[0])
        tekst = mk[1]
        sub = mk[2]
        high = mk[3]

        if sub == 0 or sub == 1:
            if high:
                if sub == 0:
                    path1 = os.path.join(picDir,'high.png')
                else:
                    path1 = os.path.join(picDir,'high_1.png')
            else:
                path1 = os.path.join(picDir,'normaal.png')

            fontsize = 21
            fontname = "Arial"
            textExtents = pdb['gimp-text-get-extents-fontname'](tekst,fontsize,POINTS,fontname)
            rlinks = (160-textExtents[0])/2

        else:
            path1 = os.path.join(picDir,'high_2.png')
            fontsize = 15 
            fontname = "Arial"
            rlinks = 18


        img = pdb['file-png-load'](path1,path1)

        pdb['gimp-palette-set-foreground']((0,0,0))
        layer = pdb['gimp-image-get-active-layer'](img)
        tst = pdb['gimp-text-fontname'](img,layer,rlinks,-2,tekst,0,True,fontsize,POINTS,fontname)
        layerSave = pdb['gimp-image-flatten'](img)
        pdb['file-png-save'](img,layerSave,outfile,outfile,0,9,0,0,0,0,0)


    pdb['gimp-quit'](True)





register(
        "jvknop",
        "jvknop",
        "jvknop",
        "Johan Tuitman",
        "Johan Tuitman",
        "2007",
        "<Toolbox>/Xtns/Languages/Python-Fu/knoppen/jvknop",
        "",
        [
                (PF_STRING, "bestand", "bestand met gegevens", "./database.dat"),
        ],
        [],
        knop
        )

main()