summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dimension/client.py.in17
-rw-r--r--dimension/preview.py14
-rw-r--r--libdimension-python/dimension.pyx4
3 files changed, 27 insertions, 8 deletions
diff --git a/dimension/client.py.in b/dimension/client.py.in
index 9f68198..b1a3c60 100644
--- a/dimension/client.py.in
+++ b/dimension/client.py.in
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
#########################################################################
-# Copyright (C) 2011 Tavian Barnes <tavianator@tavianator.com> #
+# Copyright (C) 2011-2012 Tavian Barnes <tavianator@tavianator.com> #
# #
# This file is part of Dimension. #
# #
@@ -172,7 +172,7 @@ def main():
else:
print("Couldn't display preview window", file = sys.stderr)
if bar is not None:
- bar.join()
+ join_progress_bar(bar)
# Write the output file
export_timer = Timer()
@@ -249,4 +249,15 @@ def progress_bar(str, future):
def progress_bar_async(str, future):
thread = threading.Thread(target = progress_bar, args = (str, future))
thread.start()
- return thread
+ return (thread, future)
+
+def join_progress_bar(bar):
+ """Handle joining a progress bar thread in a way responsive to ^C."""
+ thread = bar[0]
+ future = bar[1]
+ try:
+ thread.join()
+ except:
+ future.cancel()
+ thread.join()
+ raise
diff --git a/dimension/preview.py b/dimension/preview.py
index 868c16b..fd56123 100644
--- a/dimension/preview.py
+++ b/dimension/preview.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
#########################################################################
-# Copyright (C) 2011 Tavian Barnes <tavianator@tavianator.com> #
+# Copyright (C) 2011-2012 Tavian Barnes <tavianator@tavianator.com> #
# #
# This file is part of Dimension. #
# #
@@ -23,12 +23,18 @@ from PyQt4 import QtCore, QtGui, QtOpenGL
class Preview(QtOpenGL.QGLWidget):
"""Surface that the scene is rendered to."""
- def __init__(self, parent, canvas):
+ def __init__(self, parent, canvas, future):
QtOpenGL.QGLWidget.__init__(self, parent)
self.canvas = canvas
+ self.future = future
def paintGL(self):
- self.canvas.draw_GL()
+ try:
+ self.canvas.draw_GL()
+ except:
+ self.future.cancel()
+ self.parent().close()
+ raise
class PreviewWindow(QtGui.QMainWindow):
"""Main window for a rendering preview."""
@@ -39,7 +45,7 @@ class PreviewWindow(QtGui.QMainWindow):
self.setMinimumSize(canvas.width, canvas.height)
self.setMaximumSize(canvas.width, canvas.height)
- self.widget = Preview(self, canvas)
+ self.widget = Preview(self, canvas, future)
self.setCentralWidget(self.widget)
self.render_timer = QtCore.QTimer(self)
diff --git a/libdimension-python/dimension.pyx b/libdimension-python/dimension.pyx
index abfa8eb..a50f247 100644
--- a/libdimension-python/dimension.pyx
+++ b/libdimension-python/dimension.pyx
@@ -1,5 +1,5 @@
#########################################################################
-# Copyright (C) 2011 Tavian Barnes <tavianator@tavianator.com> #
+# Copyright (C) 2011-2012 Tavian Barnes <tavianator@tavianator.com> #
# #
# This file is part of The Dimension Python Module. #
# #
@@ -96,6 +96,8 @@ cdef class Future:
return self
def __exit__(self, exc_type, exc_value, traceback):
if self._future != NULL:
+ if exc_value is not None:
+ self.cancel()
self.join()
return False