diff options
Diffstat (limited to 'Tools/pynche/Main.py')
-rw-r--r-- | Tools/pynche/Main.py | 76 |
1 files changed, 41 insertions, 35 deletions
diff --git a/Tools/pynche/Main.py b/Tools/pynche/Main.py index bb5329e..f266a8d 100644 --- a/Tools/pynche/Main.py +++ b/Tools/pynche/Main.py @@ -104,34 +104,7 @@ def initial_color(s, colordb): -def main(): - try: - opts, args = getopt.getopt( - sys.argv[1:], - 'hd:i:X', - ['database=', 'initfile=', 'ignore', 'help']) - except getopt.error, msg: - usage(1, msg) - - if len(args) == 0: - initialcolor = None - elif len(args) == 1: - initialcolor = args[0] - else: - usage(1) - - ignore = 0 - initfile = os.path.expanduser('~/.pynche') - for opt, arg in opts: - if opt in ('-h', '--help'): - usage(0) - elif opt in ('-d', '--database'): - RGB_TXT.insert(0, arg) - elif opt in ('-X', '--ignore'): - ignore = 1 - elif opt in ('-i', '--initfile'): - initfile = arg - +def build(master=None, initialcolor=None, initfile=None, ignore=None): # create the windows and go for f in RGB_TXT: try: @@ -147,12 +120,12 @@ def main(): s = Switchboard(colordb, not ignore and initfile) # create the application window decorations - app = PyncheWidget(__version__, s) - parent = app.parent() + app = PyncheWidget(__version__, s, master=master) + w = app.window() - s.add_view(StripViewer(s, parent)) - s.add_view(ChipViewer(s, parent)) - s.add_view(TypeinViewer(s, parent)) + 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 @@ -168,15 +141,48 @@ def main(): else: red, green, blue = initial_color(initialcolor, colordb) s.update_views(red, green, blue) + return app, s + +def run(app, s): try: app.start() except KeyboardInterrupt: pass - # save the option database - s.save_views(initfile) + s.save_views() + + + +def main(): + try: + opts, args = getopt.getopt( + sys.argv[1:], + 'hd:i:X', + ['database=', 'initfile=', 'ignore', 'help']) + except getopt.error, msg: + usage(1, msg) + + if len(args) == 0: + initialcolor = None + elif len(args) == 1: + initialcolor = args[0] + else: + usage(1) + + ignore = 0 + initfile = os.path.expanduser('~/.pynche') + for opt, arg in opts: + if opt in ('-h', '--help'): + usage(0) + elif opt in ('-d', '--database'): + RGB_TXT.insert(0, arg) + elif opt in ('-X', '--ignore'): + ignore = 1 + elif opt in ('-i', '--initfile'): + initfile = arg + run() if __name__ == '__main__': |