feat: custom cache directory in userpref

This commit is contained in:
Swann Martinez 2020-03-02 11:09:45 +01:00
parent 8e600778ab
commit 16147ae2ba
No known key found for this signature in database
GPG Key ID: 414CCAFD8DA720E1
9 changed files with 46 additions and 21 deletions

View File

@ -42,7 +42,7 @@ def client_list_callback(scene, context):
items = [(RP_COMMON, RP_COMMON, "")]
username = bpy.context.preferences.addons[__package__].preferences.username
username = utils.get_preferences().username
cli = operators.client
if cli:
client_ids = cli.online_users.keys()

View File

@ -2,15 +2,16 @@ import bpy
import mathutils
import os
from .. import utils, environment
from .. import utils
from .bl_datablock import BlDatablock
def dump_image(image):
pixels = None
if image.source == "GENERATED":
prefs = utils.get_preferences()
img_name = "{}.png".format(image.name)
image.filepath_raw = os.path.join(environment.CACHE_DIR, img_name)
image.filepath_raw = os.path.join(prefs.cache_directory, img_name)
image.file_format = "PNG"
image.save()
@ -43,10 +44,11 @@ class BlImage(BlDatablock):
def load(self, data, target):
image = target
prefs = utils.get_preferences()
img_name = "{}.png".format(image.name)
img_path = os.path.join(environment.CACHE_DIR, img_name)
img_path = os.path.join(prefs.cache_directory, img_name)
file = open(img_path, 'wb')
file.write(data["pixels"])

View File

@ -88,7 +88,7 @@ class DynamicRightSelectTimer(Timer):
def execute(self):
session = operators.client
settings = bpy.context.preferences.addons[__package__].preferences
settings = utils.get_preferences()
if session and session.state['STATE'] == STATE_ACTIVE:
# Find user
@ -220,7 +220,7 @@ class ClientUpdate(Timer):
self.handle_quit = False
def execute(self):
settings = bpy.context.preferences.addons[__package__].preferences
settings = utils.get_preferences()
session = getattr(operators, 'client', None)
renderer = getattr(presence, 'renderer', None)

View File

@ -9,7 +9,7 @@ logger = logging.getLogger(__name__)
logger.setLevel(logging.WARNING)
THIRD_PARTY = os.path.join(os.path.dirname(os.path.abspath(__file__)), "libs")
CACHE_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "cache")
DEFAULT_CACHE_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "cache")
PYTHON_PATH = None
SUBPROCESS_DIR = None

View File

@ -58,7 +58,7 @@ class SessionStartOperator(bpy.types.Operator):
def execute(self, context):
global client, delayables, ui_context, server_process
settings = bpy.context.preferences.addons[__package__].preferences
settings = utils.get_preferences()
runtime_settings = context.window_manager.session
users = bpy.data.window_managers['WinMan'].online_users
@ -482,7 +482,7 @@ def depsgraph_evaluation(scene):
context = bpy.context
blender_depsgraph = bpy.context.view_layer.depsgraph
dependency_updates = [u for u in blender_depsgraph.updates]
session_infos = bpy.context.preferences.addons[__package__].preferences
session_infos = utils.get_preferences()
# NOTE: maybe we don't need to check each update but only the first

View File

@ -1,7 +1,7 @@
import logging
import bpy
from . import utils, bl_types
from . import utils, bl_types, environment
logger = logging.getLogger(__name__)
@ -53,6 +53,10 @@ class SessionPrefs(bpy.types.AddonPreferences):
('STRICT', 'strict', 'strict right repartition'),
('COMMON', 'common', 'relaxed right repartition')},
default='COMMON')
cache_directory: bpy.props.StringProperty(
name="cache directory",
subtype="DIR_PATH",
default=environment.DEFAULT_CACHE_DIR)
# for UI
category: bpy.props.EnumProperty(
name="Category",
@ -79,6 +83,11 @@ class SessionPrefs(bpy.types.AddonPreferences):
description="net",
default=True
)
conf_session_cache_expanded: bpy.props.BoolProperty(
name="Cache",
description="cache",
default=True
)
def draw(self, context):
@ -140,6 +149,15 @@ class SessionPrefs(bpy.types.AddonPreferences):
row.label(text="Start with an empty scene:")
row.prop(self, "start_empty", text="")
# CACHE SETTINGS
box = grid.box()
box.prop(
self, "conf_session_cache_expanded", text="Cache",
icon='DISCLOSURE_TRI_DOWN' if self.conf_session_cache_expanded
else 'DISCLOSURE_TRI_RIGHT')
if self.conf_session_cache_expanded:
box.row().prop(self, "cache_directory", text="Cache directory")
def generate_supported_types(self):
self.supported_datablocks.clear()

