Local Card Types
Programming Knowledge
The development of local card types is not very difficult, but it does require a basic understanding of the Python programming language and ImageMagick. I can provide some support for the TCM-specific requirements, but I do not have time to teach these concepts in addition to developing TCM.
If you have an idea for a card type, but are not interested in (or cannot dedicate the time to) developing it yourself, I offer card design as a Sponsor reward on GitHub.
File Location
Any local card type files should be placed inside the card_types directory in
your main config directory. On Docker, this is /config/card_types/, and on
non-Docker this is ./config/card_types/.
TCM will automatically parse all Python (.py) files in this directory.
Syntax Requirements
There are specific requirements for how these Python files and classes must be structured in order to integrate into TCM. These are outlined below.
-
The file must be named the same as the card class.
-
The Python class must be a sub-class of
modules.BaseCardType.BaseCardType. -
The class must define
TITLE_CHARACTERISTICS, which is a dictionary which matches the type definition ofmodules.Title.SplitCharacteristics, which is:class SplitCharacteristics(TypedDict): # Character count to begin splitting titles into multiple lines max_line_width: int # Maximum number of lines a title can take up max_line_count: int # How to split titles into multiple lines style: Literal['top', 'bottom', 'even', 'forced even']Example
FancyTitleCard.py This would make TCM auto-split titles after 20 characters into at most 2 lines, and the titles would be top-heavy (i.e. more text on the first line than the second).
-
The class must define
TITLE_FONTas the string representation of the path to the default Font file. It can be useful to use the path of the Python file itself - accessed withPath(__file__)- or the path of the reference directory used by TCM itself - accessed atBaseCardType.BASE_REF_DIRECTORY.Example
This sets the default Font to a
DefaultFont.ttffile in a folderfancy_filesnext to theFancyTitleCard.pyfile. -
The class must define
TITLE_COLORas a string of the default Font color. Any format of ImageMagick color name is accepted.Example
-
The class must define
DEFAULT_FONT_CASEas the name of the case function to apply to the title text - e.g.blank,lower,source,title, orupper. Each is described below:Font Case Description blankRemove all text lowerMake all text lowercase sourceLeave the text as-is titleApply title texting to - e.g. "Title Text" upperMake all text uppercase Example
-
The class must define
FONT_REPLACEMENTSas a dictionary of text replacements to apply whose keys are the input text to replace with the values as output text. This is typically used for correcting characters missing from the default Font.Example
This would make TCM replace all instances of
éwitheandüwithu. -
The class must define the class initialization method (
__init__) as a function which accepts only keyword arguments (and**). It must have theblur,grayscale, andpreferencesarguments and pass these into thesuper()method. All arguments must be stored as attributes where needed.Example
-
The class must define
__slots__as a tuple of all the attribute names as strings.Example
-
The class must define a
createmethod which accepts no arguments, implements the actual Card creation, and must delete all intermediate files created by the Card.Example
-
The class must define
API_DETAILSas aCardDescriptionobject with all attributes defined. This information is what is displayed in the UI.Example
-
And finally, the class must define an attribute
CardModelclass which is a subclass of either thepydantic.BaseModelor any of theapp.schemas.card_type.BaseCardModelsubclasses - and performs any field validation.Example