Fields

Implementation of Field and subclasses. They are used in the templates.template.fields attribute.

Each one is responsible handling a part of data-procesing in the card-generation process. This allows easy customization of templates.Template.

class acg.fields.CheckChipOptionsField[source]

Bases: acg.fields.OptionsField

Pick multiple options using custom_widgets.selection_widgets.CheckChips.

class acg.fields.CookBook[source]

Save recipes for construction of Classes with default values.

cook(self, name, **kwargs)

Generate object from recipe.

default_kwargs in recipe can be overridden by kwargs.

get_recipe_names(self)

Return list of all registered recipes.

get_recipes(self)

Return recipes.

register(self, recipe_name, info=None, **kwargs)

Add recipe to recipes.

to_button_dict(self)

Return dict in a form as used in custom_widgets.CustomSpeedDial.button_dicts.

class acg.fields.DisplayTextField[source]

Bases: acg.fields.Field

Only displays text.

class acg.fields.DualLongTextField[source]

Bases: acg.fields.TranslationMixin, acg.fields.OptionsField

Pick a single options using custom_widgets.selection_widgets.CardCarousel.

Useful for longer text, i.e. examples or explanations.

Inheritance from TranslationMixin guarantees that translations are available.

class acg.fields.Field[source]

Base-class for fields.

Accesses the data in template.data, can perform actions on the obtained data and/or display it in a widget to allow user input to change it.

construct_widget(self)[source]

Construct widget that is used for the selection of content.

field_name[source]

Key of template.data which this field is handling.

get_content(self)[source]

If widget is set, use kv_bidict to extract.

Calls post_process() on the data before returning it.

get_data(self)[source]

Get dictionary to construct widget.

heading[source]

Heading to be shown over widget.

kv_bidict[source]

Getter function for _audio_url.

post_process(self, content)[source]

Placeholder-function.

pre_process(self)[source]

Placeholder-function.

template[source]

Reference to templates.Template.

update(self)[source]

Apply pre_process() and update_widget_data().

update_widget_data(self)[source]

Check if widget is present and update the attributes of the kivy-widget from template.data.

widget[source]

Gets constructed by load_string() from widget_kv if set.

widget_kv[source]

If set, widget gets constructed.

class acg.fields.ImgField[source]

Bases: acg.fields.OptionsField, acg.fields.MediaField

Let user choose between multiple images.

construct_widget(self)[source]

Bind on_error() to child’s on_error event.

on_error(self, _widget, child, *_)[source]

Remove urls that could not be loaded from template.data.

post_process(self, content)[source]

Download user choice and save to data-base.

class acg.fields.MediaField[source]

Bases: acg.fields.Field

Handles download of a single media-file and content of corresponding field.

The field should only contain the a single url.

file_type[source]

File-type of media-file.

get_file_strings(self)[source]

Get string that embeds the file in the anki-card.

static get_media_file(url)[source]

Download file using requests.get().

post_process(self, content)[source]

Return strings for the fields of the anki-card.

pre_process(self)[source]

Obtain url, download and save file.

save_media_file(self, media_file)[source]

Save media_file to the data-base.

class acg.fields.OptionsField[source]

Bases: acg.fields.Field

Base-class for a field with multiple options to choose from.

get_content(self)[source]

If widget is set, gets content from widget using kv_bidict.

If selection_callback is set, get content from call.

Else simply get the first option as default.

get_data(self)[source]

Get dictionaries to construct children of widget.

update_widget_data(self)[source]

Update widget (if present) with data from get_data().

class acg.fields.TextInputField[source]

Bases: acg.fields.Field

Displays text and lets user edit it.

If callback is set, it will be called on_text_validate, i.e. when the user presses enter while field is in focus.

Useful to bind to templates.Template.search() or templates.Template.update_from_single_parser.

callback[source]

Gets called on_text_validate of the kivy-widget.

construct_widget(self)[source]

Furthermore add field_name as hint-text and bind on_text_validate.

on_text_validate(self, widget)[source]

Wrapper-function for the possible call of callback.

widget_kv[source]

kv-string describing the widget.

class acg.fields.TransChipOptionsField[source]

Bases: acg.fields.TranslationMixin, acg.fields.OptionsField

Pick a single options using custom_widgets.selection_widgets.MyTransChips.

Inheritance from TranslationMixin guarantees that translations are available.

class acg.fields.TranslationMixin[source]

Mixin-Class that adds missing translations to the target_field of the template.data dict.

pre_process(self)[source]

Add translations, where they are missing.

Handles the cases that source and target are strings or list of strings.

src_field[source]

Name of the source_field of template.data.

target_field[source]

Name of the target_field of template.data.

template[source]

Instance of templates.template.

trans_callback[source]

Function that is applied to the data in source field to obtain a translation.

acg.fields.compress_img_bytes(bytes_image, width=512)[source]

Compress image given as bytes (e.g. as content of requests.Response).