refactor: continue new framework integration
This commit is contained in:
parent
349e053bd5
commit
1d935fced4
@ -213,7 +213,7 @@ def register():
|
|||||||
environment.setup(DEPENDENCIES,bpy.app.binary_path_python)
|
environment.setup(DEPENDENCIES,bpy.app.binary_path_python)
|
||||||
|
|
||||||
from . import operators
|
from . import operators
|
||||||
# from . import ui
|
from . import ui
|
||||||
|
|
||||||
for cls in classes:
|
for cls in classes:
|
||||||
bpy.utils.register_class(cls)
|
bpy.utils.register_class(cls)
|
||||||
@ -226,14 +226,14 @@ def register():
|
|||||||
bpy.context.window_manager.session.load()
|
bpy.context.window_manager.session.load()
|
||||||
save_session_config(bpy.context.window_manager.session,bpy.context)
|
save_session_config(bpy.context.window_manager.session,bpy.context)
|
||||||
operators.register()
|
operators.register()
|
||||||
# ui.register()
|
ui.register()
|
||||||
|
|
||||||
|
|
||||||
def unregister():
|
def unregister():
|
||||||
from . import operators
|
from . import operators
|
||||||
# from . import ui
|
from . import ui
|
||||||
|
|
||||||
# ui.unregister()
|
ui.unregister()
|
||||||
operators.unregister()
|
operators.unregister()
|
||||||
|
|
||||||
del bpy.types.WindowManager.session
|
del bpy.types.WindowManager.session
|
||||||
|
81
operators.py
81
operators.py
@ -16,12 +16,12 @@ from pathlib import Path
|
|||||||
|
|
||||||
from . import environment, presence, ui
|
from . import environment, presence, ui
|
||||||
from .libs import umsgpack
|
from .libs import umsgpack
|
||||||
|
from .libs.replication.client import Client
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
cli = None
|
client = None
|
||||||
|
|
||||||
server = None
|
|
||||||
context = None
|
context = None
|
||||||
execution_queue = queue.Queue()
|
execution_queue = queue.Queue()
|
||||||
|
|
||||||
@ -53,24 +53,24 @@ def clean_scene(elements=environment.rtypes):
|
|||||||
|
|
||||||
def upload_client_instance_position():
|
def upload_client_instance_position():
|
||||||
username = bpy.context.window_manager.session.username
|
username = bpy.context.window_manager.session.username
|
||||||
if client.instance:
|
if client:
|
||||||
|
|
||||||
key = "Client/{}".format(username)
|
key = "Client/{}".format(username)
|
||||||
|
|
||||||
current_coords = presence.get_client_view_rect()
|
current_coords = presence.get_client_view_rect()
|
||||||
client_list = client.instance.get(key)
|
client_list = client.get(key)
|
||||||
|
|
||||||
if current_coords and client_list:
|
if current_coords and client_list:
|
||||||
if current_coords != client_list[0][1]['location']:
|
if current_coords != client_list[0][1]['location']:
|
||||||
client_list[0][1]['location'] = current_coords
|
client_list[0][1]['location'] = current_coords
|
||||||
client.instance.set(key, client_list[0][1])
|
client.set(key, client_list[0][1])
|
||||||
|
|
||||||
|
|
||||||
def update_client_selected_object(context):
|
def update_client_selected_object(context):
|
||||||
session = bpy.context.window_manager.session
|
session = bpy.context.window_manager.session
|
||||||
username = bpy.context.window_manager.session.username
|
username = bpy.context.window_manager.session.username
|
||||||
client_key = "Client/{}".format(username)
|
client_key = "Client/{}".format(username)
|
||||||
client_data = client.instance.get(client_key)
|
client_data = client.get(client_key)
|
||||||
|
|
||||||
selected_objects = helpers.get_selected_objects(context.scene)
|
selected_objects = helpers.get_selected_objects(context.scene)
|
||||||
if len(selected_objects) > 0 and len(client_data) > 0:
|
if len(selected_objects) > 0 and len(client_data) > 0:
|
||||||
@ -79,12 +79,12 @@ def update_client_selected_object(context):
|
|||||||
# if obj not in client_data[0][1]['active_objects']:
|
# if obj not in client_data[0][1]['active_objects']:
|
||||||
client_data[0][1]['active_objects'] = selected_objects
|
client_data[0][1]['active_objects'] = selected_objects
|
||||||
|
|
||||||
client.instance.set(client_key, client_data[0][1])
|
client.set(client_key, client_data[0][1])
|
||||||
break
|
break
|
||||||
|
|
||||||
elif client_data and client_data[0][1]['active_objects']:
|
elif client_data and client_data[0][1]['active_objects']:
|
||||||
client_data[0][1]['active_objects'] = []
|
client_data[0][1]['active_objects'] = []
|
||||||
client.instance.set(client_key, client_data[0][1])
|
client.set(client_key, client_data[0][1])
|
||||||
|
|
||||||
# TODO: cleanup
|
# TODO: cleanup
|
||||||
|
|
||||||
@ -94,7 +94,7 @@ def init_datablocks():
|
|||||||
for item in getattr(bpy.data, helpers.BPY_TYPES[datatype]):
|
for item in getattr(bpy.data, helpers.BPY_TYPES[datatype]):
|
||||||
item.id = bpy.context.window_manager.session.username
|
item.id = bpy.context.window_manager.session.username
|
||||||
key = "{}/{}".format(datatype, item.name)
|
key = "{}/{}".format(datatype, item.name)
|
||||||
client.instance.set(key)
|
client.set(key)
|
||||||
|
|
||||||
|
|
||||||
def default_tick():
|
def default_tick():
|
||||||
@ -150,8 +150,8 @@ class SessionJoinOperator(bpy.types.Operator):
|
|||||||
if len(net_settings.ip) < 1:
|
if len(net_settings.ip) < 1:
|
||||||
net_settings.ip = "127.0.0.1"
|
net_settings.ip = "127.0.0.1"
|
||||||
|
|
||||||
client.instance = client.Client(execution_queue)
|
client = client.Client(execution_queue)
|
||||||
client.instance.connect(net_settings.username,
|
client.connect(net_settings.username,
|
||||||
net_settings.ip,
|
net_settings.ip,
|
||||||
net_settings.port)
|
net_settings.port)
|
||||||
|
|
||||||
@ -181,7 +181,7 @@ class SessionPropertyAddOperator(bpy.types.Operator):
|
|||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
|
|
||||||
client.instance.add(self.property_path)
|
client.add(self.property_path)
|
||||||
|
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
@ -199,7 +199,7 @@ class SessionPropertyGetOperator(bpy.types.Operator):
|
|||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
global client_instance
|
global client_instance
|
||||||
|
|
||||||
client.instance.get("client")
|
client.get("client")
|
||||||
|
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
@ -218,7 +218,7 @@ class SessionPropertyRemoveOperator(bpy.types.Operator):
|
|||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
try:
|
try:
|
||||||
del client.instance.property_map[self.property_path]
|
del client.property_map[self.property_path]
|
||||||
|
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
except:
|
except:
|
||||||
@ -236,19 +236,8 @@ class SessionHostOperator(bpy.types.Operator):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
global server
|
|
||||||
|
|
||||||
net_settings = context.window_manager.session
|
net_settings = context.window_manager.session
|
||||||
|
|
||||||
script_dir = os.path.join(os.path.dirname(
|
|
||||||
os.path.abspath(__file__)), "server.py")
|
|
||||||
|
|
||||||
python_path = Path(bpy.app.binary_path_python)
|
|
||||||
cwd_for_subprocesses = python_path.parent
|
|
||||||
|
|
||||||
server = subprocess.Popen(
|
|
||||||
[str(python_path), script_dir], shell=False, stdout=subprocess.PIPE)
|
|
||||||
|
|
||||||
bpy.ops.session.join()
|
bpy.ops.session.join()
|
||||||
|
|
||||||
if net_settings.init_scene:
|
if net_settings.init_scene:
|
||||||
@ -270,18 +259,11 @@ class SessionStopOperator(bpy.types.Operator):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
global server
|
|
||||||
|
|
||||||
net_settings = context.window_manager.session
|
net_settings = context.window_manager.session
|
||||||
|
|
||||||
if server:
|
if client:
|
||||||
server.kill()
|
client.exit()
|
||||||
time.sleep(0.25)
|
|
||||||
|
|
||||||
server = None
|
|
||||||
|
|
||||||
if client.instance:
|
|
||||||
client.instance.exit()
|
|
||||||
time.sleep(0.25)
|
time.sleep(0.25)
|
||||||
# del client_instance
|
# del client_instance
|
||||||
|
|
||||||
@ -320,15 +302,13 @@ class SessionPropertyRightOperator(bpy.types.Operator):
|
|||||||
col.prop(net_settings, "clients")
|
col.prop(net_settings, "clients")
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
global server
|
|
||||||
|
|
||||||
net_settings = context.window_manager.session
|
net_settings = context.window_manager.session
|
||||||
|
|
||||||
if net_settings.is_admin:
|
if net_settings.is_admin:
|
||||||
val = client.instance.get(self.key)
|
val = client.get(self.key)
|
||||||
val[0][1]['id'] = net_settings.clients
|
val[0][1]['id'] = net_settings.clients
|
||||||
|
|
||||||
client.instance.set(key=self.key, value=val[0][1], override=True)
|
client.set(key=self.key, value=val[0][1], override=True)
|
||||||
item = helpers.resolve_bpy_path(self.key)
|
item = helpers.resolve_bpy_path(self.key)
|
||||||
if item:
|
if item:
|
||||||
item.id = net_settings.clients
|
item.id = net_settings.clients
|
||||||
@ -355,7 +335,7 @@ class SessionSnapUserOperator(bpy.types.Operator):
|
|||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
area, region, rv3d = presence.view3d_find()
|
area, region, rv3d = presence.view3d_find()
|
||||||
|
|
||||||
target_client = client.instance.get(
|
target_client = client.get(
|
||||||
"Client/{}".format(self.target_client))
|
"Client/{}".format(self.target_client))
|
||||||
if target_client:
|
if target_client:
|
||||||
rv3d.view_location = target_client[0][1]['location'][0]
|
rv3d.view_location = target_client[0][1]['location'][0]
|
||||||
@ -389,8 +369,8 @@ class SessionDumpDatabase(bpy.types.Operator, ExportHelper):
|
|||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
print(self.filepath)
|
print(self.filepath)
|
||||||
if client.instance and client.instance.state() == 3:
|
if client and client.state() == 3:
|
||||||
client.instance.dump(self.filepath)
|
client.dump(self.filepath)
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
return {"CANCELLED"}
|
return {"CANCELLED"}
|
||||||
@ -439,7 +419,7 @@ def is_replicated(update):
|
|||||||
|
|
||||||
key = "{}/{}".format(object_type, object_name)
|
key = "{}/{}".format(object_type, object_name)
|
||||||
|
|
||||||
if client.instance.exist(key):
|
if client.exist(key):
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
logger.debug("{} Not rep".format(key))
|
logger.debug("{} Not rep".format(key))
|
||||||
@ -475,7 +455,7 @@ def toogle_update_dirty(context, update):
|
|||||||
def depsgraph_update(scene):
|
def depsgraph_update(scene):
|
||||||
ctx = bpy.context
|
ctx = bpy.context
|
||||||
|
|
||||||
if client.instance and client.instance.state() == 3:
|
if client and client.state() == 3:
|
||||||
if ctx.mode in ['OBJECT','PAINT_GPENCIL']:
|
if ctx.mode in ['OBJECT','PAINT_GPENCIL']:
|
||||||
updates = ctx.view_layer.depsgraph.updates
|
updates = ctx.view_layer.depsgraph.updates
|
||||||
username = ctx.window_manager.session.username
|
username = ctx.window_manager.session.username
|
||||||
@ -503,7 +483,7 @@ def depsgraph_update(scene):
|
|||||||
item_type = 'Light'
|
item_type = 'Light'
|
||||||
|
|
||||||
key = "{}/{}".format(item_type , item.name)
|
key = "{}/{}".format(item_type , item.name)
|
||||||
client.instance.set(key)
|
client.set(key)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
getattr(bpy.data, helpers.BPY_TYPES[update.id.__class__.__name__]).remove(item)
|
getattr(bpy.data, helpers.BPY_TYPES[update.id.__class__.__name__]).remove(item)
|
||||||
@ -524,21 +504,16 @@ def register():
|
|||||||
|
|
||||||
|
|
||||||
def unregister():
|
def unregister():
|
||||||
global server
|
global client
|
||||||
|
|
||||||
presence.unregister()
|
presence.unregister()
|
||||||
|
|
||||||
if bpy.app.handlers.depsgraph_update_post.count(depsgraph_update) > 0:
|
if bpy.app.handlers.depsgraph_update_post.count(depsgraph_update) > 0:
|
||||||
bpy.app.handlers.depsgraph_update_post.remove(depsgraph_update)
|
bpy.app.handlers.depsgraph_update_post.remove(depsgraph_update)
|
||||||
|
|
||||||
if server:
|
if client:
|
||||||
server.kill()
|
client.exit()
|
||||||
server = None
|
client = None
|
||||||
del server
|
|
||||||
|
|
||||||
if client.instance:
|
|
||||||
client.instance.exit()
|
|
||||||
client.instance = None
|
|
||||||
|
|
||||||
from bpy.utils import unregister_class
|
from bpy.utils import unregister_class
|
||||||
for cls in reversed(classes):
|
for cls in reversed(classes):
|
||||||
|
18
ui.py
18
ui.py
@ -1,5 +1,5 @@
|
|||||||
import bpy
|
import bpy
|
||||||
from .libs.replication import client
|
from . import operators
|
||||||
|
|
||||||
|
|
||||||
ICONS = {'Image': 'IMAGE_DATA', 'Curve':'CURVE_DATA', 'Client':'SOLO_ON','Collection': 'FILE_FOLDER', 'Mesh': 'MESH_DATA', 'Object': 'OBJECT_DATA', 'Material': 'MATERIAL_DATA',
|
ICONS = {'Image': 'IMAGE_DATA', 'Curve':'CURVE_DATA', 'Client':'SOLO_ON','Collection': 'FILE_FOLDER', 'Mesh': 'MESH_DATA', 'Object': 'OBJECT_DATA', 'Material': 'MATERIAL_DATA',
|
||||||
@ -25,7 +25,7 @@ class SESSION_PT_settings(bpy.types.Panel):
|
|||||||
window_manager = context.window_manager
|
window_manager = context.window_manager
|
||||||
|
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
if not client.instance or (client.instance and client.instance.state() == 1):
|
if not operators.client or (operators.client and operators.client.state() == 1):
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
|
|
||||||
# USER SETTINGS
|
# USER SETTINGS
|
||||||
@ -98,7 +98,7 @@ class SESSION_PT_settings(bpy.types.Panel):
|
|||||||
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if client.instance.state() == 3:
|
if operators.client.state() == 3:
|
||||||
|
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
row.operator("session.stop", icon='QUIT', text="Exit")
|
row.operator("session.stop", icon='QUIT', text="Exit")
|
||||||
@ -111,11 +111,11 @@ class SESSION_PT_settings(bpy.types.Panel):
|
|||||||
row = box.row()
|
row = box.row()
|
||||||
row.label(text="", icon='INFO')
|
row.label(text="", icon='INFO')
|
||||||
row = box.row()
|
row = box.row()
|
||||||
row.label(text="Sync tasks: {}".format(client.instance.active_tasks))
|
row.label(text="Sync tasks: {}".format(operators.client.active_tasks))
|
||||||
else:
|
else:
|
||||||
status = "connecting..."
|
status = "connecting..."
|
||||||
if net_settings.is_admin:
|
if net_settings.is_admin:
|
||||||
status = "init scene...({} tasks remaining)".format(client.instance.active_tasks)
|
status = "init scene...({} tasks remaining)".format(operators.client.active_tasks)
|
||||||
row.label(text=status)
|
row.label(text=status)
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
row.operator("session.stop", icon='QUIT', text="CANCEL")
|
row.operator("session.stop", icon='QUIT', text="CANCEL")
|
||||||
@ -132,7 +132,7 @@ class SESSION_PT_user(bpy.types.Panel):
|
|||||||
bl_category = "Multiuser"
|
bl_category = "Multiuser"
|
||||||
@classmethod
|
@classmethod
|
||||||
def poll(cls, context):
|
def poll(cls, context):
|
||||||
return client.instance and client.instance.state() == 3
|
return operators.client and operators.client.state() == 3
|
||||||
|
|
||||||
|
|
||||||
def draw(self, context):
|
def draw(self, context):
|
||||||
@ -142,7 +142,7 @@ class SESSION_PT_user(bpy.types.Panel):
|
|||||||
scene = context.window_manager
|
scene = context.window_manager
|
||||||
# Create a simple row.
|
# Create a simple row.
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
client_keys = client.instance.list()
|
client_keys = operators.client.list()
|
||||||
if client_keys and len(client_keys) > 0:
|
if client_keys and len(client_keys) > 0:
|
||||||
for key in client_keys:
|
for key in client_keys:
|
||||||
if 'Client' in key[0]:
|
if 'Client' in key[0]:
|
||||||
@ -179,7 +179,7 @@ class SESSION_PT_properties(bpy.types.Panel):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def poll(cls, context):
|
def poll(cls, context):
|
||||||
return client.instance and client.instance.state() == 3
|
return operators.client and operators.client.state() == 3
|
||||||
|
|
||||||
def draw_header(self, context):
|
def draw_header(self, context):
|
||||||
self.layout.label(text="", icon='OUTLINER_OB_GROUP_INSTANCE')
|
self.layout.label(text="", icon='OUTLINER_OB_GROUP_INSTANCE')
|
||||||
@ -204,7 +204,7 @@ class SESSION_PT_properties(bpy.types.Panel):
|
|||||||
|
|
||||||
# Property area
|
# Property area
|
||||||
area_msg = row.box()
|
area_msg = row.box()
|
||||||
client_keys = client.instance.list()
|
client_keys = operators.client.list()
|
||||||
if client_keys and len(client_keys) > 0:
|
if client_keys and len(client_keys) > 0:
|
||||||
|
|
||||||
for item in sorted(client_keys, key=get_client_key):
|
for item in sorted(client_keys, key=get_client_key):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user