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 #####
23 imp
.reload(settings_i18n
)
26 from bpy
.props
import (BoolProperty
,
35 from bl_i18n_utils
import settings
as settings_i18n
41 settings
= settings_i18n
.I18nSettings()
44 class UI_OT_i18n_settings_load(bpy
.types
.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(description
="Path to the saved settings file",
53 filter_glob
= StringProperty(default
="*.json", options
={'HIDDEN'})
55 def invoke(self
, context
, event
):
56 if not self
.properties
.is_property_set("filepath"):
57 context
.window_manager
.fileselect_add(self
)
58 return {'RUNNING_MODAL'}
60 return self
.execute(context
)
62 def execute(self
, context
):
63 if not (self
.filepath
and settings
):
65 settings
.load(self
.filepath
, reset
=True)
69 class UI_OT_i18n_settings_save(bpy
.types
.Operator
):
70 """Save translations' settings in a persistent JSon file"""
71 bl_idname
= "ui.i18n_settings_save"
72 bl_label
= "I18n Save Settings"
73 bl_option
= {'REGISTER'}
76 filepath
= StringProperty(description
="Path to the saved settings file",
78 filter_glob
= StringProperty(default
="*.json", options
={'HIDDEN'})
80 def invoke(self
, context
, event
):
81 if not self
.properties
.is_property_set("filepath"):
82 context
.window_manager
.fileselect_add(self
)
83 return {'RUNNING_MODAL'}
85 return self
.execute(context
)
87 def execute(self
, context
):
88 if not (self
.filepath
and settings
):
90 settings
.save(self
.filepath
)
94 def _setattr(self
, name
, val
):
95 print(self
, name
, val
)
96 setattr(self
, name
, val
)
98 class UI_AP_i18n_settings(bpy
.types
.AddonPreferences
):
99 bl_idname
= __name__
.split(".")[0] # We want "top" module name!
100 bl_option
= {'REGISTER'}
104 WARN_MSGID_NOT_CAPITALIZED
= BoolProperty(
105 name
="Warn Msgid Not Capitalized",
106 description
="Warn about messages not starting by a capitalized letter (with a few allowed exceptions!)",
108 get
=lambda self
: self
._settings
.WARN_MSGID_NOT_CAPITALIZED
,
109 set=lambda self
, val
: _setattr(self
._settings
, "WARN_MSGID_NOT_CAPITALIZED", val
),
112 GETTEXT_MSGFMT_EXECUTABLE
= StringProperty(
113 name
="Gettext 'msgfmt' executable",
114 description
="The gettext msgfmt 'compiler'. You’ll likely have to edit it if you’re under Windows",
117 get
=lambda self
: self
._settings
.GETTEXT_MSGFMT_EXECUTABLE
,
118 set=lambda self
, val
: setattr(self
._settings
, "GETTEXT_MSGFMT_EXECUTABLE", val
),
121 FRIBIDI_LIB
= StringProperty(
122 name
="Fribidi Library",
123 description
="The FriBidi C compiled library (.so under Linux, .dll under windows...), you’ll likely have "
124 "to edit it if you’re under Windows, e.g. using the one included in svn's libraries repository",
126 default
="libfribidi.so.0",
127 get
=lambda self
: self
._settings
.FRIBIDI_LIB
,
128 set=lambda self
, val
: setattr(self
._settings
, "FRIBIDI_LIB", val
),
131 SOURCE_DIR
= StringProperty(
133 description
="The Blender source root path",
136 get
=lambda self
: self
._settings
.SOURCE_DIR
,
137 set=lambda self
, val
: setattr(self
._settings
, "SOURCE_DIR", val
),
140 I18N_DIR
= StringProperty(
141 name
="Translation Root",
142 description
="The bf-translation repository",
145 get
=lambda self
: self
._settings
.I18N_DIR
,
146 set=lambda self
, val
: setattr(self
._settings
, "I18N_DIR", val
),
149 SPELL_CACHE
= StringProperty(
151 description
="A cache storing validated msgids, to avoid re-spellchecking them",
153 default
=os
.path
.join("/tmp", ".spell_cache"),
154 get
=lambda self
: self
._settings
.SPELL_CACHE
,
155 set=lambda self
, val
: setattr(self
._settings
, "SPELL_CACHE", val
),
158 PY_SYS_PATHS
= StringProperty(
160 description
="Additional paths to add to sys.path (';' separated)",
162 get
=lambda self
: self
._settings
.PY_SYS_PATHS
,
163 set=lambda self
, val
: setattr(self
._settings
, "PY_SYS_PATHS", val
),
166 persistent_data_path
= StringProperty(
167 name
="Persistent Data Path",
168 description
="The name of a json file storing those settings (unfortunately, Blender's system "
169 "does not work here)",
171 default
=os
.path
.join("ui_translate_settings.json"),
175 def draw(self
, context
):
177 layout
.label(text
="WARNING: preferences are lost when addon is disabled, be sure to use \"Save Persistent\" "
178 "if you want to keep your settings!")
179 layout
.prop(self
, "WARN_MSGID_NOT_CAPITALIZED")
180 layout
.prop(self
, "GETTEXT_MSGFMT_EXECUTABLE")
181 layout
.prop(self
, "FRIBIDI_LIB")
182 layout
.prop(self
, "SOURCE_DIR")
183 layout
.prop(self
, "I18N_DIR")
184 layout
.prop(self
, "SPELL_CACHE")
185 layout
.prop(self
, "PY_SYS_PATHS")
188 split
= layout
.split(0.75)
190 col
.prop(self
, "persistent_data_path")
192 row
.operator("ui.i18n_settings_save", text
="Save").filepath
= self
.persistent_data_path
193 row
.operator("ui.i18n_settings_load", text
="Load").filepath
= self
.persistent_data_path
195 col
.operator("ui.i18n_settings_save", text
="Save Persistent To...")
196 col
.operator("ui.i18n_settings_load", text
="Load Persistent From...")