Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e47e977

Browse files
committed
Implement some suggestions by Laura Creighton.
ChipWidget.__init__(): Added a message area just below the color name. Both the message and name widgets are now FLAT, DISABLED Entry widgets instead of Labels. This allows users to copy-n-paste the color names or color specs. Also, the contents of both widgets are now driven by StringVars. set_color(): This only sets the chip color; it does not set the name widgets. set_name(): New method which only sets the name widget contents. set_message(): New method which only sets the message widget contents. ChipViewer.update_yourself(): Set the color, name, and message for each chip as follows: the first line always contains the color spec in #rrggbb format. The second line will contain the color name, but slightly differently for each widget. For the Selected widget, if the color exactly matches the Nearest color, the name is shown, otherwise the message field will be empty. The name field of the Nearest widget will always contain the color name.
1 parent cf144b0 commit e47e977

1 file changed

Lines changed: 28 additions & 6 deletions

File tree

Tools/pynche/ChipViewer.py

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,37 @@ def __init__(self,
3939
height=height,
4040
background=initialcolor)
4141
self.__chip.grid(row=1, column=0)
42-
# create the color name, ctor argument must be a string
43-
self.__name = Label(master, text=initialcolor)
42+
# create the color name
43+
self.__namevar = StringVar()
44+
self.__namevar.set(initialcolor)
45+
self.__name = Entry(master, textvariable=self.__namevar,
46+
relief=FLAT, justify=CENTER, state=DISABLED,
47+
font=self.__label['font'])
4448
self.__name.grid(row=2, column=0)
45-
#
49+
# create the message area
50+
self.__msgvar = StringVar()
51+
self.__name = Entry(master, textvariable=self.__msgvar,
52+
relief=FLAT, justify=CENTER, state=DISABLED,
53+
font=self.__label['font'])
54+
self.__name.grid(row=3, column=0)
4655
# set bindings
4756
if presscmd:
4857
self.__chip.bind('<ButtonPress-1>', presscmd)
4958
if releasecmd:
5059
self.__chip.bind('<ButtonRelease-1>', releasecmd)
5160

52-
def set_color(self, color, colorname=None):
61+
def set_color(self, color):
5362
self.__chip.config(background=color)
54-
self.__name.config(text=colorname or color)
5563

5664
def get_color(self):
5765
return self.__chip['background']
5866

67+
def set_name(self, colorname):
68+
self.__namevar.set(colorname)
69+
70+
def set_message(self, message):
71+
self.__msgvar.set(message)
72+
5973
def press(self):
6074
self.__chip.configure(relief=SUNKEN)
6175

@@ -97,7 +111,15 @@ def update_yourself(self, red, green, blue):
97111
nearest_tuple = colordb.find_byname(nearest)
98112
nearest_rrggbb = ColorDB.triplet_to_rrggbb(nearest_tuple)
99113
self.__selected.set_color(rrggbb)
100-
self.__nearest.set_color(nearest_rrggbb, nearest)
114+
self.__nearest.set_color(nearest_rrggbb)
115+
# set the name and messages areas
116+
self.__selected.set_name(rrggbb)
117+
if rrggbb == nearest_rrggbb:
118+
self.__selected.set_message(nearest)
119+
else:
120+
self.__selected.set_message('')
121+
self.__nearest.set_name(nearest_rrggbb)
122+
self.__nearest.set_message(nearest)
101123

102124
def __buttonpress(self, event=None):
103125
self.__nearest.press()

0 commit comments

Comments
 (0)