annotate Tools/pynche/TextViewer.py @ 79675:c0a2294de787 2.7

Issue #16199: Backport 2to3 typo fix from 3.2.
author Chris Jerdonek <chris.jerdonek@gmail.com>
date Thu, 11 Oct 2012 16:15:46 -0700
parents 3db921f3ede0
children 37d399aa8c16
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9228
a03c6fd81d4d Docstring
Barry Warsaw <barry@python.org>
parents: 9195
diff changeset
1 """TextViewer class.
a03c6fd81d4d Docstring
Barry Warsaw <barry@python.org>
parents: 9195
diff changeset
2
a03c6fd81d4d Docstring
Barry Warsaw <barry@python.org>
parents: 9195
diff changeset
3 The TextViewer allows you to see how the selected color would affect various
a03c6fd81d4d Docstring
Barry Warsaw <barry@python.org>
parents: 9195
diff changeset
4 characteristics of a Tk text widget. This is an output viewer only.
a03c6fd81d4d Docstring
Barry Warsaw <barry@python.org>
parents: 9195
diff changeset
5
a03c6fd81d4d Docstring
Barry Warsaw <barry@python.org>
parents: 9195
diff changeset
6 In the top part of the window is a standard text widget with some sample text
18461
3db921f3ede0 __init__(): Use augmented assignments.
Barry Warsaw <barry@python.org>
parents: 17568
diff changeset
7 in it. You are free to edit this text in any way you want (BAW: allow you to
9228
a03c6fd81d4d Docstring
Barry Warsaw <barry@python.org>
parents: 9195
diff changeset
8 change font characteristics). If you want changes in other viewers to update
a03c6fd81d4d Docstring
Barry Warsaw <barry@python.org>
parents: 9195
diff changeset
9 text characteristics, turn on Track color changes.
a03c6fd81d4d Docstring
Barry Warsaw <barry@python.org>
parents: 9195
diff changeset
10
a03c6fd81d4d Docstring
Barry Warsaw <barry@python.org>
parents: 9195
diff changeset
11 To select which characteristic tracks the change, select one of the radio
a03c6fd81d4d Docstring
Barry Warsaw <barry@python.org>
parents: 9195
diff changeset
12 buttons in the window below. Text foreground and background affect the text
a03c6fd81d4d Docstring
Barry Warsaw <barry@python.org>
parents: 9195
diff changeset
13 in the window above. The Selection is what you see when you click the middle
a03c6fd81d4d Docstring
Barry Warsaw <barry@python.org>
parents: 9195
diff changeset
14 button and drag it through some text. The Insertion is the insertion cursor
a03c6fd81d4d Docstring
Barry Warsaw <barry@python.org>
parents: 9195
diff changeset
15 in the text window (which only has a background).
a03c6fd81d4d Docstring
Barry Warsaw <barry@python.org>
parents: 9195
diff changeset
16 """
a03c6fd81d4d Docstring
Barry Warsaw <barry@python.org>
parents: 9195
diff changeset
17
9195
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
18 from Tkinter import *
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
19 import ColorDB
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
20
10760
6a38e667d349 Add a module global variable ADDTOVIEW to conform to dynamic viewer
Barry Warsaw <barry@python.org>
parents: 10756
diff changeset
21 ADDTOVIEW = 'Text Window...'
6a38e667d349 Add a module global variable ADDTOVIEW to conform to dynamic viewer
Barry Warsaw <barry@python.org>
parents: 10756
diff changeset
22
18461
3db921f3ede0 __init__(): Use augmented assignments.
Barry Warsaw <barry@python.org>
parents: 17568
diff changeset
23
3db921f3ede0 __init__(): Use augmented assignments.
Barry Warsaw <barry@python.org>
parents: 17568
diff changeset
24
9195
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
25 class TextViewer:
9427
7567ef40de77 Many changes to support a second mode of operation. Pynche can now be
Barry Warsaw <barry@python.org>
parents: 9414
diff changeset
26 def __init__(self, switchboard, master=None):
9195
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
27 self.__sb = switchboard
9414
c03ffff387f8 Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents: 9264
diff changeset
28 optiondb = switchboard.optiondb()
9427
7567ef40de77 Many changes to support a second mode of operation. Pynche can now be
Barry Warsaw <barry@python.org>
parents: 9414
diff changeset
29 root = self.__root = Toplevel(master, class_='Pynche')
7567ef40de77 Many changes to support a second mode of operation. Pynche can now be
Barry Warsaw <barry@python.org>
parents: 9414
diff changeset
30 root.protocol('WM_DELETE_WINDOW', self.withdraw)
9240
Barry Warsaw <barry@python.org>
parents: 9238
diff changeset
31 root.title('Pynche Text Window')
9195
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
32 root.iconname('Pynche Text Window')
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
33 root.bind('<Alt-q>', self.__quit)
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
34 root.bind('<Alt-Q>', self.__quit)
9427
7567ef40de77 Many changes to support a second mode of operation. Pynche can now be
Barry Warsaw <barry@python.org>
parents: 9414
diff changeset
35 root.bind('<Alt-w>', self.withdraw)
7567ef40de77 Many changes to support a second mode of operation. Pynche can now be
Barry Warsaw <barry@python.org>
parents: 9414
diff changeset
36 root.bind('<Alt-W>', self.withdraw)
9195
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
37 #
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
38 # create the text widget
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
39 #
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
40 self.__text = Text(root, relief=SUNKEN,
9414
c03ffff387f8 Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents: 9264
diff changeset
41 background=optiondb.get('TEXTBG', 'black'),
c03ffff387f8 Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents: 9264
diff changeset
42 foreground=optiondb.get('TEXTFG', 'white'),
9195
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
43 width=35, height=15)
9414
c03ffff387f8 Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents: 9264
diff changeset
44 sfg = optiondb.get('TEXT_SFG')
c03ffff387f8 Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents: 9264
diff changeset
45 if sfg:
c03ffff387f8 Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents: 9264
diff changeset
46 self.__text.configure(selectforeground=sfg)
c03ffff387f8 Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents: 9264
diff changeset
47 sbg = optiondb.get('TEXT_SBG')
c03ffff387f8 Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents: 9264
diff changeset
48 if sbg:
c03ffff387f8 Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents: 9264
diff changeset
49 self.__text.configure(selectbackground=sbg)
c03ffff387f8 Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents: 9264
diff changeset
50 ibg = optiondb.get('TEXT_IBG')
c03ffff387f8 Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents: 9264
diff changeset
51 if ibg:
c03ffff387f8 Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents: 9264
diff changeset
52 self.__text.configure(insertbackground=ibg)
9195
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
53 self.__text.pack()
9414
c03ffff387f8 Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents: 9264
diff changeset
54 self.__text.insert(0.0, optiondb.get('TEXT', '''\
9195
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
55 Insert some stuff here and play
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
56 with the buttons below to see
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
57 how the colors interact in
9264
86de1fa0fbb7 Add a SELECTION to the pre-inserted text
Barry Warsaw <barry@python.org>
parents: 9259
diff changeset
58 textual displays.
86de1fa0fbb7 Add a SELECTION to the pre-inserted text
Barry Warsaw <barry@python.org>
parents: 9259
diff changeset
59
86de1fa0fbb7 Add a SELECTION to the pre-inserted text
Barry Warsaw <barry@python.org>
parents: 9259
diff changeset
60 See how the selection can also
86de1fa0fbb7 Add a SELECTION to the pre-inserted text
Barry Warsaw <barry@python.org>
parents: 9259
diff changeset
61 be affected by tickling the buttons
9414
c03ffff387f8 Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents: 9264
diff changeset
62 and choosing a color.'''))
c03ffff387f8 Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents: 9264
diff changeset
63 insert = optiondb.get('TEXTINS')
c03ffff387f8 Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents: 9264
diff changeset
64 if insert:
c03ffff387f8 Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents: 9264
diff changeset
65 self.__text.mark_set(INSERT, insert)
c03ffff387f8 Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents: 9264
diff changeset
66 try:
c03ffff387f8 Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents: 9264
diff changeset
67 start, end = optiondb.get('TEXTSEL', (6.0, END))
c03ffff387f8 Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents: 9264
diff changeset
68 self.__text.tag_add(SEL, start, end)
c03ffff387f8 Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents: 9264
diff changeset
69 except ValueError:
c03ffff387f8 Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents: 9264
diff changeset
70 # selection wasn't set
c03ffff387f8 Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents: 9264
diff changeset
71 pass
c03ffff387f8 Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents: 9264
diff changeset
72 self.__text.focus_set()
9195
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
73 #
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
74 # variables
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
75 self.__trackp = BooleanVar()
9414
c03ffff387f8 Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents: 9264
diff changeset
76 self.__trackp.set(optiondb.get('TRACKP', 0))
9195
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
77 self.__which = IntVar()
9414
c03ffff387f8 Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents: 9264
diff changeset
78 self.__which.set(optiondb.get('WHICH', 0))
9195
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
79 #
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
80 # track toggle
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
81 self.__t = Checkbutton(root, text='Track color changes',
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
82 variable=self.__trackp,
9252
590bd9b45bf6 Track color changes: disable buttons and their labels when turned off
Barry Warsaw <barry@python.org>
parents: 9240
diff changeset
83 relief=GROOVE,
590bd9b45bf6 Track color changes: disable buttons and their labels when turned off
Barry Warsaw <barry@python.org>
parents: 9240
diff changeset
84 command=self.__toggletrack)
9195
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
85 self.__t.pack(fill=X, expand=YES)
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
86 frame = self.__frame = Frame(root)
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
87 frame.pack()
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
88 #
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
89 # labels
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
90 self.__labels = []
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
91 row = 2
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
92 for text in ('Text:', 'Selection:', 'Insertion:'):
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
93 l = Label(frame, text=text)
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
94 l.grid(row=row, column=0, sticky=E)
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
95 self.__labels.append(l)
18461
3db921f3ede0 __init__(): Use augmented assignments.
Barry Warsaw <barry@python.org>
parents: 17568
diff changeset
96 row += 1
9195
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
97 col = 1
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
98 for text in ('Foreground', 'Background'):
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
99 l = Label(frame, text=text)
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
100 l.grid(row=1, column=col)
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
101 self.__labels.append(l)
18461
3db921f3ede0 __init__(): Use augmented assignments.
Barry Warsaw <barry@python.org>
parents: 17568
diff changeset
102 col += 1
9195
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
103 #
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
104 # radios
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
105 self.__radios = []
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
106 for col in (1, 2):
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
107 for row in (2, 3, 4):
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
108 # there is no insertforeground option
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
109 if row==4 and col==1:
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
110 continue
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
111 r = Radiobutton(frame, variable=self.__which,
10756
f1b2bb535eb3 When selecting a radio button in the TextViewer (to change a specific
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
112 value=(row-2)*2 + col-1,
f1b2bb535eb3 When selecting a radio button in the TextViewer (to change a specific
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
113 command=self.__set_color)
9195
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
114 r.grid(row=row, column=col)
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
115 self.__radios.append(r)
9252
590bd9b45bf6 Track color changes: disable buttons and their labels when turned off
Barry Warsaw <barry@python.org>
parents: 9240
diff changeset
116 self.__toggletrack()
9195
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
117
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
118 def __quit(self, event=None):
9259
6b6bd14d750b Better quitting
Barry Warsaw <barry@python.org>
parents: 9252
diff changeset
119 self.__root.quit()
9195
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
120
9427
7567ef40de77 Many changes to support a second mode of operation. Pynche can now be
Barry Warsaw <barry@python.org>
parents: 9414
diff changeset
121 def withdraw(self, event=None):
9195
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
122 self.__root.withdraw()
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
123
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
124 def deiconify(self, event=None):
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
125 self.__root.deiconify()
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
126
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
127 def __forceupdate(self, event=None):
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
128 self.__sb.update_views_current()
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
129
9252
590bd9b45bf6 Track color changes: disable buttons and their labels when turned off
Barry Warsaw <barry@python.org>
parents: 9240
diff changeset
130 def __toggletrack(self, event=None):
590bd9b45bf6 Track color changes: disable buttons and their labels when turned off
Barry Warsaw <barry@python.org>
parents: 9240
diff changeset
131 if self.__trackp.get():
590bd9b45bf6 Track color changes: disable buttons and their labels when turned off
Barry Warsaw <barry@python.org>
parents: 9240
diff changeset
132 state = NORMAL
590bd9b45bf6 Track color changes: disable buttons and their labels when turned off
Barry Warsaw <barry@python.org>
parents: 9240
diff changeset
133 fg = self.__radios[0]['foreground']
590bd9b45bf6 Track color changes: disable buttons and their labels when turned off
Barry Warsaw <barry@python.org>
parents: 9240
diff changeset
134 else:
590bd9b45bf6 Track color changes: disable buttons and their labels when turned off
Barry Warsaw <barry@python.org>
parents: 9240
diff changeset
135 state = DISABLED
590bd9b45bf6 Track color changes: disable buttons and their labels when turned off
Barry Warsaw <barry@python.org>
parents: 9240
diff changeset
136 fg = self.__radios[0]['disabledforeground']
590bd9b45bf6 Track color changes: disable buttons and their labels when turned off
Barry Warsaw <barry@python.org>
parents: 9240
diff changeset
137 for r in self.__radios:
590bd9b45bf6 Track color changes: disable buttons and their labels when turned off
Barry Warsaw <barry@python.org>
parents: 9240
diff changeset
138 r.configure(state=state)
590bd9b45bf6 Track color changes: disable buttons and their labels when turned off
Barry Warsaw <barry@python.org>
parents: 9240
diff changeset
139 for l in self.__labels:
590bd9b45bf6 Track color changes: disable buttons and their labels when turned off
Barry Warsaw <barry@python.org>
parents: 9240
diff changeset
140 l.configure(foreground=fg)
590bd9b45bf6 Track color changes: disable buttons and their labels when turned off
Barry Warsaw <barry@python.org>
parents: 9240
diff changeset
141
10756
f1b2bb535eb3 When selecting a radio button in the TextViewer (to change a specific
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
142 def __set_color(self, event=None):
f1b2bb535eb3 When selecting a radio button in the TextViewer (to change a specific
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
143 which = self.__which.get()
f1b2bb535eb3 When selecting a radio button in the TextViewer (to change a specific
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
144 text = self.__text
f1b2bb535eb3 When selecting a radio button in the TextViewer (to change a specific
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
145 if which == 0:
f1b2bb535eb3 When selecting a radio button in the TextViewer (to change a specific
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
146 color = text['foreground']
f1b2bb535eb3 When selecting a radio button in the TextViewer (to change a specific
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
147 elif which == 1:
f1b2bb535eb3 When selecting a radio button in the TextViewer (to change a specific
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
148 color = text['background']
f1b2bb535eb3 When selecting a radio button in the TextViewer (to change a specific
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
149 elif which == 2:
f1b2bb535eb3 When selecting a radio button in the TextViewer (to change a specific
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
150 color = text['selectforeground']
f1b2bb535eb3 When selecting a radio button in the TextViewer (to change a specific
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
151 elif which == 3:
f1b2bb535eb3 When selecting a radio button in the TextViewer (to change a specific
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
152 color = text['selectbackground']
f1b2bb535eb3 When selecting a radio button in the TextViewer (to change a specific
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
153 elif which == 5:
f1b2bb535eb3 When selecting a radio button in the TextViewer (to change a specific
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
154 color = text['insertbackground']
f1b2bb535eb3 When selecting a radio button in the TextViewer (to change a specific
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
155 try:
f1b2bb535eb3 When selecting a radio button in the TextViewer (to change a specific
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
156 red, green, blue = ColorDB.rrggbb_to_triplet(color)
f1b2bb535eb3 When selecting a radio button in the TextViewer (to change a specific
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
157 except ColorDB.BadColor:
f1b2bb535eb3 When selecting a radio button in the TextViewer (to change a specific
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
158 # must have been a color name
f1b2bb535eb3 When selecting a radio button in the TextViewer (to change a specific
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
159 red, green, blue = self.__sb.colordb().find_byname(color)
f1b2bb535eb3 When selecting a radio button in the TextViewer (to change a specific
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
160 self.__sb.update_views(red, green, blue)
f1b2bb535eb3 When selecting a radio button in the TextViewer (to change a specific
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
161
9195
195e748cf696 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
162 def update_yourself(self, red, green, blue):
9252
590bd9b45bf6 Track color changes: disable buttons and their labels when turned off
Barry Warsaw <barry@python.org>
parents: 9240
diff changeset
163 if self.__trackp.get():
590bd9b45bf6 Track color changes: disable buttons and their labels when turned off
Barry Warsaw <barry@python.org>
parents: 9240
diff changeset
164 colorname = ColorDB.triplet_to_rrggbb((red, green, blue))
590bd9b45bf6 Track color changes: disable buttons and their labels when turned off
Barry Warsaw <barry@python.org>
parents: 9240
diff changeset
165 which = self.__which.get()
10756
f1b2bb535eb3 When selecting a radio button in the TextViewer (to change a specific
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
166 text = self.__text
9252
590bd9b45bf6 Track color changes: disable buttons and their labels when turned off
Barry Warsaw <barry@python.org>
parents: 9240
diff changeset
167 if which == 0:
10756
f1b2bb535eb3 When selecting a radio button in the TextViewer (to change a specific
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
168 text.configure(foreground=colorname)
9252
590bd9b45bf6 Track color changes: disable buttons and their labels when turned off
Barry Warsaw <barry@python.org>
parents: 9240
diff changeset
169 elif which == 1:
10756
f1b2bb535eb3 When selecting a radio button in the TextViewer (to change a specific
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
170 text.configure(background=colorname)
9252
590bd9b45bf6 Track color changes: disable buttons and their labels when turned off
Barry Warsaw <barry@python.org>
parents: 9240
diff changeset
171 elif which == 2:
10756
f1b2bb535eb3 When selecting a radio button in the TextViewer (to change a specific
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
172 text.configure(selectforeground=colorname)
9252
590bd9b45bf6 Track color changes: disable buttons and their labels when turned off
Barry Warsaw <barry@python.org>
parents: 9240
diff changeset
173 elif which == 3:
10756
f1b2bb535eb3 When selecting a radio button in the TextViewer (to change a specific
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
174 text.configure(selectbackground=colorname)
9252
590bd9b45bf6 Track color changes: disable buttons and their labels when turned off
Barry Warsaw <barry@python.org>
parents: 9240
diff changeset
175 elif which == 5:
10756
f1b2bb535eb3 When selecting a radio button in the TextViewer (to change a specific
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
176 text.configure(insertbackground=colorname)
9414
c03ffff387f8 Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents: 9264
diff changeset
177
c03ffff387f8 Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents: 9264
diff changeset
178 def save_options(self, optiondb):
c03ffff387f8 Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents: 9264
diff changeset
179 optiondb['TRACKP'] = self.__trackp.get()
c03ffff387f8 Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents: 9264
diff changeset
180 optiondb['WHICH'] = self.__which.get()
c03ffff387f8 Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents: 9264
diff changeset
181 optiondb['TEXT'] = self.__text.get(0.0, 'end - 1c')
c03ffff387f8 Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents: 9264
diff changeset
182 optiondb['TEXTSEL'] = self.__text.tag_ranges(SEL)[0:2]
c03ffff387f8 Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents: 9264
diff changeset
183 optiondb['TEXTINS'] = self.__text.index(INSERT)
c03ffff387f8 Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents: 9264
diff changeset
184 optiondb['TEXTFG'] = self.__text['foreground']
c03ffff387f8 Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents: 9264
diff changeset
185 optiondb['TEXTBG'] = self.__text['background']
c03ffff387f8 Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents: 9264
diff changeset
186 optiondb['TEXT_SFG'] = self.__text['selectforeground']
c03ffff387f8 Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents: 9264
diff changeset
187 optiondb['TEXT_SBG'] = self.__text['selectbackground']
c03ffff387f8 Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents: 9264
diff changeset
188 optiondb['TEXT_IBG'] = self.__text['insertbackground']