formField

Store internally as a string. Provide validation routines.

class lib.formField.AlignHorizontalField(value, **keyw)
Bases: lib.formField.ChoiceField
class lib.formField.AlignVerticalField(value, **keyw)
Bases: lib.formField.ChoiceField
class lib.formField.BooleanField(value, visible=True)

Bases: lib.formField.Field

to_python(x, label)
to_string(x)
class lib.formField.CharField(value=None, visible=True, choices=None)
Bases: lib.formField.Field
class lib.formField.ChoiceField(value, choices, **keyw)

Bases: lib.formField.NotEmptyCharField

set_choices(choices)
class lib.formField.ColorField(value, visible=True)
Bases: lib.formField.Field
class lib.formField.CommandLineField(*args, **keyw)

Bases: lib.formField.NotEmptyCharField

raise_error_file(label, what)
raise_error_not_found(label, what)
raise_error_out_max(label)
to_python(x, label)
class lib.formField.CsvFileField(value=None, visible=True, choices=None)
Bases: lib.formField.FileField
class lib.formField.DictionaryReadFileField(value=None, visible=True, choices=None)

Bases: lib.formField.ReadFileField

init_dictionary()
to_python(x, label, test=False)
class lib.formField.DpiField(value=None, visible=True, choices=None)

Bases: lib.formField.PositiveNonZeroIntegerField

PIL defines the resolution in two dimensions as a tuple (x, y). Phatch ignores this possibility and simplifies by using only one resolution

class lib.formField.EmptyFileField(value=None, visible=True, choices=None)
Bases: lib.formField.FileField
class lib.formField.ExifItpcField(value=None, visible=True, choices=None)

Bases: lib.formField.NotEmptyCharField

fix_string(x)
to_python(x, label)
class lib.formField.Field(value, visible=True)

Bases: object

Base class for fields. This needs to be subclassed but, never used directly.

Required to overwrite: description - describes the expected value

Optional to overwrite to_python - raise here exceptions in case of validation errors (defaults

to string).

to_string - (defaults to string)

Never overwrite: validate - will work right out of the box as exceptions are raised by

the to_python method

get - gets the current value as a string set - sets the current value as a string

You can access the value by self.value_as_string

This field interpolates <variables> within a info. << or >> will be interpolated as < or >

Parameters:
  • value (str) – initial value
  • visible (str) – if the field will be visible as a field

Invisible fields request a different kind of user interaction to change their values than a normal field. In Phatch this is used eg for enabling/disabling actions.

A get_relevant_* method of a Form will show/hide fields which depend on other conditions.

assert_safe(label, info)
eval(x, label)
fix_string(x)
For the ui (see ‘write tag’ action)
get(info=None, label='?', value_as_string=None, test=False)

For code: Interpolated, but not translated - value_as_string can be optionally provided to test the expression

Ignore test parameter (only for compatiblity with TestField)

get_as_string()
For GUI: Translation, but no interpolation here
interpolate(x, info, label)
set(x)
For code: Interpolated, but not translated
set_as_string(x)
For GUI: Translation, but no interpolation here
set_as_string_dirty(x)
For GUI: Translation, but no interpolation here
static set_globals(_globals)
to_python(x, label)
to_string(x)
validate(names, _globals, _locals)
Helper method for safe.compile_expr().
class lib.formField.FileField(value=None, visible=True, choices=None)

Bases: lib.formField.NotEmptyCharField

to_python(x, label)
class lib.formField.FileNameField(value=None, visible=True, choices=None)

Bases: lib.formField.NotEmptyCharField

Without extension

class lib.formField.FileSizeField(value=None, visible=True, choices=None)

Bases: lib.formField.IntegerField

Can be in bytes (bt), kilo bytes (kb), mega bytes (mb), or giga bytes (gb).

>>> FileSizeField('5kb').get()
5120
>>> FileSizeField('5mb').get()
5242880
to_python(x, label)
class lib.formField.FloatField(value, visible=True)

Bases: lib.formField.Field

to_python(x, label)
class lib.formField.FloatSliderField(value, minValue, maxValue, **keyw)

Bases: lib.formField.FloatField, lib.formField.SliderField

A value with boundaries set by a slider.

class lib.formField.FolderField(value=None, visible=True, choices=None)
Bases: lib.formField.NotEmptyCharField
class lib.formField.FontFileField(value=None, visible=True, choices=None)

Bases: lib.formField.DictionaryReadFileField

