diff --git a/examples/operation_channels.py b/examples/operation_channels.py new file mode 100644 index 00000000..9274a08a --- /dev/null +++ b/examples/operation_channels.py @@ -0,0 +1,12 @@ +"""A examples to show you how to operation active document channels.""" + +from photoshop import Session + +with Session() as ps: + doc = ps.active_document + print(len(doc.channels)) + doc.channels.add() + doc.channels.removeAll() + channel = doc.channels.getByName("Red") + print(channel.name) + channel.remove() diff --git a/src/photoshop/_channel.py b/src/photoshop/_channel.py new file mode 100644 index 00000000..6eb45f30 --- /dev/null +++ b/src/photoshop/_channel.py @@ -0,0 +1,61 @@ +from photoshop._core import Photoshop + + +# pylint: disable=too-many-public-methods +class Channel(Photoshop): + def __init__(self, parent): + super().__init__(parent=parent) + + @property + def color(self): + return self.app.color + + @color.setter + def color(self, value): + self.app.color = value + + @property + def histogram(self): + return self.app.histogram + + @histogram.setter + def histogram(self, value): + self.app.histogram = value + + @property + def kind(self): + return self.app.kind + + @kind.setter + def kind(self, value): + self.app.kind = value + + @property + def opacity(self): + return self.app.opacity + + @opacity.setter + def opacity(self, value): + self.app.opacity = value + + @property + def visible(self): + return self.app.visible + + @visible.setter + def visible(self, value): + self.app.visible = value + + @property + def name(self): + return self.app.name + + def duplicate(self, targetDocument=None): + self.app.duplicate(targetDocument) + + def merge(self): + self.app.merge() + + def remove(self): + channel = f'app.activeDocument.channels.getByName("{self.name}")' + self.eval_javascript(f"{channel}.remove()") diff --git a/src/photoshop/_channels.py b/src/photoshop/_channels.py new file mode 100644 index 00000000..3fcf8d5e --- /dev/null +++ b/src/photoshop/_channels.py @@ -0,0 +1,40 @@ +from photoshop._core import Photoshop +from photoshop._channel import Channel +from photoshop.errors import PhotoshopPythonAPIError + + +# pylint: disable=too-many-public-methods +class Channels(Photoshop): + def __init__(self, parent): + super().__init__(parent=parent) + + @property + def _channels(self): + return list(self.app) + + def __len__(self): + return self.length + + def __iter__(self): + for layer in self.app: + yield layer + + def __getitem__(self, item): + return self.app[item] + + @property + def length(self): + return len(self._channels) + + def add(self): + self.app.add() + + def removeAll(self): + self.app.removeAll() + + def getByName(self, name): + for channel in self._channels: + if channel.name == name: + return Channel(channel) + raise PhotoshopPythonAPIError("Could not find a channel named " + f'"{name}"') diff --git a/src/photoshop/_document.py b/src/photoshop/_document.py index 146d1041..e870384a 100644 --- a/src/photoshop/_document.py +++ b/src/photoshop/_document.py @@ -21,6 +21,7 @@ # Import local modules from photoshop._core import Photoshop +from photoshop._channels import Channels from photoshop._documentinfo import DocumentInfo from photoshop._layers import Layers from photoshop._layerSet import LayerSet @@ -95,7 +96,7 @@ def bitsPerChannel(self, value): @property def channels(self): - return self.app.channels + return Channels(self.app.channels) @property def colorProfileName(self): diff --git a/src/photoshop/_layerSet.py b/src/photoshop/_layerSet.py index 1ee05073..58fec3eb 100644 --- a/src/photoshop/_layerSet.py +++ b/src/photoshop/_layerSet.py @@ -3,7 +3,6 @@ from photoshop._layers import Layers from photoshop._artlayer import ArtLayer from photoshop.enumerations import AnchorPosition -from photoshop._layerSets import LayerSets class LayerSet(Photoshop): @@ -42,6 +41,8 @@ def layers(self): @property def layerSets(self): + # pylint: disable=import-outside-toplevel + from photoshop._layerSets import LayerSets return LayerSets(self.app.layerSets) @property diff --git a/src/photoshop/_layerSets.py b/src/photoshop/_layerSets.py index 9d1fd903..68422448 100644 --- a/src/photoshop/_layerSets.py +++ b/src/photoshop/_layerSets.py @@ -1,6 +1,6 @@ from photoshop._core import Photoshop -from photoshop._layerSet import LayerSet from photoshop.errors import PhotoshopPythonAPIError +from photoshop._layerSet import LayerSet class LayerSets(Photoshop): @@ -31,5 +31,5 @@ def getByName(self, name): for layer in self.app: if name == layer.name: return LayerSet(layer) - raise PhotoshopPythonAPIError("Could not find a LayerSet named " + raise PhotoshopPythonAPIError("Could not find a LayerSet named " f'"{name}"')