Skip to content

Commit

Permalink
Commands 'select' and 'mask' added. Readme actual.
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-brajer committed Jun 5, 2020
1 parent 21b0e4e commit 47661b4
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 5 deletions.
19 changes: 14 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ For example: `<position parse="tuple">100, 125</position>`.
- name (string)
- monochrome
- size (tuple)
- color (string)
- color (string) - hex code
- *name (string) = "Monochrome"*
- *position (tuple) = (0, 0)*
- *addToPosition (int) = 0*
- *addToPosition (int) = 0* - `-1` adds to just defined group
- import_layer_load
- filename (string)
- name (string)
- import_layer
- targetFile (string) - use `filename` filled in import_layer_load
- targetFile (string) - use `name` filled in import_layer_load
- targetLayer (string)
- *name (string) = targetLayer*
- *position (tuple) = (0, 0)*
Expand All @@ -75,15 +75,24 @@ For example: `<position parse="tuple">100, 125</position>`.
- text (string)
- font (string)
- fontSize (int)
- *textScale (float) = 1*
- *fontScale (float) = 1*
- *name (string) = "Text Layer"*
- *color (string) = "#000000"*
- *size (tuple) = autosize*
- *lineSpacing (float) = 0*
- *letterSpacing (float) = 0*
- *justification (int) = 0*
- *justification (int) = 0* - left: `0`, right: `1`, center: `2`, fill: `3`
- *position (tuple) = (0, 0)*
- *addToPosition (int) = 0*
- select
- *mode(string) = "select"* - possible values: `select`, `deselect`, any other
- *left(float) = 0* - dimensions in percentage of image size
- *right(float) = 100*
- *top(float) = 0*
- *bottom(float) = 100*
- mask
- layer(string)
- *<`select` commands>*
- hide
- *no parameters*

Expand Down
58 changes: 58 additions & 0 deletions card-assembler.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ def __init__(self, dataFolder):
'import_layer': self._command_import_layer,
'group': self._command_group,
'text': self._command_text,
'select': self._command_select,
'mask': self._command_mask,
'hide': self._command_hide,
}

Expand Down Expand Up @@ -247,6 +249,62 @@ def _command_text(self, command):
GF.pdb.gimp_layer_set_offsets(
textLayer, *command.get('position', (0, 0)))

def _command_select(self, command):
""" New selection by percentage of image size.
Parameters: [mode(string)], [left(float)], [right(float)],
[top(float)], [bottom(float)].
"""
if self.image is None:
raise AttributeError('Image to add the layer to not found.')

mode = command.get('mode', 'select')
if mode == 'deselect':
GF.pdb.gimp_selection_none(self.image)

elif mode == 'select':
x = round(GF.pdb.gimp_image_width(self.image)
* command.get('left', 0) / 100)
y = round(GF.pdb.gimp_image_height(self.image)
* command.get('top', 0) / 100)

width = round(GF.pdb.gimp_image_width(self.image)
* command.get('right', 100) / 100) - x
height = round(GF.pdb.gimp_image_height(self.image)
* command.get('bottom', 100) / 100) - y

if width <= 0:
raise ArithmeticError(
'Parameter "left" must be lesser than "right".')
if height <= 0:
raise ArithmeticError(
'Parameter "top" must be lesser than "bottom".')

GF.pdb.gimp_image_select_rectangle(
self.image,
0, # GIMP_CHANNEL_OP_ADD
x, y, width, height)
else:
pass

def _command_mask(self, command):
""" Mask layer.
Create mask for given layer from given selection.
Parameters: layer(string), [<'select' commands>].
"""
self._command_select(command)

layer = GF.pdb.gimp_image_get_layer_by_name(
self.image, command['targetLayer'])
mask = GF.pdb.gimp_layer_create_mask(
layer, 4) # GIMP_ADD_SELECTION_MASK
GF.pdb.gimp_layer_add_mask(layer, mask)

command['mode'] = 'deselect'
self._command_select(command)

def _command_hide(self, command):
""" Ignore command.
Expand Down

0 comments on commit 47661b4

Please sign in to comment.