3b1b / manim

Animation engine for explanatory math videos
MIT License
62.93k stars 5.83k forks source link

Opening quote highlighting doesn't work #262

Open GrahamBenHarper opened 6 years ago

GrahamBenHarper commented 6 years ago

I'm running through some of the older examples and playing with opening quotes. It seems like opening quote highlighting isn't working.

Consider the toy example (although any opening quote from the eoc/eola projects does this):

class FunnyOpeningQuote(OpeningQuote):
    CONFIG = {
        "quote" : [
            "I am ",
            "error", 
            ".",
        ],
        "highlighted_quote_terms" : {
            "error" : RED,
        },
        "author" : "A wise man"
    }

When generating a video from this with python extract_scene.py my_scenes.py FunnyOpeningQuote -pl the following error occurs

Traceback (most recent call last):
  File "extract_scene.py", line 273, in main
    handle_scene(SceneClass(**scene_kwargs), **config)
  File "/home/graham/Programming/Python/manim/scene/scene.py", line 71, in __init__
    self.construct(*self.construct_args)
  File "/home/graham/Programming/Python/manim/for_3b1b_videos/common_scenes.py", line 48, in construct
    self.quote = self.get_quote()
  File "/home/graham/Programming/Python/manim/for_3b1b_videos/common_scenes.py", line 78, in get_quote
    for term, color in self.highlighted_quote_terms:
ValueError: too many values to unpack

This seems like a string parsing error on the part of library, so I looked a little further into it and if I were to provide the following example:

class FunnyOpeningQuote(OpeningQuote):
    CONFIG = {
        "quote" : [
            "I am ",
            "error", 
            ".A",
        ],
        "highlighted_quote_terms" : {
            ".A" : RED,
        },
        "author" : "A wise man"
    }

Then the error provides more useful information:

...
  File "/home/graham/.local/lib/python2.7/site-packages/colour.py", line 990, in __setattr__
    fc(value)
  File "/home/graham/.local/lib/python2.7/site-packages/colour.py", line 1071, in set_web
    self.hex = web2hex(value)
  File "/home/graham/.local/lib/python2.7/site-packages/colour.py", line 667, in web2hex
    raise ValueError("%r is not a recognized color." % web)
ValueError: 'a' is not a recognized color.

To me, this is telling me that instead of reading it as a string followed by a color value, this is reading the entire thing as a sequence of characters followed by a color at the end. I'm not strong on python language, but I'm assuming that this means the following line from common_scenes.py needs to be modified in some way for term, color in self.highlighted_quote_terms: quote.set_color_by_tex(term, color)

Let me know if this is a real issue or if I've gone completely bananas here.

rocka0 commented 6 years ago

Yes, I too am facing the exact same issue. Trying to run the python extract_scene.py returns the same error:

ValueError: too many values to unpack.

Have you found any fix for this issue? Or is it that this is a deprecated feature now and newer versions of Manim don't work with highlighted_quote_terms? @3b1b Any thoughts?

d-siganos commented 5 years ago

Maybe it doesn't access the quote

Aathish04 commented 4 years ago

I know I'm more than a year late, but adding .items() to the end of for term, color in self.highlighted_quote_terms: which is at almost at the end of the get_quote function in the OpeningQuote class like so: for term, color in self.highlighted_quote_terms.items(): should fix the problem, since self_highlighted_quote_terms.items() actually returns the items in the dictionary, unlike self.highlighted_quote_terms. Hope this helps!