Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAINT: port code from PySide2 to PySide6. #362

Merged
merged 1 commit into from
Dec 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions python/oddkiva/sara/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
from oddkiva.sara.timer import *
# The following imports may fail because PySide2 may not be available on recent
# Python versions.
try:
from oddkiva.sara.graphics import *
except:
pass
from oddkiva.sara.graphics import *
from pysara_pybind11 import *
4 changes: 2 additions & 2 deletions python/oddkiva/sara/graphics/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from PySide2.QtGui import QImage
from PySide2.QtWidgets import QApplication
from PySide6.QtGui import QImage
from PySide6.QtWidgets import QApplication

from oddkiva.sara.graphics.derived_qobjects.graphics_context import GraphicsContext
import oddkiva.sara.graphics.image_draw as image_draw
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from PySide2.QtCore import QObject, Qt
from PySide2.QtWidgets import QApplication
from PySide6.QtCore import QObject, Qt
from PySide6.QtWidgets import QApplication

from oddkiva.sara.graphics.derived_qobjects.painting_window import PaintingWindow
from oddkiva.sara.graphics.derived_qobjects.user_thread import UserThread
Expand Down
14 changes: 9 additions & 5 deletions python/oddkiva/sara/graphics/derived_qobjects/painting_window.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from PySide2.QtCore import (QObject, QPointF, QRectF, QTimer, Qt, qWarning,
from PySide6.QtCore import (QObject, QPointF, QRectF, QTimer, Qt, qWarning,
Signal, Slot)
from PySide2.QtWidgets import QApplication, QScrollArea, QWidget
from PySide2.QtGui import QColor, QFont, QPainter, QPen, QPixmap
from PySide6.QtWidgets import QApplication, QScrollArea, QWidget
from PySide6.QtGui import QColor, QFont, QPainter, QPen, QPixmap


class ScrollArea(QScrollArea):
Expand Down Expand Up @@ -60,8 +60,12 @@ def __init__(self, sizes, window_title="Sara", position=None, parent=None):
self._scroll_area.setFocusProxy(self)

# Maximize if necessary.
if w >= QApplication.instance().desktop().width() or \
h >= QApplication.instance().desktop().height():
w_screen, h_screen = QApplication.instance()\
.screens()[0]\
.size()\
.toTuple()
if w >= w_screen or \
h >= h_screen:
self._scroll_area.showMaximized()
# Resize the scroll area with the size plus a two-pixel offset.
else:
Expand Down
4 changes: 2 additions & 2 deletions python/oddkiva/sara/graphics/derived_qobjects/user_thread.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from PySide2.QtCore import QMutex, QObject, QThread, Qt, QWaitCondition, Signal
from PySide2.QtWidgets import QApplication
from PySide6.QtCore import QMutex, QObject, QThread, Qt, QWaitCondition, Signal
from PySide6.QtWidgets import QApplication


class UserThreadSignals(QObject):
Expand Down
20 changes: 10 additions & 10 deletions python/oddkiva/sara/graphics/examples/hello_coordinate_systems.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@

import OpenGL.GL as gl

from PySide2.QtCore import QObject, QElapsedTimer, QTimer
from PySide2.QtGui import (QGuiApplication,
from PySide6.QtCore import QObject, QElapsedTimer, QTimer
from PySide6.QtGui import (QGuiApplication,
QImage,
QMatrix4x4,
QOpenGLBuffer,
QOpenGLShader,
QOpenGLShaderProgram,
QOpenGLTexture,
QOpenGLVertexArrayObject,
QOpenGLWindow,
QSurfaceFormat,
QVector3D)
from PySide6.QtOpenGL import (QOpenGLBuffer,
QOpenGLShader,
QOpenGLShaderProgram,
QOpenGLTexture,
QOpenGLVertexArrayObject,
QOpenGLWindow)


DATA_DIR = path.join(path.dirname(__file__), '../../../../..', 'data')
Expand Down Expand Up @@ -155,7 +155,7 @@ def initialize_geometry_on_gpu(self):
raise ValueError('Could not create VBO')
self.vbo.bind()
self.vbo.setUsagePattern(QOpenGLBuffer.StaticDraw)
vertices_data = self.vertices.tostring()
vertices_data = self.vertices.tobytes()
self.vbo.allocate(len(vertices_data))
self.vbo.write(0, vertices_data, len(vertices_data))

Expand Down Expand Up @@ -292,4 +292,4 @@ def cleanup():

app.aboutToQuit.connect(cleanup)

sys.exit(app.exec_())
sys.exit(app.exec())
2 changes: 1 addition & 1 deletion python/oddkiva/sara/graphics/examples/hello_sara.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys

from PySide2.QtCore import Qt
from PySide6.QtCore import Qt

import numpy as np

Expand Down
16 changes: 8 additions & 8 deletions python/oddkiva/sara/graphics/examples/hello_square.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

import OpenGL.GL as gl

from PySide2.QtCore import QObject
from PySide2.QtGui import (QGuiApplication,
QOpenGLBuffer,
QOpenGLShader,
QOpenGLShaderProgram,
QOpenGLVertexArrayObject,
QOpenGLWindow,
from PySide6.QtCore import QObject
from PySide6.QtGui import (QGuiApplication,
QSurfaceFormat)
from PySide6.QtOpenGL import (QOpenGLBuffer,
QOpenGLShader,
QOpenGLShaderProgram,
QOpenGLVertexArrayObject,
QOpenGLWindow)


class SquareObject(QObject):
Expand Down Expand Up @@ -161,4 +161,4 @@ def paintGL(self):
win.resize(800, 600)
win.show()

sys.exit(app.exec_())
sys.exit(app.exec())
22 changes: 11 additions & 11 deletions python/oddkiva/sara/graphics/examples/hello_transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@

import OpenGL.GL as gl

from PySide2.QtCore import QObject, QElapsedTimer, QTimer
from PySide2.QtGui import (QGuiApplication,
from PySide6.QtCore import QObject, QElapsedTimer, QTimer
from PySide6.QtGui import (QGuiApplication,
QImage,
QMatrix4x4,
QOpenGLBuffer,
QOpenGLShader,
QOpenGLShaderProgram,
QOpenGLTexture,
QOpenGLVertexArrayObject,
QOpenGLWindow,
QSurfaceFormat,
QVector3D)
from PySide6.QtOpenGL import (QOpenGLBuffer,
QOpenGLShader,
QOpenGLShaderProgram,
QOpenGLTexture,
QOpenGLVertexArrayObject,
QOpenGLWindow)


DATA_DIR = path.join(path.dirname(__file__), '../../../../..', 'data')
Expand Down Expand Up @@ -128,7 +128,7 @@ def initialize_geometry_on_gpu(self):
raise ValueError('Could not create VBO')
self.vbo.bind()
self.vbo.setUsagePattern(QOpenGLBuffer.StaticDraw)
vertices_data = self.vertices.tostring()
vertices_data = self.vertices.tobytes()
self.vbo.allocate(len(vertices_data))
self.vbo.write(0, vertices_data, len(vertices_data))

Expand All @@ -137,7 +137,7 @@ def initialize_geometry_on_gpu(self):
raise ValueError('Could not create EBO')
self.ebo.bind()
self.ebo.setUsagePattern(QOpenGLBuffer.StaticDraw)
triangles_data = self.triangles.tostring()
triangles_data = self.triangles.tobytes()
self.ebo.allocate(len(triangles_data))
self.ebo.write(0, triangles_data, len(triangles_data))

Expand Down Expand Up @@ -260,4 +260,4 @@ def cleanup():

app.aboutToQuit.connect(cleanup)

sys.exit(app.exec_())
sys.exit(app.exec())
18 changes: 9 additions & 9 deletions python/oddkiva/sara/graphics/examples/hello_triangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

import OpenGL.GL as gl

from PySide2 import QtGui
from PySide6 import QtGui, QtOpenGL


class TriangleWindow(QtGui.QOpenGLWindow):
class TriangleWindow(QtOpenGL.QOpenGLWindow):

def __init__(self):
super(TriangleWindow, self).__init__()

def setup_shader_program(self):
self._program = QtGui.QOpenGLShaderProgram(self.context())
self._program = QtOpenGL.QOpenGLShaderProgram(self.context())
self._vertex_shader = """
#version 330 core
layout (location = 0) in vec3 in_coords;
Expand Down Expand Up @@ -50,15 +50,15 @@ def setup_shader_program(self):
self._arg_pos = {'in_coords': 0, 'in_color': 1, 'out_color': 0}

self._program.addCacheableShaderFromSourceCode(
QtGui.QOpenGLShader.Vertex, self._vertex_shader)
QtOpenGL.QOpenGLShader.Vertex, self._vertex_shader)
self._program.addCacheableShaderFromSourceCode(
QtGui.QOpenGLShader.Fragment, self._fragment_shader)
QtOpenGL.QOpenGLShader.Fragment, self._fragment_shader)

self._vao = QtGui.QOpenGLVertexArrayObject(self.context())
self._vao = QtOpenGL.QOpenGLVertexArrayObject(self.context())
if not self._vao.create():
raise QtCore.QException()

self._vbo = QtGui.QOpenGLBuffer()
self._vbo = QtOpenGL.QOpenGLBuffer()
if not self._vbo.create():
raise QtCore.QException()

Expand All @@ -72,7 +72,7 @@ def setup_shader_program(self):
self._program.bind()
self._vao.bind()
self._vbo.bind()
self._vbo.setUsagePattern(QtGui.QOpenGLBuffer.StaticDraw)
self._vbo.setUsagePattern(QtOpenGL.QOpenGLBuffer.StaticDraw)
self._vbo.allocate(len(self._data))
self._vbo.write(0, self._data, len(self._data))

Expand Down Expand Up @@ -119,4 +119,4 @@ def paintGL(self):
win.setFormat(format)
win.show()

sys.exit(app.exec_())
sys.exit(app.exec())
4 changes: 2 additions & 2 deletions python/oddkiva/sara/graphics/examples/hello_world.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import random
import sys

from PySide2 import QtCore, QtWidgets
from PySide6 import QtCore, QtWidgets


class MyWidget(QtWidgets.QWidget):
Expand Down Expand Up @@ -32,4 +32,4 @@ def magic(self):
widget.resize(800, 600)
widget.show()

sys.exit(app.exec_())
sys.exit(app.exec())
4 changes: 2 additions & 2 deletions python/oddkiva/sara/graphics/image_draw.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from PySide2.QtCore import QPointF
from PySide2.QtGui import QColor, QFont, QImage, QPainter, QPen
from PySide6.QtCore import QPointF
from PySide6.QtGui import QColor, QFont, QImage, QPainter, QPen


def to_qimage(array):
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ torchaudio==2.1.1
coremltools

PyOpenGL
# PySide2
pyside6