From dc281b3471773935ec4da66864e6a6c768c41ff6 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Thu, 3 Nov 2011 23:39:07 -0400 Subject: Add a preview window written with PyQt. --- dimension/client.py.in | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'dimension/client.py.in') 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 -- cgit v1.2.3