Skip to content

Commit bfd9edd

Browse files
committed
timeline: Add qt_log2, now with log levels
1 parent b16901b commit bfd9edd

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

src/timeline/app.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ $(document).ready(function () {
7272
body_object.keydown(function (event) {
7373
if (event.which === 16) {
7474
if (timeline) {
75-
timeline.qt_log("Shift pressed!");
75+
timeline.qt_log2("DEBUG", "Shift pressed!");
7676
}
7777
body_object.scope().shift_pressed = true;
7878
}
@@ -81,7 +81,7 @@ $(document).ready(function () {
8181
body_object.keyup(function () {
8282
if (event.which === 16) {
8383
if (timeline) {
84-
timeline.qt_log("Shift released!");
84+
timeline.qt_log2("DEBUG", "Shift released!");
8585
}
8686
body_object.scope().shift_pressed = false;
8787
}

src/windows/views/timeline_webview.py

+21-3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from functools import partial
3434
from random import uniform
3535
from operator import itemgetter
36+
import logging
3637

3738
import openshot # Python module for libopenshot (required video editing module installed separately)
3839
from PyQt5.QtCore import QFileInfo, pyqtSlot, QUrl, Qt, QCoreApplication, QTimer
@@ -174,13 +175,15 @@ def get_thumb_address(self):
174175
thumb_address = "http://%s:%s/thumbnails/" % (thumb_server_details[0], thumb_server_details[1])
175176
return thumb_address
176177

177-
def run_js(self, code, callback=None):
178+
def run_js(self, code, callback=None, retries=0):
178179
'''Run JS code async and optionally have a callback for response'''
179180
# Check if document.Ready has fired in JS
180181
if not self.document_is_ready:
181182
# Not ready, try again in a few moments
182-
log.error("TimelineWebView::run_js() called before document ready event. Script queued: %s" % code)
183-
QTimer.singleShot(50, partial(self.run_js, code, callback))
183+
if retries > 0 and retries % 5 == 0:
184+
log.warning("WebEngine backend still not processing requests, queueing script.")
185+
log.debug("TimelineWebView::run_js() called before document ready event. Script queued: %s" % code)
186+
QTimer.singleShot(50, partial(self.run_js, code, callback, retries + 1))
184187
return None
185188
else:
186189
# Execute JS code
@@ -2719,6 +2722,21 @@ def removeSelection(self, item_id, item_type):
27192722
def qt_log(self, message=None):
27202723
log.info(message)
27212724

2725+
@pyqtSlot(str, str)
2726+
def qt_log2(self, level="INFO", message=None):
2727+
levels = {
2728+
"DEBUG": logging.DEBUG,
2729+
"INFO": logging.INFO,
2730+
"WARN": logging.WARNING,
2731+
"WARNING": logging.WARNING,
2732+
"ERROR": logging.ERROR,
2733+
"CRITICAL": logging.CRITICAL,
2734+
"FATAL": logging.FATAL,
2735+
}
2736+
if isinstance(level, str):
2737+
level = levels.get(level, logging.INFO)
2738+
log.log(level, message)
2739+
27222740
# Handle changes to zoom level, update js
27232741
def update_zoom(self, newValue):
27242742
_ = get_app()._tr

0 commit comments

Comments
 (0)