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_FONT
as 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.ttf
file in a folderfancy_files
next to theFancyTitleCard.py
file. -
The class must define
TITLE_COLOR
as a string of the default Font color. Any format of ImageMagick color name is accepted.Example
-
The class must define
DEFAULT_FONT_CASE
as 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 blank
Remove all text lower
Make all text lowercase source
Leave the text as-is title
Apply title texting to - e.g. "Title Text" upper
Make all text uppercase Example
-
The class must define
FONT_REPLACEMENTS
as 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
é
withe
andü
withu
. -
The class must define the class initialization method (
__init__
) as a function which accepts only keyword arguments (and**
). It must have theblur
,grayscale
, andpreferences
arguments 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
create
method 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_DETAILS
as aCardDescription
object with all attributes defined. This information is what is displayed in the UI.Example
-
And finally, the class must define an attribute
CardModel
class which is a subclass of either thepydantic.BaseModel
or any of theapp.schemas.card_type.BaseCardModel
subclasses - and performs any field validation.Example