diff options
author | Tavian Barnes <tavianator@gmail.com> | 2011-11-03 23:39:07 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2011-11-04 18:10:10 -0400 |
commit | dc281b3471773935ec4da66864e6a6c768c41ff6 (patch) | |
tree | bd7003df0f2571f3a53c22dc8638209e7970a3f1 /dimension/client.py.in | |
parent | e8bdfce85fbf792eaf8be47c6ecff01f99c94ee6 (diff) | |
download | dimension-dc281b3471773935ec4da66864e6a6c768c41ff6.tar.xz |
Add a preview window written with PyQt.
Diffstat (limited to 'dimension/client.py.in')
-rw-r--r-- | dimension/client.py.in | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/dimension/client.py.in b/dimension/client.py.in index 4881f62..127b96c 100644 --- a/dimension/client.py.in +++ b/dimension/client.py.in @@ -23,9 +23,16 @@ import argparse import re import os import sys +import threading from contextlib import contextmanager from dimension import * +have_preview = True +try: + from dimension import preview +except ImportError: + have_preview = False + def main(): """Invoke the client from the command line.""" @@ -68,6 +75,9 @@ def main(): parser.add_argument("input", action = "store", type = str, help = "the input scene description file") + parser.add_argument("-p", "--preview", action = "store_true", + help = "display a preview while the image renders") + # Debugging/testing options parser.add_argument("--strict", action = "store_true", help = argparse.SUPPRESS) @@ -118,6 +128,8 @@ def main(): # Make the canvas canvas = Canvas(width = args.region_width, height = args.region_height) canvas.optimize_PNG() + if args.preview: + canvas.optimize_GL() # Make the scene object scene = Scene(canvas = canvas, @@ -146,12 +158,19 @@ def main(): # Ray-trace the scene future = scene.ray_trace_async() + bar = None if not args.quiet: if scene.nthreads == 1: render_message = "Rendering scene" else: render_message = "Rendering scene (using %d threads)" % scene.nthreads - progress_bar(render_message, future) + bar = progress_bar_async(render_message, future) + if args.preview: + if have_preview: + preview.show_preview(canvas, future) + else: + print("Couldn't display preview window", file = sys.stderr) + bar.join() future.join() # Write the output file @@ -238,3 +257,8 @@ def progress_bar(str, future): # Swallow the failure exception pass raise + +def progress_bar_async(str, future): + thread = threading.Thread(target = progress_bar, args = (str, future)) + thread.start() + return thread |