refactor: pep8 compliant

This commit is contained in:
Swann Martinez
2019-08-23 12:28:57 +02:00
parent c9ec711230
commit 594b82f814
6 changed files with 162 additions and 146 deletions

View File

@ -10,14 +10,15 @@ bl_info = {
import logging
import os
import random
import sys
import os
import bpy
from . import environment
from . import utils
from bpy.app.handlers import persistent
from . import environment, utils
DEPENDENCIES = {
"zmq",
"umsgpack",

View File

@ -1,12 +1,15 @@
import bpy
from .libs.replication.constants import *
from .libs import debug
from . import operators, utils
from .bl_types.bl_user import BlUser
from .libs import debug
from .libs.replication.constants import FETCHED
class Delayable():
"""Delayable task interface
"""
def register(self):
raise NotImplementedError
@ -16,11 +19,13 @@ class Delayable():
def unregister(self):
raise NotImplementedError
class Timer(Delayable):
"""Timer binder interface for blender
Run a bpy.app.Timer in the background looping at the given rate
"""
def __init__(self, duration=1):
self._timeout = duration
@ -42,6 +47,7 @@ class Timer(Delayable):
except:
print("timer already unregistered")
class ApplyTimer(Timer):
def __init__(self, timout=1, target_type=None):
self._type = target_type
@ -59,6 +65,7 @@ class ApplyTimer(Timer):
return self._timeout
class Draw(Delayable):
def __init__(self):
self._handler = None
@ -77,6 +84,7 @@ class Draw(Delayable):
except:
print("draw already unregistered")
class ClientUpdate(Draw):
def __init__(self, client_uuid=None):
assert(client_uuid)
@ -89,4 +97,3 @@ class ClientUpdate(Draw):
if client:
client.pointer.update_location()

View File

@ -60,6 +60,7 @@ ORDERED_TYPES = [
rtypes = []
def load_config():
import yaml
@ -71,6 +72,7 @@ def load_config():
return DEFAULT_CONFIG
def get_replicated_types():
config = load_config()
rtpyes = config["replicated_types"]
@ -82,6 +84,7 @@ def get_replicated_types():
return tlist
def genererate_replicated_types():
rtypes.clear()
@ -133,7 +136,6 @@ def setup(dependencies, python_path):
PYTHON_PATH = Path(python_path)
SUBPROCESS_DIR = PYTHON_PATH.parent
if not module_can_be_imported("pip"):
install_pip()

View File

@ -26,6 +26,7 @@ client = None
delayables = []
ui_context = None
def add_datablock(datablock):
global client
child = []
@ -35,7 +36,8 @@ def add_datablock(datablock):
if hasattr(datablock, "materials"):
for mat in datablock.materials:
child.append(add_datablock(mat))
if hasattr(datablock, "collection") and hasattr(datablock.collection, "children"):
if hasattr(datablock, "collection") \
and hasattr(datablock.collection, "children"):
for coll in datablock.collection.children:
child.append(add_datablock(coll))
if hasattr(datablock, "children"):
@ -44,7 +46,9 @@ def add_datablock(datablock):
if hasattr(datablock, "objects"):
for obj in datablock.objects:
child.append(add_datablock(obj))
if hasattr(datablock,'uuid') and datablock.uuid and client.exist(datablock.uuid):
if hasattr(datablock, 'uuid') \
and datablock.uuid \
and client.exist(datablock.uuid):
return datablock.uuid
else:
new_uuid = client.add(datablock, childs=child)
@ -62,7 +66,6 @@ def init_supported_datablocks(supported_types_id):
add_datablock(item)
# OPERATORS
class SessionStartOperator(bpy.types.Operator):
bl_idname = "session.start"
@ -94,10 +97,16 @@ class SessionStartOperator(bpy.types.Operator):
_type = getattr(bl_types, type)
supported_bl_types.append(_type.bl_id)
bpy_factory.register_type(_type.bl_class, _type.bl_rep_class, timer=_type.bl_delay_refresh,automatic=True)
bpy_factory.register_type(
_type.bl_class,
_type.bl_rep_class,
timer=_type.bl_delay_refresh,
automatic=True)
if _type.bl_delay_apply > 0:
delayables.append(delayable.ApplyTimer(timout=_type.bl_delay_apply,target_type=_type.bl_rep_class))
delayables.append(delayable.ApplyTimer(
timout=_type.bl_delay_apply,
target_type=_type.bl_rep_class))
client = Client(factory=bpy_factory)
@ -126,7 +135,8 @@ class SessionStartOperator(bpy.types.Operator):
)
settings.user_uuid = client.add(usr)
delayables.append(delayable.ClientUpdate(client_uuid=settings.user_uuid))
delayables.append(delayable.ClientUpdate(
client_uuid=settings.user_uuid))
# Push all added values
client.push()
@ -218,7 +228,6 @@ class SessionPropertyRightOperator(bpy.types.Operator):
if client:
client.right(self.key, settings.clients)
return {"FINISHED"}
@ -247,8 +256,6 @@ class SessionSnapUserOperator(bpy.types.Operator):
return {"CANCELLED"}
pass
class SessionApply(bpy.types.Operator):
bl_idname = "session.apply"

View File

@ -17,6 +17,7 @@ from gpu_extras.batch import batch_for_shader
global renderer
def view3d_find():
for area in bpy.data.window_managers[0].windows[0].screen.areas:
if area.type == 'VIEW_3D':
@ -86,6 +87,7 @@ def get_client_2d(coords):
else:
return (0, 0)
class User():
def __init__(self, username=None, color=(0, 0, 0, 1)):
self.name = username
@ -101,8 +103,6 @@ class User():
if current_coords:
self.location = list(current_coords)
def update_client_selected_object(self, context):
session = bpy.context.window_manager.session
username = bpy.context.window_manager.session.username
@ -123,8 +123,6 @@ class User():
client.set(client_key, client_data[0][1])
class DrawFactory(object):
def __init__(self):
@ -136,12 +134,12 @@ class DrawFactory(object):
self.coords = None
self.active_object = None
def run(self):
self.register_handlers()
def stop(self):
self.unregister_handlers()
def register_handlers(self):
self.draw3d_handle = bpy.types.SpaceView3D.draw_handler_add(
self.draw3d_callback, (), 'WINDOW', 'POST_VIEW')
@ -184,28 +182,23 @@ class DrawFactory(object):
(0, 4), (1, 5), (2, 6), (3, 7)
)
if select_ob in bpy.data.objects.keys():
ob = bpy.data.objects[select_ob]
else:
return
bbox_corners = [ob.matrix_world @ mathutils.Vector(corner) for corner in ob.bound_box]
bbox_corners = [ob.matrix_world @ mathutils.Vector(
corner) for corner in ob.bound_box]
coords = [(point.x, point.y, point.z)
for point in bbox_corners]
shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
color = client['color']
batch = batch_for_shader(
shader, 'LINES', {"pos": coords}, indices=indices)
drawable_key = "{}/{}".format(client['id'], select_ob)
self.d3d_items["{}/{}".format(client['id'],
select_ob)] = (shader, batch, color)
else:
pass
self.d3d_items[drawable_key] = (shader, batch, color)
def draw_client_camera(self, client_uuid, client_location, client_color):
if client_location:
@ -213,14 +206,15 @@ class DrawFactory(object):
try:
indices = (
(1, 3), (2, 1), (3, 0), (2, 0),(4,5),(1, 6), (2, 6), (3, 6), (0, 6)
(1, 3), (2, 1), (3, 0),
(2, 0), (4, 5), (1, 6),
(2, 6), (3, 6), (0, 6)
)
shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
position = [tuple(coord) for coord in client_location]
color = client_color
batch = batch_for_shader(
shader, 'LINES', {"pos": position}, indices=indices)
@ -237,7 +231,7 @@ class DrawFactory(object):
shader.bind()
shader.uniform_float("color", color)
batch.draw(shader)
except Exception as e:
except Exception:
print("3D Exception")
def draw2d_callback(self):
@ -251,9 +245,10 @@ class DrawFactory(object):
blf.color(0, color[0], color[1], color[2], color[3])
blf.draw(0, font)
except Exception as e:
except Exception:
print("2D EXCEPTION")
def register():
global renderer
renderer = DrawFactory()

46
ui.py
View File

@ -1,6 +1,6 @@
import bpy
from . import operators
from .libs.replication.constants import *
from .libs.replication.constants import FETCHED, ERROR
from .bl_types.bl_user import BlUser
@ -11,6 +11,7 @@ PROP_STATES = [ 'KEYTYPE_BREAKDOWN_VEC',
'KEYTYPE_JITTER_VEC',
'KEYTYPE_KEYFRAME_VEC']
class SESSION_PT_settings(bpy.types.Panel):
"""Settings panel"""
bl_idname = "MULTIUSER_SETTINGS_PT_panel"
@ -22,18 +23,15 @@ class SESSION_PT_settings(bpy.types.Panel):
def draw_header(self, context):
self.layout.label(text="", icon='TOOL_SETTINGS')
def draw(self, context):
layout = self.layout
layout.use_property_split = True
row = layout.row()
if hasattr(context.window_manager, 'session'):
settings = context.window_manager.session
window_manager = context.window_manager
if hasattr(context.window_manager, 'session'):
# STATE INITIAL
if not operators.client or (operators.client and operators.client.state == 0):
if not operators.client \
or (operators.client and operators.client.state == 0):
pass
# REPLICATION SETTINGS
# row = layout.row()
@ -69,15 +67,17 @@ class SESSION_PT_settings_network(bpy.types.Panel):
bl_region_type = 'UI'
bl_category = "Multiuser"
bl_parent_id = 'MULTIUSER_SETTINGS_PT_panel'
@classmethod
def poll(cls, context):
return not operators.client or (operators.client and operators.client.state == 0)
return not operators.client \
or (operators.client and operators.client.state == 0)
def draw(self, context):
layout = self.layout
settings = context.window_manager.session
scene = context.window_manager
row = layout.row()
# USER SETTINGS
row.label(text="draw overlay:")
@ -107,7 +107,6 @@ class SESSION_PT_settings_network(bpy.types.Panel):
row.prop(settings, "port", text="")
row = box.row()
row = box.row()
row.operator("session.start", text="CONNECT").host = False
@ -119,15 +118,17 @@ class SESSION_PT_settings_user(bpy.types.Panel):
bl_region_type = 'UI'
bl_category = "Multiuser"
bl_parent_id = 'MULTIUSER_SETTINGS_PT_panel'
@classmethod
def poll(cls, context):
return not operators.client or (operators.client and operators.client.state == 0)
return not operators.client \
or (operators.client and operators.client.state == 0)
def draw(self, context):
layout = self.layout
settings = context.window_manager.session
scene = context.window_manager
row = layout.row()
# USER SETTINGS
row.prop(settings, "username", text="id")
@ -144,16 +145,16 @@ class SESSION_PT_user(bpy.types.Panel):
bl_region_type = 'UI'
bl_category = "Multiuser"
bl_parent_id = 'MULTIUSER_SETTINGS_PT_panel'
@classmethod
def poll(cls, context):
return operators.client and operators.client.state == 2
def draw(self, context):
layout = self.layout
settings = context.window_manager.session
scene = context.window_manager
# Create a simple row.
col = layout.column(align=True)
@ -163,14 +164,13 @@ class SESSION_PT_user(bpy.types.Panel):
area_msg = col.row(align=True)
item_box = area_msg.box()
client = operators.client.get(key).buffer
pointer = operators.client.get(key).pointer
info = ""
detail_item_row = item_box.row(align=True)
username = client['name']
is_local_user = username == settings.username
if is_local_user:
@ -181,7 +181,9 @@ class SESSION_PT_user(bpy.types.Panel):
if not is_local_user:
detail_item_row.operator(
"session.snapview", text="", icon='VIEW_CAMERA').target_client = key
"session.snapview",
text="",
icon='VIEW_CAMERA').target_client = key
row = layout.row()
else:
row.label(text="Empty")
@ -207,7 +209,10 @@ def draw_property(context,parent,property_uuid, level=0):
detail_item_box = line.row(align=True)
if item.state == FETCHED:
detail_item_box.operator("session.apply",text="", icon=PROP_STATES[item.state]).target = item.uuid
detail_item_box.operator(
"session.apply",
text="",
icon=PROP_STATES[item.state]).target = item.uuid
else:
detail_item_box.label(text="", icon=PROP_STATES[item.state])
@ -218,7 +223,8 @@ def draw_property(context,parent,property_uuid, level=0):
if item.owner != settings.username:
right_icon = "DECORATE_LOCKED"
ro = detail_item_box.operator("session.right", text="", icon=right_icon, emboss=settings.is_admin)
ro = detail_item_box.operator(
"session.right", text="", icon=right_icon, emboss=settings.is_admin)
ro.key = property_uuid
detail_item_box.operator(
@ -242,10 +248,8 @@ class SESSION_PT_outliner(bpy.types.Panel):
def draw(self, context):
layout = self.layout
if hasattr(context.window_manager, 'session'):
settings = context.window_manager.session
scene = context.window_manager
row = layout.row()
row.prop(settings, 'outliner_filter', text="")