-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContext.py
44 lines (38 loc) · 1.45 KB
/
Context.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
# Module: Context.py | [ Language Python ]
# Author: Gaps | sGaps | ArtGaps
# LICENSE: GPLv3 (available in ./LICENSE.txt)
# --------------------------------------------
""" Utility module used to manage and test the GUI inside and outside krita.
When Krita is available, CONTEXT = 'INSIDE_KRITA', and Krita's built-in
can be used safely.
Otherwise, CONTEXT = 'OUTSIDE_KRITA' and you won't be able to use
Krita's functions.
[:] Defined in this module
--------------------------
RUN :: function
It's an alias for the exec_ function defined on QApplication class.
Use this after setup all GUI's component.
Extension :: class
It's an QWidget outside Krita. Otherwise it's a Krita.Extension
Used as base class for the PixelExtension.
CONTEXT :: str
Says when the context is INSIDE_KRITA or OUTSIDE_KRITA.
[*] Author
|- Gaps : sGaps : ArtGaps
"""
from sys import stderr
try:
from krita import Extension
except ImportError:
print( "[CONTEXT] Unable to find krita. Trying to use PyQt5 instead." , file = stderr )
try:
from PyQt5.QtWidgets import QWidget , QApplication
except ImportError:
print( "[CONTEXT] Unable to use PyQt package." , file = stderr , flush = True )
CONTEXT = "NO-REQUIRED-PACKAGES"
else:
CONTEXT = "OUTSIDE_KRITA"
Extension = QWidget
else:
CONTEXT = "INSIDE_KRITA"
RUN = lambda _ : ()