-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathtask.py
More file actions
53 lines (41 loc) · 1.79 KB
/
Copy pathtask.py
File metadata and controls
53 lines (41 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# Copyright (c) 2013 Shotgun Software Inc.
#
# CONFIDENTIAL AND PROPRIETARY
#
# This work is provided "AS IS" and subject to the Shotgun Pipeline Toolkit
# Source Code License included in this distribution package. See LICENSE.
# By accessing, using, copying or modifying this work you indicate your
# agreement to the Shotgun Pipeline Toolkit Source Code License. All rights
# not expressly granted therein are reserved by Shotgun Software Inc.
import tank
from tank.platform.qt import QtCore
class Task(QtCore.QObject):
"""
This is a wrapper class which allows us to run tank commands
inside the QT universe. This approach is handy when an engine needs
to start up a qt event loop as part of its initailization.
"""
finished = QtCore.Signal()
def __init__(self, engine, callback, args):
QtCore.QObject.__init__(self)
self._callback = callback
self._args = args
self._engine = engine
def run_command(self):
try:
# execute the callback
self._callback(*self._args)
except tank.TankError as e:
self._engine.log_error(str(e))
except KeyboardInterrupt:
self._engine.log_info("The operation was cancelled by the user.")
except Exception:
self._engine.log_exception("A general error was reported.")
finally:
# broadcast that we have finished this command
if not self._engine.has_received_ui_creation_requests():
# while the app has been doing its thing, no UIs were
# created (at least not any tank UIs) - assume it is a
# console style app and that the end of its callback
# execution means that it is complete and that we should return
self.finished.emit()