1 """DetailsViewer class.
3 This class implements a pure input window which allows you to meticulously
4 edit the current color. You have both mouse control of the color (via the
5 buttons along the bottom row), and there are keyboard bindings for each of the
6 increment/decrement buttons.
8 The top three check buttons allow you to specify which of the three color
9 variations are tied together when incrementing and decrementing. Red, green,
10 and blue are self evident. By tying together red and green, you can modify
11 the yellow level of the color. By tying together red and blue, you can modify
12 the magenta level of the color. By tying together green and blue, you can
13 modify the cyan level, and by tying all three together, you can modify the
16 The behavior at the boundaries (0 and 255) are defined by the `At boundary'
20 When the increment or decrement would send any of the tied variations
21 out of bounds, the entire delta is discarded.
24 When the increment or decrement would send any of the tied variations
25 out of bounds, the out of bounds variation is wrapped around to the
26 other side. Thus if red were at 238 and 25 were added to it, red
27 would have the value 7.
30 When the increment or decrement would send any of the tied variations
31 out of bounds, all tied variations are wrapped as one, so as to
32 preserve the distance between them. Thus if green and blue were tied,
33 and green was at 238 while blue was at 223, and an increment of 25
34 were applied, green would be at 15 and blue would be at 0.
37 When the increment or decrement would send any of the tied variations
38 out of bounds, the out of bounds variation is set to the ceiling of
39 255 or floor of 0, as appropriate. In this way, all tied variations
40 are squashed to one edge or the other.
42 The following key bindings can be used as accelerators. Note that Pynche can
43 fall behind if you hold the key down as a key repeat:
59 RATIO
= 'Preserve Distance'
64 def __init__(self
, switchboard
, master
=None):
65 self
.__sb
= switchboard
66 optiondb
= switchboard
.optiondb()
67 self
.__red
, self
.__green
, self
.__blue
= switchboard
.current_rgb()
69 root
= self
.__root
= Toplevel(master
, class_
='Pynche')
70 root
.protocol('WM_DELETE_WINDOW', self
.withdraw
)
71 root
.title('Pynche Details Window')
72 root
.iconname('Pynche Details Window')
73 root
.bind('<Alt-q>', self
.__quit
)
74 root
.bind('<Alt-Q>', self
.__quit
)
75 root
.bind('<Alt-w>', self
.withdraw
)
76 root
.bind('<Alt-W>', self
.withdraw
)
78 root
.bind('<KeyPress-Left>', self
.__minus
1)
79 root
.bind('<KeyPress-Right>', self
.__plus
1)
80 root
.bind('<Control-KeyPress-Left>', self
.__minus
10)
81 root
.bind('<Control-KeyPress-Right>', self
.__plus
10)
82 root
.bind('<Shift-KeyPress-Left>', self
.__minus
25)
83 root
.bind('<Shift-KeyPress-Right>', self
.__plus
25)
86 frame
= self
.__frame
= Frame(root
)
87 frame
.pack(expand
=YES
, fill
=X
)
88 self
.__l1 = Label(frame
, text
='Move Sliders:')
89 self
.__l1.grid(row
=1, column
=0, sticky
=E
)
90 self
.__rvar
= IntVar()
91 self
.__rvar
.set(optiondb
.get('RSLIDER', 4))
92 self
.__radio
1 = Checkbutton(frame
, text
='Red',
94 command
=self
.__effect
,
95 onvalue
=4, offvalue
=0)
96 self
.__radio
1.grid(row
=1, column
=1, sticky
=W
)
97 self
.__gvar
= IntVar()
98 self
.__gvar
.set(optiondb
.get('GSLIDER', 2))
99 self
.__radio
2 = Checkbutton(frame
, text
='Green',
100 variable
=self
.__gvar
,
101 command
=self
.__effect
,
102 onvalue
=2, offvalue
=0)
103 self
.__radio
2.grid(row
=2, column
=1, sticky
=W
)
104 self
.__bvar
= IntVar()
105 self
.__bvar
.set(optiondb
.get('BSLIDER', 1))
106 self
.__radio
3 = Checkbutton(frame
, text
='Blue',
107 variable
=self
.__bvar
,
108 command
=self
.__effect
,
109 onvalue
=1, offvalue
=0)
110 self
.__radio
3.grid(row
=3, column
=1, sticky
=W
)
111 self
.__l2 = Label(frame
)
112 self
.__l2.grid(row
=4, column
=1, sticky
=W
)
116 self
.__l3 = Label(frame
, text
='At boundary:')
117 self
.__l3.grid(row
=5, column
=0, sticky
=E
)
118 self
.__boundvar
= StringVar()
119 self
.__boundvar
.set(optiondb
.get('ATBOUND', STOP
))
120 self
.__omenu
= OptionMenu(frame
, self
.__boundvar
,
121 STOP
, WRAP
, RATIO
, GRAV
)
122 self
.__omenu
.grid(row
=5, column
=1, sticky
=W
)
123 self
.__omenu
.configure(width
=17)
126 frame
= self
.__btnframe
= Frame(frame
)
127 frame
.grid(row
=0, column
=0, columnspan
=2, sticky
='EW')
128 self
.__down
25 = Button(frame
, text
='-25',
129 command
=self
.__minus
25)
130 self
.__down
10 = Button(frame
, text
='-10',
131 command
=self
.__minus
10)
132 self
.__down
1 = Button(frame
, text
='-1',
133 command
=self
.__minus
1)
134 self
.__up
1 = Button(frame
, text
='+1',
135 command
=self
.__plus
1)
136 self
.__up
10 = Button(frame
, text
='+10',
137 command
=self
.__plus
10)
138 self
.__up
25 = Button(frame
, text
='+25',
139 command
=self
.__plus
25)
140 self
.__down
25.pack(expand
=YES
, fill
=X
, side
=LEFT
)
141 self
.__down
10.pack(expand
=YES
, fill
=X
, side
=LEFT
)
142 self
.__down
1.pack(expand
=YES
, fill
=X
, side
=LEFT
)
143 self
.__up
1.pack(expand
=YES
, fill
=X
, side
=LEFT
)
144 self
.__up
10.pack(expand
=YES
, fill
=X
, side
=LEFT
)
145 self
.__up
25.pack(expand
=YES
, fill
=X
, side
=LEFT
)
147 def __effect(self
, event
=None):
148 tie
= self
.__rvar
.get() + self
.__gvar
.get() + self
.__bvar
.get()
149 if tie
in (0, 1, 2, 4):
152 text
= '(= %s Level)' % {3: 'Cyan',
156 self
.__l2.configure(text
=text
)
158 def __quit(self
, event
=None):
161 def withdraw(self
, event
=None):
162 self
.__root
.withdraw()
164 def deiconify(self
, event
=None):
165 self
.__root
.deiconify()
167 def __minus25(self
, event
=None):
170 def __minus10(self
, event
=None):
173 def __minus1(self
, event
=None):
176 def __plus1(self
, event
=None):
179 def __plus10(self
, event
=None):
182 def __plus25(self
, event
=None):
185 def __delta(self
, delta
):
187 if self
.__rvar
.get():
188 red
= self
.__red
+ delta
192 if self
.__gvar
.get():
193 green
= self
.__green
+ delta
197 if self
.__bvar
.get():
198 blue
= self
.__blue
+ delta
202 # now apply at boundary behavior
203 atbound
= self
.__boundvar
.get()
205 if red
< 0 or green
< 0 or blue
< 0 or \
206 red
> 255 or green
> 255 or blue
> 255:
208 red
, green
, blue
= self
.__red
, self
.__green
, self
.__blue
209 elif atbound
== WRAP
or (atbound
== RATIO
and len(tie
) < 2):
222 elif atbound
== RATIO
:
223 # for when 2 or 3 colors are tied together
232 if self
.__rvar
.get():
233 red
= red
+ 255 - delta
234 if self
.__gvar
.get():
235 green
= green
+ 255 - delta
236 if self
.__bvar
.get():
237 blue
= blue
+ 255 - delta
240 if self
.__rvar
.get():
242 if self
.__gvar
.get():
243 green
= green
- delta
244 if self
.__bvar
.get():
246 elif atbound
== GRAV
:
259 self
.__sb
.update_views(red
, green
, blue
)
260 self
.__root
.update_idletasks()
262 def update_yourself(self
, red
, green
, blue
):
267 def save_options(self
, optiondb
):
268 optiondb
['RSLIDER'] = self
.__rvar
.get()
269 optiondb
['GSLIDER'] = self
.__gvar
.get()
270 optiondb
['BSLIDER'] = self
.__bvar
.get()
271 optiondb
['ATBOUND'] = self
.__boundvar
.get()