File headers: use SPDX license identifiers
[blender-addons.git] / power_sequencer / addon_preferences.py
blob014f63ddb7e4b8fbf6a2a4a2220cd18d0125eb26
2 # Copyright (C) 2016-2020 by Nathan Lovato, Daniel Oakey, Razvan Radulescu, and contributors
4 # This file is part of Power Sequencer.
6 # Power Sequencer is free software: you can redistribute it and/or modify it under the terms of the
7 # GNU General Public License as published by the Free Software Foundation, either version 3 of the
8 # License, or (at your option) any later version.
10 # Power Sequencer is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
11 # without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along with Power Sequencer. If
15 # not, see <https://www.gnu.org/licenses/>.
17 """
18 Add-on preferences and interface in the Blender preferences window.
19 """
20 import subprocess
22 import bpy
23 from bpy.props import BoolProperty, StringProperty
26 def get_preferences(context):
27 return context.preferences.addons[__package__].preferences
30 class PowerSequencerPreferences(bpy.types.AddonPreferences):
31 bl_idname = __package__
33 proxy_25: bpy.props.BoolProperty(name="25%", default=False)
34 proxy_50: bpy.props.BoolProperty(name="50%", default=False)
35 proxy_75: bpy.props.BoolProperty(name="75%", default=False)
36 proxy_100: bpy.props.BoolProperty(name="100%", default=False)
38 # Code adapted from Krzysztof TrzciƄski's work
39 ffmpeg_executable: StringProperty(
40 name="Path to ffmpeg executable",
41 default="",
42 update=lambda self, context: self.update_ffmpeg_executable(context),
43 subtype="FILE_PATH",
45 ffmpeg_status: StringProperty(default="")
46 ffmpeg_is_executable_valid: BoolProperty(default=False)
48 def update_ffmpeg_executable(self, context):
49 error_message, info = self._try_run_ffmpeg(self.ffmpeg_executable)
50 self.ffmpeg_is_executable_valid = error_message == ""
51 self.ffmpeg_status = error_message if error_message != "" else info
53 def _try_run_ffmpeg(self, path):
54 """Runs ffmpeg -version, and returns an error message if it failed"""
55 error_message, info = "", ""
56 try:
57 info: str = subprocess.check_output([path, "-version"]).decode("utf-8")
58 info = info[: info.find("Copyright")]
59 print(info)
60 except (OSError, subprocess.CalledProcessError):
61 error_message = "Path `{}` is not a valid ffmpeg executable".format(path)
62 return error_message, info
64 def draw(self, context):
65 layout = self.layout
67 layout.label(text="Proxy")
69 row = layout.row()
70 row.prop(self, "proxy_25")
71 row.prop(self, "proxy_50")
72 row.prop(self, "proxy_75")
73 row.prop(self, "proxy_100")
75 text = [
76 "(Optional) FFMpeg executable to use for multithread renders and proxy generation. "
77 "Use this to render with a version of ffmpeg that's not on your system's PATH variable."
79 for line in text:
80 layout.label(text=line)
81 layout.prop(self, "ffmpeg_executable")
82 icon = "INFO" if self.ffmpeg_is_executable_valid else "ERROR"
83 layout.label(text=self.ffmpeg_status, icon=icon)
86 register_preferences, unregister_preferences = bpy.utils.register_classes_factory(
87 [PowerSequencerPreferences]