init_dictionary()
class lib.formField.Form(**options)

Bases: object

class AlignHorizontalField(value, **keyw)
Bases: lib.formField.ChoiceField
class Form.AlignVerticalField(value, **keyw)
Bases: lib.formField.ChoiceField
class Form.BooleanField(value, visible=True)

Bases: lib.formField.Field

to_python(x, label)
to_string(x)
class Form.CharField(value=None, visible=True, choices=None)
Bases: lib.formField.Field
class Form.ChoiceField(value, choices, **keyw)

Bases: lib.formField.NotEmptyCharField

set_choices(choices)
class Form.ColorField(value, visible=True)
Bases: lib.formField.Field
class Form.CommandLineField(*args, **keyw)

Bases: lib.formField.NotEmptyCharField

raise_error_file(label, what)
raise_error_not_found(label, what)
raise_error_out_max(label)
to_python(x, label)
class Form.CsvFileField(value=None, visible=True, choices=None)
Bases: lib.formField.FileField
class Form.DictionaryReadFileField(value=None, visible=True, choices=None)

Bases: lib.formField.ReadFileField

init_dictionary()
to_python(x, label, test=False)
class Form.DpiField(value=None, visible=True, choices=None)

Bases: lib.formField.PositiveNonZeroIntegerField

PIL defines the resolution in two dimensions as a tuple (x, y). Phatch ignores this possibility and simplifies by using only one resolution

class Form.EmptyFileField(value=None, visible=True, choices=None)
Bases: lib.formField.FileField
class Form.ExifItpcField(value=None, visible=True, choices=None)

Bases: lib.formField.NotEmptyCharField

fix_string(x)
to_python(x, label)
class Form.Field(value, visible=True)

Bases: object

Base class for fields. This needs to be subclassed but, never used directly.

Required to overwrite: description - describes the expected value

Optional to overwrite to_python - raise here exceptions in case of validation errors (defaults

to string).

to_string - (defaults to string)

Never overwrite: validate - will work right out of the box as exceptions are raised by

the to_python method

get - gets the current value as a string set - sets the current value as a string

You can access the value by self.value_as_string

This field interpolates <variables> within a info. << or >> will be interpolated as < or >

Parameters:
  • value (str) – initial value
  • visible (str) – if the field will be visible as a field

Invisible fields request a different kind of user interaction to change their values than a normal field. In Phatch this is used eg for enabling/disabling actions.

A get_relevant_* method of a Form will show/hide fields which depend on other conditions.

assert_safe(label, info)
eval(x, label)
fix_string(x)
For the ui (see ‘write tag’ action)
get(info=None, label='?', value_as_string=None, test=False)

For code: Interpolated, but not translated - value_as_string can be optionally provided to test the expression

Ignore test parameter (only for compatiblity with TestField)

get_as_string()
For GUI: Translation, but no interpolation here
interpolate(x, info, label)
set(x)
For code: Interpolated, but not translated
set_as_string(x)
For GUI: Translation, but no interpolation here
set_as_string_dirty(x)
For GUI: Translation, but no interpolation here
static set_globals(_globals)
to_python(x, label)
to_string(x)
validate(names, _globals, _locals)
Helper method for safe.compile_expr().
class Form.FileField(value=None, visible=True, choices=None)

Bases: lib.formField.NotEmptyCharField

to_python(x, label)
class Form.FileNameField(value=None, visible=True, choices=None)

Bases: lib.formField.NotEmptyCharField

Without extension

class Form.FileSizeField(value=None, visible=True, choices=None)

Bases: lib.formField.IntegerField

Can be in bytes (bt), kilo bytes (kb), mega bytes (mb), or giga bytes (gb).

>>> FileSizeField('5kb').get()
5120
>>> FileSizeField('5mb').get()
5242880
to_python(x, label)
class Form.FloatField(value, visible=True)

Bases: lib.formField.Field

to_python(x, label)
class Form.FloatSliderField(value, minValue, maxValue, **keyw)

Bases: lib.formField.FloatField, lib.formField.SliderField

A value with boundaries set by a slider.

class Form.FolderField(value=None, visible=True, choices=None)
Bases: lib.formField.NotEmptyCharField
class Form.FontFileField(value=None, visible=True, choices=None)

Bases: lib.formField.DictionaryReadFileField

