Fix io_anim_camera error exporting cameras with quotes in their name
[blender-addons.git] / ui_translate / settings.py
blobe9de6537c3c17557c6ec7b95b32b57f8f80a5d0f
1 # SPDX-License-Identifier: GPL-2.0-or-later
3 # <pep8 compliant>
5 import os
7 if "bpy" in locals():
8 import importlib
9 importlib.reload(settings_i18n)
10 else:
11 import bpy
12 from bpy.types import (
13 Operator,
14 AddonPreferences,
16 from bpy.props import (
17 BoolProperty,
18 StringProperty,
20 from bl_i18n_utils import settings as settings_i18n
23 settings = settings_i18n.I18nSettings()
26 # Operators ###################################################################
28 class UI_OT_i18n_settings_load(Operator):
29 """Load translations' settings from a persistent JSon file"""
30 bl_idname = "ui.i18n_settings_load"
31 bl_label = "I18n Load Settings"
32 bl_option = {'REGISTER'}
34 # Operator Arguments
35 filepath: StringProperty(
36 subtype='FILE_PATH',
37 description="Path to the saved settings file",
40 filter_glob: StringProperty(
41 default="*.json",
42 options={'HIDDEN'}
44 # /End Operator Arguments
46 def invoke(self, context, event):
47 if not self.properties.is_property_set("filepath"):
48 context.window_manager.fileselect_add(self)
49 return {'RUNNING_MODAL'}
50 else:
51 return self.execute(context)
53 def execute(self, context):
54 if not (self.filepath and settings):
55 return {'CANCELLED'}
56 settings.load(self.filepath, reset=True)
57 return {'FINISHED'}
60 class UI_OT_i18n_settings_save(Operator):
61 """Save translations' settings in a persistent JSon file"""
62 bl_idname = "ui.i18n_settings_save"
63 bl_label = "I18n Save Settings"
64 bl_option = {'REGISTER'}
66 # Operator Arguments
67 filepath: StringProperty(
68 description="Path to the saved settings file",
69 subtype='FILE_PATH',
72 filter_glob: StringProperty(
73 default="*.json",
74 options={'HIDDEN'},
76 # /End Operator Arguments
78 def invoke(self, context, event):
79 if not self.properties.is_property_set("filepath"):
80 context.window_manager.fileselect_add(self)
81 return {'RUNNING_MODAL'}
82 else:
83 return self.execute(context)
85 def execute(self, context):
86 if not (self.filepath and settings):
87 return {'CANCELLED'}
88 settings.save(self.filepath)
89 return {'FINISHED'}
92 # Addon Preferences ###########################################################
94 def _setattr(self, name, val):
95 print(self, name, val)
96 setattr(self, name, val)
99 class UI_AP_i18n_settings(AddonPreferences):
100 bl_idname = __name__.split(".")[0] # We want "top" module name!
101 bl_option = {'REGISTER'}
103 _settings = settings
105 WARN_MSGID_NOT_CAPITALIZED: BoolProperty(
106 name="Warn Msgid Not Capitalized",
107 description="Warn about messages not starting by a capitalized letter (with a few allowed exceptions!)",
108 default=True,
109 get=lambda self: self._settings.WARN_MSGID_NOT_CAPITALIZED,
110 set=lambda self, val: _setattr(self._settings, "WARN_MSGID_NOT_CAPITALIZED", val),
113 GETTEXT_MSGFMT_EXECUTABLE: StringProperty(
114 name="Gettext 'msgfmt' executable",
115 description="The gettext msgfmt 'compiler'. You’ll likely have to edit it if you’re under Windows",
116 subtype='FILE_PATH',
117 default="msgfmt",
118 get=lambda self: self._settings.GETTEXT_MSGFMT_EXECUTABLE,
119 set=lambda self, val: setattr(self._settings, "GETTEXT_MSGFMT_EXECUTABLE", val),
122 FRIBIDI_LIB: StringProperty(
123 name="Fribidi Library",
124 description="The FriBidi C compiled library (.so under Linux, .dll under windows...), you’ll likely have "
125 "to edit it if you’re under Windows, e.g. using the one included in svn's libraries repository",
126 subtype='FILE_PATH',
127 default="libfribidi.so.0",
128 get=lambda self: self._settings.FRIBIDI_LIB,
129 set=lambda self, val: setattr(self._settings, "FRIBIDI_LIB", val),
132 SOURCE_DIR: StringProperty(
133 name="Source Root",
134 description="The Blender source root path",
135 subtype='FILE_PATH',
136 default="blender",
137 get=lambda self: self._settings.SOURCE_DIR,
138 set=lambda self, val: setattr(self._settings, "SOURCE_DIR", val),
141 I18N_DIR: StringProperty(
142 name="Translation Root",
143 description="The bf-translation repository",
144 subtype='FILE_PATH',
145 default="i18n",
146 get=lambda self: self._settings.I18N_DIR,
147 set=lambda self, val: setattr(self._settings, "I18N_DIR", val),
150 SPELL_CACHE: StringProperty(
151 name="Spell Cache",
152 description="A cache storing validated msgids, to avoid re-spellchecking them",
153 subtype='FILE_PATH',
154 default=os.path.join("/tmp", ".spell_cache"),
155 get=lambda self: self._settings.SPELL_CACHE,
156 set=lambda self, val: setattr(self._settings, "SPELL_CACHE", val),
159 PY_SYS_PATHS: StringProperty(
160 name="Import Paths",
161 description="Additional paths to add to sys.path (';' separated)",
162 default="",
163 get=lambda self: self._settings.PY_SYS_PATHS,
164 set=lambda self, val: setattr(self._settings, "PY_SYS_PATHS", val),
167 persistent_data_path: StringProperty(
168 name="Persistent Data Path",
169 description="The name of a json file storing those settings (unfortunately, Blender's system "
170 "does not work here)",
171 subtype='FILE_PATH',
172 default=os.path.join("ui_translate_settings.json"),
174 _is_init = False
176 def draw(self, context):
177 layout = self.layout
178 layout.label(text="WARNING: preferences are lost when add-on is disabled, be sure to use \"Save Persistent\" "
179 "if you want to keep your settings!")
180 layout.prop(self, "WARN_MSGID_NOT_CAPITALIZED")
181 layout.prop(self, "GETTEXT_MSGFMT_EXECUTABLE")
182 layout.prop(self, "FRIBIDI_LIB")
183 layout.prop(self, "SOURCE_DIR")
184 layout.prop(self, "I18N_DIR")
185 layout.prop(self, "SPELL_CACHE")
186 layout.prop(self, "PY_SYS_PATHS")
188 layout.separator()
189 split = layout.split(factor=0.75)
190 col = split.column()
191 col.prop(self, "persistent_data_path")
192 row = col.row()
193 row.operator("ui.i18n_settings_save", text="Save").filepath = self.persistent_data_path
194 row.operator("ui.i18n_settings_load", text="Load").filepath = self.persistent_data_path
195 col = split.column()
196 col.operator("ui.i18n_settings_save", text="Save Persistent To...")
197 col.operator("ui.i18n_settings_load", text="Load Persistent From...")
200 classes = (
201 UI_OT_i18n_settings_load,
202 UI_OT_i18n_settings_save,
203 UI_AP_i18n_settings,