From 9ca3541c827353f4da8656853f6469f2ea7ab320 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Thu, 26 Mar 2020 15:30:46 +0100 Subject: [PATCH] slates are more like package, fixed few bugs and example is in specific file with more data of example --- pype/scripts/slates/__init__.py | 2 + pype/scripts/slates/__main__.py | 10 + pype/scripts/slates/slate_base/api.py | 15 ++ pype/scripts/slates/slate_base/example.py | 254 ++++++++++++++++++++ pype/scripts/slates/slate_base/items.py | 1 + pype/scripts/slates/{ => slate_base}/lib.py | 69 ++---- 6 files changed, 300 insertions(+), 51 deletions(-) create mode 100644 pype/scripts/slates/__init__.py create mode 100644 pype/scripts/slates/__main__.py create mode 100644 pype/scripts/slates/slate_base/api.py create mode 100644 pype/scripts/slates/slate_base/example.py rename pype/scripts/slates/{ => slate_base}/lib.py (63%) diff --git a/pype/scripts/slates/__init__.py b/pype/scripts/slates/__init__.py new file mode 100644 index 0000000000..52937708ea --- /dev/null +++ b/pype/scripts/slates/__init__.py @@ -0,0 +1,2 @@ +from . import slate_base +from .slate_base import api diff --git a/pype/scripts/slates/__main__.py b/pype/scripts/slates/__main__.py new file mode 100644 index 0000000000..29282d3226 --- /dev/null +++ b/pype/scripts/slates/__main__.py @@ -0,0 +1,10 @@ +from slate_base import api + + +def main(in_args=None): + # TODO proper argument handling + api.example() + + +if __name__ == "__main__": + main() diff --git a/pype/scripts/slates/slate_base/api.py b/pype/scripts/slates/slate_base/api.py new file mode 100644 index 0000000000..cd64c68134 --- /dev/null +++ b/pype/scripts/slates/slate_base/api.py @@ -0,0 +1,15 @@ +from .font_factory import FontFactory +from .base import BaseObj, load_default_style +from .main_frame import MainFrame +from .layer import Layer +from .items import ( + BaseItem, + ItemImage, + ItemRectangle, + ItemPlaceHolder, + ItemText, + ItemTable, + TableField +) +from .lib import create_slates +from .example import example diff --git a/pype/scripts/slates/slate_base/example.py b/pype/scripts/slates/slate_base/example.py new file mode 100644 index 0000000000..560f9ec02d --- /dev/null +++ b/pype/scripts/slates/slate_base/example.py @@ -0,0 +1,254 @@ +# import sys +# sys.append(r"PATH/TO/PILLOW/PACKAGE") + +from . import api + + +def example(): + """Example data to demontrate function. + + It is required to fill "destination_path", "thumbnail_path" + and "color_bar_path" in `example_fill_data` to be able to execute. + """ + + example_fill_data = { + "destination_path": "PATH/TO/OUTPUT/FILE", + "project": { + "name": "Testing project" + }, + "intent": "WIP", + "version_name": "seq01_sh0100_compositing_v01", + "date": "2019-08-09", + "shot_type": "2d comp", + "submission_note": ( + "Lorem ipsum dolor sit amet, consectetuer adipiscing elit." + " Aenean commodo ligula eget dolor. Aenean massa." + " Cum sociis natoque penatibus et magnis dis parturient montes," + " nascetur ridiculus mus. Donec quam felis, ultricies nec," + " pellentesque eu, pretium quis, sem. Nulla consequat massa quis" + " enim. Donec pede justo, fringilla vel," + " aliquet nec, vulputate eget, arcu." + ), + "thumbnail_path": "PATH/TO/THUMBNAIL/FILE", + "color_bar_path": "PATH/TO/COLOR/BAR/FILE", + "vendor": "Our Studio", + "shot_name": "sh0100", + "frame_start": 1001, + "frame_end": 1004, + "duration": 3 + } + + example_presets = {"example_HD": { + "width": 1920, + "height": 1080, + "destination_path": "{destination_path}", + "style": { + "*": { + "font-family": "arial", + "font-color": "#ffffff", + "font-bold": False, + "font-italic": False, + "bg-color": "#0077ff", + "alignment-horizontal": "left", + "alignment-vertical": "top" + }, + "layer": { + "padding": 0, + "margin": 0 + }, + "rectangle": { + "padding": 0, + "margin": 0, + "bg-color": "#E9324B", + "fill": True + }, + "main_frame": { + "padding": 0, + "margin": 0, + "bg-color": "#252525" + }, + "table": { + "padding": 0, + "margin": 0, + "bg-color": "transparent" + }, + "table-item": { + "padding": 5, + "padding-bottom": 10, + "margin": 0, + "bg-color": "#212121", + "bg-alter-color": "#272727", + "font-color": "#dcdcdc", + "font-bold": False, + "font-italic": False, + "alignment-horizontal": "left", + "alignment-vertical": "top", + "word-wrap": False, + "ellide": True, + "max-lines": 1 + }, + "table-item-col[0]": { + "font-size": 20, + "font-color": "#898989", + "font-bold": True, + "ellide": False, + "word-wrap": True, + "max-lines": None + }, + "table-item-col[1]": { + "font-size": 40, + "padding-left": 10 + }, + "#colorbar": { + "bg-color": "#9932CC" + } + }, + "items": [{ + "type": "layer", + "direction": 1, + "name": "MainLayer", + "style": { + "#MainLayer": { + "width": 1094, + "height": 1000, + "margin": 25, + "padding": 0 + }, + "#LeftSide": { + "margin-right": 25 + } + }, + "items": [{ + "type": "layer", + "name": "LeftSide", + "items": [{ + "type": "layer", + "direction": 1, + "style": { + "table-item": { + "bg-color": "transparent", + "padding-bottom": 20 + }, + "table-item-col[0]": { + "font-size": 20, + "font-color": "#898989", + "alignment-horizontal": "right" + }, + "table-item-col[1]": { + "alignment-horizontal": "left", + "font-bold": True, + "font-size": 40 + } + }, + "items": [{ + "type": "table", + "values": [ + ["Show:", "{project[name]}"] + ], + "style": { + "table-item-field[0:0]": { + "width": 150 + }, + "table-item-field[0:1]": { + "width": 580 + } + } + }, { + "type": "table", + "values": [ + ["Submitting For:", "{intent}"] + ], + "style": { + "table-item-field[0:0]": { + "width": 160 + }, + "table-item-field[0:1]": { + "width": 218, + "alignment-horizontal": "right" + } + } + }] + }, { + "type": "rectangle", + "style": { + "bg-color": "#bc1015", + "width": 1108, + "height": 5, + "fill": True + } + }, { + "type": "table", + "use_alternate_color": True, + "values": [ + ["Version name:", "{version_name}"], + ["Date:", "{date}"], + ["Shot Types:", "{shot_type}"], + ["Submission Note:", "{submission_note}"] + ], + "style": { + "table-item": { + "padding-bottom": 20 + }, + "table-item-field[0:1]": { + "font-bold": True + }, + "table-item-field[3:0]": { + "word-wrap": True, + "ellide": True, + "max-lines": 4 + }, + "table-item-col[0]": { + "alignment-horizontal": "right", + "width": 150 + }, + "table-item-col[1]": { + "alignment-horizontal": "left", + "width": 958 + } + } + }] + }, { + "type": "layer", + "name": "RightSide", + "items": [{ + "type": "placeholder", + "name": "thumbnail", + "path": "{thumbnail_path}", + "style": { + "width": 730, + "height": 412 + } + }, { + "type": "placeholder", + "name": "colorbar", + "path": "{color_bar_path}", + "return_data": True, + "style": { + "width": 730, + "height": 55 + } + }, { + "type": "table", + "use_alternate_color": True, + "values": [ + ["Vendor:", "{vendor}"], + ["Shot Name:", "{shot_name}"], + ["Frames:", "{frame_start} - {frame_end} ({duration})"] + ], + "style": { + "table-item-col[0]": { + "alignment-horizontal": "left", + "width": 200 + }, + "table-item-col[1]": { + "alignment-horizontal": "right", + "width": 530, + "font-size": 30 + } + } + }] + }] + }] + }} + + api.create_slates(example_fill_data, "example_HD", example_presets) diff --git a/pype/scripts/slates/slate_base/items.py b/pype/scripts/slates/slate_base/items.py index ea31443f80..1183d73305 100644 --- a/pype/scripts/slates/slate_base/items.py +++ b/pype/scripts/slates/slate_base/items.py @@ -1,3 +1,4 @@ +import os import re from PIL import Image diff --git a/pype/scripts/slates/lib.py b/pype/scripts/slates/slate_base/lib.py similarity index 63% rename from pype/scripts/slates/lib.py rename to pype/scripts/slates/slate_base/lib.py index 154c689349..3c7a465e98 100644 --- a/pype/scripts/slates/lib.py +++ b/pype/scripts/slates/slate_base/lib.py @@ -1,17 +1,19 @@ import logging - try: from queue import Queue except Exception: from Queue import Queue -from .slate_base.main_frame import MainFrame -from .slate_base.layer import Layer -from .slate_base.items import ( +from .main_frame import MainFrame +from .layer import Layer +from .items import ( ItemTable, ItemImage, ItemRectangle, ItemPlaceHolder ) -from pypeapp import config +try: + from pypeapp.config import get_presets +except Exception: + get_presets = dict log = logging.getLogger(__name__) @@ -19,17 +21,20 @@ log = logging.getLogger(__name__) RequiredSlateKeys = ["width", "height", "destination_path"] -def create_slates(fill_data, slate_name): - presets = config.get_presets() - slate_presets = ( - presets - .get("tools", {}) - .get("slates") - ) or {} +def create_slates(fill_data, slate_name, slate_presets=None): + if slate_presets is None: + presets = get_presets() + slate_presets = ( + presets + .get("tools", {}) + .get("slates") + ) or {} slate_data = slate_presets.get(slate_name) if not slate_data: - log.error("Slate data of <{}> does not exists.") + log.error( + "Name \"{}\" was not found in slate presets.".format(slate_name) + ) return False missing_keys = [] @@ -111,41 +116,3 @@ def create_slates(fill_data, slate_name): main.draw() log.debug("Slate creation finished") - - -def example(): - # import sys - # sys.append(r"PATH/TO/PILLOW/PACKAGE") - # sys.append(r"PATH/TO/PYPE-SETUP") - - fill_data = { - "destination_path": "PATH/TO/OUTPUT/FILE", - "project": { - "name": "Testing project" - }, - "intent": "WIP", - "version_name": "seq01_sh0100_compositing_v01", - "date": "2019-08-09", - "shot_type": "2d comp", - "submission_note": ( - "Lorem ipsum dolor sit amet, consectetuer adipiscing elit." - " Aenean commodo ligula eget dolor. Aenean massa." - " Cum sociis natoque penatibus et magnis dis parturient montes," - " nascetur ridiculus mus. Donec quam felis, ultricies nec," - " pellentesque eu, pretium quis, sem. Nulla consequat massa quis" - " enim. Donec pede justo, fringilla vel," - " aliquet nec, vulputate eget, arcu." - ), - "thumbnail_path": "PATH/TO/THUMBNAIL/FILE", - "color_bar_path": "PATH/TO/COLOR/BAR/FILE", - "vendor": "Our Studio", - "shot_name": "sh0100", - "frame_start": 1001, - "frame_end": 1004, - "duration": 3 - } - create_slates(fill_data, "example_HD") - - -if __name__ == "__main__": - example()