Skip to content

Commit

Permalink
[core] avoid direct includes to PySide2
Browse files Browse the repository at this point in the history
  • Loading branch information
julien-hdev committed Aug 10, 2020
1 parent 212e12b commit 34e1f59
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
5 changes: 3 additions & 2 deletions meshroom/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
BaseObject = None
Variant = None
VariantList = None
JSValue = None

if meshroom.backend == meshroom.Backend.PYSIDE:
# PySide types
from .qt import DictModel, ListModel, Slot, Signal, Property, BaseObject, Variant, VariantList
from .qt import DictModel, ListModel, Slot, Signal, Property, BaseObject, Variant, VariantList, JSValue
elif meshroom.backend == meshroom.Backend.STANDALONE:
# Core types
from .core import DictModel, ListModel, Slot, Signal, Property, BaseObject, Variant, VariantList
from .core import DictModel, ListModel, Slot, Signal, Property, BaseObject, Variant, VariantList, JSValue


class _BaseModel:
Expand Down
1 change: 1 addition & 0 deletions meshroom/common/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,4 @@ def parent(self):
BaseObject = CoreObject
Variant = object
VariantList = object
JSValue = None
3 changes: 2 additions & 1 deletion meshroom/common/qt.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from PySide2 import QtCore
from PySide2 import QtCore, QtQml


class QObjectListModel(QtCore.QAbstractListModel):
Expand Down Expand Up @@ -374,3 +374,4 @@ def sort(self):
BaseObject = QtCore.QObject
Variant = "QVariant"
VariantList = "QVariantList"
JSValue = QtQml.QJSValue
7 changes: 3 additions & 4 deletions meshroom/core/desc.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from meshroom.common import BaseObject, Property, Variant, VariantList
from meshroom.common import BaseObject, Property, Variant, VariantList, JSValue
from meshroom.core import pyCompatibility
from enum import Enum # available by default in python3. For python2: "pip install enum34"
import math
import os
import psutil
import PySide2
import ast

class Attribute(BaseObject):
Expand Down Expand Up @@ -69,7 +68,7 @@ def __init__(self, elementDesc, name, label, description, group='allParams', adv
joinChar = Property(str, lambda self: self._joinChar, constant=True)

def validateValue(self, value):
if isinstance(value, PySide2.QtQml.QJSValue):
if JSValue is not None and isinstance(value, JSValue):
# Note: we could use isArray(), property("length").toInt() to retrieve all values
raise ValueError("ListAttribute.validateValue: cannot recognize QJSValue. Please, use JSON.stringify(value) in QML.")
if isinstance(value, pyCompatibility.basestring):
Expand Down Expand Up @@ -105,7 +104,7 @@ def __init__(self, groupDesc, name, label, description, group='allParams', advan

def validateValue(self, value):
""" Ensure value is compatible with the group description and convert value if needed. """
if isinstance(value, PySide2.QtQml.QJSValue):
if JSValue is not None and isinstance(value, JSValue):
# Note: we could use isArray(), property("length").toInt() to retrieve all values
raise ValueError("GroupAttribute.validateValue: cannot recognize QJSValue. Please, use JSON.stringify(value) in QML.")
if isinstance(value, pyCompatibility.basestring):
Expand Down

0 comments on commit 34e1f59

Please sign in to comment.