Skip to content

Commit

Permalink
style(examples): processed with black and isort
Browse files Browse the repository at this point in the history
  • Loading branch information
TsXor committed Sep 4, 2022
1 parent b9a8a0b commit 92899c8
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 62 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
7 changes: 5 additions & 2 deletions examples/convert_smartobject_to_layer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Convert Smart object to artLayer."""

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

# Import local modules
Expand All @@ -10,10 +11,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},
},
},
}
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()
9 changes: 4 additions & 5 deletions examples/import_image_as_layer.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
"""Import a image as a artLayer."""

# Import built-in modules
import pathlib

# Import local modules
from photoshop import Session
import pathlib


with Session(action="new_document") as ps:
import_dict = {
'_classID':None,
'null':pathlib.Path("your/image/path") # replace it with your own path here
}
import_dict = {"_classID": None, "null": pathlib.Path("your/image/path")} # replace it with your own path here
import_desc = ps.ActionDescriptor.load(import_dict)
ps.app.executeAction(am.str2id("Plc "), import_desc) # `Plc` need one space in here.
6 changes: 2 additions & 4 deletions examples/replace_images.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""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
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
16 changes: 8 additions & 8 deletions examples/session_smart_sharpen.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,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"),
"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)
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"),
"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)

0 comments on commit 92899c8

Please sign in to comment.