Back to index

python3.2  3.2.2
Functions | Variables
pynche.Main Namespace Reference

Functions

def docstring
def usage
def initial_color
def build
def run
def main

Variables

string __version__ = '1.4.1'
list PROGRAM = sys.argv[0]
string AUTHNAME = 'Barry Warsaw'
string AUTHEMAIL = 'barry@python.org'
list RGB_TXT

Detailed Description

Pynche -- The PYthon Natural Color and Hue Editor.

Contact: %(AUTHNAME)s
Email:   %(AUTHEMAIL)s
Version: %(__version__)s

Pynche is based largely on a similar color editor I wrote years ago for the
SunView window system.  That editor was called ICE: the Interactive Color
Editor.  I'd always wanted to port the editor to X but didn't feel like
hacking X and C code to do it.  Fast forward many years, to where Python +
Tkinter provides such a nice programming environment, with enough power, that
I finally buckled down and implemented it.  I changed the name because these
days, 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 file
Alternate location of a color database file

    --initfile file
    -i file
Alternate location of the initialization file.  This file contains a
persistent database of the current Pynche options and color.  This
means that Pynche restores its option settings and current color when
it restarts, using this file (unless the -X option is used).  The
default is ~/.pynche

    --ignore
    -X
Ignore the initialization file when starting up.  Pynche will still
write the current option settings to this file when it quits.

    --version
    -v
print the version number and exit

    --help
    -h
print this message

    initialcolor
initial color, as a color name or #RRGGBB format

Function Documentation

def pynche.Main.build (   master = None,
  initialcolor = None,
  initfile = None,
  ignore = None,
  dbfile = None 
)

Definition at line 124 of file Main.py.

00124 
00125           dbfile=None):
00126     # create all output widgets
00127     s = Switchboard(not ignore and initfile)
00128     # defer to the command line chosen color database, falling back to the one
00129     # in the .pynche file.
00130     if dbfile is None:
00131         dbfile = s.optiondb().get('DBFILE')
00132     # find a parseable color database
00133     colordb = None
00134     files = RGB_TXT[:]
00135     if dbfile is None:
00136         dbfile = files.pop()
00137     while colordb is None:
00138         try:
00139             colordb = ColorDB.get_colordb(dbfile)
00140         except (KeyError, IOError):
00141             pass
00142         if colordb is None:
00143             if not files:
00144                 break
00145             dbfile = files.pop(0)
00146     if not colordb:
00147         usage(1, 'No color database file found, see the -d option.')
00148     s.set_colordb(colordb)
00149 
00150     # create the application window decorations
00151     app = PyncheWidget(__version__, s, master=master)
00152     w = app.window()
00153 
00154     # these built-in viewers live inside the main Pynche window
00155     s.add_view(StripViewer(s, w))
00156     s.add_view(ChipViewer(s, w))
00157     s.add_view(TypeinViewer(s, w))
00158 
00159     # get the initial color as components and set the color on all views.  if
00160     # there was no initial color given on the command line, use the one that's
00161     # stored in the option database
00162     if initialcolor is None:
00163         optiondb = s.optiondb()
00164         red = optiondb.get('RED')
00165         green = optiondb.get('GREEN')
00166         blue = optiondb.get('BLUE')
00167         # but if there wasn't any stored in the database, use grey50
00168         if red is None or blue is None or green is None:
00169             red, green, blue = initial_color('grey50', colordb)
00170     else:
00171         red, green, blue = initial_color(initialcolor, colordb)
00172     s.update_views(red, green, blue)
00173     return app, s
00174 

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 83 of file Main.py.

00083 
00084 def docstring():
00085     return __doc__ % globals()
00086 

Here is the caller graph for this function:

def pynche.Main.initial_color (   s,
  colordb 
)

Definition at line 95 of file Main.py.

00095 
00096 def initial_color(s, colordb):
00097     # function called on every color
00098     def scan_color(s, colordb=colordb):
00099         try:
00100             r, g, b = colordb.find_byname(s)
00101         except ColorDB.BadColor:
00102             try:
00103                 r, g, b = ColorDB.rrggbb_to_triplet(s)
00104             except ColorDB.BadColor:
00105                 return None, None, None
00106         return r, g, b
00107     #
00108     # First try the passed in color
00109     r, g, b = scan_color(s)
00110     if r is None:
00111         # try the same color with '#' prepended, since some shells require
00112         # this to be escaped, which is a pain
00113         r, g, b = scan_color('#' + s)
00114     if r is None:
00115         print('Bad initial color, using gray50:', s)
00116         r, g, b = scan_color('gray50')
00117     if r is None:
00118         usage(1, 'Cannot find an initial color to use')
00119         # does not return
00120     return r, g, b
00121 
00122 


Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 183 of file Main.py.

00183 
00184 def main():
00185     try:
00186         opts, args = getopt.getopt(
00187             sys.argv[1:],
00188             'hd:i:Xv',
00189             ['database=', 'initfile=', 'ignore', 'help', 'version'])
00190     except getopt.error as msg:
00191         usage(1, msg)
00192 
00193     if len(args) == 0:
00194         initialcolor = None
00195     elif len(args) == 1:
00196         initialcolor = args[0]
00197     else:
00198         usage(1)
00199 
00200     ignore = False
00201     dbfile = None
00202     initfile = os.path.expanduser('~/.pynche')
00203     for opt, arg in opts:
00204         if opt in ('-h', '--help'):
00205             usage(0)
00206         elif opt in ('-v', '--version'):
00207             print("""\
00208 Pynche -- The PYthon Natural Color and Hue Editor.
00209 Contact: %(AUTHNAME)s
00210 Email:   %(AUTHEMAIL)s
00211 Version: %(__version__)s""" % globals())
00212             sys.exit(0)
00213         elif opt in ('-d', '--database'):
00214             dbfile = arg
00215         elif opt in ('-X', '--ignore'):
00216             ignore = True
00217         elif opt in ('-i', '--initfile'):
00218             initfile = arg
00219 
00220     app, sb = build(initialcolor=initialcolor,
00221                     initfile=initfile,
00222                     ignore=ignore,
00223                     dbfile=dbfile)
00224     run(app, sb)
00225     sb.save_views()
00226 
00227 


Here is the call graph for this function:

def pynche.Main.run (   app,
  s 
)

Definition at line 175 of file Main.py.

00175 
00176 def run(app, s):
00177     try:
00178         app.start()
00179     except KeyboardInterrupt:
00180         pass
00181 
00182 


Here is the caller graph for this function:

def pynche.Main.usage (   code,
  msg = '' 
)

Definition at line 87 of file Main.py.

00087 
00088 def usage(code, msg=''):
00089     print(docstring())
00090     if msg:
00091         print(msg)
00092     sys.exit(code)
00093 
00094 


Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 49 of file Main.py.

string pynche.Main.AUTHEMAIL = 'barry@python.org'

Definition at line 66 of file Main.py.

string pynche.Main.AUTHNAME = 'Barry Warsaw'

Definition at line 65 of file Main.py.

Definition at line 64 of file Main.py.

Initial value:
00001 [
00002     # Solaris OpenWindows
00003     '/usr/openwin/lib/rgb.txt',
00004     # Linux
00005     '/usr/lib/X11/rgb.txt',
00006     # The X11R6.4 rgb.txt file
00007     os.path.join(sys.path[0], 'X/rgb.txt'),
00008     # add more here
00009     ]

Definition at line 69 of file Main.py.