From 92899c8da2c86a9919990bdd4c2ce4f282fb43cb Mon Sep 17 00:00:00 2001 From: TsXor Date: Mon, 5 Sep 2022 00:03:54 +0800 Subject: [PATCH] style(examples): processed with black and isort --- examples/apply_crystallize_filter_action.py | 5 +- examples/convert_smartobject_to_layer.py | 7 ++- examples/emboss_action.py | 55 +++++++++------------ examples/import_image_as_layer.py | 9 ++-- examples/replace_images.py | 6 +-- examples/session_smart_sharpen.py | 16 +++--- examples/smart_sharpen.py | 17 ++++--- 7 files changed, 53 insertions(+), 62 deletions(-) diff --git a/examples/apply_crystallize_filter_action.py b/examples/apply_crystallize_filter_action.py index 7d4b38a8..5303a6e0 100644 --- a/examples/apply_crystallize_filter_action.py +++ b/examples/apply_crystallize_filter_action.py @@ -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) diff --git a/examples/convert_smartobject_to_layer.py b/examples/convert_smartobject_to_layer.py index c5ebfc28..5ff63957 100644 --- a/examples/convert_smartobject_to_layer.py +++ b/examples/convert_smartobject_to_layer.py @@ -1,6 +1,7 @@ """Convert Smart object to artLayer.""" # Import builtin modules +# Import built-in modules from textwrap import dedent # Import local modules @@ -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 diff --git a/examples/emboss_action.py b/examples/emboss_action.py index 5869bdf1..9fa08d92 100644 --- a/examples/emboss_action.py +++ b/examples/emboss_action.py @@ -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() diff --git a/examples/import_image_as_layer.py b/examples/import_image_as_layer.py index 49c39ceb..c2a77aed 100644 --- a/examples/import_image_as_layer.py +++ b/examples/import_image_as_layer.py @@ -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. diff --git a/examples/replace_images.py b/examples/replace_images.py index 66cd28f6..5f10a1fe 100644 --- a/examples/replace_images.py +++ b/examples/replace_images.py @@ -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 @@ -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) diff --git a/examples/session_smart_sharpen.py b/examples/session_smart_sharpen.py index ff279953..e1e6ee5a 100644 --- a/examples/session_smart_sharpen.py +++ b/examples/session_smart_sharpen.py @@ -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) \ No newline at end of file + SmartSharpen(300, 2.0, 20) diff --git a/examples/smart_sharpen.py b/examples/smart_sharpen.py index f850d05e..c23d554a 100644 --- a/examples/smart_sharpen.py +++ b/examples/smart_sharpen.py @@ -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) \ No newline at end of file + +SmartSharpen(300, 2.0, 20)