summaryrefslogtreecommitdiffstats
path: root/dimension
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2012-12-17 16:28:23 -0500
committerTavian Barnes <tavianator@tavianator.com>2012-12-17 16:36:29 -0500
commitc1c2d76ba9ec33fd94a06ba8c698d21bf4e1b774 (patch)
treec71d7e2c2a57a499d09f2dd8baef6595291e4953 /dimension
parent9defe68bb518bb7e4c7d6b9954a6f604191b7abd (diff)
downloaddimension-c1c2d76ba9ec33fd94a06ba8c698d21bf4e1b774.tar.xz
client: Respond to ^C right away if possible.
Diffstat (limited to 'dimension')
-rw-r--r--dimension/client.py.in17
-rw-r--r--dimension/preview.py14
2 files changed, 24 insertions, 7 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)