-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathscene_operation_tk-krita.py
109 lines (86 loc) · 3.53 KB
/
scene_operation_tk-krita.py
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# ----------------------------------------------------------------------------
# Copyright (c) 2019-2020, Diego Garcia Huerta.
#
# Your use of this software as distributed in this GitHub repository, is
# governed by the BSD 3-clause License.
#
# Your use of the Shotgun Pipeline Toolkit is governed by the applicable license
# agreement between you and Autodesk / Shotgun.
#
# The full license is in the file LICENSE, distributed with this software.
# ----------------------------------------------------------------------------
import sgtk
from krita import Krita
__author__ = "Diego Garcia Huerta"
__contact__ = "https://www.linkedin.com/in/diegogh/"
HookClass = sgtk.get_hook_baseclass()
class SceneOperation(HookClass):
"""
Hook called to perform an operation with the
current scene
"""
def execute(
self,
operation,
file_path,
context,
parent_action,
file_version,
read_only,
**kwargs
):
"""
Main hook entry point
:param operation: String
Scene operation to perform
:param file_path: String
File path to use if the operation
requires it (e.g. open)
:param context: Context
The context the file operation is being
performed in.
:param parent_action: This is the action that this scene operation is
being executed for. This can be one of:
- open_file
- new_file
- save_file_as
- version_up
:param file_version: The version/revision of the file to be opened. If this is 'None'
then the latest version should be opened.
:param read_only: Specifies if the file should be opened read-only or not
:returns: Depends on operation:
'current_path' - Return the current scene
file path as a String
'reset' - True if scene was reset to an empty
state, otherwise False
all others - None
"""
krita_app = Krita.instance()
active_doc = Krita.instance().activeDocument()
if operation == "current_path":
current_project_filename = None
if active_doc:
current_project_filename = active_doc.fileName()
return current_project_filename
elif operation == "open":
doc = krita_app.openDocument(file_path)
krita_app.activeWindow().addView(doc)
doc.waitForDone()
elif operation == "save":
if active_doc:
active_doc.save()
active_doc.waitForDone()
elif operation == "save_as":
if active_doc:
success = active_doc.saveAs(file_path)
active_doc.waitForDone()
if success:
active_doc.setFileName(file_path)
elif operation == "reset":
if active_doc:
active_doc.waitForDone()
active_doc.close()
return True
elif operation == "prepare_new":
krita_app.action("file_new").trigger()
return True