def update_yourself(self, red, green, blue): canvas = self.__canvas # turn off the last box if self.__lastbox: canvas.itemconfigure(self.__lastbox, outline='') # turn on the current box colortag = ColorDB.triplet_to_rrggbb((red, green, blue)) canvas.itemconfigure(colortag, outline='black') self.__lastbox = colortag # fill the aliases self.__aliases.delete(0, END) try: aliases = self.__sb.colordb().aliases_of(red, green, blue)[1:] except ColorDB.BadColor: self.__aliases.insert(END, '<no matching color>') return if not aliases: self.__aliases.insert(END, '<no aliases>') else: for name in aliases: self.__aliases.insert(END, name) # maybe scroll the canvas so that the item is visible if self.__dontcenter: self.__dontcenter = 0 else: ig, ig, ig, y1 = canvas.coords(colortag) ig, ig, ig, y2 = canvas.coords(self.__bboxes[-1]) h = int(canvas['height']) * 0.5 canvas.yview('moveto', (y1-h) / y2)
def update_yourself(self, red, green, blue): # Selected always shows the #rrggbb name of the color, nearest always # shows the name of the nearest color in the database. TBD: should # an exact match be indicated in some way? # # Always use the #rrggbb style to actually set the color, since we may # not be using X color names (e.g. "web-safe" names) colordb = self.__sb.colordb() rgbtuple = (red, green, blue) rrggbb = ColorDB.triplet_to_rrggbb(rgbtuple) # find the nearest nearest = colordb.nearest(red, green, blue) nearest_tuple = colordb.find_byname(nearest) nearest_rrggbb = ColorDB.triplet_to_rrggbb(nearest_tuple) self.__selected.set_color(rrggbb) self.__nearest.set_color(nearest_rrggbb, nearest)
def __populate(self): # # create all the buttons colordb = self.__sb.colordb() canvas = self.__canvas row = 0 widest = 0 bboxes = self.__bboxes = [] for name in colordb.unique_names(): exactcolor = ColorDB.triplet_to_rrggbb(colordb.find_byname(name)) canvas.create_rectangle(5, row*20 + 5, 20, row*20 + 20, fill=exactcolor) textid = canvas.create_text(25, row*20 + 13, text=name, anchor=W) x1, y1, textend, y2 = canvas.bbox(textid) boxid = canvas.create_rectangle(3, row*20+3, textend+3, row*20 + 23, outline='', tags=(exactcolor, 'all')) canvas.bind('<ButtonRelease>', self.__onrelease) bboxes.append(boxid) if textend+3 > widest: widest = textend+3 row += 1 canvheight = (row-1)*20 + 25 canvas.config(scrollregion=(0, 0, 150, canvheight)) for box in bboxes: x1, y1, x2, y2 = canvas.coords(box) canvas.coords(box, x1, y1, widest, y2)
def update_yourself(self, red, green, blue): canvas = self.__canvas # turn off the last box if self.__lastbox: canvas.itemconfigure(self.__lastbox, outline='') # turn on the current box colortag = ColorDB.triplet_to_rrggbb((red, green, blue)) canvas.itemconfigure(colortag, outline='black') self.__lastbox = colortag # fill the aliases self.__aliases.delete(0, END) try: aliases = self.__sb.colordb().aliases_of(red, green, blue)[1:] except ColorDB.BadColor: self.__aliases.insert(END, '<no matching color>') return if not aliases: self.__aliases.insert(END, '<no aliases>') else: for name in aliases: self.__aliases.insert(END, name) # maybe scroll the canvas so that the item is visible if self.__dontcenter: self.__dontcenter = 0 else: height = canvas['height'] ig, ig, ig, y1 = canvas.coords(colortag) ig, ig, ig, y2 = canvas.coords(self.__bboxes[-1]) h = int(canvas['height']) * 0.5 canvas.yview('moveto', (y1-h) / y2)
def update_yourself(self, red, green, blue): # Selected always shows the #rrggbb name of the color, nearest always # shows the name of the nearest color in the database. TBD: should # an exact match be indicated in some way? # # Always use the #rrggbb style to actually set the color, since we may # not be using X color names (e.g. "web-safe" names) colordb = self.__sb.colordb() rgbtuple = (red, green, blue) rrggbb = ColorDB.triplet_to_rrggbb(rgbtuple) # find the nearest nearest = colordb.nearest(red, green, blue) nearest_tuple = colordb.find_byname(nearest) nearest_rrggbb = ColorDB.triplet_to_rrggbb(nearest_tuple) self.__selected.set_color(rrggbb) self.__nearest.set_color(nearest_rrggbb, nearest)
def __populate(self): # # create all the buttons colordb = self.__sb.colordb() canvas = self.__canvas row = 0 widest = 0 bboxes = self.__bboxes = [] for name in colordb.unique_names(): exactcolor = ColorDB.triplet_to_rrggbb(colordb.find_byname(name)) canvas.create_rectangle(5, row*20 + 5, 20, row*20 + 20, fill=exactcolor) textid = canvas.create_text(25, row*20 + 13, text=name, anchor=W) x1, y1, textend, y2 = canvas.bbox(textid) boxid = canvas.create_rectangle(3, row*20+3, textend+3, row*20 + 23, outline='', tags=(exactcolor, 'all')) canvas.bind('<ButtonRelease>', self.__onrelease) bboxes.append(boxid) if textend+3 > widest: widest = textend+3 row = row + 1 canvheight = (row-1)*20 + 25 canvas.config(scrollregion=(0, 0, 150, canvheight)) for box in bboxes: x1, y1, x2, y2 = canvas.coords(box) canvas.coords(box, x1, y1, widest, y2)
def update_yourself(self, red, green, blue): if self.__trackp.get(): colorname = ColorDB.triplet_to_rrggbb((red, green, blue)) which = self.__which.get() if which == 0: self.__text.configure(foreground=colorname) elif which == 1: self.__text.configure(background=colorname) elif which == 2: self.__text.configure(selectforeground=colorname) elif which == 3: self.__text.configure(selectbackground=colorname) elif which == 5: self.__text.configure(insertbackground=colorname)
def update_yourself(self, red, green, blue): # TBD: should exactname default to X11 color name if their is an exact # match for the rgb triplet? Part of me says it's nice to see both # names for the color, the other part says that it's better to # feedback the exact match. rgbtuple = (red, green, blue) try: allcolors = self.__sb.colordb().find_byrgb(rgbtuple) exactname = allcolors[0] except ColorDB.BadColor: exactname = ColorDB.triplet_to_rrggbb(rgbtuple) nearest = self.__sb.colordb().nearest(red, green, blue) self.__selected.set_color(exactname) self.__nearest.set_color(nearest)
def update_yourself(self, red, green, blue): # TBD: should exactname default to X11 color name if their is an exact # match for the rgb triplet? Part of me says it's nice to see both # names for the color, the other part says that it's better to # feedback the exact match. rgbtuple = (red, green, blue) try: allcolors = self.__sb.colordb().find_byrgb(rgbtuple) exactname = allcolors[0] except ColorDB.BadColor: exactname = ColorDB.triplet_to_rrggbb(rgbtuple) nearest = self.__sb.colordb().nearest(red, green, blue) self.__selected.set_color(exactname) self.__nearest.set_color(nearest)
def update_yourself(self, red, green, blue): if self.__trackp.get(): colorname = ColorDB.triplet_to_rrggbb((red, green, blue)) which = self.__which.get() if which == 0: self.__text.configure(foreground=colorname) elif which == 1: self.__text.configure(background=colorname) elif which == 2: self.__text.configure(selectforeground=colorname) elif which == 3: self.__text.configure(selectbackground=colorname) elif which == 5: self.__text.configure(insertbackground=colorname)
def show(self, color, options): # scan for options that can override the ctor options self.__wantspec = options.get('wantspec', self.__wantspec) dbfile = options.get('databasefile', self.__databasefile) # load the database file colordb = None if dbfile <> self.__databasefile: colordb = ColorDB.get_colordb(dbfile) if not self.__master: from Tkinter import Tk self.__master = Tk() if not self.__pw: self.__pw, self.__sb = \ Main.build(master = self.__master, initfile = self.__initfile, ignore = self.__ignore) else: self.__pw.deiconify() # convert color if colordb: self.__sb.set_colordb(colordb) else: colordb = self.__sb.colordb() if color: r, g, b = Main.initial_color(color, colordb) self.__sb.update_views(r, g, b) # reset the canceled flag and run it self.__sb.canceled(0) Main.run(self.__pw, self.__sb) rgbtuple = self.__sb.current_rgb() self.__pw.withdraw() # check to see if the cancel button was pushed if self.__sb.canceled_p(): return None, None # Try to return the color name from the database if there is an exact # match, otherwise use the "#rrggbb" spec. BAW: Forget about color # aliases for now, maybe later we should return these too. name = None if not self.__wantspec: try: name = colordb.find_byrgb(rgbtuple)[0] except ColorDB.BadColor: pass if name is None: name = ColorDB.triplet_to_rrggbb(rgbtuple) return rgbtuple, name
def show(self, color, options): # scan for options that can override the ctor options self.__wantspec = options.get('wantspec', self.__wantspec) dbfile = options.get('databasefile', self.__databasefile) # load the database file colordb = None if dbfile <> self.__databasefile: colordb = ColorDB.get_colordb(dbfile) if not self.__master: from Tkinter import Tk self.__master = Tk() if not self.__pw: self.__pw, self.__sb = \ Main.build(master = self.__master, initfile = self.__initfile, ignore = self.__ignore) else: self.__pw.deiconify() # convert color if colordb: self.__sb.set_colordb(colordb) else: colordb = self.__sb.colordb() if color: r, g, b = Main.initial_color(color, colordb) self.__sb.update_views(r, g, b) # reset the canceled flag and run it self.__sb.canceled(0) Main.run(self.__pw, self.__sb) rgbtuple = self.__sb.current_rgb() self.__pw.withdraw() # check to see if the cancel button was pushed if self.__sb.canceled_p(): return None, None # Try to return the color name from the database if there is an exact # match, otherwise use the "#rrggbb" spec. BAW: Forget about color # aliases for now, maybe later we should return these too. name = None if not self.__wantspec: try: name = colordb.find_byrgb(rgbtuple)[0] except ColorDB.BadColor: pass if name is None: name = ColorDB.triplet_to_rrggbb(rgbtuple) return rgbtuple, name
def update_yourself(self, red, green, blue): assert self.__generator i = 1 chip = 0 chips = self.__chips = [] tk = self.__canvas.tk # get the red, green, and blue components for all chips for t in self.__generator(self.__numchips, red, green, blue): rrggbb = ColorDB.triplet_to_rrggbb(t) chips.append(rrggbb) tred, tgreen, tblue = t if tred <= red and tgreen <= green and tblue <= blue: chip = i i = i + 1 # call the raw tcl script colors = SPACE.join(chips) tk.eval('setcolor %s {%s}' % (self.__canvas._w, colors)) # move the arrows around self.__trackarrow(chip, (red, green, blue))
def update_yourself(self, red, green, blue): assert self.__generator i = 1 chip = 0 chips = self.__chips = [] tk = self.__canvas.tk # get the red, green, and blue components for all chips for t in self.__generator(self.__numchips, red, green, blue): rrggbb = ColorDB.triplet_to_rrggbb(t) chips.append(rrggbb) tred, tgreen, tblue = t if tred <= red and tgreen <= green and tblue <= blue: chip = i i = i + 1 # call the raw tcl script colors = SPACE.join(chips) tk.eval('setcolor %s {%s}' % (self.__canvas._w, colors)) # move the arrows around self.__trackarrow(chip, (red, green, blue))
"""Chip viewer and widget.
def __init__(self, switchboard, master=None): self.__sb = switchboard optiondb = switchboard.optiondb() self.__lastbox = None self.__dontcenter = 0 # GUI root = self.__root = Toplevel(master, class_='Pynche') root.protocol('WM_DELETE_WINDOW', self.withdraw) root.title('Pynche Color List') root.iconname('Pynche Color List') root.bind('<Alt-q>', self.__quit) root.bind('<Alt-Q>', self.__quit) root.bind('<Alt-w>', self.withdraw) root.bind('<Alt-W>', self.withdraw) # # create the canvas which holds everything, and its scrollbar # frame = self.__frame = Frame(root) frame.pack() canvas = self.__canvas = Canvas(frame, width=160, height=300, borderwidth=2, relief=SUNKEN) self.__scrollbar = Scrollbar(frame) self.__scrollbar.pack(fill=Y, side=RIGHT) canvas.pack(fill=BOTH, expand=1) canvas.configure(yscrollcommand=(self.__scrollbar, 'set')) self.__scrollbar.configure(command=(canvas, 'yview')) # # create all the buttons colordb = switchboard.colordb() row = 0 widest = 0 bboxes = self.__bboxes = [] for name in colordb.unique_names(): exactcolor = ColorDB.triplet_to_rrggbb(colordb.find_byname(name)) canvas.create_rectangle(5, row*20 + 5, 20, row*20 + 20, fill=exactcolor) textid = canvas.create_text(25, row*20 + 13, text=name, anchor=W) x1, y1, textend, y2 = canvas.bbox(textid) boxid = canvas.create_rectangle(3, row*20+3, textend+3, row*20 + 23, outline='', tags=(exactcolor,)) canvas.bind('<ButtonRelease>', self.__onrelease) bboxes.append(boxid) if textend+3 > widest: widest = textend+3 row = row + 1 canvheight = (row-1)*20 + 25 canvas.config(scrollregion=(0, 0, 150, canvheight)) for box in bboxes: x1, y1, x2, y2 = canvas.coords(box) canvas.coords(box, x1, y1, widest, y2) # # Update on click self.__uoc = BooleanVar() self.__uoc.set(optiondb.get('UPONCLICK', 1)) self.__uocbtn = Checkbutton(root, text='Update on Click', variable=self.__uoc, command=self.__toggleupdate) self.__uocbtn.pack(expand=1, fill=BOTH) # # alias list self.__alabel = Label(root, text='Aliases:') self.__alabel.pack() self.__aliases = Listbox(root, height=5, selectmode=BROWSE) self.__aliases.pack(expand=1, fill=BOTH)
"""Strip viewer and related widgets.
"""ListViewer class.
"""Chip viewer and widget.
def __init__(self, switchboard, master=None): self.__sb = switchboard optiondb = switchboard.optiondb() self.__lastbox = None self.__dontcenter = 0 # GUI root = self.__root = Toplevel(master, class_='Pynche') root.protocol('WM_DELETE_WINDOW', self.withdraw) root.title('Pynche Color List') root.iconname('Pynche Color List') root.bind('<Alt-q>', self.__quit) root.bind('<Alt-Q>', self.__quit) root.bind('<Alt-w>', self.withdraw) root.bind('<Alt-W>', self.withdraw) # # create the canvas which holds everything, and its scrollbar # frame = self.__frame = Frame(root) frame.pack() canvas = self.__canvas = Canvas(frame, width=160, height=300, borderwidth=2, relief=SUNKEN) self.__scrollbar = Scrollbar(frame) self.__scrollbar.pack(fill=Y, side=RIGHT) canvas.pack(fill=BOTH, expand=1) canvas.configure(yscrollcommand=(self.__scrollbar, 'set')) self.__scrollbar.configure(command=(canvas, 'yview')) # # create all the buttons colordb = switchboard.colordb() row = 0 widest = 0 bboxes = self.__bboxes = [] for name in colordb.unique_names(): exactcolor = ColorDB.triplet_to_rrggbb(colordb.find_byname(name)) canvas.create_rectangle(5, row * 20 + 5, 20, row * 20 + 20, fill=exactcolor) textid = canvas.create_text(25, row * 20 + 13, text=name, anchor=W) x1, y1, textend, y2 = canvas.bbox(textid) boxid = canvas.create_rectangle(3, row * 20 + 3, textend + 3, row * 20 + 23, outline='', tags=(exactcolor, )) canvas.bind('<ButtonRelease>', self.__onrelease) bboxes.append(boxid) if textend + 3 > widest: widest = textend + 3 row = row + 1 canvheight = (row - 1) * 20 + 25 canvas.config(scrollregion=(0, 0, 150, canvheight)) for box in bboxes: x1, y1, x2, y2 = canvas.coords(box) canvas.coords(box, x1, y1, widest, y2) # # Update on click self.__uoc = BooleanVar() self.__uoc.set(optiondb.get('UPONCLICK', 1)) self.__uocbtn = Checkbutton(root, text='Update on Click', variable=self.__uoc, command=self.__toggleupdate) self.__uocbtn.pack(expand=1, fill=BOTH) # # alias list self.__alabel = Label(root, text='Aliases:') self.__alabel.pack() self.__aliases = Listbox(root, height=5, selectmode=BROWSE) self.__aliases.pack(expand=1, fill=BOTH)
"""TextViewer class.
"""TextViewer class.
"""ListViewer class.
"""Strip viewer and related widgets.
"""Color chooser implementing (almost) the tkColorColor interface
"""Color chooser implementing (almost) the tkColorColor interface