diff --git a/README.md b/README.md index a4f1b1f..29430bf 100644 --- a/README.md +++ b/README.md @@ -55,15 +55,15 @@ For example: `100, 125`. - 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)* @@ -75,15 +75,24 @@ For example: `100, 125`. - 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* diff --git a/card-assembler.py b/card-assembler.py index 89017f6..45f5208 100644 --- a/card-assembler.py +++ b/card-assembler.py @@ -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, } @@ -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.