Browse Source

upgraded to qt6

master
Christian Voigt 1 year ago
parent
commit
54a2954a69
  1. 8
      main.py
  2. 3
      requirements.txt
  3. 15
      sdtd_world/region_label.py
  4. 8
      sdtd_world/region_label_collection.py
  5. 38
      sdtd_world/world_regions_widget.py

8
main.py

@ -1,10 +1,10 @@
import sys
from PyQt5.QtCore import (
from PyQt6.QtCore import (
Qt, QSettings, QByteArray, QSize
)
from PyQt5.QtWidgets import (
from PyQt6.QtWidgets import (
QMainWindow, QApplication, QWidget,
QHBoxLayout, QVBoxLayout,
QProgressBar
@ -56,7 +56,7 @@ class GuiTest(QMainWindow):
general_progress_bar = QProgressBar()
general_progress_bar.setRange(0, 100)
general_progress_bar.setValue(0)
general_progress_bar.setAlignment(Qt.AlignCenter)
general_progress_bar.setAlignment(Qt.Alignment.AlignCenter)
general_progress_bar.setMaximumWidth(staging_view_width)
window_layout.addWidget(region_view)
@ -94,7 +94,7 @@ def main():
app = QApplication(sys.argv)
gt = GuiTest()
gt.show()
sys.exit(app.exec_())
sys.exit(app.exec())
if __name__ == '__main__':

3
requirements.txt

@ -1 +1,2 @@
pyqt5
pyqt6
numpy

15
sdtd_world/region_label.py

@ -1,6 +1,10 @@
from PyQt5 import QtCore
from PyQt5.QtGui import QPixmap, QColor, QImage
from PyQt5.QtWidgets import QLabel, QGraphicsColorizeEffect
from PyQt6.QtCore import Qt
from PyQt6.QtGui import (
QPixmap, QColor, QImage
)
from PyQt6.QtWidgets import (
QLabel, QGraphicsColorizeEffect
)
class RegionLabel(QLabel):
@ -39,10 +43,7 @@ class RegionLabel(QLabel):
return True
def mousePressEvent(self, event):
# if event.buttons() == QtCore.Qt.LeftButton:
# pass
if event.buttons() == QtCore.Qt.RightButton:
if event.buttons() == Qt.MouseButtons.RightButton:
self.is_selected = not self.is_selected
if self.is_selected:

8
sdtd_world/region_label_collection.py

@ -2,8 +2,10 @@ import math
from pathlib import Path
import numpy as np
from PyQt5.QtGui import QImage
from PyQt5.QtWidgets import QGridLayout, QFileDialog
from PyQt6.QtGui import QImage
from PyQt6.QtWidgets import (
QGridLayout, QFileDialog
)
from .region_label import RegionLabel
@ -53,5 +55,5 @@ class RegionLabelCollection(QGridLayout):
regions_per_row = int(length / 512)
offset = int(self.max_regions_per_row / 2) - int(regions_per_row / 2)
self.loaded_image.map_image = QImage(raw_data_array, length, length, QImage.Format_Grayscale16)
self.loaded_image.map_image = QImage(raw_data_array, length, length, QImage.Format.Format_Grayscale16)
self.loaded_image.map_array = raw_data_array

38
sdtd_world/world_regions_widget.py

@ -1,9 +1,9 @@
from PyQt5.QtCore import Qt, QPoint
from PyQt5.QtGui import QCursor
from PyQt6.QtCore import Qt, QPoint
from PyQt6.QtGui import QCursor
from PyQt5.QtWidgets import (
from PyQt6.QtWidgets import (
QWidget,
QScrollArea, QFrame, QApplication, QAction,
QScrollArea, QFrame, QApplication
)
from .region_label_collection import RegionLabelCollection
@ -41,8 +41,8 @@ class WorldRegionsWidget(QScrollArea):
region_label_collection_wrapper_widget = QWidget()
region_label_collection_wrapper_widget.setLayout(self.region_label_collection)
self.setAlignment(Qt.AlignCenter)
self.setFrameShape(QFrame.NoFrame)
self.setAlignment(Qt.Alignment.AlignCenter)
self.setFrameShape(QFrame.Shape.NoFrame)
self.setWidget(region_label_collection_wrapper_widget)
def get_zoom_adjusted_label_size(self):
@ -71,30 +71,36 @@ class WorldRegionsWidget(QScrollArea):
""" altering class functions """
def mousePressEvent(self, event):
modifiers = QApplication.keyboardModifiers()
if modifiers == Qt.ControlModifier and event.button() == Qt.LeftButton:
if modifiers == Qt.KeyboardModifiers.ControlModifier and event.button() == Qt.MouseButtons.LeftButton:
self.drag_in_progress = True
self.drag_start.setX(event.x())
self.drag_start.setY(event.y())
self.drag_start.setX(event.position().x())
self.drag_start.setY(event.position().y())
super().mousePressEvent(event)
def mouseReleaseEvent(self, event):
if event.button() == Qt.LeftButton:
if event.button() == Qt.MouseButtons.LeftButton:
self.drag_in_progress = False
super().mouseReleaseEvent(event)
def mouseMoveEvent(self, event):
if self.drag_in_progress:
self.verticalScrollBar().setValue(self.verticalScrollBar().value() - (event.y() - self.drag_start.y()))
self.horizontalScrollBar().setValue(self.horizontalScrollBar().value() - (event.x() - self.drag_start.x()))
self.drag_start = QPoint(event.x(), event.y())
self.verticalScrollBar().setValue(
self.verticalScrollBar().value() - (event.position().y() - self.drag_start.y())
)
self.horizontalScrollBar().setValue(
self.horizontalScrollBar().value() - (event.position().x() - self.drag_start.x())
)
self.drag_start = QPoint(
event.position().x(), event.position().y()
)
super().mouseMoveEvent(event)
def wheelEvent(self, event):
modifiers = QApplication.keyboardModifiers()
if modifiers == Qt.ControlModifier:
if modifiers == Qt.KeyboardModifiers.ControlModifier:
if event.angleDelta().y() > 0:
self.action_zoom_in()
else:
@ -106,12 +112,12 @@ class WorldRegionsWidget(QScrollArea):
def keyPressEvent(self, event):
if event.key() in (16777249, 16777250):
self.setCursor(QCursor(Qt.SizeAllCursor))
self.setCursor(QCursor(Qt.CursorShape.SizeAllCursor))
super().keyPressEvent(event)
def keyReleaseEvent(self, event):
if event.key() in (16777249, 16777250):
self.setCursor(QCursor(Qt.ArrowCursor))
self.setCursor(QCursor(Qt.CursorShape.ArrowCursor))
super().keyReleaseEvent(event)

Loading…
Cancel
Save