It is currently Fri Jun 28, 2024 12:41 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 39 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Script won't run the second time (solved)
PostPosted: Mon Aug 24, 2020 8:02 am  (#1) 
Offline
GimpChat Member

Joined: Jul 28, 2018
Posts: 1196
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.

#!/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()

_________________
https://www.deviantart.com/pocholo17
Image


Last edited by Pocholo on Wed Aug 26, 2020 3:17 pm, edited 8 times in total.

Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: Script won't run the second time
PostPosted: Mon Aug 24, 2020 10:06 am  (#2) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
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.

_________________
"Where am I ?"


Top
 Post subject: Re: Script won't run the second time
PostPosted: Mon Aug 24, 2020 2:21 pm  (#3) 
Offline
GimpChat Member

Joined: Jul 28, 2018
Posts: 1196
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.

_________________
https://www.deviantart.com/pocholo17
Image


Top
 Post subject: Re: Script won't run the second time
PostPosted: Mon Aug 24, 2020 4:12 pm  (#4) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4750
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.

_________________
Image


Top
 Post subject: Re: Script won't run the second time
PostPosted: Mon Aug 24, 2020 4:58 pm  (#5) 
Offline
GimpChat Member

Joined: Jul 28, 2018
Posts: 1196
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

_________________
https://www.deviantart.com/pocholo17
Image


Top
 Post subject: Re: Script won't run the second time
PostPosted: Mon Aug 24, 2020 10:18 pm  (#6) 
Offline
GimpChat Member
User avatar

Joined: Jan 13, 2011
Posts: 2260
Location: Poland
Hi Pocholo.

Solution 1.

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


Image

Solution 2.

Line 30
def pm_icon_pressed_effect(bgColor):


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


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


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


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

_________________
Image

Slava
Ukraini!


Top
 Post subject: Re: Script won't run the second time
PostPosted: Tue Aug 25, 2020 1:35 pm  (#7) 
Offline
GimpChat Member

Joined: Jul 28, 2018
Posts: 1196
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.
(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
(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.

_________________
https://www.deviantart.com/pocholo17
Image


Top
 Post subject: Re: Script won't run the second time
PostPosted: Tue Aug 25, 2020 2:40 pm  (#8) 
Offline
GimpChat Member
User avatar

Joined: Sep 27, 2016
Posts: 345
Location: Germany, BW
when I start gimp -c to get output on the console
this is what I get when it "runs" the second time:
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'

_________________
Regards
nelo

(Gimp 2.10 on Linux Mint MATE 20.1)


Top
 Post subject: Re: Script won't run the second time
PostPosted: Wed Aug 26, 2020 2:14 am  (#9) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4750
nelo wrote:
when I start gimp -c to get output on the console
this is what I get when it "runs" the second time:
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...

_________________
Image


Top
 Post subject: Re: Script won't run the second time (Unsolved)
PostPosted: Wed Aug 26, 2020 2:53 am  (#10) 
Offline
GimpChat Member

Joined: Mar 04, 2011
Posts: 2435
Looks like this problem has a history.

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

_________________
Image


Top
 Post subject: Re: Script won't run the second time (Unsolved)
PostPosted: Wed Aug 26, 2020 7:51 am  (#11) 
Offline
GimpChat Member

Joined: Jul 28, 2018
Posts: 1196
Thank you guy, I guess the developers never fixed it. I'm going to have to settle with:

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

_________________
https://www.deviantart.com/pocholo17
Image


Top
 Post subject: Re: Script won't run the second time (Unsolved)
PostPosted: Wed Aug 26, 2020 2:11 pm  (#12) 
Offline
GimpChat Member
User avatar

Joined: Jan 13, 2011
Posts: 2260
Location: Poland
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.


Attachments:
Active brush -  to icon.png
Active brush - to icon.png [ 115.78 KiB | Viewed 2178 times ]

_________________
Image

Slava
Ukraini!


Last edited by MareroQ on Wed Aug 26, 2020 5:16 pm, edited 1 time in total.
Top
 Post subject: Re: Script won't run the second time (Unsolved)
PostPosted: Wed Aug 26, 2020 2:58 pm  (#13) 
Offline
GimpChat Member
User avatar

Joined: Jul 06, 2013
Posts: 2607
Location: California
MareroQ,

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


Top
 Post subject: Re: Script won't run the second time (Unsolved)
PostPosted: Wed Aug 26, 2020 3:14 pm  (#14) 
Offline
GimpChat Member

Joined: Jul 28, 2018
Posts: 1196
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.

_________________
https://www.deviantart.com/pocholo17
Image


Top
 Post subject: Re: Script won't run the second time (solved)
PostPosted: Wed Aug 26, 2020 5:17 pm  (#15) 
Offline
GimpChat Member
User avatar

Joined: Jan 13, 2011
Posts: 2260
Location: Poland
I would like to always make progress as fast as you do. :hi5

_________________
Image

Slava
Ukraini!


Top
 Post subject: Re: Script won't run the second time (solved)
PostPosted: Wed Aug 26, 2020 6:03 pm  (#16) 
Offline
GimpChat Member

Joined: Jul 28, 2018
Posts: 1196
Thanks MareroQ! :)

_________________
https://www.deviantart.com/pocholo17
Image


Top
 Post subject: Re: Script won't run the second time (solved)
PostPosted: Thu Aug 27, 2020 9:56 am  (#17) 
Offline
GimpChat Member
User avatar

Joined: Jan 13, 2011
Posts: 2260
Location: Poland
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.


Attachments:
Icon with text.png
Icon with text.png [ 60.31 KiB | Viewed 2104 times ]

_________________
Image

Slava
Ukraini!


Last edited by MareroQ on Fri Aug 28, 2020 1:13 am, edited 1 time in total.
Top
 Post subject: Re: Script won't run the second time (solved)
PostPosted: Thu Aug 27, 2020 10:22 am  (#18) 
Offline
GimpChat Member
User avatar

Joined: May 10, 2013
Posts: 1389
Location: FInland
Edit, works okay. :tyspin


Last edited by Nidhogg on Thu Aug 27, 2020 11:43 am, edited 2 times in total.

Top
 Post subject: Re: Script won't run the second time (solved)
PostPosted: Thu Aug 27, 2020 10:35 am  (#19) 
Offline
GimpChat Member
User avatar

Joined: Jan 13, 2011
Posts: 2260
Location: Poland
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).


Attachments:
example Unicode1.png
example Unicode1.png [ 98.86 KiB | Viewed 2093 times ]
example Unicode2.png
example Unicode2.png [ 57.9 KiB | Viewed 2093 times ]

_________________
Image

Slava
Ukraini!
Top
 Post subject: Re: Script won't run the second time (solved)
PostPosted: Thu Aug 27, 2020 10:48 am  (#20) 
Offline
GimpChat Member
User avatar

Joined: May 10, 2013
Posts: 1389
Location: FInland
MareroQ, the Unicode plug-in(s) you wrote are good for this :bigthup

Attachment:
ZapfDingbats-Rho.png
ZapfDingbats-Rho.png [ 42.58 KiB | Viewed 2080 times ]


Last edited by Nidhogg on Thu Aug 27, 2020 11:41 am, edited 1 time in total.

Top
Post new topic Reply to topic  [ 39 posts ]  Go to page 1, 2  Next

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Time to update your script-fu...

3

No new posts Attachment(s) Wanted Part-time/full-time Moderators

64

No new posts Seeing the Stars for the first time

3

No new posts Time For A New Wilber

2

No new posts What a time to be alive.

8



* Login  



Powered by phpBB3 © phpBB Group