-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextension.py
More file actions
55 lines (48 loc) · 1.34 KB
/
extension.py
File metadata and controls
55 lines (48 loc) · 1.34 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
54
55
# -*- coding: utf-8 -*-
"""
A layer representing a smartimage extension
"""
from smartimage.image import *
class ExtensionLayer(ImageLayer):
"""
A layer representing a smartimage extension
"""
def __init__(self,parent,xml):
ImageLayer.__init__(self,parent,xml)
@property
def type(self):
"""
the type for the extension
"""
return self._getProperty('type')
@property
def filename(self)->str:
"""
turn this extension+id into a filename to save
the extension's output image
"""
return self.type+'/'+self.elementId+'.png'
@property
def extensionClass(self):
"""
get the external extension class or None
"""
extPkgName=self.type.replace('.','_')
try:
exec('import extensions.'+extPkgName)
return eval('extensions.'+extPkgName+'Extension')
except ImportError:
pass
@property
def image(self)->Union[PilPlusImage,None]:
"""
get the layer's image
"""
extensionClass=self.extensionClass
if extensionClass is None:
image=ImageLayer.image
else:
ext=extensionClass(self.root,self,self.xml)
image=ext.image
self.root.saveImage(image,self.filename)
return image