Skip to content

Commit

Permalink
Implement doc channels (#23)
Browse files Browse the repository at this point in the history
* Add new example

* Add new option to save tga

* Remove _layer.py

* Clear up and add more enumerations

* Clear up

* Update package version

* implement doc channels

* Clear up

Co-authored-by: hao.long <[email protected]>
  • Loading branch information
loonghao and hao.long authored May 7, 2020
1 parent 38b178e commit 1633ed2
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 4 deletions.
12 changes: 12 additions & 0 deletions examples/operation_channels.py
Original file line number Diff line number Diff line change
@@ -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()
61 changes: 61 additions & 0 deletions src/photoshop/_channel.py
Original file line number Diff line number Diff line change
@@ -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()")
40 changes: 40 additions & 0 deletions src/photoshop/_channels.py
Original file line number Diff line number Diff line change
@@ -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}"')
3 changes: 2 additions & 1 deletion src/photoshop/_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion src/photoshop/_layerSet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/photoshop/_layerSets.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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}"')

0 comments on commit 1633ed2

Please sign in to comment.