Let the user specify which monitor the window should show up in

This commit is contained in:
Grant Sanderson 2021-02-09 10:53:26 -08:00
parent 3770fae6cf
commit 36e8421395
4 changed files with 14 additions and 63 deletions

View file

@ -1,56 +0,0 @@
directories:
# Set this to true if you want the path to video files
# to match the directory structure of the path to the
# sourcecode generating that video
mirror_module_path: False
# Where should manim output video and image files?
output: ""
# If you want to use images, manim will look to these folders to find them
raster_images: ""
vector_images: ""
# If you want to use sounds, manim will look here to find it.
sounds: ""
# Manim often generates tex_files or other kinds of serialized data
# to keep from having to generate the same thing too many times. By
# default, these will be stored at tempfile.gettempdir(), e.g. this might
# return whatever is at to the TMPDIR environment variable. If you want to
# specify them elsewhere,
temporary_storage: ""
tex:
executable: "latex"
template_file: "tex_template.tex"
intermediate_filetype: "dvi"
text_to_replace: "[tex_expression]"
# For ctex, use the following configuration
# executable: "xelatex -no-pdf"
# template_file: "ctex_template.tex"
# intermediate_filetype: "xdv"
universal_import_line: "from manimlib.imports import *"
style:
font: "Consolas"
background_color: "#333333"
# Set the position of preview window, you can use directions, e.g. UL/DR/OL/OO/...
# also, you can also specify the position(pixel) of the upper left corner of
# the window on the monitor, e.g. "960,540"
window_position: UR
# If break_into_partial_movies is set to True, then many small
# files will be written corresponding to each Scene.play and
# Scene.wait call, and these files will then be combined
# to form the full scene. Sometimes video-editing is made
# easier when working with the broken up scene, which
# effectively has cuts at all the places you might want.
break_into_partial_movies: False
camera_qualities:
low:
resolution: "854x480"
frame_rate: 15
medium:
resolution: "1280x720"
frame_rate: 30
high:
resolution: "1920x1080"
frame_rate: 30
ultra_high:
resolution: "3840x2160"
frame_rate: 60
default_quality: "high"

View file

@ -151,13 +151,13 @@ def get_module(file_name):
def get_custom_defaults():
filename = "custom_defaults.yml"
manim_defaults_file = os.path.join(get_manim_dir(), "manimlib", "defaults.yml")
with open(manim_defaults_file, "r") as file:
custom_defaults = yaml.safe_load(file)
# See if there's a custom_defaults file in current directory,
# and if so, it further updates the defaults based on it.
filename = "custom_defaults.yml"
if os.path.exists(filename):
with open(filename, "r") as file:
local_defaults = yaml.safe_load(file)
@ -214,9 +214,9 @@ def get_configuration(args):
# Camera configuration
config["camera_config"] = get_camera_configuration(args, custom_defaults)
# Default to putting window in the upper right of screen,
# Default to making window half the screen size
# but make it full screen if -f is passed in
monitor = get_monitors()[0]
monitor = get_monitors()[custom_defaults["window_monitor"]]
window_width = monitor.width
if not args.full_screen:
window_width //= 2

View file

@ -33,6 +33,7 @@ style:
# also, you can also specify the position(pixel) of the upper left corner of
# the window on the monitor, e.g. "960,540"
window_position: UR
window_monitor: 0
# If break_into_partial_movies is set to True, then many small
# files will be written corresponding to each Scene.play and
# Scene.wait call, and these files will then be combined

View file

@ -20,7 +20,13 @@ class Window(PygletWindow):
self.scene = scene
self.title = str(scene)
self.pressed_keys = set()
self.position = self.find_initial_position()
# No idea why, but when self.position is set once
# it sometimes doesn't actually change the position
# to the specified tuple on the rhs, but doing it
# twice seems to make it work. ¯\_(ツ)_/¯
initial_position = self.find_initial_position()
self.position = initial_position
self.position = initial_position
mglw.activate_context(window=self)
self.timer = Timer()
@ -29,7 +35,7 @@ class Window(PygletWindow):
def find_initial_position(self):
custom_position = get_customization()["window_position"]
monitor = get_monitors()[0]
monitor = get_monitors()[get_customization()["window_monitor"]]
window_width, window_height = self.size
# Position might be specified with a string of the form
# x,y for integers x and y
@ -42,8 +48,8 @@ class Window(PygletWindow):
width_diff = monitor.width - window_width
height_diff = monitor.height - window_height
return (
char_to_n[custom_position[1]] * width_diff // 2,
char_to_n[custom_position[0]] * height_diff // 2,
monitor.x + char_to_n[custom_position[1]] * width_diff // 2,
-monitor.y + char_to_n[custom_position[0]] * height_diff // 2,
)
# Delegate event handling to scene