Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Thu 17 Oct 2019, 22:35
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Listing all color names
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 2 [22 Posts]   Goto page: 1, 2 Next
Author Message
MochiMoppel


Joined: 26 Jan 2011
Posts: 1921
Location: Japan

PostPosted: Wed 06 Feb 2019, 04:14    Post subject:  Listing all color names  

Problem 1
Setting a color option for X applications usually requires to specify a color as RGB hex value (e.g. #FF0022) .
As an alternative to those cryptic hex values the user may use color names like "white" or "orange", which is fine, but more than 700 of such names exist, some of them exotic like
██████ #6B8E23 OliveDrab
██████ #EECBAD PeachPuff2
██████ #1874CD DodgerBlue3
So the question is: Where to find those names?

Well, usable color names are listed in the file /usr/share/X11/rgb.txt , but....

Problem 2
names in /usr/share/X11/rgb.txt are listed with their decimal RGB codes, e.g. "238 203 173 PeachPuff2" instead of "#EECBAD PeachPuff2". How to list all names with their hex codes?

Listing with sed
Using sed for this job may sound odd since sed is not really good at on-the-fly conversions. But it can be done. GNU sed knows an e flag for the s command (not to be confused with the -e option), which allows to process a match with a shell command and then replace the found match with the shell command output. My shell command of choice here is the bash built-in printf, which is able to convert decimal values to hex:
Code:
sed -rn 's/(^[0-9    ]+)(.*)/printf "#%02X%02X%02X\t%s %s" \1 \2/ep' /usr/share/X11/rgb.txt


Listing with awk
While sed works for me, I find it awfully slow. On my netbook it takes 5 sec.
I tried awk and find it to be 100 times (!) faster. After all awk comes with its own printf implementation and does not require to run a printf shell command for each of the 700+ lines. This should fly:
Code:
awk 'NF<7 {printf "#%02X%02X%02X\t%s %s %s\n",$1,$2,$3,$4,$5,$6}' /usr/share/X11/rgb.txt


Showing the colors
Above generated list can be used to create more sophisticated displays. The goal is to see the colors, not just the names. It should be possible to create a yad list, an svg image or a HTML page. I tried my luck with gtkdialog and its colorbutton widget. Simple code and it even works, though there is a catch: The number of widgets seems to be limited. Above a certain limit gtkdialog generates a "Segmentation fault" error. I therefore removed the numerous grey/gray variants and also all names with spaces and kept only their otherwise identical camelcase variants (e.g. removed "forest green" but kept "ForestGreen" - which could also be written "forestgreen" as names are not case sensitive):
Code:
awk 'BEGIN {print "<window title=\"Color Names\" allow-shrink=\"true\" width-request=\"300\" height-request=\"500\"><vbox scrollable=\"true\" >"}
!/[Gg]r[ea]y/ && NF<5 {printf "%s%02X%02X%02X%s%02X%02X%02X  %s%s\n","<hbox><colorbutton><default>#",$1,$2,$3,"</default></colorbutton><entry><default>\"#",$1,$2,$3,$4,"\"</default></entry></hbox>"}
END {print "</vbox></window>"}' /usr/share/X11/rgb.txt | gtkdialog -s


Should this go into the HOWTO forum? - Ah... maybe not. No pet file Laughing
color_names.png
 Description   
 Filesize   15.77 KB
 Viewed   492 Time(s)

color_names.png

Back to top
View user's profile Send private message 
musher0

Joined: 04 Jan 2009
Posts: 14406
Location: Gatineau (Qc), Canada

PostPosted: Wed 06 Feb 2019, 04:33    Post subject:  

Hello MochiMoppei.

Interesting work.

For more named colors, you may find this site of interest.

IHTH.

Edit, 10 miutes later:
I suppose you know you did the above that as pure exercise to keep your
Linux muscles in good shape? Wink

I am teasing you in hopefully a friendly manner because gcolor2 is already
designed to offer its users what you no doubt took pains to offer us above
-- if you put a link of /usr/share/X11/rgb.txt in /root, like so:
Code:
ln -s /usr/share/X11/rgb.txt /root/.rgb
I have been using this trick since DPup-4.82.

BFN.

_________________
musher0
~~~~~~~~~~
Je suis né pour aimer et non pas pour haïr. (Sophocle) /
I was born to love and not to hate. (Sophocles)
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1921
Location: Japan

PostPosted: Wed 06 Feb 2019, 07:29    Post subject:  

Yad can read the file /usr/share/X11/rgb.txt directly ... or any other file with user defined colors.
Code:
yad --color --gtk-palette --expand-palette --palette=/usr/share/X11/rgb.txt

Nice to have a sort option. With hex values sorted it becomes clear how many duplicates the rgb.txt file contains.
yad_color_dialog.png
 Description   
 Filesize   70 KB
 Viewed   455 Time(s)

yad_color_dialog.png

Back to top
View user's profile Send private message 
vovchik


Joined: 23 Oct 2006
Posts: 1504
Location: Ukraine

PostPosted: Wed 06 Feb 2019, 08:24    Post subject:  

Dear MochiMoppel,

Thanks. The AWK gtkdialog version is very clever, and the YAD version is very fast and convenient. I have added a self-contained icon and copy the selection result to the clipboard in this little mod.

With kind regards,
vovchik
yadcol.tar.gz
Description 
gz

 Download 
Filename  yadcol.tar.gz 
Filesize  1.76 KB 
Downloaded  76 Time(s) 
Back to top
View user's profile Send private message 
musher0

Joined: 04 Jan 2009
Posts: 14406
Location: Gatineau (Qc), Canada

PostPosted: Wed 06 Feb 2019, 09:29    Post subject:  

Hi guys.

gcolor2 has a sort too.

The rgb.txt list itself originates from X.org. I know because there is a note
inside the file.

It has duplicates because, among other things, of the American and
British spelling of "grey" (vs "gray").

IMO you have done this for nothing. It already existed and still exists.
But hey, who am I to decide of one's pastimes ?

I'm trying to figure out why. Please tell me. You have never tried gcolor2
before, and you created your YAD widget thinking there was a genuine
need? Is that it? Without researching if something similar already existed?

One should always do good research before setting on a project, to avoid
duplications. Tsk, tsk, this is such a waste of everybody's time and of your
talent... (IMO)

Sorry for being so frank.

BFN.

_________________
musher0
~~~~~~~~~~
Je suis né pour aimer et non pas pour haïr. (Sophocle) /
I was born to love and not to hate. (Sophocles)
Back to top
View user's profile Send private message 
perdido


Joined: 09 Dec 2013
Posts: 1371
Location: ¿Altair IV , Just north of Eeyore Junction.?

PostPosted: Wed 06 Feb 2019, 10:32    Post subject:  

Hi MochiMoppel,

A little bit off-topic but still about colors Smile

What forum code did you use to insert the colors in your first post?
██████#6B8E23 OliveDrab
██████ #EECBAD PeachPuff2
██████ #1874CD DodgerBlue3

I didn't know those colors were available Shocked

.
Back to top
View user's profile Send private message 
musher0

Joined: 04 Jan 2009
Posts: 14406
Location: Gatineau (Qc), Canada

PostPosted: Wed 06 Feb 2019, 14:01    Post subject:  

MochiMoppel wrote:
Yad can read the file /usr/share/X11/rgb.txt directly ... or any other file with user defined colors.
Code:
yad --color --gtk-palette --expand-palette --palette=/usr/share/X11/rgb.txt
(...)

One should investigate if this is not a case of the YAD people plagiarizing
the work of the gcolor2 people. We should check the dates of creation of
each, which one came first.

gcolor2 has been around for a long time. And its deisgn is more horizontal
compared to the result of the above yad command.

Just a thought.

_________________
musher0
~~~~~~~~~~
Je suis né pour aimer et non pas pour haïr. (Sophocle) /
I was born to love and not to hate. (Sophocles)
Back to top
View user's profile Send private message 
Keef


Joined: 20 Dec 2007
Posts: 971
Location: Staffordshire

PostPosted: Wed 06 Feb 2019, 14:20    Post subject:  

They both use gtk widgets, some similarity is to be expected.
Back to top
View user's profile Send private message 
fredx181


Joined: 11 Dec 2013
Posts: 4123
Location: holland

PostPosted: Wed 06 Feb 2019, 14:43    Post subject:  

Great info ! Thanks @MochiMoppel

Fred

_________________
Dog Linux website
Tinylinux blog by wiak
Back to top
View user's profile Send private message 
step

Joined: 04 May 2012
Posts: 1207

PostPosted: Wed 06 Feb 2019, 18:52    Post subject:  

Thank you very much, MochiMoppel and vovchik.

@vovchik, nice icon! Please try selecting color "blue2", which string gets copied to the clipboard for you?

_________________
Fatdog64-802|+Packages|Kodi|Findnrun|+forum|gtkmenuplus
Back to top
View user's profile Send private message 
puppy_apprentice


Joined: 07 Feb 2012
Posts: 300

PostPosted: Wed 06 Feb 2019, 19:46    Post subject:  

perdido wrote:
Hi MochiMoppel,

A little bit off-topic but still about colors Smile

What forum code did you use to insert the colors in your first post?
██████#6B8E23 OliveDrab
██████ #EECBAD PeachPuff2
██████ #1874CD DodgerBlue3

I didn't know those colors were available Shocked

.


Code:
[color=#6B8E23]OliveDrab[/color]

Last edited by puppy_apprentice on Wed 06 Feb 2019, 19:57; edited 2 times in total
Back to top
View user's profile Send private message 
musher0

Joined: 04 Jan 2009
Posts: 14406
Location: Gatineau (Qc), Canada

PostPosted: Wed 06 Feb 2019, 19:54    Post subject:  

Edit, about an hour later:
superseded by v. 0.2, a couple of posts below.

~~~~~~~~~~~

vovchik wrote:
Dear MochiMoppel,

Thanks. The AWK gtkdialog version is very clever, and the YAD version is
very fast and convenient. I have added a self-contained icon and copy the
selection result to the clipboard in this little mod.

With kind regards,
vovchik
Ah.

Finally I understand. I was wondering what the fuss was about.

Now, this is original. It adds something and is worth keeping.

I reworked vovchik's archive into a pet. (Please see attached.) I added
a desktop file for it, so it will show in the WM's menu under "Graphics
Utilities" as "yadcol".

Do not enjoy! Wink
yadcol-0.1.pet
Description 
pet

 Download 
Filename  yadcol-0.1.pet 
Filesize  9.16 KB 
Downloaded  54 Time(s) 
named-colors.jpg
 Description   This is what it looks like on the wmx WM.
 Filesize   158.28 KB
 Viewed   322 Time(s)

named-colors.jpg


_________________
musher0
~~~~~~~~~~
Je suis né pour aimer et non pas pour haïr. (Sophocle) /
I was born to love and not to hate. (Sophocles)

Last edited by musher0 on Wed 06 Feb 2019, 21:38; edited 1 time in total
Back to top
View user's profile Send private message 
perdido


Joined: 09 Dec 2013
Posts: 1371
Location: ¿Altair IV , Just north of Eeyore Junction.?

PostPosted: Wed 06 Feb 2019, 20:02    Post subject:  

puppy_apprentice wrote:
perdido wrote:
Hi MochiMoppel,

A little bit off-topic but still about colors Smile

What forum code did you use to insert the colors in your first post?
██████#6B8E23 OliveDrab
██████ #EECBAD PeachPuff2
██████ #1874CD DodgerBlue3

I didn't know those colors were available Shocked

.


Code:
[color=#6B8E23]OliveDrab[/color]


Thank You puppy_apprentice!

That is a nice option I did not know about.Smile

.
Back to top
View user's profile Send private message 
musher0

Joined: 04 Jan 2009
Posts: 14406
Location: Gatineau (Qc), Canada

PostPosted: Wed 06 Feb 2019, 22:02    Post subject:  

Hello all.

V. 0.2:
Code:
#!/bin/ash
# (c) "vovchik", Febr. 6, 2019
# Incorporating the hexa color site's colors to the old Xorg ones.
# Adaptation: musher0, Febr. 6, 2019
####
# icon # Since it's been created and it's now stored in
# /usr/share/icons, do we need it here? # musher0
mycol=$(yad --window-icon="/usr/share/icons/named_colors.svg" \
     --title "Named Colours" --width=640 --height=400 \
   --color --gtk-palette --expand-palette \
   --palette=/usr/local/share/more-RGB-colors.txt3)
echo "$mycol"
echo -n "$mycol" | xclip -selection clipboard
exit

Notes
Changed width and height, so there is less "white" underneath
the color names window.
# When run from console, gives error:
# (yad:11119): Gtk-WARNING **: Allocating size to yad-dialog-window
# 0x6c32e8 without calling gtk_widget_get_preferred_width/height(). How
# does the code know the size to allocate?
# (Automatic comment, BTW; not by me.)

As I say in the comments in the script,
-- I changed the width and height of the display, so there is less "white"
underneath the color names window. It fits tighter.

-- I removed the icon creation part (with apologies to vovchik), since it's
been created and it's now stored in /usr/share/icons,

-- this version incorporates the hexa site list of color names (which I
mentioned in post # 2 above) to our traditional Xorg list. There are
approx 1,425 lines in this list, if you exclude the 3 or 4 "!" comment lines.
This list contains approx. twice the color names that the default "rgb.txt"
Xorg list offers.

I used the -dump from links and some awk code to extract the hexa list,
and afterwards did a manual, "de visu", edit. There may still be
inconsistencies in the colors, however, I am not a color expert.
Kindly forgive and report below? I'll do my best to correct them.

-- Concerning the run error: I do not know YAD, so I cannot correct this
error. Is anyone up to it? But the script is working fine AFAICT.

BFN.
named-colors-new-look.jpg
 Description   Again on wmx WM. YMMV.
 Filesize   170.52 KB
 Viewed   301 Time(s)

named-colors-new-look.jpg

yadcol-0.2.pet
Description  This one incorporates the hexa color names list from post no 2 above.
pet

 Download 
Filename  yadcol-0.2.pet 
Filesize  19.14 KB 
Downloaded  53 Time(s) 

_________________
musher0
~~~~~~~~~~
Je suis né pour aimer et non pas pour haïr. (Sophocle) /
I was born to love and not to hate. (Sophocles)

Last edited by musher0 on Thu 07 Feb 2019, 14:22; edited 1 time in total
Back to top
View user's profile Send private message 
step

Joined: 04 May 2012
Posts: 1207

PostPosted: Thu 07 Feb 2019, 07:49    Post subject:  

These lines
Code:

   --palette=/usr/share/X11/rgb.txt)
echo "$mycol"
echo -n "$mycol" | xclip -selection clipboard

could be changed to
Code:

   --palette=/usr/share/X11/rgb.txt) &&
echo "$mycol" &&
echo -n "$mycol" | xclip -selection clipboard

This way if you cancel the dialog existing clipboard contents won't be clobbered.

_________________
Fatdog64-802|+Packages|Kodi|Findnrun|+forum|gtkmenuplus
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 2 [22 Posts]   Goto page: 1, 2 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0850s ][ Queries: 12 (0.0084s) ][ GZIP on ]