Пример #1
0
    def __load(self, event=None):
        while 1:
            idir, ifile = os.path.split(self.__sb.colordb().filename())
            file = filedialog.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:
                messagebox.showerror('Read error', '''\
Could not open file for reading:
%s''' % file)
                continue
            if colordb is None:
                messagebox.showerror('Unrecognized color file type', '''\
Unrecognized color file type in file:
%s''' % file)
                continue
            break
        self.__sb.set_colordb(colordb)
Пример #2
0
    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)
Пример #3
0
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
Пример #4
0
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
Пример #5
0
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
Пример #6
0
 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
Пример #7
0
 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
Пример #8
0
def build(master=None, initialcolor=None, initfile=None, ignore=None):
    # create the windows and go
    for f in RGB_TXT:
	try:
	    colordb = ColorDB.get_colordb(f)
            if colordb:
                break
	except IOError:
	    pass
    else:
        usage(1, 'No color database file found, see the -d option.')

    # create all output widgets
    s = Switchboard(colordb, not ignore and initfile)

    # create the application window decorations
    app = PyncheWidget(__version__, s, master=master)
    w = app.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
Пример #9
0
def build(master=None, initialcolor=None, initfile=None, ignore=None):
    # create the windows and go
    for f in RGB_TXT:
        try:
            colordb = ColorDB.get_colordb(f)
            if colordb:
                break
        except IOError:
            pass
    else:
        usage(1, 'No color database file found, see the -d option.')

    # create all output widgets
    s = Switchboard(colordb, not ignore and initfile)

    # create the application window decorations
    app = PyncheWidget(__version__, s, master=master)
    w = app.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
Пример #10
0
"""Pynche -- The PYthon Natural Color and Hue Editor.
Пример #11
0
"""Color chooser implementing (almost) the tkColorColor interface
Пример #12
0
"""Main Pynche (Pythonically Natural Color and Hue Editor) widget.
Пример #13
0
"""Pynche -- The PYthon Natural Color and Hue Editor.
Пример #14
0
"""Color chooser implementing (almost) the tkColorColor interface