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/preview.py | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 dimension/preview.py (limited to 'dimension/preview.py') diff --git a/dimension/preview.py b/dimension/preview.py new file mode 100644 index 0000000..868c16b --- /dev/null +++ b/dimension/preview.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python3 + +######################################################################### +# Copyright (C) 2011 Tavian Barnes # +# # +# This file is part of Dimension. # +# # +# Dimension is free software; you can redistribute it and/or modify it # +# under the terms of the GNU General Public License as published by the # +# Free Software Foundation; either version 3 of the License, or (at # +# your option) any later version. # +# # +# Dimension is distributed in the hope that it will be useful, but # +# WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # +# General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +######################################################################### + +from PyQt4 import QtCore, QtGui, QtOpenGL + +class Preview(QtOpenGL.QGLWidget): + """Surface that the scene is rendered to.""" + def __init__(self, parent, canvas): + QtOpenGL.QGLWidget.__init__(self, parent) + self.canvas = canvas + + def paintGL(self): + self.canvas.draw_GL() + +class PreviewWindow(QtGui.QMainWindow): + """Main window for a rendering preview.""" + def __init__(self, canvas, future): + QtGui.QMainWindow.__init__(self) + self.canvas = canvas + self.future = future + + self.setMinimumSize(canvas.width, canvas.height) + self.setMaximumSize(canvas.width, canvas.height) + self.widget = Preview(self, canvas) + self.setCentralWidget(self.widget) + + self.render_timer = QtCore.QTimer(self) + self.render_timer.timeout.connect(self.update_preview) + self.render_timer.start(0) + + @QtCore.pyqtSlot() + def update_preview(self): + self.widget.updateGL() + if self.future.progress() == 1: + self.render_timer.stop() + self.close_timer = QtCore.QTimer(self) + self.close_timer.singleShot(1000, self.close) + + @QtCore.pyqtSlot() + def close(self): + QtCore.QCoreApplication.instance().quit() + +def show_preview(canvas, future): + app = QtGui.QApplication(["Dimension Preview"]) + window = PreviewWindow(canvas, future) + window.show() + app.exec() + del window -- cgit v1.2.3