diff options
Diffstat (limited to 'examples/corelib/threads/mandelbrot.py')
-rw-r--r-- | examples/corelib/threads/mandelbrot.py | 68 |
1 files changed, 16 insertions, 52 deletions
diff --git a/examples/corelib/threads/mandelbrot.py b/examples/corelib/threads/mandelbrot.py index 824f4197d..d2d108e1f 100644 --- a/examples/corelib/threads/mandelbrot.py +++ b/examples/corelib/threads/mandelbrot.py @@ -1,44 +1,7 @@ - -############################################################################# -## -## Copyright (C) 2013 Riverbank Computing Limited. -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the Qt for Python examples of the Qt Toolkit. -## -## $QT_BEGIN_LICENSE:BSD$ -## You may use this file under the terms of the BSD license as follows: -## -## "Redistribution and use in source and binary forms, with or without -## modification, are permitted provided that the following conditions are -## met: -## * Redistributions of source code must retain the above copyright -## notice, this list of conditions and the following disclaimer. -## * Redistributions in binary form must reproduce the above copyright -## notice, this list of conditions and the following disclaimer in -## the documentation and/or other materials provided with the -## distribution. -## * Neither the name of The Qt Company Ltd nor the names of its -## contributors may be used to endorse or promote products derived -## from this software without specific prior written permission. -## -## -## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -## -## $QT_END_LICENSE$ -## -############################################################################# +# Copyright (C) 2013 Riverbank Computing Limited. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +from __future__ import annotations """PySide6 port of the corelib/threads/mandelbrot example from Qt v5.x, originating from PyQt""" @@ -47,7 +10,7 @@ import sys from PySide6.QtCore import (Signal, QMutex, QElapsedTimer, QMutexLocker, QPoint, QPointF, QSize, Qt, QThread, - QWaitCondition) + QWaitCondition, Slot) from PySide6.QtGui import QColor, QImage, QPainter, QPixmap, qRgb from PySide6.QtWidgets import QApplication, QWidget @@ -68,7 +31,7 @@ INFO_KEY = 'info' HELP = ("Use mouse wheel or the '+' and '-' keys to zoom. Press and " - "hold left mouse button to scroll.") + "hold left mouse button to scroll.") class RenderThread(QThread): @@ -91,7 +54,8 @@ class RenderThread(QThread): self.abort = False for i in range(RenderThread.colormap_size): - self.colormap.append(self.rgb_from_wave_length(380.0 + (i * 400.0 / RenderThread.colormap_size))) + self.colormap.append( + self.rgb_from_wave_length(380.0 + (i * 400.0 / RenderThread.colormap_size))) def stop(self): self.mutex.lock() @@ -170,7 +134,8 @@ class RenderThread(QThread): if num_iterations < max_iterations: image.setPixel(x + half_width, y + half_height, - self.colormap[num_iterations % RenderThread.colormap_size]) + self.colormap[ + num_iterations % RenderThread.colormap_size]) all_black = False else: image.setPixel(x + half_width, y + half_height, qRgb(0, 0, 0)) @@ -259,7 +224,7 @@ class MandelbrotWidget(QWidget): if self.pixmap.isNull(): painter.setPen(Qt.white) painter.drawText(self.rect(), Qt.AlignCenter, - "Rendering initial image, please wait...") + "Rendering initial image, please wait...") return if self._cur_scale == self._pixmap_scale: @@ -288,10 +253,10 @@ class MandelbrotWidget(QWidget): painter.setPen(Qt.NoPen) painter.setBrush(QColor(0, 0, 0, 127)) painter.drawRect((self.width() - text_width) / 2 - 5, 0, text_width + 10, - metrics.lineSpacing() + 5) + metrics.lineSpacing() + 5) painter.setPen(Qt.white) painter.drawText((self.width() - text_width) / 2, - metrics.leading() + metrics.ascent(), text) + metrics.leading() + metrics.ascent(), text) def resizeEvent(self, event): self.thread.render(self._center_x, self._center_y, self._cur_scale, self.size()) @@ -340,6 +305,7 @@ class MandelbrotWidget(QWidget): delta_y = (self.height() - self.pixmap.height()) / 2 - self._pixmap_offset.y() self.scroll(delta_x, delta_y) + @Slot(QImage, float) def update_pixmap(self, image, scale_factor): if not self._last_drag_pos.isNull(): return @@ -354,15 +320,13 @@ class MandelbrotWidget(QWidget): def zoom(self, zoomFactor): self._cur_scale *= zoomFactor self.update() - self.thread.render(self._center_x, self._center_y, self._cur_scale, - self.size()) + self.thread.render(self._center_x, self._center_y, self._cur_scale, self.size()) def scroll(self, deltaX, deltaY): self._center_x += deltaX * self._cur_scale self._center_y += deltaY * self._cur_scale self.update() - self.thread.render(self._center_x, self._center_y, self._cur_scale, - self.size()) + self.thread.render(self._center_x, self._center_y, self._cur_scale, self.size()) if __name__ == '__main__': |