refactor: session handler encapsulation
This commit is contained in:
@ -44,7 +44,7 @@ from . import environment, utils
|
|||||||
|
|
||||||
|
|
||||||
DEPENDENCIES = {
|
DEPENDENCIES = {
|
||||||
("replication", '0.0.21a14'),
|
("replication", '0.0.21a15'),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -362,7 +362,7 @@ class SessionUserSync(Timer):
|
|||||||
new_key.username = user
|
new_key.username = user
|
||||||
|
|
||||||
|
|
||||||
class SessionBackgroundExecutor(Timer):
|
class MainThreadExecutor(Timer):
|
||||||
def __init__(self, timout=1, execution_queue=None):
|
def __init__(self, timout=1, execution_queue=None):
|
||||||
super().__init__(timout)
|
super().__init__(timout)
|
||||||
self.execution_queue = execution_queue
|
self.execution_queue = execution_queue
|
||||||
|
@ -43,12 +43,27 @@ from replication.interface import session
|
|||||||
|
|
||||||
|
|
||||||
client = None
|
client = None
|
||||||
background_exec_queue = Queue()
|
background_execution_queue = Queue()
|
||||||
delayables = []
|
delayables = []
|
||||||
stop_modal_executor = False
|
stop_modal_executor = False
|
||||||
|
|
||||||
|
|
||||||
def on_connection_start():
|
def session_callback(name):
|
||||||
|
""" Session callback wrapper
|
||||||
|
|
||||||
|
This allow to encapsulate session callbacks to background_execution_queue.
|
||||||
|
By doing this way callback are executed from the main thread.
|
||||||
|
"""
|
||||||
|
def func_wrapper(func):
|
||||||
|
@session.register(name)
|
||||||
|
def add_background_task():
|
||||||
|
background_execution_queue.put(func)
|
||||||
|
return add_background_task
|
||||||
|
return func_wrapper
|
||||||
|
|
||||||
|
|
||||||
|
@session_callback('on_connection')
|
||||||
|
def initialize_session():
|
||||||
"""Session connection init hander
|
"""Session connection init hander
|
||||||
"""
|
"""
|
||||||
settings = utils.get_preferences()
|
settings = utils.get_preferences()
|
||||||
@ -77,6 +92,8 @@ def on_connection_start():
|
|||||||
if settings.update_method == 'DEPSGRAPH':
|
if settings.update_method == 'DEPSGRAPH':
|
||||||
bpy.app.handlers.depsgraph_update_post.append(depsgraph_evaluation)
|
bpy.app.handlers.depsgraph_update_post.append(depsgraph_evaluation)
|
||||||
|
|
||||||
|
|
||||||
|
@session_callback('on_exit')
|
||||||
def on_connection_end():
|
def on_connection_end():
|
||||||
"""Session connection finished handler
|
"""Session connection finished handler
|
||||||
"""
|
"""
|
||||||
@ -119,7 +136,7 @@ class SessionStartOperator(bpy.types.Operator):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
global client, delayables
|
global delayables
|
||||||
|
|
||||||
settings = utils.get_preferences()
|
settings = utils.get_preferences()
|
||||||
runtime_settings = context.window_manager.session
|
runtime_settings = context.window_manager.session
|
||||||
@ -183,12 +200,11 @@ class SessionStartOperator(bpy.types.Operator):
|
|||||||
timout=type_local_config.bl_delay_apply,
|
timout=type_local_config.bl_delay_apply,
|
||||||
target_type=type_module_class))
|
target_type=type_module_class))
|
||||||
|
|
||||||
session.setup( factory=bpy_factory,
|
session.configure(
|
||||||
|
factory=bpy_factory,
|
||||||
python_path=bpy.app.binary_path_python,
|
python_path=bpy.app.binary_path_python,
|
||||||
external_update_handling=use_extern_update)
|
external_update_handling=use_extern_update)
|
||||||
|
|
||||||
client = session
|
|
||||||
|
|
||||||
if settings.update_method == 'DEPSGRAPH':
|
if settings.update_method == 'DEPSGRAPH':
|
||||||
delayables.append(delayable.ApplyTimer(
|
delayables.append(delayable.ApplyTimer(
|
||||||
settings.depsgraph_update_rate/1000))
|
settings.depsgraph_update_rate/1000))
|
||||||
@ -246,7 +262,8 @@ class SessionStartOperator(bpy.types.Operator):
|
|||||||
|
|
||||||
session_update = delayable.SessionStatusUpdate()
|
session_update = delayable.SessionStatusUpdate()
|
||||||
session_user_sync = delayable.SessionUserSync()
|
session_user_sync = delayable.SessionUserSync()
|
||||||
session_background_executor = delayable.SessionBackgroundExecutor(execution_queue=background_exec_queue)
|
session_background_executor = delayable.MainThreadExecutor(
|
||||||
|
execution_queue=background_execution_queue)
|
||||||
|
|
||||||
session_update.register()
|
session_update.register()
|
||||||
session_user_sync.register()
|
session_user_sync.register()
|
||||||
@ -256,14 +273,6 @@ class SessionStartOperator(bpy.types.Operator):
|
|||||||
delayables.append(session_update)
|
delayables.append(session_update)
|
||||||
delayables.append(session_user_sync)
|
delayables.append(session_user_sync)
|
||||||
|
|
||||||
@session.register('on_connection')
|
|
||||||
def initialize_session():
|
|
||||||
background_exec_queue.put(on_connection_start)
|
|
||||||
|
|
||||||
@session.register('on_exit')
|
|
||||||
def desinitialize_session():
|
|
||||||
background_exec_queue.put(on_connection_end)
|
|
||||||
|
|
||||||
bpy.ops.session.apply_armature_operator()
|
bpy.ops.session.apply_armature_operator()
|
||||||
|
|
||||||
self.report(
|
self.report(
|
||||||
@ -749,9 +758,8 @@ def register():
|
|||||||
|
|
||||||
|
|
||||||
def unregister():
|
def unregister():
|
||||||
if session and session.state['STATE'] == 2:
|
if session and session.state['STATE'] == STATE_ACTIVE:
|
||||||
session.disconnect()
|
session.disconnect()
|
||||||
client = None
|
|
||||||
|
|
||||||
from bpy.utils import unregister_class
|
from bpy.utils import unregister_class
|
||||||
for cls in reversed(classes):
|
for cls in reversed(classes):
|
||||||
|
Reference in New Issue
Block a user