refactor: cleanup

related to #18
This commit is contained in:
Swann Martinez
2019-12-02 17:34:08 +01:00
parent a12d32341c
commit 315c2903c0

View File

@ -32,6 +32,8 @@ stop_modal_executor = False
modal_executor_queue = None modal_executor_queue = None
# OPERATORS # OPERATORS
class SessionStartOperator(bpy.types.Operator): class SessionStartOperator(bpy.types.Operator):
bl_idname = "session.start" bl_idname = "session.start"
bl_label = "start" bl_label = "start"
@ -104,8 +106,6 @@ class SessionStartOperator(bpy.types.Operator):
"A session is already hosted on this address") "A session is already hosted on this address")
return {"CANCELLED"} return {"CANCELLED"}
# Init user settings # Init user settings
usr = presence.User( usr = presence.User(
username=settings.username, username=settings.username,
@ -115,7 +115,7 @@ class SessionStartOperator(bpy.types.Operator):
1), 1),
) )
settings.user_uuid = client.add(usr,owner=settings.username) settings.user_uuid = client.add(usr, owner=settings.username)
client.commit(settings.user_uuid) client.commit(settings.user_uuid)
if settings.init_scene and self.host: if settings.init_scene and self.host:
@ -142,7 +142,7 @@ class SessionStartOperator(bpy.types.Operator):
global modal_executor_queue global modal_executor_queue
modal_executor_queue = queue.Queue() modal_executor_queue = queue.Queue()
bpy.ops.wm.modal_executor_operator() bpy.ops.session.apply_armature_operator()
self.report( self.report(
{'INFO'}, {'INFO'},
@ -163,7 +163,7 @@ class SessionStopOperator(bpy.types.Operator):
def execute(self, context): def execute(self, context):
global client, delayables, stop_modal_executor global client, delayables, stop_modal_executor
stop_modal_executor= True stop_modal_executor = True
settings = context.window_manager.session settings = context.window_manager.session
settings.is_admin = False settings.is_admin = False
assert(client) assert(client)
@ -274,7 +274,8 @@ class SessionSnapUserOperator(bpy.types.Operator):
target_client = client.get(uuid=self.target_client) target_client = client.get(uuid=self.target_client)
if target_client: if target_client:
rv3d.view_matrix = mathutils.Matrix(target_client.data['view_matrix']) rv3d.view_matrix = mathutils.Matrix(
target_client.data['view_matrix'])
else: else:
return {"CANCELLED"} return {"CANCELLED"}
@ -320,9 +321,10 @@ class SessionCommit(bpy.types.Operator):
client.push(self.target) client.push(self.target)
return {"FINISHED"} return {"FINISHED"}
class ModalExecutorOperator(bpy.types.Operator):
class ApplyArmatureOperator(bpy.types.Operator):
"""Operator which runs its self from a timer""" """Operator which runs its self from a timer"""
bl_idname = "wm.modal_executor_operator" bl_idname = "session.apply_armature_operator"
bl_label = "Modal Executor Operator" bl_label = "Modal Executor Operator"
_timer = None _timer = None
@ -344,7 +346,8 @@ class ModalExecutorOperator(bpy.types.Operator):
try: try:
client.apply(node) client.apply(node)
except Exception as e: except Exception as e:
logger.error("fail to apply {}: {}".format(node_ref.uuid,e)) logger.error(
"fail to apply {}: {}".format(node_ref.uuid, e))
return {'PASS_THROUGH'} return {'PASS_THROUGH'}
@ -371,7 +374,7 @@ classes = (
SessionPropertyRightOperator, SessionPropertyRightOperator,
SessionApply, SessionApply,
SessionCommit, SessionCommit,
ModalExecutorOperator, ApplyArmatureOperator,
) )
@ -380,6 +383,7 @@ def register():
for cls in classes: for cls in classes:
register_class(cls) register_class(cls)
def unregister(): def unregister():
global client global client
@ -391,5 +395,6 @@ def unregister():
for cls in reversed(classes): for cls in reversed(classes):
unregister_class(cls) unregister_class(cls)
if __name__ == "__main__": if __name__ == "__main__":
register() register()