Node Wrangler: do not add reroutes to unavailable outputs
[blender-addons.git] / ui_translate / settings.py
blob23d3b23aa915789470c042fd93f36dcb89d2f50a
1 # SPDX-FileCopyrightText: 2013-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
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 FRIBIDI_LIB: StringProperty(
114 name="Fribidi Library",
115 description="The FriBidi C compiled library (.so under Linux, .dll under windows...), you’ll likely have "
116 "to edit it if you’re under Windows, e.g. using the one included in Blender libraries repository",
117 subtype='FILE_PATH',
118 default="libfribidi.so.0",
119 get=lambda self: self._settings.FRIBIDI_LIB,
120 set=lambda self, val: setattr(self._settings, "FRIBIDI_LIB", val),
123 SOURCE_DIR: StringProperty(
124 name="Source Root",
125 description="The Blender source root path",
126 subtype='FILE_PATH',
127 default="blender",
128 get=lambda self: self._settings.SOURCE_DIR,
129 set=lambda self, val: setattr(self._settings, "SOURCE_DIR", val),
132 I18N_DIR: StringProperty(
133 name="Translation Root",
134 description="The bf-translation repository",
135 subtype='FILE_PATH',
136 default="i18n",
137 get=lambda self: self._settings.I18N_DIR,
138 set=lambda self, val: setattr(self._settings, "I18N_DIR", val),
141 SPELL_CACHE: StringProperty(
142 name="Spell Cache",
143 description="A cache storing validated msgids, to avoid re-spellchecking them",
144 subtype='FILE_PATH',
145 default=os.path.join("/tmp", ".spell_cache"),
146 get=lambda self: self._settings.SPELL_CACHE,
147 set=lambda self, val: setattr(self._settings, "SPELL_CACHE", val),
150 PY_SYS_PATHS: StringProperty(
151 name="Import Paths",
152 description="Additional paths to add to sys.path (';' separated)",
153 default="",
154 get=lambda self: self._settings.PY_SYS_PATHS,
155 set=lambda self, val: setattr(self._settings, "PY_SYS_PATHS", val),
158 persistent_data_path: StringProperty(
159 name="Persistent Data Path",
160 description="The name of a json file storing those settings (unfortunately, Blender's system "
161 "does not work here)",
162 subtype='FILE_PATH',
163 default=os.path.join("ui_translate_settings.json"),
165 _is_init = False
167 def draw(self, context):
168 layout = self.layout
169 layout.label(text="WARNING: preferences are lost when add-on is disabled, be sure to use \"Save Persistent\" "
170 "if you want to keep your settings!")
171 layout.prop(self, "WARN_MSGID_NOT_CAPITALIZED")
172 layout.prop(self, "FRIBIDI_LIB")
173 layout.prop(self, "SOURCE_DIR")
174 layout.prop(self, "I18N_DIR")
175 layout.prop(self, "SPELL_CACHE")
176 layout.prop(self, "PY_SYS_PATHS")
178 layout.separator()
179 split = layout.split(factor=0.75)
180 col = split.column()
181 col.prop(self, "persistent_data_path")
182 row = col.row()
183 row.operator("ui.i18n_settings_save", text="Save").filepath = self.persistent_data_path
184 row.operator("ui.i18n_settings_load", text="Load").filepath = self.persistent_data_path
185 col = split.column()
186 col.operator("ui.i18n_settings_save", text="Save Persistent To...")
187 col.operator("ui.i18n_settings_load", text="Load Persistent From...")
190 classes = (
191 UI_OT_i18n_settings_load,
192 UI_OT_i18n_settings_save,
193 UI_AP_i18n_settings,