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 Wed 20 Mar 2019, 23:37
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 2 of 2 [22 Posts]   Goto page: Previous 1, 2
Author Message
MochiMoppel


Joined: 26 Jan 2011
Posts: 1805
Location: Japan

PostPosted: Fri 15 Feb 2019, 22:33    Post subject:  

vovchik wrote:
I have added a self-contained icon and copy the selection result to the clipboard in this little mod.
Thank you. Great artwork - as always.

As for sending output to clipboard I see some issues.

- Adding to step's observation I would go further. IMO any overwriting of the clipboard should require the explicit consent of the user. Could be done with an extra button. Normally the GtkColorChooser writes to stdout (which your mod still does), but additionally writing to clipboard might be regarded as unexpected and unwanted.

- Some Puppies use xsel instead of xclip. Should be considered when coding clipboard interaction.

- Color hex values can already be easily selected and copied from the "Color name" field of the GtkColorChooser, so I don't see a need to make copying easier or even compulsory. On the other hand there is no way to copy the names Crying or Very sad (well, not with GtkColorChooser but with MochiMoppel's "waste of time" scripts Wink )

- The GtkColorChooser already has a dedicated clipboard: the 20-field color palette. A bit feeble as the palette can not be saved but useful as long as the application is not closed (e.g. see implementation in Geany).

Instead of writing to the clipboad I think writing to a custom palette file would be a better feature. Yad can optionally return the decimal values instead of the hex values, though in a format that needs further tweaking. I don't know if for yad such saving and ideally updating the color name list is possible while keeping the dialog open, but at least it should be possible after dismissing the dialog.
Back to top
View user's profile Send private message 
tlchost

Joined: 05 Aug 2007
Posts: 2107
Location: Baltimore, Maryland USA

PostPosted: Sat 16 Feb 2019, 07:47    Post subject: foregound/background  

What would be very helpful for folks developing web pages would be a way of manipulating the values of foreground and background colors and viewing the result on the screen...it could avoid unfortunate combinations like white/yellow or black/blue [/i]
Back to top
View user's profile Send private message Visit poster's website 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1805
Location: Japan

PostPosted: Tue 19 Feb 2019, 01:32    Post subject:  

OK, here is my prototype for a yad color picker with save capability.
This capability is not meant for X11 colors and therefore slightly off-topic. Since X11 colors should not be messed with and mixed with other names, the save option is disabled for /usr/share/X11/rgb.txt but can be useful to create/read custom color palettes.

How to run the script:
1) Create a new file for the colors you are going to save. Example: File name mycolors.gpl in directory /root/.config/mm_yadcolors/.
The first line of the file should read "GIMP Palette" (mandatory for use in mtPaint) and the following lines should contain the palette name and one or more comments, starting with #
The content would look like this:
GIMP Palette
Name: My favorite colors
#


2) Run below script (let's call it mm_yadcolors) as
Code:
mm_yadcolors  /root/.config/mm_yadcolors/mycolors.gpl

This should open the yad colorpicker with an empty color list and a "Save" button to save your custom colors.
If mm_yadcolors is run without a palette file as argument, the script will open /usr/share/X11/rgb.txt . No "Save" button.

The script saves the last used color and the last used window geometry to the /tmp directory. Change to the .config directory if these values need to survive a reboot.

[Update 2019-2-21] Added support for mtPaint/GIMP palette format.
[Update 2019-2-23] Removed demo code from script and reworded explanation.
Code:
#!/bin/bash
## loads default X11 rgb palette or - when passed as parameter - any user defined color palette
## option to save user defined colors (disabled for X11 palette)
## supports mtPaint and GIMP palette formats (read/write) 
## remembers last used color, window size and location

[[ -f $1 ]] && palettefile=$1 || palettefile=/usr/share/X11/rgb.txt
[[ $palettefile = /usr/share/X11/rgb.txt ]] && disable=X || disable=''
export geofile=/tmp/yadcol_geometry.txt
    valfile=/tmp/yadcol_lastused.txt

function savegeo {
 WINDOWID=$(xprop -root _NET_ACTIVE_WINDOW)
 WINDOWID=${WINDOWID##* }
 XWININFO=$(xwininfo -id $WINDOWID)
 set -- ${@} ${XWININFO#* X: }
 AX=$1 AY=$5 RX=$9 RY=${13}
 echo -n "${15}x${17}+$((AX-RX))+$((AY-RY))" > $geofile
};export -f savegeo

fileheader=$(grep '^[^ 0-9].*' -o "$palettefile")   #extract GIMP file header
[[ $fileheader ]] && fileheader=${fileheader}$'\n'  #keep variable empty if header does not exist

while : ;do
 colorval=$(yad --color --title="YAD - ${palettefile##*/}" --init-color="$(< $valfile)"  --geometry="$(< $geofile)" --always-print-result --gtk-palette --expand-palette --palette=<(awk "/^[ 0-9]/" "$palettefile") --${disable}button="Save color:bash -c 'savegeo; kill -s SIGUSR2 \$YAD_PID'" --button="OK:bash -c 'savegeo; kill -s SIGUSR1 \$YAD_PID'" --button="Cancel:9" )
 ret=$?
 case $ret in
 0) : OK; echo -n $colorval; echo $colorval > "$valfile" ; break ;;
 1) : SAVE; newname=$(gxmessage -title "Save color" -bg $colorval -c -entrytext 'NewColorName' $'\n\t'"Color $colorval")
      (($?)) || printf '%s%d %d %d\t%s\n%s\n' "$fileheader" 0\x${colorval:1:2} 0\x${colorval:3:2} 0\x${colorval:5:2} "$newname" "$(awk '/^[ 0-9]/' "$palettefile")" > "$palettefile"
      echo $colorval > "$valfile" ;;
 *) : CANCEL; break ;; #ret = 9 or 252
 esac
