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

Skip to content

Commit 7b28122

Browse files
committed
When selecting a radio button in the TextViewer (to change a specific
text widget attribute), the color the attribute currently has is set in the main widget.
1 parent f5e9857 commit 7b28122

1 file changed

Lines changed: 28 additions & 6 deletions

File tree

Tools/pynche/TextViewer.py

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ def __init__(self, switchboard, master=None):
106106
if row==4 and col==1:
107107
continue
108108
r = Radiobutton(frame, variable=self.__which,
109-
value=(row-2)*2 + col-1)
109+
value=(row-2)*2 + col-1,
110+
command=self.__set_color)
110111
r.grid(row=row, column=col)
111112
self.__radios.append(r)
112113
self.__toggletrack()
@@ -135,20 +136,41 @@ def __toggletrack(self, event=None):
135136
for l in self.__labels:
136137
l.configure(foreground=fg)
137138

139+
def __set_color(self, event=None):
140+
which = self.__which.get()
141+
text = self.__text
142+
if which == 0:
143+
color = text['foreground']
144+
elif which == 1:
145+
color = text['background']
146+
elif which == 2:
147+
color = text['selectforeground']
148+
elif which == 3:
149+
color = text['selectbackground']
150+
elif which == 5:
151+
color = text['insertbackground']
152+
try:
153+
red, green, blue = ColorDB.rrggbb_to_triplet(color)
154+
except ColorDB.BadColor:
155+
# must have been a color name
156+
red, green, blue = self.__sb.colordb().find_byname(color)
157+
self.__sb.update_views(red, green, blue)
158+
138159
def update_yourself(self, red, green, blue):
139160
if self.__trackp.get():
140161
colorname = ColorDB.triplet_to_rrggbb((red, green, blue))
141162
which = self.__which.get()
163+
text = self.__text
142164
if which == 0:
143-
self.__text.configure(foreground=colorname)
165+
text.configure(foreground=colorname)
144166
elif which == 1:
145-
self.__text.configure(background=colorname)
167+
text.configure(background=colorname)
146168
elif which == 2:
147-
self.__text.configure(selectforeground=colorname)
169+
text.configure(selectforeground=colorname)
148170
elif which == 3:
149-
self.__text.configure(selectbackground=colorname)
171+
text.configure(selectbackground=colorname)
150172
elif which == 5:
151-
self.__text.configure(insertbackground=colorname)
173+
text.configure(insertbackground=colorname)
152174

153175
def save_options(self, optiondb):
154176
optiondb['TRACKP'] = self.__trackp.get()

0 commit comments

Comments
 (0)