Barry Warsaw | f9c6ddc | 1998-10-01 16:45:32 +0000 | [diff] [blame] | 1 | import sys |
| 2 | from Tkinter import * |
| 3 | from pynche import __version__ |
| 4 | import ColorDB |
| 5 | |
| 6 | class TextViewer: |
| 7 | def __init__(self, switchboard, parent=None): |
| 8 | self.__sb = switchboard |
| 9 | root = self.__root = Toplevel(parent, class_='Pynche') |
| 10 | root.protocol('WM_DELETE_WINDOW', self.__withdraw) |
| 11 | root.title('Pynche %s' % __version__) |
| 12 | root.iconname('Pynche Text Window') |
| 13 | root.bind('<Alt-q>', self.__quit) |
| 14 | root.bind('<Alt-Q>', self.__quit) |
| 15 | # |
| 16 | # create the text widget |
| 17 | # |
| 18 | self.__text = Text(root, relief=SUNKEN, |
| 19 | background='black', |
| 20 | foreground='white', |
| 21 | width=35, height=15) |
| 22 | self.__text.pack() |
| 23 | self.__text.insert(0.0, '''\ |
| 24 | Insert some stuff here and play |
| 25 | with the buttons below to see |
| 26 | how the colors interact in |
| 27 | textual displays.''') |
| 28 | # |
| 29 | # variables |
| 30 | self.__trackp = BooleanVar() |
| 31 | self.__trackp.set(0) |
| 32 | self.__which = IntVar() |
| 33 | self.__which.set(4) |
| 34 | # |
| 35 | # track toggle |
| 36 | self.__t = Checkbutton(root, text='Track color changes', |
| 37 | variable=self.__trackp, |
| 38 | relief=GROOVE) |
| 39 | self.__t.pack(fill=X, expand=YES) |
| 40 | frame = self.__frame = Frame(root) |
| 41 | frame.pack() |
| 42 | # |
| 43 | # labels |
| 44 | self.__labels = [] |
| 45 | row = 2 |
| 46 | for text in ('Text:', 'Selection:', 'Insertion:'): |
| 47 | l = Label(frame, text=text) |
| 48 | l.grid(row=row, column=0, sticky=E) |
| 49 | self.__labels.append(l) |
| 50 | row = row + 1 |
| 51 | col = 1 |
| 52 | for text in ('Foreground', 'Background'): |
| 53 | l = Label(frame, text=text) |
| 54 | l.grid(row=1, column=col) |
| 55 | self.__labels.append(l) |
| 56 | col = col + 1 |
| 57 | # |
| 58 | # radios |
| 59 | self.__radios = [] |
| 60 | val = 0 |
| 61 | for col in (1, 2): |
| 62 | for row in (2, 3, 4): |
| 63 | # there is no insertforeground option |
| 64 | if row==4 and col==1: |
| 65 | continue |
| 66 | r = Radiobutton(frame, variable=self.__which, |
| 67 | value=(row-2)*2 + col-1) |
| 68 | r.grid(row=row, column=col) |
| 69 | self.__radios.append(r) |
| 70 | |
| 71 | def __quit(self, event=None): |
| 72 | sys.exit(0) |
| 73 | |
| 74 | def __withdraw(self, event=None): |
| 75 | self.__root.withdraw() |
| 76 | |
| 77 | def deiconify(self, event=None): |
| 78 | self.__root.deiconify() |
| 79 | |
| 80 | def __forceupdate(self, event=None): |
| 81 | self.__sb.update_views_current() |
| 82 | |
| 83 | def update_yourself(self, red, green, blue): |
| 84 | colorname = ColorDB.triplet_to_rrggbb((red, green, blue)) |
| 85 | which = self.__which.get() |
| 86 | if which == 0: |
| 87 | self.__text.configure(foreground=colorname) |
| 88 | elif which == 1: |
| 89 | self.__text.configure(background=colorname) |
| 90 | elif which == 2: |
| 91 | self.__text.configure(selectforeground=colorname) |
| 92 | elif which == 3: |
| 93 | self.__text.configure(selectbackground=colorname) |
| 94 | elif which == 5: |
| 95 | self.__text.configure(insertbackground=colorname) |