annotate Tools/pynche/ListViewer.py @ 54294:dba767bc3155 legacy-trunk

remove mention of old ctypes version
author Benjamin Peterson <benjamin@python.org>
date Sat, 23 May 2009 20:59:09 +0000
parents 6b931bf6bdf6
children 37d399aa8c16
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9227
79400d078f1b Docstring
Barry Warsaw <barry@python.org>
parents: 9222
diff changeset
1 """ListViewer class.
79400d078f1b Docstring
Barry Warsaw <barry@python.org>
parents: 9222
diff changeset
2
79400d078f1b Docstring
Barry Warsaw <barry@python.org>
parents: 9222
diff changeset
3 This class implements an input/output view on the color model. It lists every
79400d078f1b Docstring
Barry Warsaw <barry@python.org>
parents: 9222
diff changeset
4 unique color (e.g. unique r/g/b value) found in the color database. Each
79400d078f1b Docstring
Barry Warsaw <barry@python.org>
parents: 9222
diff changeset
5 color is shown by small swatch and primary color name. Some colors have
79400d078f1b Docstring
Barry Warsaw <barry@python.org>
parents: 9222
diff changeset
6 aliases -- more than one name for the same r/g/b value. These aliases are
79400d078f1b Docstring
Barry Warsaw <barry@python.org>
parents: 9222
diff changeset
7 displayed in the small listbox at the bottom of the screen.
79400d078f1b Docstring
Barry Warsaw <barry@python.org>
parents: 9222
diff changeset
8
79400d078f1b Docstring
Barry Warsaw <barry@python.org>
parents: 9222
diff changeset
9 Clicking on a color name or swatch selects that color and updates all other
79400d078f1b Docstring
Barry Warsaw <barry@python.org>
parents: 9222
diff changeset
10 windows. When a color is selected in a different viewer, the color list is
79400d078f1b Docstring
Barry Warsaw <barry@python.org>
parents: 9222
diff changeset
11 scrolled to the selected color and it is highlighted. If the selected color
79400d078f1b Docstring
Barry Warsaw <barry@python.org>
parents: 9222
diff changeset
12 is an r/g/b value without a name, no scrolling occurs.
79400d078f1b Docstring
Barry Warsaw <barry@python.org>
parents: 9222
diff changeset
13
79400d078f1b Docstring
Barry Warsaw <barry@python.org>
parents: 9222
diff changeset
14 You can turn off Update On Click if all you want to see is the alias for a
79400d078f1b Docstring
Barry Warsaw <barry@python.org>
parents: 9222
diff changeset
15 given name, without selecting the color.
79400d078f1b Docstring
Barry Warsaw <barry@python.org>
parents: 9222
diff changeset
16 """
79400d078f1b Docstring
Barry Warsaw <barry@python.org>
parents: 9222
diff changeset
17
9207
670967be6db3 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
18 from Tkinter import *
670967be6db3 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
19 import ColorDB
670967be6db3 *** 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: 10744
diff changeset
21 ADDTOVIEW = 'Color %List Window...'
6a38e667d349 Add a module global variable ADDTOVIEW to conform to dynamic viewer
Barry Warsaw <barry@python.org>
parents: 10744
diff changeset
22
9207
670967be6db3 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
23 class ListViewer:
9427
7567ef40de77 Many changes to support a second mode of operation. Pynche can now be
Barry Warsaw <barry@python.org>
parents: 9414
diff changeset
24 def __init__(self, switchboard, master=None):
9207
670967be6db3 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
25 self.__sb = switchboard
9414
c03ffff387f8 Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents: 9259
diff changeset
26 optiondb = switchboard.optiondb()
9207
670967be6db3 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
27 self.__lastbox = None
9222
9848f42343c9 Functionality complete
Barry Warsaw <barry@python.org>
parents: 9217
diff changeset
28 self.__dontcenter = 0
9238
4c4cec54ba63 Added Alt-w bindings
Barry Warsaw <barry@python.org>
parents: 9227
diff changeset
29 # GUI
9427
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 = 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
31 root.protocol('WM_DELETE_WINDOW', self.withdraw)
9240
Barry Warsaw <barry@python.org>
parents: 9238
diff changeset
32 root.title('Pynche Color List')
9207
670967be6db3 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
33 root.iconname('Pynche Color List')
670967be6db3 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
34 root.bind('<Alt-q>', self.__quit)
670967be6db3 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
35 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
36 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
37 root.bind('<Alt-W>', self.withdraw)
9207
670967be6db3 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
38 #
670967be6db3 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
39 # create the canvas which holds everything, and its scrollbar
670967be6db3 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
40 #
9208
8148d44f9903 Lots of good UI working, but not yet update-while-dragging
Barry Warsaw <barry@python.org>
parents: 9207
diff changeset
41 frame = self.__frame = Frame(root)
8148d44f9903 Lots of good UI working, but not yet update-while-dragging
Barry Warsaw <barry@python.org>
parents: 9207
diff changeset
42 frame.pack()
9222
9848f42343c9 Functionality complete
Barry Warsaw <barry@python.org>
parents: 9217
diff changeset
43 canvas = self.__canvas = Canvas(frame, width=160, height=300,
9848f42343c9 Functionality complete
Barry Warsaw <barry@python.org>
parents: 9217
diff changeset
44 borderwidth=2, relief=SUNKEN)
9208
8148d44f9903 Lots of good UI working, but not yet update-while-dragging
Barry Warsaw <barry@python.org>
parents: 9207
diff changeset
45 self.__scrollbar = Scrollbar(frame)
9207
670967be6db3 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
46 self.__scrollbar.pack(fill=Y, side=RIGHT)
670967be6db3 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
47 canvas.pack(fill=BOTH, expand=1)
670967be6db3 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
48 canvas.configure(yscrollcommand=(self.__scrollbar, 'set'))
670967be6db3 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
49 self.__scrollbar.configure(command=(canvas, 'yview'))
10744
4c9de6fd267b Lots of changes to support loading alternative color name database.
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
50 self.__populate()
9222
9848f42343c9 Functionality complete
Barry Warsaw <barry@python.org>
parents: 9217
diff changeset
51 #
9848f42343c9 Functionality complete
Barry Warsaw <barry@python.org>
parents: 9217
diff changeset
52 # Update on click
9848f42343c9 Functionality complete
Barry Warsaw <barry@python.org>
parents: 9217
diff changeset
53 self.__uoc = BooleanVar()
9414
c03ffff387f8 Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents: 9259
diff changeset
54 self.__uoc.set(optiondb.get('UPONCLICK', 1))
9222
9848f42343c9 Functionality complete
Barry Warsaw <barry@python.org>
parents: 9217
diff changeset
55 self.__uocbtn = Checkbutton(root,
9848f42343c9 Functionality complete
Barry Warsaw <barry@python.org>
parents: 9217
diff changeset
56 text='Update on Click',
9254
9d393a0f727c Update main window when Update on Click is turned on
Barry Warsaw <barry@python.org>
parents: 9240
diff changeset
57 variable=self.__uoc,
9d393a0f727c Update main window when Update on Click is turned on
Barry Warsaw <barry@python.org>
parents: 9240
diff changeset
58 command=self.__toggleupdate)
9222
9848f42343c9 Functionality complete
Barry Warsaw <barry@python.org>
parents: 9217
diff changeset
59 self.__uocbtn.pack(expand=1, fill=BOTH)
9848f42343c9 Functionality complete
Barry Warsaw <barry@python.org>
parents: 9217
diff changeset
60 #
9848f42343c9 Functionality complete
Barry Warsaw <barry@python.org>
parents: 9217
diff changeset
61 # alias list
9848f42343c9 Functionality complete
Barry Warsaw <barry@python.org>
parents: 9217
diff changeset
62 self.__alabel = Label(root, text='Aliases:')
9848f42343c9 Functionality complete
Barry Warsaw <barry@python.org>
parents: 9217
diff changeset
63 self.__alabel.pack()
9848f42343c9 Functionality complete
Barry Warsaw <barry@python.org>
parents: 9217
diff changeset
64 self.__aliases = Listbox(root, height=5,
9848f42343c9 Functionality complete
Barry Warsaw <barry@python.org>
parents: 9217
diff changeset
65 selectmode=BROWSE)
9848f42343c9 Functionality complete
Barry Warsaw <barry@python.org>
parents: 9217
diff changeset
66 self.__aliases.pack(expand=1, fill=BOTH)
9207
670967be6db3 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
67
10744
4c9de6fd267b Lots of changes to support loading alternative color name database.
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
68 def __populate(self):
4c9de6fd267b Lots of changes to support loading alternative color name database.
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
69 #
4c9de6fd267b Lots of changes to support loading alternative color name database.
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
70 # create all the buttons
4c9de6fd267b Lots of changes to support loading alternative color name database.
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
71 colordb = self.__sb.colordb()
4c9de6fd267b Lots of changes to support loading alternative color name database.
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
72 canvas = self.__canvas
4c9de6fd267b Lots of changes to support loading alternative color name database.
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
73 row = 0
4c9de6fd267b Lots of changes to support loading alternative color name database.
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
74 widest = 0
4c9de6fd267b Lots of changes to support loading alternative color name database.
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
75 bboxes = self.__bboxes = []
4c9de6fd267b Lots of changes to support loading alternative color name database.
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
76 for name in colordb.unique_names():
4c9de6fd267b Lots of changes to support loading alternative color name database.
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
77 exactcolor = ColorDB.triplet_to_rrggbb(colordb.find_byname(name))
4c9de6fd267b Lots of changes to support loading alternative color name database.
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
78 canvas.create_rectangle(5, row*20 + 5,
4c9de6fd267b Lots of changes to support loading alternative color name database.
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
79 20, row*20 + 20,
4c9de6fd267b Lots of changes to support loading alternative color name database.
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
80 fill=exactcolor)
4c9de6fd267b Lots of changes to support loading alternative color name database.
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
81 textid = canvas.create_text(25, row*20 + 13,
4c9de6fd267b Lots of changes to support loading alternative color name database.
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
82 text=name,
4c9de6fd267b Lots of changes to support loading alternative color name database.
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
83 anchor=W)
4c9de6fd267b Lots of changes to support loading alternative color name database.
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
84 x1, y1, textend, y2 = canvas.bbox(textid)
4c9de6fd267b Lots of changes to support loading alternative color name database.
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
85 boxid = canvas.create_rectangle(3, row*20+3,
4c9de6fd267b Lots of changes to support loading alternative color name database.
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
86 textend+3, row*20 + 23,
4c9de6fd267b Lots of changes to support loading alternative color name database.
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
87 outline='',
4c9de6fd267b Lots of changes to support loading alternative color name database.
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
88 tags=(exactcolor, 'all'))
4c9de6fd267b Lots of changes to support loading alternative color name database.
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
89 canvas.bind('<ButtonRelease>', self.__onrelease)
4c9de6fd267b Lots of changes to support loading alternative color name database.
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
90 bboxes.append(boxid)
4c9de6fd267b Lots of changes to support loading alternative color name database.
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
91 if textend+3 > widest:
4c9de6fd267b Lots of changes to support loading alternative color name database.
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
92 widest = textend+3
18458
6b931bf6bdf6 __populate(): Use augmented assignments.
Barry Warsaw <barry@python.org>
parents: 17569
diff changeset
93 row += 1
10744
4c9de6fd267b Lots of changes to support loading alternative color name database.
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
94 canvheight = (row-1)*20 + 25
4c9de6fd267b Lots of changes to support loading alternative color name database.
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
95 canvas.config(scrollregion=(0, 0, 150, canvheight))
4c9de6fd267b Lots of changes to support loading alternative color name database.
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
96 for box in bboxes:
4c9de6fd267b Lots of changes to support loading alternative color name database.
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
97 x1, y1, x2, y2 = canvas.coords(box)
4c9de6fd267b Lots of changes to support loading alternative color name database.
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
98 canvas.coords(box, x1, y1, widest, y2)
4c9de6fd267b Lots of changes to support loading alternative color name database.
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
99
9217
44ff1ac5295b Got click on working. Dragging is disabled for now
Barry Warsaw <barry@python.org>
parents: 9208
diff changeset
100 def __onrelease(self, event=None):
9207
670967be6db3 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
101 canvas = self.__canvas
670967be6db3 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
102 # find the current box
670967be6db3 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
103 x = canvas.canvasx(event.x)
670967be6db3 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
104 y = canvas.canvasy(event.y)
670967be6db3 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
105 ids = canvas.find_overlapping(x, y, x, y)
670967be6db3 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
106 for boxid in ids:
670967be6db3 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
107 if boxid in self.__bboxes:
670967be6db3 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
108 break
670967be6db3 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
109 else:
9208
8148d44f9903 Lots of good UI working, but not yet update-while-dragging
Barry Warsaw <barry@python.org>
parents: 9207
diff changeset
110 ## print 'No box found!'
9207
670967be6db3 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
111 return
9217
44ff1ac5295b Got click on working. Dragging is disabled for now
Barry Warsaw <barry@python.org>
parents: 9208
diff changeset
112 tags = self.__canvas.gettags(boxid)
44ff1ac5295b Got click on working. Dragging is disabled for now
Barry Warsaw <barry@python.org>
parents: 9208
diff changeset
113 for t in tags:
44ff1ac5295b Got click on working. Dragging is disabled for now
Barry Warsaw <barry@python.org>
parents: 9208
diff changeset
114 if t[0] == '#':
44ff1ac5295b Got click on working. Dragging is disabled for now
Barry Warsaw <barry@python.org>
parents: 9208
diff changeset
115 break
9207
670967be6db3 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
116 else:
9217
44ff1ac5295b Got click on working. Dragging is disabled for now
Barry Warsaw <barry@python.org>
parents: 9208
diff changeset
117 ## print 'No color tag found!'
44ff1ac5295b Got click on working. Dragging is disabled for now
Barry Warsaw <barry@python.org>
parents: 9208
diff changeset
118 return
44ff1ac5295b Got click on working. Dragging is disabled for now
Barry Warsaw <barry@python.org>
parents: 9208
diff changeset
119 red, green, blue = ColorDB.rrggbb_to_triplet(t)
9222
9848f42343c9 Functionality complete
Barry Warsaw <barry@python.org>
parents: 9217
diff changeset
120 self.__dontcenter = 1
9848f42343c9 Functionality complete
Barry Warsaw <barry@python.org>
parents: 9217
diff changeset
121 if self.__uoc.get():
9848f42343c9 Functionality complete
Barry Warsaw <barry@python.org>
parents: 9217
diff changeset
122 self.__sb.update_views(red, green, blue)
9848f42343c9 Functionality complete
Barry Warsaw <barry@python.org>
parents: 9217
diff changeset
123 else:
9848f42343c9 Functionality complete
Barry Warsaw <barry@python.org>
parents: 9217
diff changeset
124 self.update_yourself(red, green, blue)
9254
9d393a0f727c Update main window when Update on Click is turned on
Barry Warsaw <barry@python.org>
parents: 9240
diff changeset
125 self.__red, self.__green, self.__blue = red, green, blue
9d393a0f727c Update main window when Update on Click is turned on
Barry Warsaw <barry@python.org>
parents: 9240
diff changeset
126
9d393a0f727c Update main window when Update on Click is turned on
Barry Warsaw <barry@python.org>
parents: 9240
diff changeset
127 def __toggleupdate(self, event=None):
9d393a0f727c Update main window when Update on Click is turned on
Barry Warsaw <barry@python.org>
parents: 9240
diff changeset
128 if self.__uoc.get():
9d393a0f727c Update main window when Update on Click is turned on
Barry Warsaw <barry@python.org>
parents: 9240
diff changeset
129 self.__sb.update_views(self.__red, self.__green, self.__blue)
9208
8148d44f9903 Lots of good UI working, but not yet update-while-dragging
Barry Warsaw <barry@python.org>
parents: 9207
diff changeset
130
9207
670967be6db3 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
131 def __quit(self, event=None):
9259
6b6bd14d750b Better quitting
Barry Warsaw <barry@python.org>
parents: 9254
diff changeset
132 self.__root.quit()
9207
670967be6db3 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
133
9427
7567ef40de77 Many changes to support a second mode of operation. Pynche can now be
Barry Warsaw <barry@python.org>
parents: 9414
diff changeset
134 def withdraw(self, event=None):
9207
670967be6db3 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
135 self.__root.withdraw()
670967be6db3 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
136
670967be6db3 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
137 def deiconify(self, event=None):
670967be6db3 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
138 self.__root.deiconify()
670967be6db3 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
139
670967be6db3 *** empty log message ***
Barry Warsaw <barry@python.org>
parents:
diff changeset
140 def update_yourself(self, red, green, blue):
9217
44ff1ac5295b Got click on working. Dragging is disabled for now
Barry Warsaw <barry@python.org>
parents: 9208
diff changeset
141 canvas = self.__canvas
44ff1ac5295b Got click on working. Dragging is disabled for now
Barry Warsaw <barry@python.org>
parents: 9208
diff changeset
142 # turn off the last box
44ff1ac5295b Got click on working. Dragging is disabled for now
Barry Warsaw <barry@python.org>
parents: 9208
diff changeset
143 if self.__lastbox:
44ff1ac5295b Got click on working. Dragging is disabled for now
Barry Warsaw <barry@python.org>
parents: 9208
diff changeset
144 canvas.itemconfigure(self.__lastbox, outline='')
44ff1ac5295b Got click on working. Dragging is disabled for now
Barry Warsaw <barry@python.org>
parents: 9208
diff changeset
145 # turn on the current box
44ff1ac5295b Got click on working. Dragging is disabled for now
Barry Warsaw <barry@python.org>
parents: 9208
diff changeset
146 colortag = ColorDB.triplet_to_rrggbb((red, green, blue))
44ff1ac5295b Got click on working. Dragging is disabled for now
Barry Warsaw <barry@python.org>
parents: 9208
diff changeset
147 canvas.itemconfigure(colortag, outline='black')
44ff1ac5295b Got click on working. Dragging is disabled for now
Barry Warsaw <barry@python.org>
parents: 9208
diff changeset
148 self.__lastbox = colortag
9222
9848f42343c9 Functionality complete
Barry Warsaw <barry@python.org>
parents: 9217
diff changeset
149 # fill the aliases
9848f42343c9 Functionality complete
Barry Warsaw <barry@python.org>
parents: 9217
diff changeset
150 self.__aliases.delete(0, END)
9848f42343c9 Functionality complete
Barry Warsaw <barry@python.org>
parents: 9217
diff changeset
151 try:
9848f42343c9 Functionality complete
Barry Warsaw <barry@python.org>
parents: 9217
diff changeset
152 aliases = self.__sb.colordb().aliases_of(red, green, blue)[1:]
9848f42343c9 Functionality complete
Barry Warsaw <barry@python.org>
parents: 9217
diff changeset
153 except ColorDB.BadColor:
9848f42343c9 Functionality complete
Barry Warsaw <barry@python.org>
parents: 9217
diff changeset
154 self.__aliases.insert(END, '<no matching color>')
9848f42343c9 Functionality complete
Barry Warsaw <barry@python.org>
parents: 9217
diff changeset
155 return
9848f42343c9 Functionality complete
Barry Warsaw <barry@python.org>
parents: 9217
diff changeset
156 if not aliases:
9848f42343c9 Functionality complete
Barry Warsaw <barry@python.org>
parents: 9217
diff changeset
157 self.__aliases.insert(END, '<no aliases>')
9848f42343c9 Functionality complete
Barry Warsaw <barry@python.org>
parents: 9217
diff changeset
158 else:
9848f42343c9 Functionality complete
Barry Warsaw <barry@python.org>
parents: 9217
diff changeset
159 for name in aliases:
9848f42343c9 Functionality complete
Barry Warsaw <barry@python.org>
parents: 9217
diff changeset
160 self.__aliases.insert(END, name)
9848f42343c9 Functionality complete
Barry Warsaw <barry@python.org>
parents: 9217
diff changeset
161 # maybe scroll the canvas so that the item is visible
9848f42343c9 Functionality complete
Barry Warsaw <barry@python.org>
parents: 9217
diff changeset
162 if self.__dontcenter:
9848f42343c9 Functionality complete
Barry Warsaw <barry@python.org>
parents: 9217
diff changeset
163 self.__dontcenter = 0
9848f42343c9 Functionality complete
Barry Warsaw <barry@python.org>
parents: 9217
diff changeset
164 else:
9848f42343c9 Functionality complete
Barry Warsaw <barry@python.org>
parents: 9217
diff changeset
165 ig, ig, ig, y1 = canvas.coords(colortag)
9848f42343c9 Functionality complete
Barry Warsaw <barry@python.org>
parents: 9217
diff changeset
166 ig, ig, ig, y2 = canvas.coords(self.__bboxes[-1])
9848f42343c9 Functionality complete
Barry Warsaw <barry@python.org>
parents: 9217
diff changeset
167 h = int(canvas['height']) * 0.5
9848f42343c9 Functionality complete
Barry Warsaw <barry@python.org>
parents: 9217
diff changeset
168 canvas.yview('moveto', (y1-h) / y2)
9414
c03ffff387f8 Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents: 9259
diff changeset
169
c03ffff387f8 Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents: 9259
diff changeset
170 def save_options(self, optiondb):
c03ffff387f8 Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents: 9259
diff changeset
171 optiondb['UPONCLICK'] = self.__uoc.get()
10744
4c9de6fd267b Lots of changes to support loading alternative color name database.
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
172
10760
6a38e667d349 Add a module global variable ADDTOVIEW to conform to dynamic viewer
Barry Warsaw <barry@python.org>
parents: 10744
diff changeset
173 def colordb_changed(self, colordb):
10744
4c9de6fd267b Lots of changes to support loading alternative color name database.
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
174 self.__canvas.delete('all')
4c9de6fd267b Lots of changes to support loading alternative color name database.
Barry Warsaw <barry@python.org>
parents: 9427
diff changeset
175 self.__populate()