Skip to content

Commit

Permalink
fix(action_manager): do monkey patch to support py37
Browse files Browse the repository at this point in the history
It seems that hound still think a line should only have 80 chars though you set it to 120.

Signed-off-by: TsXor <[email protected]>
  • Loading branch information
TsXor committed Sep 7, 2022
1 parent 5835d2a commit f60b236
Show file tree
Hide file tree
Showing 33 changed files with 841 additions and 663 deletions.
5 changes: 1 addition & 4 deletions examples/apply_crystallize_filter_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@
active_document.activeLayer = active_document.layerSets.item(len(nLayerSets)).artLayers.item(len(nArtLayers))

def applyCrystallize(cellSize):
filter_dict = {
'_classID':None,
'ClSz':cellSize
}
filter_dict = {"_classID": None, "ClSz": cellSize}
filter_desc = ps.ActionDescriptor.load(filter_dict)
ps.app.executeAction(am.str2id("Crst"), filter_desc)

Expand Down
8 changes: 5 additions & 3 deletions examples/convert_smartobject_to_layer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Convert Smart object to artLayer."""

# Import builtin modules
# Import built-in modules
from textwrap import dedent

# Import local modules
Expand All @@ -10,10 +10,12 @@

# example 1
with Session() as ps:
js = dedent("""
js = dedent(
"""
var idplacedLayerConvertToLayers = stringIDToTypeID( "placedLayerConvertToLayers" );
executeAction( idplacedLayerConvertToLayers, undefined, DialogModes.NO );
""")
"""
)
ps.app.doJavaScript(js)

# example 2
Expand Down
55 changes: 24 additions & 31 deletions examples/emboss_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,47 @@
from photoshop import Session
import photoshop.api.action_manager as am


with Session() as ps:
app = ps.app
for index, x in enumerate(range(50)):
# Execute an existing action from action palette.
exec_dict = {
'_classID':None,
'null':[
'!ref',
am.ReferenceKey(desiredclass='action', value='Sepia Toning (layer)'),
am.ReferenceKey(desiredclass='actionSet', value='Default Actions')
]
"_classID": None,
"null": [
"!ref",
am.ReferenceKey(desiredclass="action", value="Sepia Toning (layer)"),
am.ReferenceKey(desiredclass="actionSet", value="Default Actions"),
],
}
exec_desc = ps.ActionDescriptor.load(exec_dict)
app.executeAction(am.str2id('Ply '), exec_desc, ps.DialogModes.DisplayNoDialogs)
app.executeAction(am.str2id("Ply "), exec_desc, ps.DialogModes.DisplayNoDialogs)

# Create solid color fill layer.
filledlayer_dict = {
'_classID':None,
'null':[
'!ref',
am.ReferenceKey(desiredclass='contentLayer',value=None)
],
'using':{
'_classID':'contentLayer',
'type':{
'_classID':'solidColorLayer',
'color':{
'_classID':'RGBColor',
'red':index,
'grain':index,
'blue':index
}
}
}
"_classID": None,
"null": ["!ref", am.ReferenceKey(desiredclass="contentLayer", value=None)],
"using": {
"_classID": "contentLayer",
"type": {
"_classID": "solidColorLayer",
"color": {"_classID": "RGBColor", "red": index, "grain": index, "blue": index}, # noqa
},
},
}
filledlayer_desc = ps.ActionDescriptor.load(filledlayer_dict)
app.executeAction(am.str2id('Mk '), filledlayer_desc, ps.DialogModes.DisplayNoDialogs)
app.executeAction(am.str2id("Mk "), filledlayer_desc, ps.DialogModes.DisplayNoDialogs)

# Select mask.
selectmask_dict = {
'_classID':None,
'null':[
'!ref',
am.ReferenceKey(desiredclass='channel', value=am.Enumerated(type='channel',value='mask'))
"_classID": None,
"null": [
"!ref",
am.ReferenceKey(desiredclass="channel", value=am.Enumerated(type="channel", value="mask")),
],
'makeVisible':False
"makeVisible": False,
}
selectmask_desc = ps.ActionDescriptor.load(selectmask_dict)
app.executeAction(am.str2id('slct'), selectmask_desc, ps.DialogModes.DisplayNoDialogs)
app.executeAction(am.str2id("slct"), selectmask_desc, ps.DialogModes.DisplayNoDialogs)

app.activeDocument.activeLayer.invert()
14 changes: 8 additions & 6 deletions examples/import_image_as_layer.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
"""Import a image as a artLayer."""

# Import built-in modules
import pathlib

# Import local modules
from photoshop import Session
import pathlib
import photoshop.api.action_manager as am


with Session(action="new_document") as ps:
import_dict = {
'_classID':None,
'null':pathlib.Path("your/image/path") # replace it with your own path here
}
# replace it with your own path here
import_dict = {"_classID": None, "null": pathlib.Path("your/image/path")}
import_desc = ps.ActionDescriptor.load(import_dict)
ps.app.executeAction(am.str2id("Plc "), import_desc) # `Plc` need one space in here.
ps.app.executeAction(am.str2id("Plc "), import_desc)
# length of charID should always be 4, if not, pad with spaces
8 changes: 3 additions & 5 deletions examples/replace_images.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
"""Replace the image of the current active layer with a new image."""

# Import builtin modules
# Import built-in modules
import pathlib

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

# Import local modules
from photoshop import Session
import photoshop.api.action_manager as am


PSD_FILE = psd.get_psd_files()
Expand All @@ -17,10 +18,7 @@
active_layer = ps.active_document.activeLayer
bounds = active_layer.bounds
print(f"current layer {active_layer.name}: {bounds}")
input_dict = {
'_classID':None,
'null':pathlib.Path(PSD_FILE["red_100x200.png"])
}
input_dict = {"_classID": None, "null": pathlib.Path(PSD_FILE["red_100x200.png"])}
input_desc = ps.ActionDescriptor.load(input_dict)
ps.app.executeAction(am.str2id("placedLayerReplaceContents"), input_desc)

Expand Down
17 changes: 9 additions & 8 deletions examples/session_smart_sharpen.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

# Import local modules
from photoshop import Session
import photoshop.api.action_manager as am


PSD_FILE = psd.get_psd_files()
Expand All @@ -20,14 +21,14 @@

def SmartSharpen(inAmount, inRadius, inNoise):
ss_dict = {
'_classID':None,
'presetKindType':am.Enumerated(type='presetKindType', value='presetKindCustom'),
'amount':am.UnitDouble(unit='radius', double=inAmount),
'radius':am.UnitDouble(unit='pixelsUnit', double=inRadius),
'noiseReduction':am.UnitDouble(unit='percentUnit', double=inNoise),
'blur':am.Enumerated(type='blurType', value='gaussianBlur')
"_classID": None,
"presetKindType": am.Enumerated(type="presetKindType", value="presetKindCustom"), # noqa
"amount": am.UnitDouble(unit="radius", double=inAmount),
"radius": am.UnitDouble(unit="pixelsUnit", double=inRadius),
"noiseReduction": am.UnitDouble(unit="percentUnit", double=inNoise),
"blur": am.Enumerated(type="blurType", value="gaussianBlur"),
}
ss_desc = ps.ActionDescriptor.load(ss_dict)
app.ExecuteAction(am.str2id('smartSharpen'), ss_desc)
ps.app.ExecuteAction(am.str2id("smartSharpen"), ss_desc)

SmartSharpen(300, 2.0, 20)
SmartSharpen(300, 2.0, 20)
17 changes: 9 additions & 8 deletions examples/smart_sharpen.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@

def SmartSharpen(inAmount, inRadius, inNoise):
ss_dict = {
'_classID':None,
'presetKindType':am.Enumerated(type='presetKindType', value='presetKindCustom'),
'amount':am.UnitDouble(unit='radius', double=inAmount),
'radius':am.UnitDouble(unit='pixelsUnit', double=inRadius),
'noiseReduction':am.UnitDouble(unit='percentUnit', double=inNoise),
'blur':am.Enumerated(type='blurType', value='gaussianBlur')
"_classID": None,
"presetKindType": am.Enumerated(type="presetKindType", value="presetKindCustom"), # noqa
"amount": am.UnitDouble(unit="radius", double=inAmount),
"radius": am.UnitDouble(unit="pixelsUnit", double=inRadius),
"noiseReduction": am.UnitDouble(unit="percentUnit", double=inNoise),
"blur": am.Enumerated(type="blurType", value="gaussianBlur"),
}
ss_desc = ps.ActionDescriptor.load(ss_dict)
app.ExecuteAction(am.str2id('smartSharpen'), ss_desc)
app.ExecuteAction(am.str2id("smartSharpen"), ss_desc)

SmartSharpen(300, 2.0, 20)

SmartSharpen(300, 2.0, 20)
24 changes: 15 additions & 9 deletions photoshop/api/_actionmanager_type_binder.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,25 @@

# Import local modules
from photoshop.api.action_descriptor import ActionDescriptor as AD_proto
from photoshop.api.action_manager._main_types.action_descriptor import ActionDescriptor as AD_utils_proto
from photoshop.api.action_list import ActionList as AL_proto
from photoshop.api.action_manager._main_types.action_list import ActionList as AL_utils_proto
from photoshop.api.action_manager._main_types.action_descriptor import (
ActionDescriptor as AD_utils_proto,
)
from photoshop.api.action_manager._main_types.action_list import (
ActionList as AL_utils_proto,
)
from photoshop.api.action_manager._main_types.action_reference import (
ActionReference as AR_utils_proto,
)
from photoshop.api.action_reference import ActionReference as AR_proto
from photoshop.api.action_manager._main_types.action_reference import ActionReference as AR_utils_proto
from photoshop.api.enumerations import DescValueType
from photoshop.api.enumerations import ReferenceFormType


class ActionDescriptor(AD_proto, AD_utils_proto):
@classmethod
def load(cls, adict: dict) -> 'ActionDescriptor':
'''Convert a python object to an ActionDescriptor'''
def load(cls, adict: dict) -> "ActionDescriptor":
"""Convert a python object to an ActionDescriptor"""
return super().load(adict, globals())

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

class ActionList(AL_proto, AL_utils_proto):
@classmethod
def load(cls, alist: list) -> 'ActionList':
'''Convert a python object to an ActionList'''
def load(cls, alist: list) -> "ActionList":
"""Convert a python object to an ActionList"""
return super().load(alist, globals())

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

class ActionReference(AR_proto, AR_utils_proto):
@classmethod
def load(cls, adict: dict) -> 'ActionReference':
'''Convert a python object to an ActionReference'''
def load(cls, adict: dict) -> "ActionReference":
"""Convert a python object to an ActionReference"""
return super().load(adict)

def getForm(self) -> ReferenceFormType:
Expand Down
42 changes: 25 additions & 17 deletions photoshop/api/action_manager/__init__.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
from .ref_form_types import *
from .desc_value_types import *
from .utils import *
from .desc_value_types import Enumerated
from .desc_value_types import TypeID
from .desc_value_types import UnitDouble
from .jprint import jformat
from .jprint import jprint
from .js_converter import dump as dumpjs
from .jprint import *
from .ref_form_types import Identifier
from .ref_form_types import Index
from .ref_form_types import Offset
from .ref_form_types import ReferenceKey
from .utils import id2str
from .utils import str2id


__all__ = [ # noqa: F405
'str2id',
'id2str',
'Enumerated',
'TypeID',
'UnitDouble',
'Identifier',
'Index',
'Offset',
'ReferenceKey',
'dumpjs',
'jprint',
'jformat',
]
"str2id",
"id2str",
"Enumerated",
"TypeID",
"UnitDouble",
"Identifier",
"Index",
"Offset",
"ReferenceKey",
"dumpjs",
"jprint",
"jformat",
]
Loading

0 comments on commit f60b236

Please sign in to comment.