400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438 | 400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442 |
+
-
+
-
+
+
+
-
-
+
+
+
-
-
+
+
-
+
-
+
-
-
+
+
-
+
| c.set_current_name(re.sub(r"\.(m3u|pls|xspf|jspf|asx|json|smil|wpl)$", ext.strip("*"), fn))
# Spool gtk update calls from non-main threads (optional immediate=1 flag to run task next, not last)
@staticmethod
def do(callback, *args, **kwargs):
name = inspect.getsource(callback).strip() if callback.__name__=='<lambda>' else str(callback)
pos = kwargs.get("immediate", -1)
if kwargs.get("immediate"):
if pos and pos >= 0:
del kwargs["immediate"]
pos = 0
else:
pos = -1
# Run callback right away
if uikit.idle_run:
log.UIKIT_DORUN(str(callback))
if uikit.in_idle or conf.nothreads:
log.UIKIT_RUN_NOW(name)
callback(*args, **kwargs)
# Spool them for Gtk idle handling
else:
log.UIKIT_SPOOL(str(callback))
uikit.idle_tasks.insert(pos, [lambda: callback(*args, **kwargs), str(callback)])
log.UIKIT_SPOOL(name)
uikit.idle_tasks.insert(pos, [lambda: callback(*args, **kwargs), name])
gobject.idle_add(uikit.idle_do)
# Collect tasks to perform in gtk.main loop
idle_tasks = []
idle_run = False
in_idle = False
# Execute UI updating tasks in order
@staticmethod
def idle_do():
uikit.idle_run = True
uikit.in_idle = True
if uikit.idle_tasks:
task, callback = uikit.idle_tasks.pop(0)
log.UIKIT_EXEC(callback)
task, name = uikit.idle_tasks.pop(0)
log.UIKIT_EXEC(name)
task()
uikit.idle_run = False
uikit.in_idle = False
return len(uikit.idle_tasks) > 0
# adds background color to widget,
# eventually wraps it into a gtk.Window, if it needs a container
@staticmethod |