You are here

Register with variables (Python)

I'm trying to personalize a gimp script. Script should only create a copyright text on an image.

I found out that we could write some code into ~/.pythonrc.py Code is this
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
from datetime import *

sys.path.append('/usr/lib/gimp/2.0/python')

d = date.today()

MySelf = {
'CopyRight':'(©) 2009 Hans-G. Normann',
'Name':'Hans-G. Normann',
'IsoDate': d.isoformat(),
'Font':'Utopia',
'FontSize':50
}

del sys>/code> if we type import user into our Gimp script, then this exutes ~/pythonrc.py. But if I Use Variable MySelf, then script will be loaded without error message, but during execute it will be shown with expected content but with clicking OK it is stressing GIMP Needs a lot of CPU resources). I have to kill the GIMP process.

Replace Variables with normal text, runs without errors.


# Register with The Gimp
#crashing version
register( "hans_kurs0040",
"Kurs PyGimp, Lektion 0040",
"pyGimp Kurs",
"Hans-G. Normann",
user.MySelf['CopyRight'],
user.MySelf['IsoDate'],
"/Python-Fu/Kurs/Lektion 0040",
None,
[ (PF_FONT, 'hans_font', "Copyright Font", user.MySelf['Font']),
(PF_SLIDER, 'hans_size', "Font Size", user.MySelf['FontSize'], [1,300,1]),
(PF_STRING, 'hans_text', "Copyright", user.MySelf['CopyRight'])
],
'',
kurs0040)

#This is ok
register( "hans_kurs0041",
"Kurs PyGimp, Lektion 0041",
"pyGimp Kurs",
"Hans-G. Normann",
"(c) 2009 H. G. Normann",
"2009-05-17",
"/Python-Fu/Kurs/Lektion 0041",
None,
[ (PF_FONT, 'hans_font', "Copyright Font", 'Utopia'),
(PF_SLIDER, 'hans_size', "Font Size", 10, [1,300,1]),
(PF_STRING, 'hans_text', "Copyright", "(c) 2009 H. G. Normann")
],
'',
kurs0040)

Question: Is it possible to use Variables for register function?

Regardless of the current problem you're having... copyright and date are supposed to be static values, making them adjust to the user kinda defeats their pupose.

What's the reason for setting them to variables?

It was my idea, to customize scripts based on current login without changing of code. It should be possible that more then one person running same scripts with different default values. Do you have an other solution? Because I started programming in pygimp weeks before, I'm interested in find out what's possible and what's not. My problem is, I have no experience to find out is it a bug or only impossible.

Yes it's possible, for example register( "python-fu-photolab-addborder", Photolab_addborder_description, Photolab_addborder_help, "Raymond Ostertag", "GPL License", "2009", _("Add border"), "*", Standalone_parameters + Photolab_addborder_parameters + Standalone_export_parameters, [], python_fu_photolab_addborder, menu="/Filters"+"/"+_("Photolab"), domain=("gimp20-photolab", locale_directory) ) where Standalone_parameters could be Standalone_export_parameters = [ (PF_TOGGLE, "export", _("Export"), False), (PF_DIRNAME, "expDirectory", _("Export directory"), os.getcwd() ), ] and os.getcwd() is specific to user
Subscribe to Comments for "Register with variables (Python)"