init_dictionary()
class Form.GeoReadFileField(value=None, visible=True, choices=None)
Bases: lib.formField.ReadFileField
class Form.ImageDictionaryField(value=None, visible=True, choices=None)
Bases: lib.formField.ImageDictionaryReadFileField
class Form.ImageDictionaryReadFileField(value=None, visible=True, choices=None)
Bases: lib.formField.ImageReadFileField
class Form.ImageEffectField(value, **keyw)
Bases: lib.formField.PilConstantMixin, lib.formField.ChoiceField
class Form.ImageFilterField(value, **keyw)
Bases: lib.formField.PilConstantMixin, lib.formField.ChoiceField
class Form.ImageModeField(value, **keyw)

Bases: lib.formField.ChoiceField

to_python(x, label)
class Form.ImageReadFileField(value=None, visible=True, choices=None)
Bases: lib.formField.DictionaryReadFileField
class Form.ImageReadTypeField(value, **keyw)
Bases: lib.formField.ChoiceField
class Form.ImageResampleAutoField(value, **keyw)
Bases: lib.formField.PilConstantMixin, lib.formField.ChoiceField
class Form.ImageResampleField(value, **keyw)
Bases: lib.formField.PilConstantMixin, lib.formField.ChoiceField
class Form.ImageTransposeField(value, **keyw)
Bases: lib.formField.PilConstantMixin, lib.formField.ChoiceField
class Form.ImageTypeField(value, **keyw)

Bases: lib.formField.ChoiceField

fix_string(x)
class Form.ImageWriteTypeField(value, **keyw)
Bases: lib.formField.ChoiceField
class Form.IntegerField(value=None, visible=True, choices=None)

Bases: lib.formField.NotEmptyCharField

to_python(x, label)
class Form.NotEmptyCharField(value=None, visible=True, choices=None)
Bases: lib.formField.CharField
class Form.OptionalTransposeField(value, **keyw)
Bases: lib.formField.PilConstantMixin, lib.formField.ChoiceField
class Form.OrientationField(value, **keyw)

Bases: lib.formField.PilConstantMixin, lib.formField.ChoiceField

to_python(x, label)
class Form.PixelField(value=None, visible=True, choices=None)

Bases: lib.formField.IntegerField

Can be pixels, cm, inch, %.

get_size(info, base, dpi, label, value_as_string=None)
class Form.PositiveFloatField(value, visible=True)

Bases: lib.formField.FloatField

to_python(x, label)
class Form.PositiveIntegerField(value=None, visible=True, choices=None)

Bases: lib.formField.IntegerField

to_python(x, label)
class Form.PositiveNonZeroFloatField(value, visible=True)

Bases: lib.formField.PositiveFloatField

to_python(x, label)
class Form.PositiveNonZeroIntegerField(value=None, visible=True, choices=None)

Bases: lib.formField.PositiveIntegerField

to_python(x, label)
class Form.RankSizeField(value, **keyw)
Bases: lib.formField.IntegerField, lib.formField.ChoiceField
class Form.ReadFileField(value=None, visible=True, choices=None)

Bases: lib.formField.TestFieldMixin, lib.formField.FileField

This is a test field to ensure that the file exists. It could also have been called the MustExistFileField.

to_python(x, label, test=False)
class Form.SliderField(value, minValue, maxValue, **keyw)

Bases: lib.formField.IntegerField

A value with boundaries set by a slider.

class Form.TiffCompressionField(value, **keyw)
Bases: lib.formField.ChoiceField
Form.dump()
Dump as raw strings
Form.ensure_path(path)
Form.find_exe(program, name=None)
Form.get_field(label, info=None)
Form.get_field_labels()
Form.get_field_size(label, info, base, dpi)
Form.get_field_string(label)
Form.get_fields(info, convert=False, pixel_fields=None, exclude=None)
Form.interface(fields)

Describe here the fields. This is called from the __init__ method.

Parameter:fields (odict) – an (usually empty) ordered dictionary
Form.is_enabled()
Form.is_field_true(label)
Form.load(fields)
Load dumped, raw strings.
Form.set_field(label, value)
Form.set_field_as_string(label, value_as_string)
Form.set_field_as_string_dirty(label, value_as_string)
Form.set_fields(**options)
class lib.formField.GeoReadFileField(value=None, visible=True, choices=None)
Bases: lib.formField.ReadFileField
class lib.formField.ImageDictionaryField(value=None, visible=True, choices=None)
Bases: lib.formField.ImageDictionaryReadFileField
class lib.formField.ImageDictionaryReadFileField(value=None, visible=True, choices=None)
Bases: lib.formField.ImageReadFileField
class lib.formField.ImageEffectField(value, **keyw)
Bases: lib.formField.PilConstantMixin, lib.formField.ChoiceField
class lib.formField.ImageFilterField(value, **keyw)
Bases: lib.formField.PilConstantMixin, lib.formField.ChoiceField
class lib.formField.ImageModeField(value, **keyw)

