Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <bastien@blender.org>2021-08-16 13:42:08 +0300
committerBastien Montagne <bastien@blender.org>2021-08-16 13:45:21 +0300
commit21dc384d15305a01d8f5042ae0d3bde7525fb925 (patch)
treede9440d503730b89f7aecb7da4de1496ea2f2193
parent763da384c5f25fc662ec3eee8c9c2401b92e3e62 (diff)
Translation update: Fix after recent changes to Blender init code.
Recent changes broke calling an operator from python too early during init process, including during first draw calls. So now moved most of `UI_OT_i18n_updatetranslation_svn_init_settings` logic into a static method that can be called directly in this specific case. Also improved situation where init fails, by showing the reset/init settings operator in the UI still.
-rw-r--r--ui_translate/__init__.py2
-rw-r--r--ui_translate/update_ui.py34
2 files changed, 24 insertions, 12 deletions
diff --git a/ui_translate/__init__.py b/ui_translate/__init__.py
index 20f7b884..a03fb56b 100644
--- a/ui_translate/__init__.py
+++ b/ui_translate/__init__.py
@@ -21,7 +21,7 @@
bl_info = {
"name": "Manage UI translations",
"author": "Bastien Montagne",
- "version": (1, 3, 1),
+ "version": (1, 3, 2),
"blender": (2, 92, 0),
"location": "Main \"File\" menu, text editor, any UI control",
"description": "Allows managing UI translations directly from Blender "
diff --git a/ui_translate/update_ui.py b/ui_translate/update_ui.py
index aff41b4c..f9b55b03 100644
--- a/ui_translate/update_ui.py
+++ b/ui_translate/update_ui.py
@@ -159,11 +159,14 @@ class UI_PT_i18n_update_translations_settings(Panel):
i18n_sett = context.window_manager.i18n_update_svn_settings
if not i18n_sett.is_init and bpy.ops.ui.i18n_updatetranslation_svn_init_settings.poll():
- bpy.ops.ui.i18n_updatetranslation_svn_init_settings()
+ # Cannot call the operator from here, this code might run while `pyrna_write_check()` returns False
+ # (which prevents any operator call from Python), during initalization of Blender.
+ UI_OT_i18n_updatetranslation_svn_init_settings.execute_static(context, settings.settings)
if not i18n_sett.is_init:
layout.label(text="Could not init languages data!")
layout.label(text="Please edit the preferences of the UI Translate add-on")
+ layout.operator("ui.i18n_updatetranslation_svn_init_settings", text="Init Settings")
else:
split = layout.split(factor=0.75)
split.template_list("UI_UL_i18n_languages", "", i18n_sett, "langs", i18n_sett, "active_lang", rows=8)
@@ -220,20 +223,20 @@ class UI_OT_i18n_updatetranslation_svn_init_settings(Operator):
def poll(cls, context):
return context.window_manager is not None
- def execute(self, context):
- if not hasattr(self, "settings"):
- self.settings = settings.settings
+ @staticmethod
+ def execute_static(context, self_settings):
i18n_sett = context.window_manager.i18n_update_svn_settings
# First, create the list of languages from settings.
i18n_sett.langs.clear()
- root_br = self.settings.BRANCHES_DIR
- root_tr_po = self.settings.TRUNK_PO_DIR
- root_git_po = self.settings.GIT_I18N_PO_DIR
- root_tr_mo = os.path.join(self.settings.TRUNK_DIR, self.settings.MO_PATH_TEMPLATE, self.settings.MO_FILE_NAME)
+ root_br = self_settings.BRANCHES_DIR
+ root_tr_po = self_settings.TRUNK_PO_DIR
+ root_git_po = self_settings.GIT_I18N_PO_DIR
+ root_tr_mo = os.path.join(self_settings.TRUNK_DIR, self_settings.MO_PATH_TEMPLATE, self_settings.MO_FILE_NAME)
if not (os.path.isdir(root_br) and os.path.isdir(root_tr_po)):
- return {'CANCELLED'}
- for can_use, uid, num_id, name, isocode, po_path_branch in utils_i18n.list_po_dir(root_br, self.settings):
+ i18n_sett.is_init = False
+ return;
+ for can_use, uid, num_id, name, isocode, po_path_branch in utils_i18n.list_po_dir(root_br, self_settings):
lng = i18n_sett.langs.add()
lng.use = can_use
lng.uid = uid
@@ -245,8 +248,17 @@ class UI_OT_i18n_updatetranslation_svn_init_settings(Operator):
lng.mo_path_trunk = root_tr_mo.format(isocode)
lng.po_path_git = os.path.join(root_git_po, isocode + ".po")
- i18n_sett.pot_path = self.settings.FILE_NAME_POT
+ i18n_sett.pot_path = self_settings.FILE_NAME_POT
i18n_sett.is_init = True
+
+ def execute(self, context):
+ if not hasattr(self, "settings"):
+ self.settings = settings.settings
+
+ self.execute_static(context, self.settings)
+
+ if context.window_manager.i18n_update_svn_settings.is_init is False:
+ return {'CANCELLED'}
return {'FINISHED'}