File: Color.html

package info (click to toggle)
python-pmw 1.2-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,024 kB
  • ctags: 3,802
  • sloc: python: 17,143; makefile: 41
file content (326 lines) | stat: -rw-r--r-- 12,876 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326

    <html>
    <head>
    <meta name="description" content="Pmw - a toolkit for building high-level compound widgets in Python">
    <meta name="content" content="python, megawidget, mega widget, compound widget, gui, tkinter">
    <title>Pmw.Color reference manual</title>
    </head>

    <body bgcolor="#ffffff" text="#000000" link="#0000ee"
	vlink="551a8b" alink="ff0000">

    <h1 ALIGN="CENTER">Pmw.Color</h1>
    
<dl>
<dt> <h3>Name</h3></dt><dd>
<p>Pmw.Color - 
    contains functions for handling colors and color schemes</p>
<p></p>



</dd>
<dt> <h3>Description</h3></dt><dd>
<p>
    This module is a set of functions for manipulating colors and for
    modifying the color scheme of an application or a widget.  Many of
    the functions in this module take or return colors.  These values
    may represent colors in the following ways:</p>
<dl><dt><strong>name</strong></dt><dd>a standard color name, eg <code>'orange'</code> or <code>'#ffa500'</code><p></p>

</dd>
<dt><strong>rgb</strong></dt><dd>a 3-element sequence of red, green and blue intensities
        each between 0.0 (dark) and 1.0 (light), eg <code>[1.0, 0.6, 0.0]</code>.<p></p>

</dd>
<dt><strong>hsi</strong></dt><dd>a 3-element sequence (<em>hue</em>, <em>saturation</em>,
        <em>intensity</em>).  The value of <em>hue</em> is between 0.0 and <strong>2pi</strong>
        (6.28318) giving a range of colors covering, in order, red,
        orange, yellow green, cyan, blue, magenta and back to red. 
        The value of <em>saturation</em> is between 0.0 (grey) and 1.0
        (brilliant) and the value of <em>intensity</em> is between 0.0 (dark)
        and 1.0 (bright).<p></p>

</dd></dl>

<p>    As used in these functions, the <strong>brightness</strong> of a color is the
    perceived grey level of the color as registered by the human eye. 
    For example, even though the colors red, blue and yellow have the
    same intensity (1.0), they have different brightnesses, 0.299,
    0.114 and 0.886 respectively, reflecting the different way these
    colors appear to the eye.  The brightness of a color is a value
    between 0.0 (dark) and 1.0 (bright).</p>

<p>    A <strong>color scheme</strong> is a set of colors defined for each of the
    default color options in the Tk option database.  Color schemes
    can be used in two ways.  Firstly, using <code>Pmw.Color.setscheme()</code>,
    the Tk option database can be set to the values in the color
    scheme.  This will not have any effect on currently existing
    widgets, but any new widgets created after setting the options
    will have these colors as their defaults.  Secondly, using
    <code>Pmw.Color.changecolor()</code> the color scheme can be used to change
    the colors of a widget and all its child widgets.</p>

<p>    A color scheme is specified by defining one or more color options
    (one of the defined options must be <code>background</code>).  Not all
    options need be specified - if any options are not defined, they
    are calculated from the other colors.  These are the options used
    by a color scheme, together with their values if not specified:</p>
<dl><dd><pre> background:            (must be specified)
 foreground:            black
 activeForeground:      same as foreground
 insertBackground:      same as foreground
 selectForeground:      same as foreground
 highlightColor:        same as foreground
 disabledForeground:    between fg and bg but closer to bg
 highlightBackground:   same as background
 activeBackground:      a little lighter that bg
 selectBackground:      a little darker that bg
 troughColor:           a little darker that bg
 selectColor:           yellow</pre></dd></dl>


<p>    There are many functions in this module.  As well as
    <code>Pmw.Color.setscheme()</code> and <code>Pmw.Color.changecolor()</code>, some of the
    most useful are <code>Pmw.Color.spectrum()</code>,
    <code>Pmw.Color.changebrightness()</code> and
    <code>Pmw.Color.getdefaultpalette()</code>.</p>

<p></p>


</dd>
<dt> <h3>Functions</h3></dt><dd>
The following functions are available.<p></p>
<dl>
<dt> <strong>Pmw.Color.average</strong>(<em>rgb1</em>, <em>rgb2</em>, <em>fraction</em>)</dt><dd>

    Return an <strong>rgb</strong> color <em>fraction</em> of the way "between" the colors
    <em>rgb1</em> and <em>rgb2</em>, where <em>fraction</em> must be between <strong>0.0</strong> and
    <strong>1.0</strong>.  If <em>fraction</em> is close to <strong>0.0</strong>, then the color returned
    will be close to <em>rgb1</em>.  If it is close to <strong>1.0</strong>, then the color
    returned will be close to <em>rgb2</em>.  If it is near <strong>0.5</strong>, then the
    color returned will be half way between the two colors.</p>

