refactor: state with progression !

This commit is contained in:
Swann Martinez 2020-02-07 17:56:58 +01:00
parent 81752e9a23
commit 8a2d178a4f
No known key found for this signature in database
GPG Key ID: 414CCAFD8DA720E1
4 changed files with 46 additions and 21 deletions

View File

@ -89,7 +89,7 @@ class DynamicRightSelectTimer(Timer):
session = operators.client
settings = bpy.context.window_manager.session
if session and session.state == STATE_ACTIVE:
if session and session.state['STATE'] == STATE_ACTIVE:
# Find user
if self._user is None:
self._user = session.online_users.get(settings.username)
@ -195,7 +195,7 @@ class DrawClient(Draw):
session = getattr(operators, 'client', None)
renderer = getattr(presence, 'renderer', None)
if session and renderer and session.state == STATE_ACTIVE:
if session and renderer and session.state['STATE'] == STATE_ACTIVE:
settings = bpy.context.window_manager.session
users = session.online_users
@ -221,9 +221,9 @@ class ClientUpdate(Timer):
session = getattr(operators, 'client', None)
renderer = getattr(presence, 'renderer', None)
if session and renderer and session.state == STATE_ACTIVE:
if session and renderer and session.state['STATE'] == STATE_ACTIVE:
# Check if session has been closes prematurely
if session.state == 0:
if session.state['STATE'] == 0:
bpy.ops.session.stop()
local_user = operators.client.online_users.get(

@ -1 +1 @@
Subproject commit d0f2338fb62f2b21dba4ed4737ecaa2b28a9e2ff
Subproject commit 5a5571d943a1cb8a4b26e9397d0ced42acbea938

View File

@ -400,7 +400,7 @@ class ApplyArmatureOperator(bpy.types.Operator):
if event.type == 'TIMER':
global client
if client.state == STATE_ACTIVE:
if client.state['STATE'] == STATE_ACTIVE:
nodes = client.list(filter=bl_types.bl_armature.BlArmature)
for node in nodes:
@ -448,7 +448,7 @@ classes = (
def load_pre_handler(dummy):
global client
if client and client.state in [STATE_ACTIVE, STATE_SYNCING]:
if client and client.state['STATE'] in [STATE_ACTIVE, STATE_SYNCING]:
bpy.ops.session.stop()
@ -462,21 +462,21 @@ def sanitize_deps_graph(dummy):
"""
global client
if client and client.state in [STATE_ACTIVE]:
if client and client.state['STATE'] in [STATE_ACTIVE]:
for node_key in client.list():
client.get(node_key).resolve()
@persistent
def update_client_frame(scene):
if client and client.state == STATE_ACTIVE:
if client and client.state['STATE'] == STATE_ACTIVE:
client.update_user_metadata({
'frame_current': scene.frame_current
})
@persistent
def depsgraph_evaluation(scene):
if client and client.state == STATE_ACTIVE:
if client and client.state['STATE'] == STATE_ACTIVE:
context = bpy.context
blender_depsgraph = bpy.context.view_layer.depsgraph
dependency_updates = [u for u in blender_depsgraph.updates]
@ -528,7 +528,7 @@ def register():
def unregister():
global client
if client and client.state == 2:
if client and client.state['STATE'] == 2:
client.disconnect()
client = None

View File

@ -2,7 +2,11 @@ import bpy
from . import operators
from .libs.replication.replication.constants import (ADDED, ERROR, FETCHED,
MODIFIED, RP_COMMON, UP)
MODIFIED, RP_COMMON, UP,
STATE_ACTIVE, STATE_AUTH,
STATE_CONFIG, STATE_SYNCING,
STATE_INITIAL, STATE_SRV_SYNC,
STATE_WAITING)
ICONS_PROP_STATES = ['TRIA_DOWN', # ADDED
'TRIA_UP', # COMMITED
@ -11,6 +15,21 @@ ICONS_PROP_STATES = ['TRIA_DOWN', # ADDED
'FILE_REFRESH', # UP
'TRIA_UP'] # CHANGED
def get_state_str(state):
state_str = 'None'
if state == STATE_WAITING:
state_str = 'WAITING'
elif state == STATE_SYNCING:
state_str = 'SYNCING'
elif state == STATE_AUTH:
state_str = 'AUTHENTIFICATION'
elif state == STATE_CONFIG:
state_str = 'CONFIGURATION'
elif state == STATE_ACTIVE:
state_str = 'ACTIVE'
elif state == STATE_SRV_SYNC:
state_str = 'SERVER SYNC'
return state_str
class SESSION_PT_settings(bpy.types.Panel):
"""Settings panel"""
@ -31,19 +50,25 @@ class SESSION_PT_settings(bpy.types.Panel):
if hasattr(context.window_manager, 'session'):
# STATE INITIAL
if not operators.client \
or (operators.client and operators.client.state == 0):
or (operators.client and operators.client.state['STATE'] == STATE_INITIAL):
pass
else:
cli_state = operators.client.state
# STATE ACTIVE
if operators.client.state == 2:
if cli_state['STATE'] == STATE_ACTIVE:
row = layout.row()
row.operator("session.stop", icon='QUIT', text="Exit")
row = layout.row()
# STATE SYNCING
else:
status = "connecting..."
row.label(text=status)
row.label(text='Connecting:')
row = layout.row()
row.label(text=f"{get_state_str(cli_state['STATE'])}")
row = layout.row()
if cli_state['STATE'] in [STATE_SYNCING,STATE_SRV_SYNC]:
row.label(text=f"{cli_state['CURRENT']}/{cli_state['TOTAL']}")
row = layout.row()
row.operator("session.stop", icon='QUIT', text="CANCEL")
@ -59,7 +84,7 @@ class SESSION_PT_settings_network(bpy.types.Panel):
@classmethod
def poll(cls, context):
return not operators.client \
or (operators.client and operators.client.state == 0)
or (operators.client and operators.client.state['STATE'] == 0)
def draw(self, context):
layout = self.layout
@ -110,7 +135,7 @@ class SESSION_PT_settings_user(bpy.types.Panel):
@classmethod
def poll(cls, context):
return not operators.client \
or (operators.client and operators.client.state == 0)
or (operators.client and operators.client.state['STATE'] == 0)
def draw(self, context):
layout = self.layout
@ -138,7 +163,7 @@ class SESSION_PT_settings_replication(bpy.types.Panel):
@classmethod
def poll(cls, context):
return not operators.client \
or (operators.client and operators.client.state == 0)
or (operators.client and operators.client.state['STATE'] == 0)
def draw(self, context):
layout = self.layout
@ -180,7 +205,7 @@ class SESSION_PT_user(bpy.types.Panel):
@classmethod
def poll(cls, context):
return operators.client and operators.client.state == 2
return operators.client and operators.client.state['STATE'] == 2
def draw(self, context):
layout = self.layout
@ -336,7 +361,7 @@ class SESSION_PT_outliner(bpy.types.Panel):
@classmethod
def poll(cls, context):
return operators.client and operators.client.state == 2
return operators.client and operators.client.state['STATE'] == 2
def draw_header(self, context):
self.layout.label(text="", icon='OUTLINER_OB_GROUP_INSTANCE')