Barry Warsaw | fefbf79 | 1998-01-31 23:39:01 +0000 | [diff] [blame] | 1 | """Main Pynche (Pythonically Natural Color and Hue Editor) widget. |
| 2 | """ |
| 3 | |
| 4 | from Tkinter import * |
| 5 | import Pmw |
| 6 | import ColorDB |
| 7 | from ChipWidget import ChipWidget |
| 8 | |
| 9 | class PyncheWidget(Pmw.MegaWidget): |
| 10 | def __init__(self, colordb, parent=None, **kw): |
| 11 | self.__colordb = colordb |
| 12 | |
| 13 | optionsdefs = (('color', 'grey50', self.__set_color),) |
| 14 | self.defineoptions(kw, optionsdefs) |
| 15 | |
| 16 | # initialize base class -- after defining options |
| 17 | Pmw.MegaWidget.__init__(self, parent) |
| 18 | interiorarg = (self.interior(),) |
| 19 | |
| 20 | # create color selectors |
| 21 | self.__selectors = Pmw.Group(parent, tag_text='Color Selectors') |
| 22 | self.__selectors.pack(side=TOP, expand=YES, fill=BOTH) |
| 23 | |
| 24 | # create chip window |
| 25 | group = Pmw.Group(parent, tag_text='Current Color') |
| 26 | group.pack(side=LEFT, fill=Y) |
| 27 | self.__selected = ChipWidget(group.interior(), |
| 28 | label_text='Selected') |
| 29 | self.__selected.grid() |
| 30 | self.__nearest = ChipWidget(group.interior(), |
| 31 | label_text='Nearest') |
| 32 | self.__nearest.grid(row=0, column=1) |
| 33 | |
| 34 | # create the options window |
| 35 | options = Pmw.Group(parent, tag_text='Options') |
| 36 | options.pack(expand=YES, fill=BOTH) |
| 37 | |
| 38 | # Check keywords and initialize options |
| 39 | self.initialiseoptions(PyncheWidget) |
| 40 | |
| 41 | |
| 42 | def __set_color(self): |
| 43 | color = self['color'] |
| 44 | try: |
| 45 | red, green, blue, rrggbb = self.__colordb.find_byname(color) |
| 46 | except ColorDB.BadColor: |
| 47 | red, green, blue = ColorDB.rrggbb_to_triplet(color) |
| 48 | |
| 49 | nearest = self.__colordb.nearest(red, green, blue) |
| 50 | self.__selected.configure(color=color) |
| 51 | self.__nearest.configure(color=nearest) |