Bases: lib.formField.ChoiceField

to_python(x, label)
class lib.formField.ImageReadFileField(value=None, visible=True, choices=None)
Bases: lib.formField.DictionaryReadFileField
class lib.formField.ImageReadTypeField(value, **keyw)
Bases: lib.formField.ChoiceField
class lib.formField.ImageResampleAutoField(value, **keyw)
Bases: lib.formField.PilConstantMixin, lib.formField.ChoiceField
class lib.formField.ImageResampleField(value, **keyw)
Bases: lib.formField.PilConstantMixin, lib.formField.ChoiceField
class lib.formField.ImageTransposeField(value, **keyw)
Bases: lib.formField.PilConstantMixin, lib.formField.ChoiceField
class lib.formField.ImageTypeField(value, **keyw)

Bases: lib.formField.ChoiceField

fix_string(x)
class lib.formField.ImageWriteTypeField(value, **keyw)
Bases: lib.formField.ChoiceField
class lib.formField.IntegerField(value=None, visible=True, choices=None)

Bases: lib.formField.NotEmptyCharField

to_python(x, label)
class lib.formField.NotEmptyCharField(value=None, visible=True, choices=None)
Bases: lib.formField.CharField
class lib.formField.OptionalTransposeField(value, **keyw)
Bases: lib.formField.PilConstantMixin, lib.formField.ChoiceField
class lib.formField.OrientationField(value, **keyw)

Bases: lib.formField.PilConstantMixin, lib.formField.ChoiceField

to_python(x, label)
class lib.formField.PilConstantMixin
to_python(x, label)
class lib.formField.PixelField(value=None, visible=True, choices=None)

Bases: lib.formField.IntegerField

Can be pixels, cm, inch, %.

get_size(info, base, dpi, label, value_as_string=None)
class lib.formField.PositiveFloatField(value, visible=True)

Bases: lib.formField.FloatField

to_python(x, label)
class lib.formField.PositiveIntegerField(value=None, visible=True, choices=None)

Bases: lib.formField.IntegerField

to_python(x, label)
class lib.formField.PositiveNonZeroFloatField(value, visible=True)

Bases: lib.formField.PositiveFloatField

to_python(x, label)
class lib.formField.PositiveNonZeroIntegerField(value=None, visible=True, choices=None)

Bases: lib.formField.PositiveIntegerField

to_python(x, label)
class lib.formField.RankSizeField(value, **keyw)
Bases: lib.formField.IntegerField, lib.formField.ChoiceField
class lib.formField.ReadFileField(value=None, visible=True, choices=None)

Bases: lib.formField.TestFieldMixin, lib.formField.FileField

This is a test field to ensure that the file exists. It could also have been called the MustExistFileField.

to_python(x, label, test=False)
class lib.formField.SliderField(value, minValue, maxValue, **keyw)

Bases: lib.formField.IntegerField

A value with boundaries set by a slider.

class lib.formField.TestFieldMixin

Mixin class, the to_python method should

def to_python(self, x, label, test=False):
“test parameter to signal test-validate” return x

See set_form_field_value in treeEdit.py

get(info=None, label='?', value_as_string=None, test=False)
Use this method to test-validate the user input, for example: field.get(IMAGE_TEST_INFO, value_as_string, label, test=True)
class lib.formField.TiffCompressionField(value, **keyw)
Bases: lib.formField.ChoiceField
exception lib.formField.ValidationError(expected, message, details=None)
Bases: exceptions.Exception
lib.formField.files_dictionary(paths, extensions, title_parser=None)

Collects files with a certain extension in different folders and stores the files in a dictionary of which the keys are titled versions of the filename.

Phatch uses this for fonts, highlights and masks.

>>> files_dictionary(['/etc/apt'], ['.list'])
{'Sources': '/etc/apt/sources.list'}
lib.formField.get_safe()
lib.formField.rotation_title_parser(field, filename)
lib.formField.set_safe(state)

Previous topic

fonts

Next topic

gettextFix