Fix FPS menu in "Format" panel not following translation setting

The FPS menu was using a cached value which wasn't being refreshed
when translation changed.

Add `bpy.app.handlers.translation_update_post` handler which runs
when translation changes, this can be used to clear any cached UI
values.

Ref !117049
This commit is contained in:
Damien Picard
2024-01-18 11:25:48 +11:00
committed by Campbell Barton
parent d068407a00
commit 8564e03cdf
4 changed files with 29 additions and 5 deletions

View File

@@ -104,6 +104,13 @@ _modules_loaded = [_namespace[name] for name in _modules]
del _namespace
# Bypass the caching mechanism in the "Format" panel to make sure it is properly translated on language update.
@bpy.app.handlers.persistent
def translation_update(_):
from .properties_output import RENDER_PT_format
RENDER_PT_format._frame_rate_args_prev = None
def register():
from bpy.utils import register_class
for mod in _modules_loaded:
@@ -166,6 +173,8 @@ def register():
)
del items
bpy.app.handlers.translation_update_post.append(translation_update)
# done...
@@ -176,6 +185,11 @@ def unregister():
if cls.is_registered:
unregister_class(cls)
try:
bpy.app.handlers.translation_update_post.remove(translation_update)
except ValueError:
pass
# Define a default UIList, when a list does not need any custom drawing...
# Keep in sync with its #defined name in UI_interface.hh

View File

@@ -109,6 +109,7 @@ typedef enum {
BKE_CB_EVT_COMPOSITE_CANCEL,
BKE_CB_EVT_ANIMATION_PLAYBACK_PRE,
BKE_CB_EVT_ANIMATION_PLAYBACK_POST,
BKE_CB_EVT_TRANSLATION_UPDATE_POST,
BKE_CB_EVT_EXTENSION_REPOS_UPDATE_PRE,
BKE_CB_EVT_EXTENSION_REPOS_UPDATE_POST,
BKE_CB_EVT_TOT,

View File

@@ -324,7 +324,7 @@ static void rna_userdef_font_update(Main * /*bmain*/, Scene * /*scene*/, Pointer
UI_reinit_font();
}
static void rna_userdef_language_update(Main * /*bmain*/, Scene * /*scene*/, PointerRNA * /*ptr*/)
static void rna_userdef_language_update(Main *bmain, Scene * /*scene*/, PointerRNA * /*ptr*/)
{
BLT_lang_set(nullptr);
@@ -336,6 +336,14 @@ static void rna_userdef_language_update(Main * /*bmain*/, Scene * /*scene*/, Poi
U.transopts |= (USER_TR_IFACE | USER_TR_TOOLTIPS | USER_TR_REPORTS | USER_TR_NEWDATANAME);
}
BKE_callback_exec_null(bmain, BKE_CB_EVT_TRANSLATION_UPDATE_POST);
USERDEF_TAG_DIRTY;
}
static void rna_userdef_translation_update(Main *bmain, Scene * /*scene*/, PointerRNA * /*ptr*/)
{
BKE_callback_exec_null(bmain, BKE_CB_EVT_TRANSLATION_UPDATE_POST);
WM_main_add_notifier(NC_WINDOW, nullptr);
USERDEF_TAG_DIRTY;
}
@@ -5226,7 +5234,7 @@ static void rna_def_userdef_view(BlenderRNA *brna)
RNA_def_property_ui_text(prop,
"Translate Tooltips",
"Translate the descriptions when hovering UI elements (recommended)");
RNA_def_property_update(prop, 0, "rna_userdef_update");
RNA_def_property_update(prop, 0, "rna_userdef_translation_update");
prop = RNA_def_property(srna, "use_translate_interface", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, nullptr, "transopts", USER_TR_IFACE);
@@ -5235,20 +5243,20 @@ static void rna_def_userdef_view(BlenderRNA *brna)
"Translate Interface",
"Translate all labels in menus, buttons and panels "
"(note that this might make it hard to follow tutorials or the manual)");
RNA_def_property_update(prop, 0, "rna_userdef_update");
RNA_def_property_update(prop, 0, "rna_userdef_translation_update");
prop = RNA_def_property(srna, "use_translate_reports", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, nullptr, "transopts", USER_TR_REPORTS);
RNA_def_property_ui_text(
prop, "Translate Reports", "Translate additional information, such as error messages");
RNA_def_property_update(prop, 0, "rna_userdef_update");
RNA_def_property_update(prop, 0, "rna_userdef_translation_update");
prop = RNA_def_property(srna, "use_translate_new_dataname", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, nullptr, "transopts", USER_TR_NEWDATANAME);
RNA_def_property_ui_text(prop,
"Translate New Names",
"Translate the names of new data-blocks (objects, materials...)");
RNA_def_property_update(prop, 0, "rna_userdef_update");
RNA_def_property_update(prop, 0, "rna_userdef_translation_update");
/* Status-bar. */

View File

@@ -90,6 +90,7 @@ static PyStructSequence_Field app_cb_info_fields[] = {
{"composite_cancel", "on a compositing background job (cancel)"},
{"animation_playback_pre", "on starting animation playback"},
{"animation_playback_post", "on ending animation playback"},
{"translation_update_post", "on translation settings update"},
/* NOTE(@ideasman42): This avoids bad-level calls into BPY API
* but should not be considered part of the public Python API.
* If there is a compelling reason to make these public, the leading `_` can be removed. */