Settings¶
This class controls the appearance and behavior of a plat.
Example Code¶
import pytrsplat
letter_preset = pytrsplat.Settings.preset('letter')
letter_preset.write_lot_numbers = True
plat = pytrsplat.Plat(settings=letter_preset)
# Change settings within the plat's `.settings` attribute.
# Here, changing the header font to the included 'Mono Bold' typeface.
plat.settings.set_font(purpose='header', typeface='Mono (Bold)')
Configure the .settings attribute of a Plat, MegaPlat, or
PlatGroup, or pass it as settings=<some Settings object> when
initializing one.
import pytrsplat
plat_group = pytrsplat.PlatGroup()
plat_group.settings = pytrsplat.Settings.preset('square_s')
mp_default_settings = pytrsplat.Settings.preset('megaplat_default')
mega_plat = pytrsplat.MegaPlat(settings=mp_default_settings)
Important
If you want to change any of the fonts, be sure to use the
.set_font() method.
- class pytrsplat.Settings¶
Configure the look and behavior plats (e.g., size, colors, fonts, whether to write headers/tracts/etc.). Default and presets are available and customizable.
Load a preset with
Settings.preset('some_preset_name'). List existing presets withSettings.list_presets(). Save or alter presets withSettings.save_preset(). Save configurations elsewhere with.to_json(some/path/file.json)and load them withSettings.from_json(some/path/file.json).Note
To establish a separate directory for custom presets for a specific project, change the class variable of
Settings.PRESET_DIRECTORYfor that project before loading any presets. Or presets can be loaded individually from any directory or filepath withSettings.from_json().To change font size and/or typeface, be sure to use
.set_font().All configurable settings:
dim: Dimensions of the plat in px.qq_fill_rgba: RGBA value for filled aliquotssec_length_px: Size of a section line in pxline_stroke: A dict of stroke sizes to use for section lines and subdivisionsline_rgba: A dict of RGBA color codes to use for section lines and subdivisionsmin_depth: How many times to divide each section on the plat. (2 -> QQs; 3 -> QQQs; etc.)max_depth: How small to allow aliquots (2 -> anything smaller than QQ increases to QQ)centerbox_dim: How much of the center of the section white out, in pxlot_num_offset_px: How far off the top-left corner of a QQ to write the lot numberheaderfont_typeface: Path to .ttf file for font to use for header.footerfont_typeface: Path to .ttf file for font to use for footer.secfont_typeface: Path to .ttf file for font to use for section numbers.lotfont_typeface: Path to .ttf file for font to use for lot numbers.headerfont_size: Font size for header.footerfont_size: Font size for footer.secfont_size: Font size for section numbers.lotfont_size: Font size for lot numbers.headerfont_rgba: RGBA for header font.footerfont_rgba: RGBA for footer font.secfont_rgba: RGBA for section number font.lotfont_rgba: RGBA for lot number font.warningfont_rgba: RGBA for warnings font.body_marg_top_y: Distance between top of image and top of first row of sections.header_px_above_body: Distance in px between the top section line and the headerfooter_px_below_body: How many px below the plat grid to begin writing in the footerfooter_marg_left_x: Left margin of the footer (in px)footer_marg_right_x: Right margin of the footer (in px)footer_marg_bottom_y: Bottom margin of the footerfooter_px_between_lines: How many px between lines of text in the footerwrite_header: Whether to write the default header (its Twp/Rge)short_header: Whether to shorten the default header to format ‘T154N-R97W’write_tracts: Whether to write tract descriptions in the footer.write_section_numbers: Whether to write section numberswrite_lot_numbers: Whether to write lot numberslots_only_for_queue: Limit the written lot numbers to sections in the queue.
All included ‘Liberation’ typefaces:
You can use these with
.set_font(purpose='header', typeface='Mono (Bold)', size=48), for example.'Sans-Serif''Sans-Serif (Bold)''Sans-Serif (Bold-Italic)''Sans-Serif (Italic)''Serif''Serif (Bold)''Serif (Bold-Italic)''Serif (Italic)''Mono''Mono (Bold)''Mono (Bold-Italic)''Mono (Italic)'
- classmethod list_presets() list¶
Get a sorted list of current presets in the preset directory (each returned as all lowercase).
- classmethod preset(name: str) Settings¶
Load a saved preset. The specified preset
namemust exist in the existing presets, which can be listed withSettings.list_presets().
- classmethod restore_default() Settings¶
Restore the
'default'presetSettingobject to the original, hard-coded default.
- classmethod restore_presets()¶
Restore the original presets. (Does not affect any presets created by a user.)
- save_preset(name: str)¶
Save this Settings object as a preset (with the name first converted to all lowercase).
- set_font(purpose: str, size: int = None, typeface: str | Path = None, rgba: tuple[int, int, int, int] = None) None¶
Set the font for the specified
purpose. Any unspecified parameters will remain unchanged.- Parameters:
purpose – One of
'header','footer','sec', or'lot'.size – Int of font size.
typeface –
A string specifying which typeface to use, as one of:
Relative path (str) to a stock font (with extension
.ttf) located in thepytrsplat/plat_gen/plat_settings/_fonts/directory.Example:
'_fonts/LiberationSans-Bold.ttf'Absolute path (str) to a font (with extension
.ttf) located anywhere.A key (str) in the
Settings.TYPEFACESdict, which maps keys to absolute paths to.ttffonts. Example:'Sans-Serif (Bold)'
rgba – 4-tuple of RGBA color values (0–255).
- set_layer_fill(layer_name: str, qq_fill_rgba: tuple[int, int, int, int]) None¶
Set the aliquot fill color (RGBA) for a given layer.
Note
These values do not get saved with the
.save_preset()method and must be configured individually each time.- Parameters:
layer_name – Name of the layer to set.
qq_fill_rgba – RGBA of the color to use for aliquots on that layer.
- to_dict() dict¶
Convert the settings to a dict.
- to_json(fp: str | Path) None¶
Save settings to a
.jsonfile at the filepathfp.