Moved use of global variable to a context manager
This commit is contained in:
parent
8367abeeb9
commit
f6d797512a
@ -1,5 +1,6 @@
|
|||||||
"""Handle saving and loading project-specific settings."""
|
"""Handle saving and loading project-specific settings."""
|
||||||
|
|
||||||
|
import contextlib
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
# Names of BlenderCloudPreferences properties that are both project-specific
|
# Names of BlenderCloudPreferences properties that are both project-specific
|
||||||
@ -16,6 +17,17 @@ log = logging.getLogger(__name__)
|
|||||||
project_settings_loading = False
|
project_settings_loading = False
|
||||||
|
|
||||||
|
|
||||||
|
@contextlib.contextmanager
|
||||||
|
def mark_as_loading():
|
||||||
|
"""Sets project_settings_loading=True while the context is active."""
|
||||||
|
global project_settings_loading
|
||||||
|
project_settings_loading = True
|
||||||
|
try:
|
||||||
|
yield
|
||||||
|
finally:
|
||||||
|
project_settings_loading = False
|
||||||
|
|
||||||
|
|
||||||
def handle_project_update(_=None, _2=None):
|
def handle_project_update(_=None, _2=None):
|
||||||
"""Handles changing projects, which may cause extensions to be disabled/enabled.
|
"""Handles changing projects, which may cause extensions to be disabled/enabled.
|
||||||
|
|
||||||
@ -24,9 +36,7 @@ def handle_project_update(_=None, _2=None):
|
|||||||
|
|
||||||
from .blender import preferences, project_extensions
|
from .blender import preferences, project_extensions
|
||||||
|
|
||||||
global project_settings_loading
|
with mark_as_loading():
|
||||||
project_settings_loading = True
|
|
||||||
try:
|
|
||||||
prefs = preferences()
|
prefs = preferences()
|
||||||
project_id = prefs.project.project
|
project_id = prefs.project.project
|
||||||
log.info('Updating internal state to reflect extensions enabled on current project %s.',
|
log.info('Updating internal state to reflect extensions enabled on current project %s.',
|
||||||
@ -75,8 +85,6 @@ def handle_project_update(_=None, _2=None):
|
|||||||
prefs.flamenco_job_file_path = mps['file_path']
|
prefs.flamenco_job_file_path = mps['file_path']
|
||||||
prefs.flamenco_job_output_path = mps['output_path']
|
prefs.flamenco_job_output_path = mps['output_path']
|
||||||
prefs.flamenco_job_output_strip_components = mps['output_strip_components']
|
prefs.flamenco_job_output_strip_components = mps['output_strip_components']
|
||||||
finally:
|
|
||||||
project_settings_loading = False
|
|
||||||
|
|
||||||
|
|
||||||
def store(_=None, _2=None):
|
def store(_=None, _2=None):
|
||||||
|
Reference in New Issue
Block a user