View File

@ -204,7 +204,7 @@ class DrawFactory(object):
self.d2d_items.clear()
def draw_client_selection(self, client_id, client_color, client_selection):
local_user = bpy.context.preferences.addons[__package__].preferences.username
local_user = utils.get_preferences().username
if local_user != client_id:
self.flush_selection(client_id)
@ -261,7 +261,7 @@ class DrawFactory(object):
def draw_client_camera(self, client_id, client_location, client_color):
if client_location:
local_user = bpy.context.preferences.addons[__package__].preferences.username
local_user = utils.get_preferences().username
if local_user != client_id:
try:

View File

@ -1,6 +1,6 @@
import bpy
from . import operators
from . import operators, utils
from .libs.replication.replication.constants import (ADDED, ERROR, FETCHED,
MODIFIED, RP_COMMON, UP,
STATE_ACTIVE, STATE_AUTH,
@ -140,7 +140,7 @@ class SESSION_PT_settings_network(bpy.types.Panel):
layout = self.layout
runtime_settings = context.window_manager.session
settings = bpy.context.preferences.addons[__package__].preferences
settings = utils.get_preferences()
# USER SETTINGS
row = layout.row()
@ -186,7 +186,7 @@ class SESSION_PT_settings_user(bpy.types.Panel):
layout = self.layout
runtime_settings = context.window_manager.session
settings = bpy.context.preferences.addons[__package__].preferences
settings = utils.get_preferences()
row = layout.row()
# USER SETTINGS
@ -215,7 +215,7 @@ class SESSION_PT_settings_replication(bpy.types.Panel):
layout = self.layout
runtime_settings = context.window_manager.session
settings = bpy.context.preferences.addons[__package__].preferences
settings = utils.get_preferences()
# Right managment
if runtime_settings.session_mode == 'HOST':
@ -259,7 +259,7 @@ class SESSION_PT_user(bpy.types.Panel):
layout = self.layout
online_users = context.window_manager.online_users
selected_user = context.window_manager.user_index
settings = bpy.context.preferences.addons[__package__].preferences
settings = utils.get_preferences()
active_user = online_users[selected_user] if len(online_users)-1>=selected_user else 0
@ -293,7 +293,7 @@ class SESSION_PT_user(bpy.types.Panel):
class SESSION_UL_users(bpy.types.UIList):
def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index, flt_flag):
session = operators.client
settings = bpy.context.preferences.addons[__package__].preferences
settings = utils.get_preferences()
is_local_user = item.username == settings.username
ping = '-'
frame_current = '-'
@ -368,7 +368,7 @@ class SESSION_PT_services(bpy.types.Panel):
def draw_property(context, parent, property_uuid, level=0):
settings = bpy.context.preferences.addons[__package__].preferences
settings = utils.get_preferences()
runtime_settings = context.window_manager.session
item = operators.client.get(uuid=property_uuid)
@ -449,7 +449,7 @@ class SESSION_PT_outliner(bpy.types.Panel):
if hasattr(context.window_manager, 'session'):
# Filters
settings = bpy.context.preferences.addons[__package__].preferences
settings = utils.get_preferences()
runtime_settings = context.window_manager.session
flow = layout.grid_flow(
row_major=True,

View File

@ -37,7 +37,7 @@ def find_from_attr(attr_name, attr_value, list):
def get_datablock_users(datablock):
users = []
supported_types = bpy.context.preferences.addons[__package__].preferences.supported_datablocks
supported_types = get_preferences().supported_datablocks
if hasattr(datablock, 'users_collection') and datablock.users_collection:
users.extend(list(datablock.users_collection))
if hasattr(datablock, 'users_scene') and datablock.users_scene:
@ -59,12 +59,14 @@ def random_string_digits(stringLength=6):
lettersAndDigits = string.ascii_letters + string.digits
return ''.join(random.choices(lettersAndDigits, k=stringLength))
def randomColor():
r = random.random()
v = random.random()
b = random.random()
return [r, v, b]
def clean_scene():
for type_name in dir(bpy.data):
try:
@ -166,3 +168,6 @@ def resolve_from_id(id, optionnal_type=None):
return root[id]
return None
def get_preferences():
return bpy.context.preferences.addons[__package__].preferences