blob: 9e77a021d8c734895aa37b11b2424cb286ebc0dd [file] [log] [blame]
Barry Warsaw4638c5b1998-10-02 16:20:14 +00001"""TextViewer class.
2
3The TextViewer allows you to see how the selected color would affect various
4characteristics of a Tk text widget. This is an output viewer only.
5
6In the top part of the window is a standard text widget with some sample text
7in it. You are free to edit this text in any way you want (TBD: allow you to
8change font characteristics). If you want changes in other viewers to update
9text characteristics, turn on Track color changes.
10
11To select which characteristic tracks the change, select one of the radio
12buttons in the window below. Text foreground and background affect the text
13in the window above. The Selection is what you see when you click the middle
14button and drag it through some text. The Insertion is the insertion cursor
15in the text window (which only has a background).
16"""
17
Barry Warsawf9c6ddc1998-10-01 16:45:32 +000018import sys
19from Tkinter import *
20from pynche import __version__
21import ColorDB
22
23class TextViewer:
24 def __init__(self, switchboard, parent=None):
25 self.__sb = switchboard
26 root = self.__root = Toplevel(parent, class_='Pynche')
27 root.protocol('WM_DELETE_WINDOW', self.__withdraw)
28 root.title('Pynche %s' % __version__)
29 root.iconname('Pynche Text Window')
30 root.bind('<Alt-q>', self.__quit)
31 root.bind('<Alt-Q>', self.__quit)
32 #
33 # create the text widget
34 #
35 self.__text = Text(root, relief=SUNKEN,
36 background='black',
37 foreground='white',
38 width=35, height=15)
39 self.__text.pack()
40 self.__text.insert(0.0, '''\
41Insert some stuff here and play
42with the buttons below to see
43how the colors interact in
44textual displays.''')
45 #
46 # variables
47 self.__trackp = BooleanVar()
48 self.__trackp.set(0)
49 self.__which = IntVar()
Barry Warsaw4638c5b1998-10-02 16:20:14 +000050 self.__which.set(0)
Barry Warsawf9c6ddc1998-10-01 16:45:32 +000051 #
52 # track toggle
53 self.__t = Checkbutton(root, text='Track color changes',
54 variable=self.__trackp,
55 relief=GROOVE)
56 self.__t.pack(fill=X, expand=YES)
57 frame = self.__frame = Frame(root)
58 frame.pack()
59 #
60 # labels
61 self.__labels = []
62 row = 2
63 for text in ('Text:', 'Selection:', 'Insertion:'):
64 l = Label(frame, text=text)
65 l.grid(row=row, column=0, sticky=E)
66 self.__labels.append(l)
67 row = row + 1
68 col = 1
69 for text in ('Foreground', 'Background'):
70 l = Label(frame, text=text)
71 l.grid(row=1, column=col)
72 self.__labels.append(l)
73 col = col + 1
74 #
75 # radios
76 self.__radios = []
77 val = 0
78 for col in (1, 2):
79 for row in (2, 3, 4):
80 # there is no insertforeground option
81 if row==4 and col==1:
82 continue
83 r = Radiobutton(frame, variable=self.__which,
84 value=(row-2)*2 + col-1)
85 r.grid(row=row, column=col)
86 self.__radios.append(r)
87
88 def __quit(self, event=None):
89 sys.exit(0)
90
91 def __withdraw(self, event=None):
92 self.__root.withdraw()
93
94 def deiconify(self, event=None):
95 self.__root.deiconify()
96
97 def __forceupdate(self, event=None):
98 self.__sb.update_views_current()
99
100 def update_yourself(self, red, green, blue):
101 colorname = ColorDB.triplet_to_rrggbb((red, green, blue))
102 which = self.__which.get()
103 if which == 0:
104 self.__text.configure(foreground=colorname)
105 elif which == 1:
106 self.__text.configure(background=colorname)
107 elif which == 2:
108 self.__text.configure(selectforeground=colorname)
109 elif which == 3:
110 self.__text.configure(selectbackground=colorname)
111 elif which == 5:
112 self.__text.configure(insertbackground=colorname)