text referencing others
This commit is contained in:
+14
-4
@@ -63,10 +63,19 @@ def load_item(i, item):
|
|||||||
raw_texts = utils.read_key(item, "texts", meme.texts, types=[dict], is_list=True)
|
raw_texts = utils.read_key(item, "texts", meme.texts, types=[dict], is_list=True)
|
||||||
if "texts" in item:
|
if "texts" in item:
|
||||||
meme.texts = []
|
meme.texts = []
|
||||||
|
c = 1
|
||||||
for j in range(len(raw_texts)):
|
for j in range(len(raw_texts)):
|
||||||
raw_text = raw_texts[j]
|
raw_text = raw_texts[j]
|
||||||
try:
|
try:
|
||||||
meme.texts += [load_text(j, raw_text)]
|
text = load_text(c, raw_text)
|
||||||
|
if text.text_ref is None:
|
||||||
|
c += 1
|
||||||
|
elif text.text_ref < 0 or text.text_ref >= len(meme.texts):
|
||||||
|
logger.warning(f"Item '{item_id}'({i}) / Text {j}: invalid text reference {text.text_ref}")
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
text.text = meme.texts[text.text_ref].text
|
||||||
|
meme.texts += [text]
|
||||||
except TypeError as e:
|
except TypeError as e:
|
||||||
logger.warning(f"Item '{item_id}'({i}) / Text {j}: {e}")
|
logger.warning(f"Item '{item_id}'({i}) / Text {j}: {e}")
|
||||||
for text in meme.texts:
|
for text in meme.texts:
|
||||||
@@ -89,11 +98,11 @@ def load_item(i, item):
|
|||||||
logger.warning(f"Item '{item_id}'({i}): {e}")
|
logger.warning(f"Item '{item_id}'({i}): {e}")
|
||||||
|
|
||||||
|
|
||||||
def load_text(j, raw_text, text=None):
|
def load_text(c, raw_text, text=None):
|
||||||
"""
|
"""
|
||||||
TODO
|
TODO
|
||||||
|
|
||||||
:param (int) j:
|
:param (int) c:
|
||||||
:param (dict) raw_text:
|
:param (dict) raw_text:
|
||||||
:param (Text|None) text:
|
:param (Text|None) text:
|
||||||
:raises TypeError:
|
:raises TypeError:
|
||||||
@@ -101,10 +110,11 @@ def load_text(j, raw_text, text=None):
|
|||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
if text is None:
|
if text is None:
|
||||||
text = Text(f"text {j + 1}")
|
text = Text(f"text {c}")
|
||||||
text.font = utils.read_key_safe(raw_text, "font", text.font, types=[str])
|
text.font = utils.read_key_safe(raw_text, "font", text.font, types=[str])
|
||||||
text.x_range = utils.read_key_safe(raw_text, "x_range", types=[float, int], is_list=True, is_list_size=2)
|
text.x_range = utils.read_key_safe(raw_text, "x_range", types=[float, int], is_list=True, is_list_size=2)
|
||||||
text.y_range = utils.read_key_safe(raw_text, "y_range", types=[float, int], is_list=True, is_list_size=2)
|
text.y_range = utils.read_key_safe(raw_text, "y_range", types=[float, int], is_list=True, is_list_size=2)
|
||||||
|
text.text_ref = utils.read_key_safe(raw_text, "text_ref", types=[int])
|
||||||
text.angle = utils.read_key_safe(raw_text, "angle", types=[float, int])
|
text.angle = utils.read_key_safe(raw_text, "angle", types=[float, int])
|
||||||
text.font_size = utils.read_key_safe(raw_text, "font_size", text.font_size, types=[float, int])
|
text.font_size = utils.read_key_safe(raw_text, "font_size", text.font_size, types=[float, int])
|
||||||
text.fill = utils.read_key_safe(raw_text, "fill", text.fill, types=[int], is_list=True, is_list_size=3)
|
text.fill = utils.read_key_safe(raw_text, "fill", text.fill, types=[int], is_list=True, is_list_size=3)
|
||||||
|
|||||||
@@ -39,11 +39,16 @@ def compute(*args, left_wmark_text=None, debug=False):
|
|||||||
logger.warning(f"Meme template '{meme_id}' not found")
|
logger.warning(f"Meme template '{meme_id}' not found")
|
||||||
return None
|
return None
|
||||||
if len(args) > 1:
|
if len(args) > 1:
|
||||||
|
c = 0
|
||||||
for i in range(len(meme.texts)):
|
for i in range(len(meme.texts)):
|
||||||
|
if meme.texts[i].text_ref is None:
|
||||||
if i < len(args) - 1:
|
if i < len(args) - 1:
|
||||||
meme.texts[i].text = args[i + 1]
|
meme.texts[i].text = args[c + 1]
|
||||||
else:
|
else:
|
||||||
meme.texts[i].text = ""
|
meme.texts[i].text = ""
|
||||||
|
c += 1
|
||||||
|
else:
|
||||||
|
meme.texts[i].text = meme.texts[meme.texts[i].text_ref].text
|
||||||
meme.texts += [right_wmark]
|
meme.texts += [right_wmark]
|
||||||
if left_wmark_text is not None:
|
if left_wmark_text is not None:
|
||||||
left_wmark.text = left_wmark_text
|
left_wmark.text = left_wmark_text
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ class Text:
|
|||||||
|
|
||||||
def __init__(self, text=None):
|
def __init__(self, text=None):
|
||||||
self.text = text
|
self.text = text
|
||||||
|
self.text_ref = None
|
||||||
|
|
||||||
self.x_range = (0, 1)
|
self.x_range = (0, 1)
|
||||||
self.y_range = (0, 1)
|
self.y_range = (0, 1)
|
||||||
|
|||||||
Reference in New Issue
Block a user