"""Pynche -- The PYthon Natural Color and Hue Editor.Contact: %(AUTHNAME)sEmail: %(AUTHEMAIL)sVersion: %(__version__)sPynche is based largely on a similar color editor I wrote years ago for theSunView window system. That editor was called ICE: the Interactive ColorEditor. I'd always wanted to port the editor to X but didn't feel likehacking X and C code to do it. Fast forward many years, to where Python +Tkinter provides such a nice programming environment, with enough power, thatI finally buckled down and implemented it. I changed the name because thesedays, too many other systems have the acronym `ICE'.This program currently requires Python 2.2 with Tkinter.Usage: %(PROGRAM)s [-d file] [-i file] [-X] [-v] [-h] [initialcolor]Where:--database file-d fileAlternate location of a color database file--initfile file-i fileAlternate location of the initialization file. This file contains apersistent database of the current Pynche options and color. Thismeans that Pynche restores its option settings and current color whenit restarts, using this file (unless the -X option is used). Thedefault is ~/.pynche--ignore-XIgnore the initialization file when starting up. Pynche will stillwrite the current option settings to this file when it quits.--version-vprint the version number and exit--help-hprint this messageinitialcolorinitial color, as a color name or #RRGGBB format"""__version__ = '1.4.1'import sysimport osimport getoptimport ColorDBfrom PyncheWidget import PyncheWidgetfrom Switchboard import Switchboardfrom StripViewer import StripViewerfrom ChipViewer import ChipViewerfrom TypeinViewer import TypeinViewerPROGRAM = sys.argv[0]AUTHNAME = 'Barry Warsaw'AUTHEMAIL = 'barry@python.org'# Default locations of rgb.txt or other textual color databaseRGB_TXT = [# Solaris OpenWindows'/usr/openwin/lib/rgb.txt',# Linux'/usr/lib/X11/rgb.txt',# The X11R6.4 rgb.txt fileos.path.join(sys.path[0], 'X/rgb.txt'),# add more here]# Do this because PyncheWidget.py wants to get at the interpolated docstring# too, for its Help menu.def docstring():return __doc__ % globals()def usage(code, msg=''):print(docstring())if msg:print(msg)sys.exit(code)def initial_color(s, colordb):# function called on every colordef 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, Nonereturn r, g, b## First try the passed in colorr, g, b = scan_color(s)if r is None:# try the same color with '#' prepended, since some shells require# this to be escaped, which is a painr, g, b = scan_color('#' + s)if r is None:print('Bad initial color, using gray50:', s)r, g, b = scan_color('gray50')if r is None:usage(1, 'Cannot find an initial color to use')# does not returnreturn r, g, bdef build(master=None, initialcolor=None, initfile=None, ignore=None,dbfile=None):# create all output widgetss = 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 databasecolordb = Nonefiles = RGB_TXT[:]if dbfile is None:dbfile = files.pop()while colordb is None:try:colordb = ColorDB.get_colordb(dbfile)except (KeyError, IOError):passif colordb is None:if not files:breakdbfile = 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 decorationsapp = PyncheWidget(__version__, s, master=master)w = app.window()# these built-in viewers live inside the main Pynche windows.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 databaseif 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 grey50if 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, sdef run(app, s):try:app.start()except KeyboardInterrupt:passdef main():try:opts, args = getopt.getopt(sys.argv[1:],'hd:i:Xv',['database=', 'initfile=', 'ignore', 'help', 'version'])except getopt.error as msg:usage(1, msg)if len(args) == 0:initialcolor = Noneelif len(args) == 1:initialcolor = args[0]else:usage(1)ignore = Falsedbfile = Noneinitfile = os.path.expanduser('~/.pynche')for opt, arg in opts:if opt in ('-h', '--help'):usage(0)elif opt in ('-v', '--version'):print("""\Pynche -- The PYthon Natural Color and Hue Editor.Contact: %(AUTHNAME)sEmail: %(AUTHEMAIL)sVersion: %(__version__)s""" % globals())sys.exit(0)elif opt in ('-d', '--database'):dbfile = argelif opt in ('-X', '--ignore'):ignore = Trueelif opt in ('-i', '--initfile'):initfile = argapp, sb = build(initialcolor=initialcolor,initfile=initfile,ignore=ignore,dbfile=dbfile)run(app, sb)sb.save_views()if __name__ == '__main__':main()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。