I'm searching for a method to get the color names known to Tk in a
script. I read the wiki and the man pages, but there seems to be no
way. I know, there is a list in man colors, but I don't want the names
hardcoded in the source. Is this possible or no way?
TIA
Stephan
uwe
I know that, but I need it OS independent (better: Window System
independent)...
Regards
Stephan
Adding named colors is subject of TIP 154 http://www.tcl.tk/cgi-bin/tct/tip/154.html
which is currently in draft state. If you really need this
functionality now and don't mind patching Tk, you can have a look at:
http://sourceforge.net/tracker/index.php?func=detail&aid=1637923&group_id=12997&atid=312997
which includes a patch to add the [wm colors] subcommand.
Mark
Thanks for the links, I wasn't aware of the TIP. Patching Tk is not
option, so I think, I skip named colors for the next few years until
8.6 is available... ;-)
Thanks
Stephan
Pascal
skuh...@web.de a écrit :
> As a quick fix, you can also borrow (copy/paste) the color names
> emulation from http://wiki.tcl.tk/16166 "Colors with Names"
Thanks, but as I said, I don't want the color names hardcoded into the
source. I found this and some other sources with all color names in the
wiki and of course you need only three lines of Tcl to extract them from
the man page, but it's simply not what I want...
Regards
Stephan
Maybe a small C extension would be able to pry the color names from
Tk. Would that be an option?
Mark
This is one of the areas of introspection still unavailable (another
is cursor names and perhaps built-in image names?).
It would be great if someone created a TIP (http://wiki.tcl.tk/TIP)
and worked on providing these things. It would be much better to have
something within the core that somehow dynamically obtained the valid
information, rather than having things hard coded in some script
library.
The TIP is already there (TIP 154), I guess what is missing is a
complete implementation.
Mark
To make it more explicit. The Tk colors are stored in a hash. The keys
of this hash are the color names. By traversing all hash elements a
colorname list can be constructed. Only doubt I have is whether it
requires inclusion of tkInt.h.
So would a C-extension be OK?
Mark
> Maybe a small C extension would be able to pry the color names from
> Tk. Would that be an option?
No, the script should run on a basic Tcl/Tk 8.4 or newer without any
extensions and on different plattforms (at least Linux (x86 and PPC),
MacOSX (x86, PPC) and on an embedded device with an arm compatible CPU -
and if possible on many others, but thats all I have... So compiling all
those scripts would be too much for a little gimmick.
I'm sorry to make such a noise here, since the feature is not a must have
for my script, so I can live without it. But I agree with Larry and find it
a little bit surprising, that, considering Tcl/Tk other impressive
introspection features, such basic things are not there.
Regards
Stephan
> To make it more explicit. The Tk colors are stored in a hash. The keys
> of this hash are the color names. By traversing all hash elements a
> colorname list can be constructed. Only doubt I have is whether it
> requires inclusion of tkInt.h.
> So would a C-extension be OK?
No, sorry, because of the reasons I just posted. If it were that important,
extracting the colors from the man page or rgb.txt (on X11) would the my
choice. A C extension is overkill for a simple script which should run on
many plattforms and where the feature is not important.
Regards
Stephan
Well, TIP 154 goes way beyond what the OP requested, but it could be
used to implement the specific request.
Unless I misunderstood, what the OP wanted was something like:
set colorlist [info colors]
{red white blue black green yellow}
etc.
TIP 154's color names could certainly return that kind of thing, but
it looks, to me, like the TIP is oriented towards returning things
like
{TkButtonFace TkButtonText}
etc. - generic names that represent whatever color a button's face or
text might have.
If in addition to this, TIP 154's color names also returned all the
regular "colors" (either created or pre-set), then that would meet the
OP need.
I would tend to resist having it return all the color names, unless we
include them all as redefinable colors. There basically is no value in
using those names, except in some demo script.
Jeff
> I'm searching for a method to get the color names known to Tk
Can you describe how you are planning to use this? For instance, on
Unix, one might have 800+ colors. How would you make use of a huge
list of colors?
It's for finding the nearest predefined color for a given RGB-Value
and the other way around. Not really important, as I wrote earlier,
just a gimmick for a small script, that I'm writing just for fun. But
getting the predefined color names from Tk would be a useful and
obvious feature. I even would expect the possibilty to extend the
database of named colors...
Regards
Stephan
Ain't no such thing.
If you're looking for "A list of named colors that are
likely to work in Tk on all platforms", then the list
in colors(3Tk) is your best bet.
If you're looking for "A list of named colors that are
likely to work _and look the same_ when used in Tk on
all platforms", then don't bother: you'll get less variation
with explicit #RRGGBB specifications than you will with
named colors. (Colors specified as #RRGGBB won't look the
same on all platforms, but neither will named colors, and
the latter can be significantly different from server
to server.)
If you're looking for something else, then I don't know --
what do you need this for?
--Joe English
> Ain't no such thing.
I know. I just wanted to make sure, that I haven't missed something in the
documentation.
> If you're looking for something else, then I don't know --
> what do you need this for?
It's just a gimmick for a very small fun project, nothing essential for
anything. I quote myself:
Joe English wrote:
> skuhagen wrote:
>> Uwe Klein wrote:
>>> On unix systems the names are in "rgb.txt" ( and part of the X-Server
>>> environment)
>> I know that, but I need it OS independent (better: Window System
>> independent)...
>
>
> Ain't no such thing.
>
> If you're looking for "A list of named colors that are
> likely to work in Tk on all platforms", then the list
> in colors(3Tk) is your best bet.
>
This list of color names and associated rgb values can be found as a Tcl
list (and some utility functions) in the Tcl3D source distribution
(www.tcl3d.org, file tcl3dColors.tcl).
Might be a starting point for your needs.
Paul