1212tested on Solaris 2.6. Feedback is greatly appreciated. Send email to
1313bwarsaw@python.org
1414
15- Usage: %(PROGRAM)s [-d file] [-h] [initialcolor]
15+ Usage: %(PROGRAM)s [-d file] [-i file] [-X] [- h] [initialcolor]
1616
1717Where:
1818 --database file
1919 -d file
2020 Alternate location of a color database file
2121
22+ --initfile file
23+ -i file
24+ Alternate location of the initialization file. This file contains a
25+ persistent database of the current Pynche options and color. This
26+ means that Pynche restores its option settings and current color when
27+ it restarts, using this file (unless the -X option is used). The
28+ default is ~/.pynche
29+
30+ --ignore
31+ -X
32+ Ignore the initialization file when starting up. Pynche will still
33+ write the current option settings to this file when it quits.
34+
2235 --help
2336 -h
2437 print this message
4962 # Solaris OpenWindows
5063 '/usr/openwin/lib/rgb.txt' ,
5164 # The X11R6.4 rgb.txt file
52- os .path .join (sys .path [0 ], 'rgb.txt' ),
65+ os .path .join (sys .path [0 ], 'X/ rgb.txt' ),
5366 # add more here
5467 ]
5568
@@ -95,23 +108,29 @@ def main():
95108 try :
96109 opts , args = getopt .getopt (
97110 sys .argv [1 :],
98- 'hd:' ,
99- ['database=' , 'help' ])
111+ 'hd:i:X ' ,
112+ ['database=' , 'initfile=' , 'ignore' , ' help' ])
100113 except getopt .error , msg :
101114 usage (1 , msg )
102115
103116 if len (args ) == 0 :
104- initialcolor = 'grey50'
117+ initialcolor = None
105118 elif len (args ) == 1 :
106119 initialcolor = args [0 ]
107120 else :
108121 usage (1 )
109122
123+ ignore = 0
124+ initfile = os .path .expanduser ('~/.pynche' )
110125 for opt , arg in opts :
111126 if opt in ('-h' , '--help' ):
112127 usage (0 )
113128 elif opt in ('-d' , '--database' ):
114129 RGB_TXT .insert (0 , arg )
130+ elif opt in ('-X' , '--ignore' ):
131+ ignore = 1
132+ elif opt in ('-i' , '--initfile' ):
133+ initfile = arg
115134
116135 # create the windows and go
117136 for f in RGB_TXT :
@@ -124,11 +143,8 @@ def main():
124143 else :
125144 usage (1 , 'No color database file found, see the -d option.' )
126145
127- # get the initial color as components
128- red , green , blue = initial_color (initialcolor , colordb )
129-
130146 # create all output widgets
131- s = Switchboard (colordb )
147+ s = Switchboard (colordb , not ignore and initfile )
132148
133149 # create the application window decorations
134150 app = PyncheWidget (__version__ , s )
@@ -137,13 +153,30 @@ def main():
137153 s .add_view (StripViewer (s , parent ))
138154 s .add_view (ChipViewer (s , parent ))
139155 s .add_view (TypeinViewer (s , parent ))
156+
157+ # get the initial color as components and set the color on all views. if
158+ # there was no initial color given on the command line, use the one that's
159+ # stored in the option database
160+ if initialcolor is None :
161+ optiondb = s .optiondb ()
162+ red = optiondb .get ('RED' )
163+ green = optiondb .get ('GREEN' )
164+ blue = optiondb .get ('BLUE' )
165+ # but if there wasn't any stored in the database, use grey50
166+ if red is None or blue is None or green is None :
167+ red , green , blue = initial_color ('grey50' , colordb )
168+ else :
169+ red , green , blue = initial_color (initialcolor , colordb )
140170 s .update_views (red , green , blue )
141171
142172 try :
143173 app .start ()
144174 except KeyboardInterrupt :
145175 pass
146176
177+ # save the option database
178+ s .save_views (initfile )
179+
147180
148181
149182if __name__ == '__main__' :
0 commit comments