1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
25 importlib
.reload(settings_i18n
)
28 from bpy
.types
import (
32 from bpy
.props
import (
36 from bl_i18n_utils
import settings
as settings_i18n
39 settings
= settings_i18n
.I18nSettings()
42 # Operators ###################################################################
44 class UI_OT_i18n_settings_load(Operator
):
45 """Load translations' settings from a persistent JSon file"""
46 bl_idname
= "ui.i18n_settings_load"
47 bl_label
= "I18n Load Settings"
48 bl_option
= {'REGISTER'}
51 filepath
: StringProperty(
53 description
="Path to the saved settings file",
56 filter_glob
: StringProperty(
60 # /End Operator Arguments
62 def invoke(self
, context
, event
):
63 if not self
.properties
.is_property_set("filepath"):
64 context
.window_manager
.fileselect_add(self
)
65 return {'RUNNING_MODAL'}
67 return self
.execute(context
)
69 def execute(self
, context
):
70 if not (self
.filepath
and settings
):
72 settings
.load(self
.filepath
, reset
=True)
76 class UI_OT_i18n_settings_save(Operator
):
77 """Save translations' settings in a persistent JSon file"""
78 bl_idname
= "ui.i18n_settings_save"
79 bl_label
= "I18n Save Settings"
80 bl_option
= {'REGISTER'}
83 filepath
: StringProperty(
84 description
="Path to the saved settings file",
88 filter_glob
: StringProperty(
92 # /End Operator Arguments
94 def invoke(self
, context
, event
):
95 if not self
.properties
.is_property_set("filepath"):
96 context
.window_manager
.fileselect_add(self
)
97 return {'RUNNING_MODAL'}
99 return self
.execute(context
)
101 def execute(self
, context
):
102 if not (self
.filepath
and settings
):
104 settings
.save(self
.filepath
)
108 # Addon Preferences ###########################################################
110 def _setattr(self
, name
, val
):
111 print(self
, name
, val
)
112 setattr(self
, name
, val
)
115 class UI_AP_i18n_settings(AddonPreferences
):
116 bl_idname
= __name__
.split(".")[0] # We want "top" module name!
117 bl_option
= {'REGISTER'}
121 WARN_MSGID_NOT_CAPITALIZED
: BoolProperty(
122 name
="Warn Msgid Not Capitalized",
123 description
="Warn about messages not starting by a capitalized letter (with a few allowed exceptions!)",
125 get
=lambda self
: self
._settings
.WARN_MSGID_NOT_CAPITALIZED
,
126 set=lambda self
, val
: _setattr(self
._settings
, "WARN_MSGID_NOT_CAPITALIZED", val
),
129 GETTEXT_MSGFMT_EXECUTABLE
: StringProperty(
130 name
="Gettext 'msgfmt' executable",
131 description
="The gettext msgfmt 'compiler'. You’ll likely have to edit it if you’re under Windows",
134 get
=lambda self
: self
._settings
.GETTEXT_MSGFMT_EXECUTABLE
,
135 set=lambda self
, val
: setattr(self
._settings
, "GETTEXT_MSGFMT_EXECUTABLE", val
),
138 FRIBIDI_LIB
: StringProperty(
139 name
="Fribidi Library",
140 description
="The FriBidi C compiled library (.so under Linux, .dll under windows...), you’ll likely have "
141 "to edit it if you’re under Windows, e.g. using the one included in svn's libraries repository",
143 default
="libfribidi.so.0",
144 get
=lambda self
: self
._settings
.FRIBIDI_LIB
,
145 set=lambda self
, val
: setattr(self
._settings
, "FRIBIDI_LIB", val
),
148 SOURCE_DIR
: StringProperty(
150 description
="The Blender source root path",
153 get
=lambda self
: self
._settings
.SOURCE_DIR
,
154 set=lambda self
, val
: setattr(self
._settings
, "SOURCE_DIR", val
),
157 I18N_DIR
: StringProperty(
158 name
="Translation Root",
159 description
="The bf-translation repository",
162 get
=lambda self
: self
._settings
.I18N_DIR
,
163 set=lambda self
, val
: setattr(self
._settings
, "I18N_DIR", val
),
166 SPELL_CACHE
: StringProperty(
168 description
="A cache storing validated msgids, to avoid re-spellchecking them",
170 default
=os
.path
.join("/tmp", ".spell_cache"),
171 get
=lambda self
: self
._settings
.SPELL_CACHE
,
172 set=lambda self
, val
: setattr(self
._settings
, "SPELL_CACHE", val
),
175 PY_SYS_PATHS
: StringProperty(
177 description
="Additional paths to add to sys.path (';' separated)",
179 get
=lambda self
: self
._settings
.PY_SYS_PATHS
,
180 set=lambda self
, val
: setattr(self
._settings
, "PY_SYS_PATHS", val
),
183 persistent_data_path
: StringProperty(
184 name
="Persistent Data Path",
185 description
="The name of a json file storing those settings (unfortunately, Blender's system "
186 "does not work here)",
188 default
=os
.path
.join("ui_translate_settings.json"),
192 def draw(self
, context
):
194 layout
.label(text
="WARNING: preferences are lost when add-on is disabled, be sure to use \"Save Persistent\" "
195 "if you want to keep your settings!")
196 layout
.prop(self
, "WARN_MSGID_NOT_CAPITALIZED")
197 layout
.prop(self
, "GETTEXT_MSGFMT_EXECUTABLE")
198 layout
.prop(self
, "FRIBIDI_LIB")
199 layout
.prop(self
, "SOURCE_DIR")
200 layout
.prop(self
, "I18N_DIR")
201 layout
.prop(self
, "SPELL_CACHE")
202 layout
.prop(self
, "PY_SYS_PATHS")
205 split
= layout
.split(factor
=0.75)
207 col
.prop(self
, "persistent_data_path")
209 row
.operator("ui.i18n_settings_save", text
="Save").filepath
= self
.persistent_data_path
210 row
.operator("ui.i18n_settings_load", text
="Load").filepath
= self
.persistent_data_path
212 col
.operator("ui.i18n_settings_save", text
="Save Persistent To...")
213 col
.operator("ui.i18n_settings_load", text
="Load Persistent From...")
217 UI_OT_i18n_settings_load
,
218 UI_OT_i18n_settings_save
,