Skip to content

Commit 405f8dd

Browse files
committed
fix(action_manager): patch to support py37
change patching to (try eval + except), and now run black -l 80 to avoid hound warning There will be lots of violations in hound's eye which I cannot find out locally because hound's linter is not up to date. I will have to do some shattered commits, and for these commits, I will name them hop (hound oriented programming). Signed-off-by: TsXor <[email protected]>
1 parent 5835d2a commit 405f8dd

33 files changed

+777
-654
lines changed

examples/apply_crystallize_filter_action.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@
3131
active_document.activeLayer = active_document.layerSets.item(len(nLayerSets)).artLayers.item(len(nArtLayers))
3232

3333
def applyCrystallize(cellSize):
34-
filter_dict = {
35-
'_classID':None,
36-
'ClSz':cellSize
37-
}
34+
filter_dict = {"_classID": None, "ClSz": cellSize}
3835
filter_desc = ps.ActionDescriptor.load(filter_dict)
3936
ps.app.executeAction(am.str2id("Crst"), filter_desc)
4037

examples/convert_smartobject_to_layer.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Convert Smart object to artLayer."""
22

3-
# Import builtin modules
3+
# Import built-in modules
44
from textwrap import dedent
55

66
# Import local modules
@@ -10,10 +10,12 @@
1010

1111
# example 1
1212
with Session() as ps:
13-
js = dedent("""
13+
js = dedent(
14+
"""
1415
var idplacedLayerConvertToLayers = stringIDToTypeID( "placedLayerConvertToLayers" );
1516
executeAction( idplacedLayerConvertToLayers, undefined, DialogModes.NO );
16-
""")
17+
"""
18+
)
1719
ps.app.doJavaScript(js)
1820

1921
# example 2

examples/emboss_action.py

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,54 +2,47 @@
22
from photoshop import Session
33
import photoshop.api.action_manager as am
44

5+
56
with Session() as ps:
67
app = ps.app
78
for index, x in enumerate(range(50)):
89
# Execute an existing action from action palette.
910
exec_dict = {
10-
'_classID':None,
11-
'null':[
12-
'!ref',
13-
am.ReferenceKey(desiredclass='action', value='Sepia Toning (layer)'),
14-
am.ReferenceKey(desiredclass='actionSet', value='Default Actions')
15-
]
11+
"_classID": None,
12+
"null": [
13+
"!ref",
14+
am.ReferenceKey(desiredclass="action", value="Sepia Toning (layer)"),
15+
am.ReferenceKey(desiredclass="actionSet", value="Default Actions"),
16+
],
1617
}
1718
exec_desc = ps.ActionDescriptor.load(exec_dict)
18-
app.executeAction(am.str2id('Ply '), exec_desc, ps.DialogModes.DisplayNoDialogs)
19+
app.executeAction(am.str2id("Ply "), exec_desc, ps.DialogModes.DisplayNoDialogs)
1920

2021
# Create solid color fill layer.
2122
filledlayer_dict = {
22-
'_classID':None,
23-
'null':[
24-
'!ref',
25-
am.ReferenceKey(desiredclass='contentLayer',value=None)
26-
],
27-
'using':{
28-
'_classID':'contentLayer',
29-
'type':{
30-
'_classID':'solidColorLayer',
31-
'color':{
32-
'_classID':'RGBColor',
33-
'red':index,
34-
'grain':index,
35-
'blue':index
36-
}
37-
}
38-
}
23+
"_classID": None,
24+
"null": ["!ref", am.ReferenceKey(desiredclass="contentLayer", value=None)],
25+
"using": {
26+
"_classID": "contentLayer",
27+
"type": {
28+
"_classID": "solidColorLayer",
29+
"color": {"_classID": "RGBColor", "red": index, "grain": index, "blue": index}, # noqa
30+
},
31+
},
3932
}
4033
filledlayer_desc = ps.ActionDescriptor.load(filledlayer_dict)
41-
app.executeAction(am.str2id('Mk '), filledlayer_desc, ps.DialogModes.DisplayNoDialogs)
34+
app.executeAction(am.str2id("Mk "), filledlayer_desc, ps.DialogModes.DisplayNoDialogs)
4235

4336
# Select mask.
4437
selectmask_dict = {
45-
'_classID':None,
46-
'null':[
47-
'!ref',
48-
am.ReferenceKey(desiredclass='channel', value=am.Enumerated(type='channel',value='mask'))
38+
"_classID": None,
39+
"null": [
40+
"!ref",
41+
am.ReferenceKey(desiredclass="channel", value=am.Enumerated(type="channel", value="mask")),
4942
],
50-
'makeVisible':False
43+
"makeVisible": False,
5144
}
5245
selectmask_desc = ps.ActionDescriptor.load(selectmask_dict)
53-
app.executeAction(am.str2id('slct'), selectmask_desc, ps.DialogModes.DisplayNoDialogs)
46+
app.executeAction(am.str2id("slct"), selectmask_desc, ps.DialogModes.DisplayNoDialogs)
5447

5548
app.activeDocument.activeLayer.invert()

examples/import_image_as_layer.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
"""Import a image as a artLayer."""
22

3+
# Import built-in modules
4+
import pathlib
5+
36
# Import local modules
47
from photoshop import Session
5-
import pathlib
8+
import photoshop.api.action_manager as am
69

710

811
with Session(action="new_document") as ps:
9-
import_dict = {
10-
'_classID':None,
11-
'null':pathlib.Path("your/image/path") # replace it with your own path here
12-
}
12+
# replace it with your own path here
13+
import_dict = {"_classID": None, "null": pathlib.Path("your/image/path")}
1314
import_desc = ps.ActionDescriptor.load(import_dict)
14-
ps.app.executeAction(am.str2id("Plc "), import_desc) # `Plc` need one space in here.
15+
ps.app.executeAction(am.str2id("Plc "), import_desc)
16+
# length of charID should always be 4, if not, pad with spaces

examples/replace_images.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
"""Replace the image of the current active layer with a new image."""
22

3-
# Import builtin modules
3+
# Import built-in modules
44
import pathlib
55

66
# Import third-party modules
77
import examples._psd_files as psd # Import from examples.
88

99
# Import local modules
1010
from photoshop import Session
11+
import photoshop.api.action_manager as am
1112

1213

1314
PSD_FILE = psd.get_psd_files()
@@ -17,10 +18,7 @@
1718
active_layer = ps.active_document.activeLayer
1819
bounds = active_layer.bounds
1920
print(f"current layer {active_layer.name}: {bounds}")
20-
input_dict = {
21-
'_classID':None,
22-
'null':pathlib.Path(PSD_FILE["red_100x200.png"])
23-
}
21+
input_dict = {"_classID": None, "null": pathlib.Path(PSD_FILE["red_100x200.png"])}
2422
input_desc = ps.ActionDescriptor.load(input_dict)
2523
ps.app.executeAction(am.str2id("placedLayerReplaceContents"), input_desc)
2624

examples/session_smart_sharpen.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
# Import local modules
1313
from photoshop import Session
14+
import photoshop.api.action_manager as am
1415

1516

1617
PSD_FILE = psd.get_psd_files()
@@ -20,14 +21,14 @@
2021

2122
def SmartSharpen(inAmount, inRadius, inNoise):
2223
ss_dict = {
23-
'_classID':None,
24-
'presetKindType':am.Enumerated(type='presetKindType', value='presetKindCustom'),
25-
'amount':am.UnitDouble(unit='radius', double=inAmount),
26-
'radius':am.UnitDouble(unit='pixelsUnit', double=inRadius),
27-
'noiseReduction':am.UnitDouble(unit='percentUnit', double=inNoise),
28-
'blur':am.Enumerated(type='blurType', value='gaussianBlur')
24+
"_classID": None,
25+
"presetKindType": am.Enumerated(type="presetKindType", value="presetKindCustom"), # noqa
26+
"amount": am.UnitDouble(unit="radius", double=inAmount),
27+
"radius": am.UnitDouble(unit="pixelsUnit", double=inRadius),
28+
"noiseReduction": am.UnitDouble(unit="percentUnit", double=inNoise),
29+
"blur": am.Enumerated(type="blurType", value="gaussianBlur"),
2930
}
3031
ss_desc = ps.ActionDescriptor.load(ss_dict)
31-
app.ExecuteAction(am.str2id('smartSharpen'), ss_desc)
32+
ps.app.ExecuteAction(am.str2id("smartSharpen"), ss_desc)
3233

33-
SmartSharpen(300, 2.0, 20)
34+
SmartSharpen(300, 2.0, 20)

examples/smart_sharpen.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@
2727

2828
def SmartSharpen(inAmount, inRadius, inNoise):
2929
ss_dict = {
30-
'_classID':None,
31-
'presetKindType':am.Enumerated(type='presetKindType', value='presetKindCustom'),
32-
'amount':am.UnitDouble(unit='radius', double=inAmount),
33-
'radius':am.UnitDouble(unit='pixelsUnit', double=inRadius),
34-
'noiseReduction':am.UnitDouble(unit='percentUnit', double=inNoise),
35-
'blur':am.Enumerated(type='blurType', value='gaussianBlur')
30+
"_classID": None,
31+
"presetKindType": am.Enumerated(type="presetKindType", value="presetKindCustom"), # noqa
32+
"amount": am.UnitDouble(unit="radius", double=inAmount),
33+
"radius": am.UnitDouble(unit="pixelsUnit", double=inRadius),
34+
"noiseReduction": am.UnitDouble(unit="percentUnit", double=inNoise),
35+
"blur": am.Enumerated(type="blurType", value="gaussianBlur"),
3636
}
3737
ss_desc = ps.ActionDescriptor.load(ss_dict)
38-
app.ExecuteAction(am.str2id('smartSharpen'), ss_desc)
38+
app.ExecuteAction(am.str2id("smartSharpen"), ss_desc)
3939

40-
SmartSharpen(300, 2.0, 20)
40+
41+
SmartSharpen(300, 2.0, 20)

photoshop/api/_actionmanager_type_binder.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,25 @@
77

88
# Import local modules
99
from photoshop.api.action_descriptor import ActionDescriptor as AD_proto
10-
from photoshop.api.action_manager._main_types.action_descriptor import ActionDescriptor as AD_utils_proto
1110
from photoshop.api.action_list import ActionList as AL_proto
12-
from photoshop.api.action_manager._main_types.action_list import ActionList as AL_utils_proto
11+
from photoshop.api.action_manager._main_types.action_descriptor import (
12+
ActionDescriptor as AD_utils_proto,
13+
)
14+
from photoshop.api.action_manager._main_types.action_list import (
15+
ActionList as AL_utils_proto,
16+
)
17+
from photoshop.api.action_manager._main_types.action_reference import (
18+
ActionReference as AR_utils_proto,
19+
)
1320
from photoshop.api.action_reference import ActionReference as AR_proto
14-
from photoshop.api.action_manager._main_types.action_reference import ActionReference as AR_utils_proto
1521
from photoshop.api.enumerations import DescValueType
1622
from photoshop.api.enumerations import ReferenceFormType
1723

1824

1925
class ActionDescriptor(AD_proto, AD_utils_proto):
2026
@classmethod
21-
def load(cls, adict: dict) -> 'ActionDescriptor':
22-
'''Convert a python object to an ActionDescriptor'''
27+
def load(cls, adict: dict) -> "ActionDescriptor":
28+
"""Convert a python object to an ActionDescriptor"""
2329
return super().load(adict, globals())
2430

2531
def __init__(self, parent=None, classID=None):
@@ -45,8 +51,8 @@ def getReference(self, key: int) -> "ActionReference":
4551

4652
class ActionList(AL_proto, AL_utils_proto):
4753
@classmethod
48-
def load(cls, alist: list) -> 'ActionList':
49-
'''Convert a python object to an ActionList'''
54+
def load(cls, alist: list) -> "ActionList":
55+
"""Convert a python object to an ActionList"""
5056
return super().load(alist, globals())
5157

5258
def getType(self, index: int) -> DescValueType:
@@ -68,8 +74,8 @@ def getReference(self, index: int) -> "ActionReference":
6874

6975
class ActionReference(AR_proto, AR_utils_proto):
7076
@classmethod
71-
def load(cls, adict: dict) -> 'ActionReference':
72-
'''Convert a python object to an ActionReference'''
77+
def load(cls, adict: dict) -> "ActionReference":
78+
"""Convert a python object to an ActionReference"""
7379
return super().load(adict)
7480

7581
def getForm(self) -> ReferenceFormType:
Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
1-
from .ref_form_types import *
2-
from .desc_value_types import *
3-
from .utils import *
1+
from .desc_value_types import Enumerated
2+
from .desc_value_types import TypeID
3+
from .desc_value_types import UnitDouble
4+
from .jprint import jformat
5+
from .jprint import jprint
46
from .js_converter import dump as dumpjs
5-
from .jprint import *
7+
from .ref_form_types import Identifier
8+
from .ref_form_types import Index
9+
from .ref_form_types import Offset
10+
from .ref_form_types import ReferenceKey
11+
from .utils import id2str
12+
from .utils import str2id
13+
614

715
__all__ = [ # noqa: F405
8-
'str2id',
9-
'id2str',
10-
'Enumerated',
11-
'TypeID',
12-
'UnitDouble',
13-
'Identifier',
14-
'Index',
15-
'Offset',
16-
'ReferenceKey',
17-
'dumpjs',
18-
'jprint',
19-
'jformat',
20-
]
16+
"str2id",
17+
"id2str",
18+
"Enumerated",
19+
"TypeID",
20+
"UnitDouble",
21+
"Identifier",
22+
"Index",
23+
"Offset",
24+
"ReferenceKey",
25+
"dumpjs",
26+
"jprint",
27+
"jformat",
28+
]

0 commit comments

Comments
 (0)