<p></p>


</dd>
<dt> <strong>Pmw.Color.bhi2saturation</strong>(<em>brightness</em>, <em>hue</em>, <em>intensity</em>)</dt><dd>

    Return the saturation of the color represented by <em>brightness</em>,
    <em>hue</em> and <em>intensity</em>.</p>

<p></p>


</dd>
<dt> <strong>Pmw.Color.bordercolors</strong>(<em>root</em>, <em>colorName</em>)</dt><dd>

    Return a tuple <code>(light, dark)</code> of color names that can be used as
    the light and dark border shadows on a widget where the background
    is <em>colorName</em>.  This is the same method that Tk uses for shadows
    when drawing reliefs on widget borders.  The <em>root</em> argument is
    only used to query Tk for the <strong>rgb</strong> values of <em>colorName</em>.</p>

<p></p>


</dd>
<dt> <strong>Pmw.Color.changebrightness</strong>(<em>root</em>, <em>colorName</em>, <em>brightness</em>)</dt><dd>

    Find the hue of the color <em>colorName</em> and return a color of this
    hue with the required <em>brightness</em>.  If <em>brightness</em> is <strong>None</strong>,
    return the name of color with the given hue and with saturation
    and intensity both <strong>1.0</strong>.  The <em>root</em> argument is only used to
    query Tk for the <strong>rgb</strong> values of <em>colorName</em>.</p>

<p></p>


</dd>
<dt> <strong>Pmw.Color.changecolor</strong>(<em>widget</em>, <em>background</em> = <strong>None</strong>, **<em>kw</em>)</dt><dd>

    Change the color of <em>widget</em> and all its child widgets according
    to the color scheme specified by the other arguments.  This is done
    by modifying all of the color options of existing widgets that
    have the default value.  The color options are the lower case
    versions of those described in the <strong>color scheme</strong> section.  Any
    options which are different to the previous color scheme (or the
    defaults, if this is the first call) are not changed.</p>

<p>    For example to change a widget to have a red color scheme with a
    white foreground:</p>

<dl><dd><pre> Pmw.Color.changecolor(widget,
     background = 'red3', foreground = 'white')</pre></dd></dl>

<p>    The colors of widgets created after this call will not be
    affected.</p>

<p>    Note that <em>widget</em> must be a Tk widget or toplevel.  To change the
    color of a Pmw megawidget, use it's <strong>hull</strong> component.  For example:</p>

<dl><dd><pre> widget = megawidget.component('hull')
 Pmw.Color.changecolor(widget, background = 'red3')</pre></dd></dl>

<p></p>


</dd>
<dt> <strong>Pmw.Color.correct</strong>(<em>rgb</em>, <em>correction</em>)</dt><dd>

    Return the "corrected" value of <em>rgb</em>.  This can be used to
    correct for dull monitors.  If <em>correction</em> is less than <strong>1.0</strong>,
    the color is dulled.  If <em>correction</em> is greater than <strong>1.0</strong>, the
    color is brightened.</p>

<p></p>


</dd>
<dt> <strong>Pmw.Color.getdefaultpalette</strong>(<em>root</em>)</dt><dd>

    Return a dictionary of the default values of the color options
    described in the <strong>color scheme</strong> section.</p>

<p>    To do this, a few widgets are created as children of <em>root</em>, their
    defaults are queried, and then the widgets are destroyed.  (Tk
    supplies no other way to get widget default values.)</p>

<p>    Note that <em>root</em> must be a Tk widget or toplevel.  To use a Pmw
    megawidget as the root, use it's <strong>hull</strong> component.  For example:</p>

<dl><dd><pre> root = megawidget.component('hull')
 Pmw.Color.getdefaultpalette(root)</pre></dd></dl>

<p></p>


</dd>
<dt> <strong>Pmw.Color.hsi2rgb</strong>(<em>hue</em>, <em>saturation</em>, <em>intensity</em>)</dt><dd>

    Return the <strong>rgb</strong> representation of the color represented by <em>hue</em>,
    <em>saturation</em> and <em>intensity</em>.</p>

<p></p>


