mirror of
https://github.com/3b1b/manim.git
synced 2025-11-13 13:27:48 +00:00
Make customization more accessible
This commit is contained in:
parent
d37de184d2
commit
b423a423b5
5 changed files with 31 additions and 22 deletions
|
|
@ -27,6 +27,7 @@ tex:
|
||||||
# intermediate_filetype: "xdv"
|
# intermediate_filetype: "xdv"
|
||||||
universal_import_line: "from manimlib.imports import *"
|
universal_import_line: "from manimlib.imports import *"
|
||||||
style:
|
style:
|
||||||
|
font: "Consolas"
|
||||||
background_color: "#333333"
|
background_color: "#333333"
|
||||||
camera_qualities:
|
camera_qualities:
|
||||||
low:
|
low:
|
||||||
|
|
|
||||||
|
|
@ -77,6 +77,7 @@ from manimlib.scene.vector_space_scene import *
|
||||||
from manimlib.utils.bezier import *
|
from manimlib.utils.bezier import *
|
||||||
from manimlib.utils.color import *
|
from manimlib.utils.color import *
|
||||||
from manimlib.utils.config_ops import *
|
from manimlib.utils.config_ops import *
|
||||||
|
from manimlib.utils.customization import *
|
||||||
from manimlib.utils.debug import *
|
from manimlib.utils.debug import *
|
||||||
from manimlib.utils.directories import *
|
from manimlib.utils.directories import *
|
||||||
from manimlib.utils.images import *
|
from manimlib.utils.images import *
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import cairo
|
||||||
from manimlib.constants import *
|
from manimlib.constants import *
|
||||||
from manimlib.mobject.svg.svg_mobject import SVGMobject
|
from manimlib.mobject.svg.svg_mobject import SVGMobject
|
||||||
from manimlib.utils.config_ops import digest_config
|
from manimlib.utils.config_ops import digest_config
|
||||||
|
from manimlib.utils.customization import get_customization
|
||||||
from manimlib.utils.directories import get_text_dir
|
from manimlib.utils.directories import get_text_dir
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -135,7 +136,7 @@ class Text(SVGMobject):
|
||||||
settings = self.font + self.slant + self.weight
|
settings = self.font + self.slant + self.weight
|
||||||
settings += str(self.t2f) + str(self.t2s) + str(self.t2w)
|
settings += str(self.t2f) + str(self.t2s) + str(self.t2w)
|
||||||
settings += str(self.lsh) + str(self.size)
|
settings += str(self.lsh) + str(self.size)
|
||||||
id_str = self.text+settings
|
id_str = self.text + settings
|
||||||
hasher = hashlib.sha256()
|
hasher = hashlib.sha256()
|
||||||
hasher.update(id_str.encode())
|
hasher.update(id_str.encode())
|
||||||
return hasher.hexdigest()[:16]
|
return hasher.hexdigest()[:16]
|
||||||
|
|
@ -192,11 +193,11 @@ class Text(SVGMobject):
|
||||||
lsh = self.lsh * 10
|
lsh = self.lsh * 10
|
||||||
|
|
||||||
if self.font == '':
|
if self.font == '':
|
||||||
print(NOT_SETTING_FONT_MSG)
|
self.font = get_customization()['style']['font']
|
||||||
|
|
||||||
dir_name = get_text_dir()
|
dir_name = get_text_dir()
|
||||||
hash_name = self.text2hash()
|
hash_name = self.text2hash()
|
||||||
file_name = os.path.join(dir_name, hash_name) +'.svg'
|
file_name = os.path.join(dir_name, hash_name) + '.svg'
|
||||||
if os.path.exists(file_name):
|
if os.path.exists(file_name):
|
||||||
return file_name
|
return file_name
|
||||||
|
|
||||||
|
|
|
||||||
23
manimlib/utils/customization.py
Normal file
23
manimlib/utils/customization.py
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
import os
|
||||||
|
import tempfile
|
||||||
|
|
||||||
|
from manimlib.config import get_custom_defaults
|
||||||
|
from manimlib.config import get_manim_dir
|
||||||
|
|
||||||
|
CUSTOMIZATION = {}
|
||||||
|
|
||||||
|
|
||||||
|
def get_customization():
|
||||||
|
if not CUSTOMIZATION:
|
||||||
|
CUSTOMIZATION.update(get_custom_defaults())
|
||||||
|
directories = CUSTOMIZATION["directories"]
|
||||||
|
# Unless user has specified otherwise, use the system default temp
|
||||||
|
# directory for storing tex files, mobject_data, etc.
|
||||||
|
if not directories["temporary_storage"]:
|
||||||
|
directories["temporary_storage"] = tempfile.gettempdir()
|
||||||
|
|
||||||
|
# Assumes all shaders are written into manimlib/shaders
|
||||||
|
directories["shaders"] = os.path.join(
|
||||||
|
get_manim_dir(), "manimlib", "shaders"
|
||||||
|
)
|
||||||
|
return CUSTOMIZATION
|
||||||
|
|
@ -1,28 +1,11 @@
|
||||||
import os
|
import os
|
||||||
import tempfile
|
|
||||||
|
|
||||||
from manimlib.utils.file_ops import guarantee_existence
|
from manimlib.utils.file_ops import guarantee_existence
|
||||||
from manimlib.config import get_custom_defaults
|
from manimlib.utils.customization import get_customization
|
||||||
from manimlib.config import get_manim_dir
|
|
||||||
|
|
||||||
PRE_COMPUTED_DIRS = {}
|
|
||||||
|
|
||||||
|
|
||||||
def get_directories():
|
def get_directories():
|
||||||
if not PRE_COMPUTED_DIRS:
|
return get_customization()["directories"]
|
||||||
custom_defaults = get_custom_defaults()
|
|
||||||
PRE_COMPUTED_DIRS.update(custom_defaults["directories"])
|
|
||||||
|
|
||||||
# Unless user has specified otherwise, use the system default temp
|
|
||||||
# directory for storing tex files, mobject_data, etc.
|
|
||||||
if not PRE_COMPUTED_DIRS["temporary_storage"]:
|
|
||||||
PRE_COMPUTED_DIRS["temporary_storage"] = tempfile.gettempdir()
|
|
||||||
|
|
||||||
# Assumes all shaders are written into manimlib/shaders
|
|
||||||
PRE_COMPUTED_DIRS["shaders"] = os.path.join(
|
|
||||||
get_manim_dir(), "manimlib", "shaders"
|
|
||||||
)
|
|
||||||
return PRE_COMPUTED_DIRS
|
|
||||||
|
|
||||||
|
|
||||||
def get_temp_dir():
|
def get_temp_dir():
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue