Switch to full style
Post all Gimp scripts and script writing questions here
Post a reply

Script won't run the second time (solved)

Mon Aug 24, 2020 8:02 am

Hi you all! I wrote this python script trying to create 500 x 500 px "Icon pressed effect", and I'm stuck. The script run perfect the first time but when i try to run the second time it won't appear. I'm made it that you can choose your own media icon brush. I think it has to be with the added param for the brushes. Can any of the experience coder tell me why it's not working the second time so I can fix it?

Ps Attach is a set of icon brushes I create for the testing.

Code:
#!/usr/bin/env python

# Inspire by Conbagui tutorial found here: http://fav.me/ddit8ur
# author: Pocholo
# date: 6/6/20

# Comments directed to http://gimpchat.com

# Installation:
# This script should be placed in the user plugin folder

# Copyright (C)

#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by   
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.

#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see <https://www.gnu.org/licenses/>.


from gimpfu import *

def pm_icon_pressed_effect(bgColor, brush):
   
   #Initiates the temporary state   
   pdb.gimp_context_push()
   
   #Variables
   size = 550
   
   #Create a new image
   img = pdb.gimp_image_new(size, size, RGB)
         
   #Create a transparent background
   backLayer = pdb.gimp_layer_new(img, size, size, RGB_IMAGE, "Background", 100, LAYER_MODE_NORMAL)
   pdb.gimp_image_add_layer(img, backLayer, 0)
   pdb.gimp_layer_add_alpha(backLayer)
   pdb.gimp_drawable_fill(backLayer, FILL_TRANSPARENT)
      
   #Create the icon background
   pdb.gimp_image_select_round_rectangle(img, 2, 19, 19, 512, 512, 50, 50)
   pdb.gimp_context_set_background(bgColor)
   pdb.gimp_drawable_edit_fill(backLayer, FILL_BACKGROUND)
   pdb.gimp_context_set_foreground((200, 85, 255))
   pdb.gimp_edit_blend(backLayer, 2, LAYER_MODE_NORMAL, 0, 100, 0, 0, FALSE, TRUE, 5, 0.20, TRUE, 275, 20, 275, 275)
   
   #Create a copy
   non_empty = pdb.gimp_edit_copy(backLayer)
   copyLayer = pdb.gimp_layer_new(img, img.width, img.height, RGB, "Copy", 100, LAYER_MODE_NORMAL)
   pdb.gimp_image_add_layer(img, copyLayer, 0)
   pdb.gimp_layer_add_alpha(copyLayer)
   pdb.gimp_drawable_fill(copyLayer, FILL_TRANSPARENT)
   floating_sel = pdb.gimp_edit_paste(copyLayer, FALSE)
   pdb.gimp_floating_sel_anchor(floating_sel)
   
   #Gaussian blur and merge
   pdb.gimp_image_select_item(img, 2, copyLayer)
   pdb.plug_in_gauss_rle2(img, copyLayer, 120, 120)
   backLayer = pdb.gimp_image_merge_visible_layers(img, 2)
   pdb.gimp_selection_none(img)
      
   #Create icon layer
   iconLayer = pdb.gimp_layer_new(img, img.width, img.height, RGB, "Icon", 100, LAYER_MODE_NORMAL)
   pdb.gimp_image_add_layer(img, iconLayer, 0)
   pdb.gimp_layer_add_alpha(iconLayer)
   pdb.gimp_drawable_fill(iconLayer, FILL_TRANSPARENT)
      
   #Paint icon
   name = pdb.gimp_context_get_brush()
   pdb.gimp_context_set_brush (brush)
   pdb.gimp_context_set_brush_size(500)
   pdb.gimp_context_set_brush_aspect_ratio(0)
   pdb.gimp_context_set_brush_angle(0)
   pdb.gimp_context_set_brush_spacing(10)
   pdb.gimp_context_set_brush_hardness(1)
   pdb.gimp_context_set_brush_force(1)
   pdb.gimp_context_set_foreground ((71, 30, 85))
   pdb.gimp_paintbrush_default(iconLayer, 2, [275, 275])
      
   #Drop Shadow
   pdb.python_layerfx_drop_shadow(img, iconLayer,
                          (190, 125, 207),   #color
                                    75,   #opacity
                                    0,   #contou - linear
                                    0,   #noise
                                    5,   #mode - overlay
                                    0,   #spread
                                     1,   #size
                                   100,   #offset_angle
                                    2,   #offset_distance
                                  TRUE,   #knockout
                                 FALSE)   #merge
   
   
   #Text inner shadow
   pdb.python_layerfx_inner_shadow(img, iconLayer,
                            (0, 0, 0),   #color
                                   75,   #opacity
                                   0,   #contou -linear
                                   0,   #noise
                                   3,   #mode - multiply
                                   1,   #source
                                   0,   #choke
                                    6,   #size
                                 100,   #offset_angle
                                   8,   #offset_distance
                                 FALSE)  #merge
   
   
   #Inner Glow                           
   pdb.python_layerfx_inner_glow(img, iconLayer,
                            (0, 0, 0),   #color
                                 30,   #opacity
                                 0,   #contou - linear
                                 0,   #noise
                                     3,   #mode - multiply
                                 1,   #source
                                 0,   #choke
                                  3,   #size
                              FALSE)   #merge
   
   
   #Bevel and Emboss   
   backLayer = pdb.gimp_image_get_layer_by_name(img, "Background")
   pdb.gimp_image_set_active_layer(img, backLayer)
   pdb.python_layerfx_bevel_emboss(img, backLayer,
                                    1,   #style inner bevel
                                    65,   #depth
                                     0,   #direction
                                     3,   #size
                                    4,   #soften
                                   100,   #angle
                                    30,   #altitude
                                    0,   #gloss_contour - linear
                        (255, 255, 255),   #highlight_color
                                     4,   #highlight_mode-screen
                                    75,   #highlight_opacity
                            (78, 48, 0),   #shadow_color
                                     3,   #shadow_mode-multiply
                                    20,   #shadow_opacity
                                     0,   #surface_contour - linear
                                 FALSE,   #use_texture
                            "Dried mud",   #pattern
                                   100,   #scale
                                   100,   #tex_depth
                                  TRUE,   #invert
                                 FALSE)   #merge   
   
      
   #Resets the previous user defaults
   pdb.gimp_context_pop()
   
   gimp.Display(img)
   
register(
   "pm_icon_pressed_effect",
   "Creates a pressed icon",
   "Creates a pressed icon",
   "Pocholo",
   "Pocholo",
   "2020",
   "Icon pressed effect",
   "",
[
   (PF_COLOR, "bgColor", "Background color", (150, 84, 180)),
   (PF_BRUSH, "brush", "Choose icon", 0),
],
[],
pm_icon_pressed_effect, menu="<Image>/Pocholo-scripts/Icon pressed effect"),
main()

Re: Script won't run the second time

Mon Aug 24, 2020 10:06 am

Good question for Ofnuts.

BTW, I do not understand why you pretend an input image which is not used, instead of creating one new yourself.

Re: Script won't run the second time

Mon Aug 24, 2020 2:21 pm

dinasset wrote:Good question for Ofnuts.

BTW, I do not understand why you pretend an input image which is not used, instead of creating one new yourself.


You're right. I was writing this script late last night and I was falling asleep from time to time. So I found out that you put your brain to rest and not over work it. :hehe

I fixed it so it create a new image. Still, I run the script once and It work perfectly but when I try it to run again won't do anything. I hope someone help me on this.

Re: Script won't run the second time

Mon Aug 24, 2020 4:12 pm

I don't see anything in your code that can help you debug the problem. A python script normally issues messages when crashing. See https://www.gimp-forum.net/Thread-Debug ... in-Windows for some hints and techniques.

This said, having one color and one brush as parameters when you can use those set in the context (that the user can set using the GUI...) while at the same time having the script rigidly creating 500px images tells me that you have got your priorities wrong.

Re: Script won't run the second time

Mon Aug 24, 2020 4:58 pm

ofnuts wrote:I don't see anything in your code that can help you debug the problem. A python script normally issues messages when crashing. See https://www.gimp-forum.net/Thread-Debug ... in-Windows for some hints and techniques.

This said, having one color and one brush as parameters when you can use those set in the context (that the user can set using the GUI...) while at the same time having the script rigidly creating 500px images tells me that you have got your priorities wrong.


Thank for the respond. Well, the script is not issuing any error. It worked perfectly when you run it the first time, but when you try to run it the second time the dialog won't even appear. Now, if I go to: Filters> Reset all filters, the script work.


www.youtube.com Video from : www.youtube.com

Re: Script won't run the second time

Mon Aug 24, 2020 10:18 pm

Hi Pocholo.

Solution 1.

Line 173
Code:
   (PF_STRING, "nombre", "Name brush", "GIMP Brush #26"), #(PF_BRUSH, "brush", "Choose icon", 0),


Image

Solution 2.

Line 30
Code:
def pm_icon_pressed_effect(bgColor):


Line 77
Code:
   pdb.gimp_context_set_brush (name) #pdb.gimp_context_set_brush (brush)


Line 173
Code:
#(PF_BRUSH, "brush", "Choose icon", 0),


Image
------------------------------------------------------------------------------
ps.
Line 51 (typo ..rr..)
Code:
   pdb.gimp_context_set_foreground((200, 85, 255)) #pdb.gimp_context_set_forreground((200, 85, 255))


Line 2 add:
Code:
   # -*- coding: utf-8 -*-

Re: Script won't run the second time

Tue Aug 25, 2020 1:35 pm

Thank you for the tips, MareroQ. Still the question remained unanswered. If I write it like you mention it work but instead you have to right the name of the brush you want to use for the script.
Code:
(PF_STRING, "brush", "Brush name", ""),


Meanwhile I want to user be able to choose the brush from the pop up brush dialog using the param below
Code:
(PF_BRUSH, "brush", "Choose brush", None),


The filter shows up and I'm able to choose the brush I want, but it will run only once. Try to run the script again and it doesn't shows up.

Re: Script won't run the second time

Tue Aug 25, 2020 2:40 pm

when I start gimp -c to get output on the console
this is what I get when it "runs" the second time:
Code:
Traceback (most recent call last):
  File "/app/lib/gimp/2.0/python/gimpfu.py", line 853, in _run
    res = _interact(proc_name, params[1:])
  File "/app/lib/gimp/2.0/python/gimpfu.py", line 774, in _interact
    wid = _edit_mapping[pf_type](def_val)
  File "/app/lib/gimp/2.0/python/gimpui.py", line 193, in __init__
    self.set_brush(default, -1.0, -1, -1)
AttributeError: 'BrushSelector' object has no attribute 'set_brush'

Re: Script won't run the second time

Wed Aug 26, 2020 2:14 am

nelo wrote:when I start gimp -c to get output on the console
this is what I get when it "runs" the second time:
Code:
Traceback (most recent call last):
  File "/app/lib/gimp/2.0/python/gimpfu.py", line 853, in _run
    res = _interact(proc_name, params[1:])
  File "/app/lib/gimp/2.0/python/gimpfu.py", line 774, in _interact
    wid = _edit_mapping[pf_type](def_val)
  File "/app/lib/gimp/2.0/python/gimpui.py", line 193, in __init__
    self.set_brush(default, -1.0, -1, -1)
AttributeError: 'BrushSelector' object has no attribute 'set_brush'


Looks like a Gimp bug...

Re: Script won't run the second time (Unsolved)

Wed Aug 26, 2020 2:53 am

Looks like this problem has a history.

Ofnuts posted working / non-working examples: https://www.gimp-forum.net/Thread-GIMP- ... 71#pid7971

Re: Script won't run the second time (Unsolved)

Wed Aug 26, 2020 7:51 am

Thank you guy, I guess the developers never fixed it. I'm going to have to settle with:

Code:
(PF_STRING, "brush", "Brush name", ""),

Re: Script won't run the second time (Unsolved)

Wed Aug 26, 2020 2:11 pm

Hi Pocholo.

Why didn't you try Solution 2. :gaah
This is an example of using an active brush (selectable by clicking). :yes
This is your plugin, so I will remove the attachment when you let me know you looked at some minor changes.


Edit:As announced, the attachment has been removed.

Re: Script won't run the second time (Unsolved)

Wed Aug 26, 2020 2:58 pm

MareroQ,

Your addition to Pocholo's script works well. Here's my outcome from the addition that you made: Image

Re: Script won't run the second time (Unsolved)

Wed Aug 26, 2020 3:14 pm

MareroQ wrote:Hi Pocholo.

Why didn't you try Solution 2. :gaah
This is an example of using an active brush (selectable by clicking). :yes
This is your plugin, so I will remove the attachment when you let me know you looked at some minor changes.


Sorry about that, Your script it's a little more complex, thank you for the inpunt. Since I'm still in the learning process I like to learn the "Scale factor". When I resize the Layer or image, I want the filters or plugin used in the code, to increase with the Layer.

At this age 60 yrs old and I started to learn coding just before when the pandemic stated.
So far all I done are simple scripts on what I have learn this past few months.

Re: Script won't run the second time (solved)

Wed Aug 26, 2020 5:17 pm

I would like to always make progress as fast as you do. :hi5

Re: Script won't run the second time (solved)

Wed Aug 26, 2020 6:03 pm

Thanks MareroQ! :)

Re: Script won't run the second time (solved)

Thu Aug 27, 2020 9:56 am

I'm sorry to interfere again - but the "named brush" option can be easily exploited by copying the image/text and using the "Clipboard Mask".
Plugin Pocholo (with minor changes) with using text - example in attachment.

Edit: attachment removed due to internationalization error.

Re: Script won't run the second time (solved)

Thu Aug 27, 2020 10:22 am

Edit, works okay. :tyspin

Re: Script won't run the second time (solved)

Thu Aug 27, 2020 10:35 am

A certain advantage of this solution is the possibility of using UNICODE signs (with the use of BabelMap - indicated by Nidhogg - for which I would like to thank you again).

Re: Script won't run the second time (solved)

Thu Aug 27, 2020 10:48 am

MareroQ, the Unicode plug-in(s) you wrote are good for this :bigthup

ZapfDingbats-Rho.png
ZapfDingbats-Rho.png (42.58 KiB) Viewed 2090 times
Post a reply