</dd>
<dt> <strong>Pmw.Color.hue2name</strong>(<em>hue</em>, <em>brightness</em> = <strong>None</strong>)</dt><dd>

    Return the name of the color with the specified <em>hue</em> and
    <em>brightness</em>.  If <em>hue</em> is <strong>None</strong>, return a grey of the requested
    brightness.  Otherwise, the value of <em>hue</em> should be as described
    above.  If <em>brightness</em> is <strong>None</strong>, return the name of color with
    the given hue and with saturation and intensity both <strong>1.0</strong>.</p>

<p></p>


</dd>
<dt> <strong>Pmw.Color.name2rgb</strong>(<em>root</em>, <em>colorName</em>, <em>asInt</em> = <strong>0</strong>)</dt><dd>

    Return <em>colorName</em> as an <strong>rgb</strong> value.  If <em>asInt</em> is true, then
    the elements of the return sequence are in the range <strong>0</strong> to
    <strong>65535</strong> rather than <strong>0.0</strong> to <strong>1.0</strong>.  The <em>root</em> argument is only
    used to query Tk for the <strong>rgb</strong> values of <em>colorName</em>.</p>

<p></p>


</dd>
<dt> <strong>Pmw.Color.rgb2brightness</strong>(<em>rgb</em>)</dt><dd>

    Return the brightness of the color represented by <em>rgb</em>.</p>

<p></p>


</dd>
<dt> <strong>Pmw.Color.rgb2hsi</strong>(<em>rgb</em>)</dt><dd>

    Return a tuple (<em>hue</em>, <em>saturation</em>, <em>intensity</em>) corresponding to
    the color specified by the <em>rgb</em> sequence.</p>

<p></p>


</dd>
<dt> <strong>Pmw.Color.rgb2name</strong>(<em>rgb</em>)</dt><dd>

    Return the name of the color represented by <em>rgb</em> as a string of
    the form <code>'#RRGGBB'</code> suitable for use with Tk color functions.</p>

<p></p>


</dd>
<dt> <strong>Pmw.Color.setscheme</strong>(<em>root</em>, <em>background</em> = <strong>None</strong>, **<em>kw</em>)</dt><dd>

    Set the color scheme for the application by setting default colors
    (in the Tk option database of the root window of <em>root</em>) according
    to the color scheme specified by the other arguments.  This will
    affect the initial colours of all widgets created after the call
    to this function.</p>

<p>    For example to initialise an application to have a red color
    scheme with a white foreground:</p>

<dl><dd><pre> Pmw.Color.setscheme(root,
     background = 'red3', foreground = 'white')</pre></dd></dl>

<p>    This function does not modify the colors of already existing
    widgets.  Use <strong>Pmw.Color.changecolor()</strong> to do this.</p>

<p>    Note that <em>root</em> must be a Tk widget or toplevel.  To use the Tk
    option database of the root window of a Pmw megawidget, use the
    megawidget's <strong>hull</strong> component.  For example:</p>

<dl><dd><pre> root = megawidget.component('hull')
 Pmw.Color.setscheme(root, background = 'red3')</pre></dd></dl>

<p></p>


</dd>
<dt> <strong>Pmw.Color.spectrum</strong>(<em>numColors</em>, <em>correction</em> = <strong>1.0</strong>, <em>saturation</em> = <strong>1.0</strong>, <em>intensity</em> = <strong>1.0</strong>, <em>extraOrange</em> = <strong>1</strong>, <em>returnHues</em> = <strong>0</strong>)</dt><dd>

    Return a list of <em>numColors</em> different colors making up a
    <em>spectrum</em>.  If <em>extraOrange</em> is false, the colors are evenly
    spaced by hue from one end of the spectrum (red) to the other
    (magenta).  If <em>extraOrange</em> is true, the hues are not quite
    evenly spaced - the hues around orange are emphasised, thus
    preventing the spectrum from appearing to have to many <em>cool</em>
    hues. </p>

<p>    If <em>returnHues</em> is false, the return values are the names of the
    colors represented by the hues together with <em>saturation</em> and
    <em>intensity</em> and corrected by <em>correction</em>.</p>

<p>    If <em>returnHues</em> is true, the return values are hues.</p>

<p></p>


</dd>
</dl>
</dd></dl>

    <center><P ALIGN="CENTER">
    <IMG SRC = blue_line.gif ALT = "" WIDTH=320 HEIGHT=5>
    </p></center>
    

    <font size=-1>
    <center><P ALIGN="CENTER">
    Pmw 1.2 -
     5 Aug 2003
     - <a href="index.html">Home</a>
    <br>Manual page last reviewed: 25 May 2002
    </p></center>
    </font>

    </body>
    </html>