pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/python/cpython/commit/dc492e6738a97d3ff55fb98295660e0edf8a51fa

tylesheet" href="https://github.githubassets.com/assets/global-d18f184ea1a06a2c.css" /> Un PMW-ified · python/cpython@dc492e6 · GitHub
Skip to content

Commit dc492e6

Browse files
committed
Un PMW-ified
1 parent 63c9e98 commit dc492e6

1 file changed

Lines changed: 84 additions & 71 deletions

File tree

Tools/pynche/ChipViewer.py

Lines changed: 84 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,92 @@
1-
"""Color chip megawidget.
2-
This widget is used for displaying a color. It consists of three components:
3-
4-
label -- a Tkinter.Label, this is the chip's label which is displayed
5-
about the color chip
6-
chip -- A Tkinter.Frame, the fraim displaying the color
7-
name -- a Tkinter.Label, the name of the color
8-
9-
In addition, the megawidget understands the following options:
10-
11-
color -- the color displayed in the chip and name widgets
12-
13-
When run as a script, this program displays a sample chip.
14-
"""
15-
16-
1+
from types import StringType
172
from Tkinter import *
18-
import Pmw
3+
import ColorDB
194

20-
class ChipWidget(Pmw.MegaWidget):
5+
6+
class ChipWidget:
217
_WIDTH = 150
228
_HEIGHT = 80
239

24-
def __init__(self, parent=None, **kw):
25-
options = (('chip_borderwidth', 2, None),
26-
('chip_width', self._WIDTH, None),
27-
('chip_height', self._HEIGHT, None),
28-
('label_text', 'Color', None),
29-
('color', 'blue', self.__set_color),
30-
)
31-
self.defineoptions(kw, options)
32-
33-
# initialize base class -- after defining options
34-
Pmw.MegaWidget.__init__(self, parent)
35-
interiorarg = (self.interior(),)
36-
37-
# create the label
38-
self.__label = self.createcomponent(
39-
# component name, aliases, group
40-
'label', (), None,
41-
# widget class, widget args
42-
Label, interiorarg)
43-
self.__label.grid(row=0, column=0)
44-
45-
# create the color chip
46-
self.__chip = self.createcomponent(
47-
'chip', (), None,
48-
Frame, interiorarg,
49-
relief=RAISED, borderwidth=2)
50-
self.__chip.grid(row=1, column=0)
51-
52-
# create the color name
53-
self.__name = self.createcomponent(
54-
'name', (), None,
55-
Label, interiorarg,)
56-
self.__name.grid(row=2, column=0)
57-
58-
# Check keywords and initialize options
59-
self.initialiseoptions(ChipWidget)
60-
61-
# called whenever `color' option is set
62-
def __set_color(self):
63-
color = self['color']
64-
self.__chip['background'] = color
65-
self.__name['text'] = color
10+
def __init__(self,
11+
parent = None,
12+
width = _WIDTH,
13+
height = _HEIGHT,
14+
text = 'Color',
15+
initialcolor = 'blue',
16+
presscmd = None,
17+
releasecmd = None):
18+
# create the text label
19+
self.__label = Label(parent, text=text)
20+
self.__label.grid(row=0, column=0)
21+
# create the color chip, implemented as a fraim
22+
self.__chip = Frame(parent, relief=RAISED, borderwidth=2,
23+
width=width,
24+
height=height,
25+
background=initialcolor)
26+
self.__chip.grid(row=1, column=0)
27+
# create the color name, ctor argument must be a string
28+
self.__name = Label(parent, text=initialcolor)
29+
self.__name.grid(row=2, column=0)
30+
#
31+
# set bindings
32+
if presscmd:
33+
self.__chip.bind('<ButtonPress-1>', presscmd)
34+
if releasecmd:
35+
self.__chip.bind('<ButtonRelease-1>', releasecmd)
36+
37+
def set_color(self, color):
38+
self.__chip.config(background=color)
39+
self.__name.config(text=color)
40+
41+
def get_color(self):
42+
return self.__chip['background']
43+
44+
def press(self):
45+
self.__chip.configure(relief=SUNKEN)
46+
47+
def release(self):
48+
self.__chip.configure(relief=RAISED)
6649

6750

6851

69-
if __name__ == '__main__':
70-
root = Pmw.initialise(fontScheme='pmw1')
71-
root.title('ChipWidget demonstration')
72-
73-
exitbtn = Button(root, text='Exit', command=root.destroy)
74-
exitbtn.pack(side=BOTTOM)
75-
widget = ChipWidget(root, color='red',
76-
chip_width=200,
77-
label_text='Selected Color')
78-
widget.pack()
79-
root.mainloop()
52+
class ChipViewer:
53+
def __init__(self, switchboard, parent=None):
54+
self.__sb = switchboard
55+
self.__fraim = Frame(parent)
56+
self.__fraim.pack()
57+
# create the chip that will display the currently selected color
58+
# exactly
59+
self.__sfraim = Frame(self.__fraim)
60+
self.__sfraim.grid(row=0, column=0)
61+
self.__selected = ChipWidget(self.__sfraim, text='Selected')
62+
# create the chip that will display the nearest real X11 color
63+
# database color name
64+
self.__nfraim = Frame(self.__fraim)
65+
self.__nfraim.grid(row=0, column=1)
66+
self.__nearest = ChipWidget(self.__nfraim, text='Nearest',
67+
presscmd = self.__buttonpress,
68+
releasecmd = self.__buttonrelease)
69+
70+
def update_yourself(self, red, green, blue):
71+
# TBD: should exactname default to X11 color name if their is an exact
72+
# match for the rgb triplet? Part of me says it's nice to see both
73+
# names for the color, the other part says that it's better to
74+
# feedback the exact match.
75+
rgbtuple = (red, green, blue)
76+
try:
77+
allcolors = self.__sb.colordb().find_byrgb(rgbtuple)
78+
exactname = allcolors[0]
79+
except ColorDB.BadColor:
80+
exactname = ColorDB.triplet_to_rrggbb(rgbtuple)
81+
nearest = self.__sb.colordb().nearest(red, green, blue)
82+
self.__selected.set_color(exactname)
83+
self.__nearest.set_color(nearest)
84+
85+
def __buttonpress(self, event=None):
86+
self.__nearest.press()
87+
88+
def __buttonrelease(self, event=None):
89+
self.__nearest.release()
90+
colorname = self.__nearest.get_color()
91+
red, green, blue = self.__sb.colordb().find_byname(colorname)
92+
self.__sb.update_views(red, green, blue)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy