当前位置: 首页>>代码示例>>Python>>正文


Python ColorDB类代码示例

本文整理汇总了Python中ColorDB的典型用法代码示例。如果您正苦于以下问题:Python ColorDB类的具体用法?Python ColorDB怎么用?Python ColorDB使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ColorDB类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __populate

 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)
开发者ID:10sr,项目名称:cpython,代码行数:31,代码来源:ListViewer.py

示例2: __onrelease

    def __onrelease(self, event=None):
        canvas = self.__canvas
        # find the current box
        x = canvas.canvasx(event.x)
        y = canvas.canvasy(event.y)
        ids = canvas.find_overlapping(x, y, x, y)
        for boxid in ids:
            if boxid in self.__bboxes:
                break
        else:
##            print 'No box found!'
            return
        tags = self.__canvas.gettags(boxid)
        for t in tags:
            if t[0] == '#':
                break
        else:
##            print 'No color tag found!'
            return
        red, green, blue = ColorDB.rrggbb_to_triplet(t)
        self.__dontcenter = 1
        if self.__uoc.get():
            self.__sb.update_views(red, green, blue)
        else:
            self.update_yourself(red, green, blue)
            self.__red, self.__green, self.__blue = red, green, blue
开发者ID:10sr,项目名称:cpython,代码行数:26,代码来源:ListViewer.py

示例3: update_yourself

 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)
开发者ID:Claruarius,项目名称:stblinux-2.6.37,代码行数:16,代码来源:ChipViewer.py

示例4: __load

    def __load(self, event=None):
        while 1:
            idir, ifile = os.path.split(self.__sb.colordb().filename())
            file = tkFileDialog.askopenfilename(
                filetypes=[('Text files', '*.txt'),
                           ('All files', '*'),
                           ],
                initialdir=idir,
                initialfile=ifile)
            if not file:
                # cancel button
                return
            try:
                colordb = ColorDB.get_colordb(file)
            except IOError:
                tkMessageBox.showerror('Read error', '''\
Could not open file for reading:
%s''' % file)
                continue
            if colordb is None:
                tkMessageBox.showerror('Unrecognized color file type', '''\
Unrecognized color file type in file:
%s''' % file)
                continue
            break
        self.__sb.set_colordb(colordb)
开发者ID:0xcc,项目名称:python-read,代码行数:26,代码来源:PyncheWidget.py

示例5: update_yourself

 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)
开发者ID:10sr,项目名称:cpython,代码行数:29,代码来源:ListViewer.py

示例6: __trackarrow

    def __trackarrow(self, chip, rgbtuple):
        # invert the last chip
        if self.__lastchip is not None:
            color = self.__canvas.itemcget(self.__lastchip, 'fill')
            self.__canvas.itemconfigure(self.__lastchip, outline=color)
        self.__lastchip = chip
	# get the arrow's text
	coloraxis = rgbtuple[self.__axis]
        if self.__hexp.get():
            # hex
            text = hex(coloraxis)
        else:
            # decimal
            text = repr(coloraxis)
	# move the arrow, and set it's text
	if coloraxis <= 128:
	    # use the left arrow
	    self.__leftarrow.set_text(text)
	    self.__leftarrow.move_to(self.__arrow_x(chip-1))
	    self.__rightarrow.move_to(-100)
	else:
	    # use the right arrow
	    self.__rightarrow.set_text(text)
	    self.__rightarrow.move_to(self.__arrow_x(chip-1))
	    self.__leftarrow.move_to(-100)
	# and set the chip's outline
        brightness = ColorDB.triplet_to_brightness(rgbtuple)
	if brightness <= 128:
	    outline = 'white'
	else:
	    outline = 'black'
	self.__canvas.itemconfigure(chip, outline=outline)
开发者ID:Claruarius,项目名称:stblinux-2.6.37,代码行数:32,代码来源:StripViewer.py

示例7: build

def build(master=None, initialcolor=None, initfile=None, ignore=None):
    # create all output widgets
    s = Switchboard(not ignore and initfile)

    # load the color database
    colordb = None
    try:
        dbfile = s.optiondb()['DBFILE']
        colordb = ColorDB.get_colordb(dbfile)
    except (KeyError, IOError):
        # scoot through the files listed above to try to find a usable color
        # database file
        for f in RGB_TXT:
            try:
                colordb = ColorDB.get_colordb(f)
                if colordb:
                    break
            except IOError:
                pass
    if not colordb:
        usage(1, 'No color database file found, see the -d option.')
    s.set_colordb(colordb)

    # create the application window decorations
    app = PyncheWidget(__version__, s, master=master)
    w = app.window()

    # these built-in viewers live inside the main Pynche window
    s.add_view(StripViewer(s, w))
    s.add_view(ChipViewer(s, w))
    s.add_view(TypeinViewer(s, w))

    # get the initial color as components and set the color on all views.  if
    # there was no initial color given on the command line, use the one that's 
    # stored in the option database
    if initialcolor is None:
        optiondb = s.optiondb()
        red = optiondb.get('RED')
        green = optiondb.get('GREEN')
        blue = optiondb.get('BLUE')
        # but if there wasn't any stored in the database, use grey50
        if red is None or blue is None or green is None:
            red, green, blue = initial_color('grey50', colordb)
    else:
        red, green, blue = initial_color(initialcolor, colordb)
    s.update_views(red, green, blue)
    return app, s
开发者ID:Claruarius,项目名称:stblinux-2.6.37,代码行数:47,代码来源:Main.py

示例8: show

 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
开发者ID:0xcc,项目名称:python-read,代码行数:46,代码来源:pyColorChooser.py

示例9: scan_color

 def scan_color(s, colordb=colordb):
     try:
         r, g, b = colordb.find_byname(s)
     except ColorDB.BadColor:
         try:
             r, g, b = ColorDB.rrggbb_to_triplet(s)
         except ColorDB.BadColor:
             return None, None, None
     return r, g, b
开发者ID:Claruarius,项目名称:stblinux-2.6.37,代码行数:9,代码来源:Main.py

示例10: update_yourself

 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)
开发者ID:IamMomotaros,项目名称:grailbrowser,代码行数:14,代码来源:ChipViewer.py

示例11: build

def build(master=None, initialcolor=None, initfile=None, ignore=None,
          dbfile=None):
    # create all output widgets
    s = Switchboard(not ignore and initfile)
    # defer to the command line chosen color database, falling back to the one
    # in the .pynche file.
    if dbfile is None:
        dbfile = s.optiondb().get('DBFILE')
    # find a parseable color database
    colordb = None
    files = RGB_TXT[:]
    if dbfile is None:
        dbfile = files.pop()
    while colordb is None:
        try:
            colordb = ColorDB.get_colordb(dbfile)
        except (KeyError, IOError):
            pass
        if colordb is None:
            if not files:
                break
            dbfile = files.pop(0)
    if not colordb:
        usage(1, 'No color database file found, see the -d option.')
    s.set_colordb(colordb)

    # create the application window decorations
    app = PyncheWidget(__version__, s, master=master)
    w = app.window()

    # these built-in viewers live inside the main Pynche window
    s.add_view(StripViewer(s, w))
    s.add_view(ChipViewer(s, w))
    s.add_view(TypeinViewer(s, w))

    # get the initial color as components and set the color on all views.  if
    # there was no initial color given on the command line, use the one that's
    # stored in the option database
    if initialcolor is None:
        optiondb = s.optiondb()
        red = optiondb.get('RED')
        green = optiondb.get('GREEN')
        blue = optiondb.get('BLUE')
        # but if there wasn't any stored in the database, use grey50
        if red is None or blue is None or green is None:
            red, green, blue = initial_color('grey50', colordb)
    else:
        red, green, blue = initial_color(initialcolor, colordb)
    s.update_views(red, green, blue)
    return app, s
开发者ID:KevinRoeschke,项目名称:CIDE,代码行数:50,代码来源:Main.py

示例12: update_yourself

 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)
开发者ID:IamMomotaros,项目名称:grailbrowser,代码行数:14,代码来源:TextViewer.py

示例13: __select_chip

 def __select_chip(self, event=None):
     x = event.x
     y = event.y
     canvas = self.__canvas
     chip = canvas.find_overlapping(x, y, x, y)
     if chip and (1 <= chip[0] <= self.__numchips):
         color = self.__chips[chip[0]-1]
         red, green, blue = ColorDB.rrggbb_to_triplet(color)
         etype = int(event.type)
         if (etype == BTNUP or self.__uwd.get()):
             # update everyone
             self.__sb.update_views(red, green, blue)
         else:
             # just track the arrows
             self.__trackarrow(chip[0], (red, green, blue))
开发者ID:Claruarius,项目名称:stblinux-2.6.37,代码行数:15,代码来源:StripViewer.py

示例14: update_yourself

 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))
开发者ID:5outh,项目名称:Databases-Fall2014,代码行数:19,代码来源:StripViewer.py

示例15: __set_color

 def __set_color(self, event=None):
     which = self.__which.get()
     text = self.__text
     if which == 0:
         color = text['foreground']
     elif which == 1:
         color = text['background']
     elif which == 2:
         color = text['selectforeground']
     elif which == 3:
         color = text['selectbackground']
     elif which == 5:
         color = text['insertbackground']
     try:
         red, green, blue = ColorDB.rrggbb_to_triplet(color)
     except ColorDB.BadColor:
         # must have been a color name
         red, green, blue = self.__sb.colordb().find_byname(color)
     self.__sb.update_views(red, green, blue)
开发者ID:10sr,项目名称:cpython,代码行数:19,代码来源:TextViewer.py


注:本文中的ColorDB类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。