blob: 0479d8c8dce65210d421dcc8fc3b3a2d4691d63d [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)
Barry Warsaw964fbbb1998-10-05 21:15:08 +000032 root.bind('<Alt-w>', self.__withdraw)
33 root.bind('<Alt-W>', self.__withdraw)
Barry Warsawf9c6ddc1998-10-01 16:45:32 +000034 #
35 # create the text widget
36 #
37 self.__text = Text(root, relief=SUNKEN,
38 background='black',
39 foreground='white',
40 width=35, height=15)
41 self.__text.pack()
42 self.__text.insert(0.0, '''\
43Insert some stuff here and play
44with the buttons below to see
45how the colors interact in
46textual displays.''')
47 #
48 # variables
49 self.__trackp = BooleanVar()
50 self.__trackp.set(0)
51 self.__which = IntVar()
Barry Warsaw4638c5b1998-10-02 16:20:14 +000052 self.__which.set(0)
Barry Warsawf9c6ddc1998-10-01 16:45:32 +000053 #
54 # track toggle
55 self.__t = Checkbutton(root, text='Track color changes',
56 variable=self.__trackp,
57 relief=GROOVE)
58 self.__t.pack(fill=X, expand=YES)
59 frame = self.__frame = Frame(root)
60 frame.pack()
61 #
62 # labels
63 self.__labels = []
64 row = 2
65 for text in ('Text:', 'Selection:', 'Insertion:'):
66 l = Label(frame, text=text)
67 l.grid(row=row, column=0, sticky=E)
68 self.__labels.append(l)
69 row = row + 1
70 col = 1
71 for text in ('Foreground', 'Background'):
72 l = Label(frame, text=text)
73 l.grid(row=1, column=col)
74 self.__labels.append(l)
75 col = col + 1
76 #
77 # radios
78 self.__radios = []
79 val = 0
80 for col in (1, 2):
81 for row in (2, 3, 4):
82 # there is no insertforeground option
83 if row==4 and col==1:
84 continue
85 r = Radiobutton(frame, variable=self.__which,
86 value=(row-2)*2 + col-1)
87 r.grid(row=row, column=col)
88 self.__radios.append(r)
89
90 def __quit(self, event=None):
91 sys.exit(0)
92
93 def __withdraw(self, event=None):
94 self.__root.withdraw()
95
96 def deiconify(self, event=None):
97 self.__root.deiconify()
98
99 def __forceupdate(self, event=None):
100 self.__sb.update_views_current()
101
102 def update_yourself(self, red, green, blue):
103 colorname = ColorDB.triplet_to_rrggbb((red, green, blue))
104 which = self.__which.get()
105 if which == 0:
106 self.__text.configure(foreground=colorname)
107 elif which == 1:
108 self.__text.configure(background=colorname)
109 elif which == 2:
110 self.__text.configure(selectforeground=colorname)
111 elif which == 3:
112 self.__text.configure(selectbackground=colorname)
113 elif which == 5:
114 self.__text.configure(insertbackground=colorname)