Compatibility fix for Blender 2.8
bpy.context.user_preferences was renamed to bpy.context.preferences.
This commit is contained in:
parent
5821611d89
commit
cb5a116dff
@ -662,8 +662,16 @@ class PILLAR_PT_image_custom_properties(rna_prop_ui.PropertyPanel, bpy.types.Pan
|
|||||||
_property_type = bpy.types.Image
|
_property_type = bpy.types.Image
|
||||||
|
|
||||||
|
|
||||||
|
def ctx_preferences():
|
||||||
|
"""Returns bpy.context.preferences in a 2.79-compatible way."""
|
||||||
|
try:
|
||||||
|
return bpy.context.preferences
|
||||||
|
except AttributeError:
|
||||||
|
return bpy.context.user_preferences
|
||||||
|
|
||||||
|
|
||||||
def preferences() -> BlenderCloudPreferences:
|
def preferences() -> BlenderCloudPreferences:
|
||||||
return bpy.context.user_preferences.addons[ADDON_NAME].preferences
|
return ctx_preferences().addons[ADDON_NAME].preferences
|
||||||
|
|
||||||
|
|
||||||
def load_custom_icons():
|
def load_custom_icons():
|
||||||
|
@ -34,7 +34,7 @@ import asyncio
|
|||||||
import pillarsdk
|
import pillarsdk
|
||||||
from pillarsdk import exceptions as sdk_exceptions
|
from pillarsdk import exceptions as sdk_exceptions
|
||||||
from .pillar import pillar_call
|
from .pillar import pillar_call
|
||||||
from . import async_loop, pillar, cache, blendfile, home_project
|
from . import async_loop, blender, pillar, cache, blendfile, home_project
|
||||||
|
|
||||||
SETTINGS_FILES_TO_UPLOAD = ['userpref.blend', 'startup.blend']
|
SETTINGS_FILES_TO_UPLOAD = ['userpref.blend', 'startup.blend']
|
||||||
|
|
||||||
@ -476,13 +476,13 @@ class PILLAR_OT_sync(pillar.PillarOperatorMixin,
|
|||||||
self.log.info('Overriding machine-local settings in %s', file_path)
|
self.log.info('Overriding machine-local settings in %s', file_path)
|
||||||
|
|
||||||
# Remember some settings that should not be overwritten from the Cloud.
|
# Remember some settings that should not be overwritten from the Cloud.
|
||||||
up = bpy.context.user_preferences
|
prefs = blender.ctx_preferences()
|
||||||
remembered = {}
|
remembered = {}
|
||||||
for rna_key, python_key in LOCAL_SETTINGS_RNA:
|
for rna_key, python_key in LOCAL_SETTINGS_RNA:
|
||||||
assert '.' in python_key, 'Sorry, this code assumes there is a dot in the Python key'
|
assert '.' in python_key, 'Sorry, this code assumes there is a dot in the Python key'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
value = up.path_resolve(python_key)
|
value = prefs.path_resolve(python_key)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
# Setting doesn't exist. This can happen, for example Cycles
|
# Setting doesn't exist. This can happen, for example Cycles
|
||||||
# settings on a build that doesn't have Cycles enabled.
|
# settings on a build that doesn't have Cycles enabled.
|
||||||
@ -491,7 +491,7 @@ class PILLAR_OT_sync(pillar.PillarOperatorMixin,
|
|||||||
# Map enums from strings (in Python) to ints (in DNA).
|
# Map enums from strings (in Python) to ints (in DNA).
|
||||||
dot_index = python_key.rindex('.')
|
dot_index = python_key.rindex('.')
|
||||||
parent_key, prop_key = python_key[:dot_index], python_key[dot_index + 1:]
|
parent_key, prop_key = python_key[:dot_index], python_key[dot_index + 1:]
|
||||||
parent = up.path_resolve(parent_key)
|
parent = prefs.path_resolve(parent_key)
|
||||||
prop = parent.bl_rna.properties[prop_key]
|
prop = parent.bl_rna.properties[prop_key]
|
||||||
if prop.type == 'ENUM':
|
if prop.type == 'ENUM':
|
||||||
log.debug('Rewriting %s from %r to %r',
|
log.debug('Rewriting %s from %r to %r',
|
||||||
|
@ -244,7 +244,7 @@ class MenuItem:
|
|||||||
|
|
||||||
# draw some text
|
# draw some text
|
||||||
font_id = 0
|
font_id = 0
|
||||||
text_dpi = bpy.context.user_preferences.system.dpi
|
text_dpi = blender.ctx_preferences().system.dpi
|
||||||
text_x = self.x + self.icon_margin_x + ICON_WIDTH + self.text_margin_x
|
text_x = self.x + self.icon_margin_x + ICON_WIDTH + self.text_margin_x
|
||||||
text_y = self.y + ICON_HEIGHT * 0.5 - 0.25 * self.text_size
|
text_y = self.y + ICON_HEIGHT * 0.5 - 0.25 * self.text_size
|
||||||
blf.position(font_id, text_x, text_y, 0)
|
blf.position(font_id, text_x, text_y, 0)
|
||||||
|
Reference in New Issue
Block a user