Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize with more dynamic loading #422

Merged
merged 13 commits into from
Jun 24, 2024
30 changes: 25 additions & 5 deletions src/shoopdaloop/lib/q_objects/SchemaValidator.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from ..session_schemas.session_schemas import validate_session_object
import json
from ..logging import *
import threading
import copy

# Wraps a back-end port.
class SchemaValidator(ShoopQObject):
Expand All @@ -20,11 +22,29 @@ def __init__(self, parent=None):
## SLOTS
###########

# Validate a schema. Throws if wrong.
@ShoopSlot('QVariant', str)
def validate_schema(self, obj, schemaname):
# Validate a schema asynchronously.
@ShoopSlot('QVariant', str, str, bool, result=bool)
def validate_schema(self, obj, obj_desc, schemaname, asynchronous):
_obj = obj
if isinstance(obj, QJSValue):
_obj = obj.toVariant()
self.logger.trace(lambda: "Validating against {}: {}".format(schemaname, json.dumps(_obj, indent=2)))
validate_session_object(_obj, schemaname)

if type(_obj) not in [list, dict]:
self.logger.error(lambda: f"Cannot validate a non-list/dict object: {type(_obj)}")

cpy = copy.deepcopy(_obj)
obj_desc_copy = copy.deepcopy(obj_desc)
schemaname_copy = copy.deepcopy(schemaname)
def validate_fn(obj=cpy, obj_desc=obj_desc_copy, schemaname=schemaname_copy):
try:
self.logger.trace(lambda: f"Validating against {schemaname}: {json.dumps(obj, indent=2)}")
validate_session_object(obj, schemaname)
return True
except Exception as e:
self.logger.error(lambda: f"Error validating {obj_desc} against {schemaname}: {e}")
return False

if asynchronous:
threading.Thread(target=validate_fn).start()
return True
return validate_fn()
16 changes: 16 additions & 0 deletions src/shoopdaloop/lib/qml/DynamicToolTip.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import QtQuick 6.6
import QtQuick.Controls 6.6

FirstTimeLoader {
id: root
property int delay
property string text

activate: visible

sourceComponent: ToolTip {
id: tooltip
delay: root.delay
text: root.text
}
}
9 changes: 9 additions & 0 deletions src/shoopdaloop/lib/qml/FirstTimeLoader.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import QtQuick 6.6

Loader {
property bool activate : false
active: false

Component.onCompleted: if (activate) { active = true; }
onActivateChanged: if (activate) { active = true; }
}
Loading
Loading