3 The TypeinViewer is what you see at the lower right of the main Pynche
4 widget. It contains three text entry fields, one each for red, green, blue.
5 Input into these windows is highly constrained; it only allows you to enter
6 values that are legal for a color axis. This usually means 0-255 for decimal
7 input and 0x0 - 0xff for hex input.
9 You can toggle whether you want to view and input the values in either decimal
10 or hex by clicking on Hexadecimal. By clicking on Update while typing, the
11 color selection will be made on every change to the text field. Otherwise,
12 you must hit Return or Tab to select the color.
20 def __init__(self
, switchboard
, master
=None):
22 self
.__sb
= switchboard
23 optiondb
= switchboard
.optiondb()
24 self
.__hexp
= BooleanVar()
25 self
.__hexp
.set(optiondb
.get('HEXTYPE', 0))
26 self
.__uwtyping
= BooleanVar()
27 self
.__uwtyping
.set(optiondb
.get('UPWHILETYPE', 0))
29 self
.__frame
= Frame(master
, relief
=RAISED
, borderwidth
=1)
30 self
.__frame
.grid(row
=3, column
=1, sticky
='NSEW')
32 self
.__xl
= Label(self
.__frame
, text
='Red:')
33 self
.__xl
.grid(row
=0, column
=0, sticky
=E
)
34 self
.__x
= Entry(self
.__frame
, width
=4)
35 self
.__x
.grid(row
=0, column
=1)
36 self
.__x
.bindtags(self
.__x
.bindtags() + ('Normalize', 'Update'))
37 self
.__x
.bind_class('Normalize', '<Key>', self
.__normalize
)
38 self
.__x
.bind_class('Update' , '<Key>', self
.__maybeupdate
)
40 self
.__yl
= Label(self
.__frame
, text
='Green:')
41 self
.__yl
.grid(row
=1, column
=0, sticky
=E
)
42 self
.__y
= Entry(self
.__frame
, width
=4)
43 self
.__y
.grid(row
=1, column
=1)
44 self
.__y
.bindtags(self
.__y
.bindtags() + ('Normalize', 'Update'))
46 self
.__zl
= Label(self
.__frame
, text
='Blue:')
47 self
.__zl
.grid(row
=2, column
=0, sticky
=E
)
48 self
.__z
= Entry(self
.__frame
, width
=4)
49 self
.__z
.grid(row
=2, column
=1)
50 self
.__z
.bindtags(self
.__z
.bindtags() + ('Normalize', 'Update'))
51 # Update while typing?
52 self
.__uwt
= Checkbutton(self
.__frame
,
53 text
='Update while typing',
54 variable
=self
.__uwtyping
)
55 self
.__uwt
.grid(row
=3, column
=0, columnspan
=2, sticky
=W
)
57 self
.__hex
= Checkbutton(self
.__frame
,
60 command
=self
.__togglehex
)
61 self
.__hex
.grid(row
=4, column
=0, columnspan
=2, sticky
=W
)
63 def __togglehex(self
, event
=None):
64 red
, green
, blue
= self
.__sb
.current_rgb()
65 self
.update_yourself(red
, green
, blue
)
67 def __normalize(self
, event
=None):
70 icursor
= ew
.index(INSERT
)
73 if contents
[0] in 'xX' and self
.__hexp
.get():
74 contents
= '0' + contents
75 # figure out what the contents value is in the current base
78 v
= string
.atoi(contents
, 16)
80 v
= string
.atoi(contents
)
83 # if value is not legal, delete the last character inserted and ring
85 if v
is None or v
< 0 or v
> 255:
88 contents
= contents
[:i
-1] + contents
[i
:]
91 elif self
.__hexp
.get():
96 ew
.insert(0, contents
)
99 def __maybeupdate(self
, event
=None):
100 if self
.__uwtyping
.get() or event
.keysym
in ('Return', 'Tab'):
103 def __update(self
, event
=None):
104 redstr
= self
.__x
.get()
105 greenstr
= self
.__y
.get()
106 bluestr
= self
.__z
.get()
107 if self
.__hexp
.get():
108 red
= string
.atoi(redstr
, 16)
109 green
= string
.atoi(greenstr
, 16)
110 blue
= string
.atoi(bluestr
, 16)
112 red
, green
, blue
= map(string
.atoi
, (redstr
, greenstr
, bluestr
))
113 self
.__sb
.update_views(red
, green
, blue
)
115 def update_yourself(self
, red
, green
, blue
):
116 if self
.__hexp
.get():
117 redstr
, greenstr
, bluestr
= map(hex, (red
, green
, blue
))
119 redstr
, greenstr
, bluestr
= red
, green
, blue
120 x
, y
, z
= self
.__x
, self
.__y
, self
.__z
121 xicursor
= x
.index(INSERT
)
122 yicursor
= y
.index(INSERT
)
123 zicursor
= z
.index(INSERT
)
128 y
.insert(0, greenstr
)
137 def save_options(self
, optiondb
):
138 optiondb
['HEXTYPE'] = self
.__hexp
.get()
139 optiondb
['UPWHILETYPE'] = self
.__uwtyping
.get()