Fix Print3D Toolbox: fix button alignment
[blender-addons.git] / ui_translate / settings.py
blob07479f08ec1079fcd8bc0ae22c53ccdc972c9e6d
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 #####
19 # <pep8 compliant>
21 if "bpy" in locals():
22 import imp
23 imp.reload(settings_i18n)
24 else:
25 import bpy
26 from bpy.props import (BoolProperty,
27 CollectionProperty,
28 EnumProperty,
29 FloatProperty,
30 FloatVectorProperty,
31 IntProperty,
32 PointerProperty,
33 StringProperty,
35 from bl_i18n_utils import settings as settings_i18n
38 import os
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'}
50 # "Parameters"
51 filepath = StringProperty(description="Path to the saved settings file",
52 subtype='FILE_PATH')
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'}
59 else:
60 return self.execute(context)
62 def execute(self, context):
63 if not (self.filepath and settings):
64 return {'CANCELLED'}
65 settings.load(self.filepath, reset=True)
66 return {'FINISHED'}
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'}
75 # "Parameters"
76 filepath = StringProperty(description="Path to the saved settings file",
77 subtype='FILE_PATH')
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'}
84 else:
85 return self.execute(context)
87 def execute(self, context):
88 if not (self.filepath and settings):
89 return {'CANCELLED'}
90 settings.save(self.filepath)
91 return {'FINISHED'}
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'}
102 _settings = settings
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!)",
107 default=True,
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",
115 subtype='FILE_PATH',
116 default="msgfmt",
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",
125 subtype='FILE_PATH',
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(
132 name="Source Root",
133 description="The Blender source root path",
134 subtype='FILE_PATH',
135 default="blender",
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",
143 subtype='FILE_PATH',
144 default="i18n",
145 get=lambda self: self._settings.I18N_DIR,
146 set=lambda self, val: setattr(self._settings, "I18N_DIR", val),
149 SPELL_CACHE = StringProperty(
150 name="Spell Cache",
151 description="A cache storing validated msgids, to avoid re-spellchecking them",
152 subtype='FILE_PATH',
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(
159 name="Import Paths",
160 description="Additional paths to add to sys.path (';' separated)",
161 default="",
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)",
170 subtype='FILE_PATH',
171 default=os.path.join("ui_translate_settings.json"),
173 _is_init = False
175 def draw(self, context):
176 layout = self.layout
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")
187 layout.separator()
188 split = layout.split(0.75)
189 col = split.column()
190 col.prop(self, "persistent_data_path")
191 row = col.row()
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
194 col = split.column()
195 col.operator("ui.i18n_settings_save", text="Save Persistent To...")
196 col.operator("ui.i18n_settings_load", text="Load Persistent From...")