It is currently Sun Nov 22, 2026 10:05 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 19 posts ] 
Author Message
 Post subject: names of the gradients (CLOSED)
PostPosted: Sun Nov 22, 2015 2:57 am  (#1) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14835
Location: roma, italy
GIMP Version: 2.8.14
Operating System: Windows
GIMP Experience: Basic Level



Hello Gimp gurus!
Maybe this is a stupid question.
Maybe there is a simple solution.
Anyhow my today's question is the following:

1-so far I used Gimp always setting in the Preferences the Language to English
2-now I'm using a Gimp with the default setting to system Language (Italian)
3-I noticed that the first 5 Gradients' names were changed to reflect the Italian Language set-up
but I tought it was only the way they look; NO, they seem to be really changed, in fact:
4-one of my filters which sets up the active gradient to "FG to BG (RGB)" crashes because it expects "Da pp a sf (RGB)"

IMHO it is an error the fact that Gimp changes those names, because they may have been used as constant in a script, but maybe there is an easy bypass (different from re-setting the Gimp Language to English) which I do not know.

Thanks

_________________
"Where am I ?"


Last edited by dinasset on Tue Nov 24, 2015 3:06 am, edited 2 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: names of the gradients
PostPosted: Sun Nov 22, 2015 3:09 am  (#2) 
Offline
Global Moderator
User avatar

Joined: May 16, 2010
Posts: 16293
Isn't there a way to include a "switch" in a filter to reflect the users machine language?

_________________
Image


Top
 Post subject: Re: names of the gradients
PostPosted: Sun Nov 22, 2015 3:15 am  (#3) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14835
Location: roma, italy
Thanks Rod.
No, I do not have a switch, and in any case to be flexible it should "read" the names in the active Language whatever it is (not just Italian and English, which can only work for myself but not generally).
I don't know how to do this.

_________________
"Where am I ?"


Last edited by dinasset on Sun Nov 22, 2015 9:02 am, edited 1 time in total.

Top
 Post subject: Re: names of the gradients
PostPosted: Sun Nov 22, 2015 7:37 am  (#4) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14835
Location: roma, italy
additional details:
- I know how to get the Language in Python:
    windll = ctypes.windll.kernel32
    langnr = windll.GetUserDefaultUILanguage()
    pdb.gimp_message("Your language number is:  "+str(langnr))
    lang = locale.windows_locale[ langnr ]
    pdb.gimp_message("Your language acronym is:  "+lang)
    return(lang)

this will send 2 messages (in my environment):
Your language number is: 1040
Your language acronym is: it_IT
- my script which crashes is a bit old and written in Scheme
- does someone know the equivalent set of statements to be written in Scheme?
(just to know, because I can eventually call the python routine from inside the scm script)

_________________
"Where am I ?"


Top
 Post subject: Re: names of the gradients
PostPosted: Sun Nov 22, 2015 9:25 am  (#5) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4812
dinasset wrote:
additional details:
- I know how to get the Language in Python:
    windll = ctypes.windll.kernel32
    langnr = windll.GetUserDefaultUILanguage()
    pdb.gimp_message("Your language number is:  "+str(langnr))
    lang = locale.windows_locale[ langnr ]
    pdb.gimp_message("Your language acronym is:  "+lang)
    return(lang)

this will send 2 messages (in my environment):
Your language number is: 1040
Your language acronym is: it_IT
- my script which crashes is a bit old and written in Scheme
- does someone know the equivalent set of statements to be written in Scheme?
(just to know, because I can eventually call the python routine from inside the scm script)


Two remarks: 1) your method only works on Windows, and 2) 'it_IT' is not an acronym, it is the combination of a language symbol: 'it' and a country symbol: 'IT', and people who use these things call them "locales".

About 1) have you tried to retrieve the locale from environment variables? That would work on all platforms.

_________________
Image


Top
 Post subject: Re: names of the gradients
PostPosted: Sun Nov 22, 2015 9:35 am  (#6) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14835
Location: roma, italy
Thanks Ofnuts.
I'm not an expert of python, now, only a very beginner, and I found those statements as suggested by googling
http://stackoverflow.com/questions/3425294/how-to-detect-the-os-default-language-in-python
I tried them and they work.
I don't know how to improve those to get the Language from the environment variables

_________________
"Where am I ?"


Top
 Post subject: Re: names of the gradients
PostPosted: Sun Nov 22, 2015 11:02 am  (#7) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14835
Location: roma, italy
continuing by googling I guess I found what you meant, Ofnuts.
The above code may be replaced by simply:
...
import os
...
    my_locales = os.getenv('LANGUAGE')   
    pdb.gimp_message("My language locales are:  "+my_locales)
    return(my_locales)
...


the displayed message is: My language locales are: it_IT

still open the question about the equivalent statements in Scheme (if any...)

_________________
"Where am I ?"


Top
 Post subject: Re: names of the gradients
PostPosted: Sun Nov 22, 2015 6:12 pm  (#8) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4812
dinasset wrote:
Thanks Ofnuts.
I'm not an expert of python, now, only a very beginner, and I found those statements as suggested by googling
http://stackoverflow.com/questions/3425294/how-to-detect-the-os-default-language-in-python
I tried them and they work.
I don't know how to improve those to get the Language from the environment variables


Funny that there are two answers, one with 9 points, one with one point, and you go with the one with one point... and my answer that works for you is very close to the one with 9 points :) there are plenty of bad responses on S/O but the ranking is usually right when determining the good ones.

_________________
Image


Top
 Post subject: Re: names of the gradients
PostPosted: Mon Nov 23, 2015 12:39 am  (#9) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14835
Location: roma, italy
Ofnuts, it's because the second answer (the one with 1 point) commented the first one (the one with 9 points) specifying that "you cannot rely on locale", followed by a clear example.
You don't agree?

_________________
"Where am I ?"


Top
 Post subject: Re: names of the gradients
PostPosted: Mon Nov 23, 2015 4:11 am  (#10) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4812
The actual S/O question is about "default system language" which for me doesn't mean "the current language in used for this specific process", so you aren't looking at the right question anyway:) But regarding that answer, if it were a really valid comment, it would have received more points... and the question specifically states "regardless what is the OS that is running the code" so an answer using Windows system calls it completely off-topic.

_________________
Image


Top
 Post subject: Re: names of the gradients
PostPosted: Mon Nov 23, 2015 5:23 am  (#11) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14835
Location: roma, italy
Ofnuts, only to be sure about MY LAST found solution (os.getenv('LANGUAGE'):
is it correct to detect the Language in which is running Gimp?
Or does it return the Windows (in my case) Language?
If so, how should I modify it?
Could you specify the correct statement(s) to me, I'm a bit tired to browse an infinity of Google posts....
Thanks

_________________
"Where am I ?"


Top
 Post subject: Re: names of the gradients
PostPosted: Mon Nov 23, 2015 8:53 am  (#12) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4812
For this I only believe in experimentation. It appears that
  1. the user's preferred language at the system level is in the LANGUAGE environment variable in both Linux and Windows (tested on Win7).
  2. If the user has explicitly set a different language in Gimp there is no Gimp API to find out and the LANGUAGE variable isn't changed. The only clue is the contents of the gimprc file.

So the only way to accurately figure things out is to:
  1. Parse the gimprc file and search for a (language "XX") line. If it exists use this.
  2. Otherwise, Gimp is using the system language, so fall back to the LANGUAGE environment variable

_________________
Image


Top
 Post subject: Re: names of the gradients
PostPosted: Mon Nov 23, 2015 8:55 am  (#13) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14835
Location: roma, italy
many thanks, Ofnuts

_________________
"Where am I ?"


Top
 Post subject: Re: names of the gradients
PostPosted: Mon Nov 23, 2015 11:52 am  (#14) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14835
Location: roma, italy
so, thru the OS environement and the gimprc file, it's possible to detect which is the currently active Language in Gimp; fine (thanks Ofnuts!).
But the main problem for scripts writers remains unresolved:
once detected the Language how can the script be able to translate the name appropriately?
It's easy for the author's Language (Italian in my case), because the translation is known and I can switch from English to Italian. But I'm not able to get the correct translation in other languages, so the filter cannot be published (should the author have this idea...).
I guess this is an open question for ALL SCRIPTS WRITERS.
I invite all those in the Gimp-chat arena who write and publish filters to enter this "game".
(BTW I'm still convinced that it's an error to have Gimp translating objects names)

_________________
"Where am I ?"


Top
 Post subject: Re: names of the gradients
PostPosted: Mon Nov 23, 2015 1:01 pm  (#15) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4812
dinasset wrote:
so, thru the OS environement and the gimprc file, it's possible to detect which is the currently active Language in Gimp; fine (thanks Ofnuts!).
But the main problem for scripts writers remains unresolved:
once detected the Language how can the script be able to translate the name appropriately?
It's easy for the author's Language (Italian in my case), because the translation is known and I can switch from English to Italian. But I'm not able to get the correct translation in other languages, so the filter cannot be published (should the author have this idea...).
I guess this is an open question for ALL SCRIPTS WRITERS.
I invite all those in the Gimp-chat arena who write and publish filters to enter this "game".
(BTW I'm still convinced that it's an error to have Gimp translating objects names)


You cannot really depend on these resources anyway. Not speaking of a user removing a resource he never uses, the name could change between Gimp releases... The good way to do it is to come with your own gradient, and either
  • create a temporary gradient on the fly using the rather complete gradient edition API (and delete it when you are done).
  • create a temporary gradient file from the script and then load it
  • install its own gradient in scripts/gradients (some scripts come with their specific images) and copy it to the gradient directory when needed (and remove it afterwards)

_________________
Image


Top
 Post subject: Re: names of the gradients (CLOSED)
PostPosted: Tue Nov 24, 2015 3:13 am  (#16) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14835
Location: roma, italy
OK, Ofnuts.
I wrote a routine to use a personal gradient instead of the standard FG to BG.
The filter calls this routine when needed, passing the values of the wanted FG and the wanted BG.
Here the code, in case someone else likes to have it.
def TempNewGradFGtoBG(FG, BG) :
   
    (num, listofgrad) = pdb.gimp_gradients_get_list("myFGtoBG")
    if num == 1:
        pdb.gimp_gradient_delete("myFGtoBG")   # delete the service gradient if it already exists
             
    temp_gradient = pdb.gimp_gradient_new("myFGtoBG")
   
    pdb.gimp_context_set_gradient(temp_gradient)
   
    pdb.gimp_gradient_segment_set_left_color(temp_gradient, 0, FG, 100)
    pdb.gimp_gradient_segment_set_right_color(temp_gradient, 0, BG, 100)
    pdb.gimp_gradient_segment_range_blend_colors(temp_gradient, 0, 0)
   
    pdb.gimp_gradients_refresh
   
    return(temp_gradient)



Hence, I closed the topic.

_________________
"Where am I ?"


Top
 Post subject: Re: names of the gradients (CLOSED)
PostPosted: Tue Nov 24, 2015 3:20 pm  (#17) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4812
You should better delete the gradient when you exit the script, otherwise your 'alien' gradient will remain around and users will wonder what is this strange gradient that resurrects... or at least name it after your script so they can figure out the relationship.

_________________
Image


Top
 Post subject: Re: names of the gradients (CLOSED)
PostPosted: Thu Nov 26, 2015 7:31 pm  (#18) 
Offline
Script Coder
User avatar

Joined: Jul 14, 2010
Posts: 697
Late to the party. To use one of the default gradients for any language use the following (this is the order in gimp 2.8, I don't know if it is different in other versions):

scheme:
(gimp-context-set-gradient (list-ref (cadr (gimp-gradients-get-list "")) ###))


python:
pdb.gimp_context_set_gradient(gimp.gradients_get_list()[###])


Where ### is the number:
0 - "FG to BG (Hardedge)"
1 - "FG to BG (HSV clockwise hue)"
2 - "FG to BG (HSV counter-clockwise)"
3 - "FG to BG (RGB)"
4 - "FG to Transparent"

-Rob A>

_________________
Image
Fantasy Cartography and Mapping by RobA


Top
 Post subject: Re: names of the gradients (CLOSED)
PostPosted: Fri Nov 27, 2015 12:29 am  (#19) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14835
Location: roma, italy
thanks Rob, very clean solution (as far as the Gimp developers will not change the order....as we hope)

_________________
"Where am I ?"


Top
Post new topic Reply to topic  [ 19 posts ] 

All times are UTC - 5 hours [ DST ]



* Login  



Powered by phpBB3 © phpBB Group