done
yad_custom_color_dialog.png
 Description   
 Filesize   56.01 KB
 Viewed   441 Time(s)

yad_custom_color_dialog.png


Last edited by MochiMoppel on Sun 24 Feb 2019, 23:07; edited 2 times in total
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1805
Location: Japan

PostPosted: Thu 21 Feb 2019, 05:19    Post subject:  

I made some changes to above script and added support for mtPaint/GIMP palette formats.
Files created with the script such as the included demo palette can be loaded into mtPaint and will be displayed as an indexed palette. Unfortunately mtPaint AFAIK has no support for color names.
Reading mtPaint/GIMP files was less of a problem before but their unsupported file headers produced ugly gibberish. Reading should now work without flaws (tested with palettes included in GIMP).
Back to top
View user's profile Send private message 
musher0

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

PostPosted: Thu 21 Feb 2019, 08:51    Post subject: Re: foregound/background  

tlchost wrote:
What would be very helpful for folks developing web pages would be a way of manipulating the values of foreground and background colors and viewing the result on the screen...it could avoid unfortunate combinations like white/yellow or black/blue [/i]

Thanks tlchost, MochiMoppei.

I'd add to tlchost's suggestion -- which is sorely needed, I think, -- that it
would be nice to be able to save maybe up to ten colors, and that this
"color yadget" does not close after each choice.

When I develop an urxvt pseudo-GUI window, I find myself scribbling a lot
of hex colors on a sheet of paper. Having a list handy in an editor could
save time.

As to your approach of leaving rgb.txt alone, I think it is a good idea,
although gcolor2 allows saving new color names in the rgb.txt list.

My 2 ¢. BFN.

_________________
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 21 Feb 2019, 11:45; edited 1 time in total
Back to top
View user's profile Send private message 
perdido


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

PostPosted: Fri 22 Feb 2019, 22:33    Post subject:  

MochiMoppel wrote:
OK, here is my prototype for a yad color picker with save capability.


Easy for a simpleton like myself. Looks good Smile
I have added up to 15 colors in the save window (program will do more)


.
MM_color_palette.jpg
 Description   
 Filesize   47.81 KB
 Viewed   136 Time(s)

MM_color_palette.jpg

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


Joined: 26 Jan 2011
Posts: 1805
Location: Japan

PostPosted: Sat 23 Feb 2019, 22:06    Post subject:  

@perdido: I like your EnvyGreen. Reminds me of my IKEA coasters.

I have updated my script and my explanations. I removed the demo code as it seemed to cause some confusion.

Speaking of green brings me back to my thread topic. My focus are X11 color names, not W3C color names used in web pages. Both color schemes are largely the same, but there are still differences, which makes it all the more important not to confuse them or mix them in the same palette. Sometimes different names are used for the same color (e.g. cyan vs. aqua), sometimes the same name is used for different colors, e.g. green:

This is the W3C color named "green", chosen from the "Font colour" dropdown box in this forum software:
██████
The hex value is #008000 which makes is relatively dark

This is the X11 color named "green", usable in commands like gxmessage -bg green "Hello World"
██████
The hex value is #00FF00
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 2 of 2 [22 Posts]   Goto page: Previous 1, 2
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.0459s ][ Queries: 13 (0.0110s) ][ GZIP on ]