Skip to content

Commit

Permalink
Dynamic QML loading optimizations for quicker Track instantiation (#422)
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderVocke authored Jun 24, 2024
1 parent 0b32f4f commit 947e0da
Show file tree
Hide file tree
Showing 9 changed files with 2,635 additions and 485 deletions.
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

0 comments on commit 947e0da

Please sign in to comment.