Skip to content

Commit

Permalink
port PyQt apps to PyQt6
Browse files Browse the repository at this point in the history
  • Loading branch information
hydrargyrum committed Apr 27, 2023
1 parent 0c6d7d6 commit e1e6bd6
Show file tree
Hide file tree
Showing 18 changed files with 138 additions and 106 deletions.
6 changes: 3 additions & 3 deletions all-clipboard/all-clipboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from argparse import ArgumentParser
import sys

from PyQt5.QtGui import QClipboard, QGuiApplication
from PyQt6.QtGui import QClipboard, QGuiApplication


def get_clips_of_mode(mode):
Expand Down Expand Up @@ -61,6 +61,6 @@ def do_mode(mode):
clipboard = app.clipboard()

if args.clipboard:
do_mode(QClipboard.Clipboard)
do_mode(QClipboard.Mode.Clipboard)
if args.selection:
do_mode(QClipboard.Selection)
do_mode(QClipboard.Mode.Selection)
2 changes: 1 addition & 1 deletion all-clipboard/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
PyQt5
PyQt6
2 changes: 1 addition & 1 deletion coordapp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ Press Space to stop refreshing.
Press G for a faster refresh (but fallbacks after one click).
Press A to stay always on top.

CoordApp requires Python and PyQt5.
CoordApp requires Python and PyQt6.
CoordApp is licensed under the [Do What the Fuck You Want to Public License](http://wtfpl.net)
20 changes: 10 additions & 10 deletions coordapp/coordapp.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: WTFPL

from PyQt5.QtCore import pyqtSignal as Signal, pyqtSlot as Slot, QPoint, QBasicTimer, Qt
from PyQt5.QtGui import QCursor, QKeySequence
from PyQt5.QtWidgets import QLineEdit, QWidget, QHBoxLayout, QAction, qApp, QMainWindow, QApplication, QPushButton, QMessageBox
from PyQt6.QtCore import pyqtSignal as Signal, pyqtSlot as Slot, QPoint, QBasicTimer, Qt
from PyQt6.QtGui import QCursor, QKeySequence, QAction
from PyQt6.QtWidgets import QLineEdit, QWidget, QHBoxLayout, QMainWindow, QApplication, QPushButton, QMessageBox

import sys

Expand Down Expand Up @@ -117,23 +117,23 @@ def __init__(self, parent=None):

## shortcuts
self.copyAction = QAction(self)
self.copyAction.setShortcut(QKeySequence(QKeySequence.Copy))
self.copyAction.setShortcut(QKeySequence(QKeySequence.StandardKey.Copy))
self.copyAction.triggered.connect(self.copyToClibpoard)
self.addAction(self.copyAction)

self.toggleGrabAction = QAction(self)
self.toggleGrabAction.setShortcut(QKeySequence(Qt.Key_G))
self.toggleGrabAction.setShortcut(QKeySequence(Qt.Key.Key_G))
self.toggleGrabAction.triggered.connect(self.follower.toggleGrab)
self.toggleGrabAction.triggered.connect(self._showGrabInfo)
self.addAction(self.toggleGrabAction)

self.toggleFollowAction = QAction(self)
self.toggleFollowAction.setShortcut(QKeySequence(Qt.Key_Space))
self.toggleFollowAction.setShortcut(QKeySequence(Qt.Key.Key_Space))
self.toggleFollowAction.triggered.connect(self.follower.toggleFollow)
self.addAction(self.toggleFollowAction)

self.toggleAlwaysOnTopAction = QAction(self)
self.toggleAlwaysOnTopAction.setShortcut(QKeySequence(Qt.Key_A))
self.toggleAlwaysOnTopAction.setShortcut(QKeySequence(Qt.Key.Key_A))
self.toggleAlwaysOnTopAction.triggered.connect(self.toggleAlwaysOnTop)
self.addAction(self.toggleAlwaysOnTopAction)

Expand All @@ -157,7 +157,7 @@ def hideEvent(self, ev):
return QMainWindow.hideEvent(self, ev)

def toggleAlwaysOnTop(self):
self.setWindowFlags(self.windowFlags() ^ Qt.WindowStaysOnTopHint)
self.setWindowFlags(self.windowFlags() ^ Qt.WindowType.WindowStaysOnTopHint)
self.show() # setWindowFlags hides...

@Slot()
Expand All @@ -168,7 +168,7 @@ def displayInfo(self):
@Slot()
def copyToClibpoard(self):
text = self.label.text().replace(' ', '')
qApp.clipboard().setText(text)
QApplication.instance().clipboard().setText(text)
self.statusBar().showMessage('%s copied to clipboard' % text, 2000)

def showHelp(self):
Expand All @@ -183,4 +183,4 @@ def showHelp(self):
app = QApplication(sys.argv)
gui = CoordApp()
gui.show()
sys.exit(app.exec_())
sys.exit(app.exec())
2 changes: 1 addition & 1 deletion coordapp/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
PyQt5
PyQt6
17 changes: 10 additions & 7 deletions lch-color-chooser/lch-color-chooser.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
# import colorspacious # lib seems buggy
from colormath.color_objects import LCHabColor, sRGBColor
from colormath.color_conversions import convert_color
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt6.QtWidgets import *
from PyQt6.QtGui import *
from PyQt6.QtCore import *


Slot = pyqtSlot
Expand All @@ -32,7 +32,10 @@ def __init__(self):
self.setLayout(QHBoxLayout())
self.setMaximum(self.maximum())
self.setMinimumSize(self.maximum(), 5)
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
self.setSizePolicy(
QSizePolicy.Policy.Expanding,
QSizePolicy.Policy.Preferred
)

@Slot(int)
def setChroma(self, value):
Expand Down Expand Up @@ -139,23 +142,23 @@ def paintEvent(self, ev):

def mousePressEvent(self, ev):
vw = self.width() - self.margin * 2
vpos = clamp(0, ev.x() - self.margin, vw)
vpos = clamp(0, ev.pos().x() - self.margin, vw)
lpos = int(vpos * self.maximum() / vw)

self.setSliderDown(True)
self.setSliderPosition(lpos)

def mouseMoveEvent(self, ev):
vw = self.width() - self.margin * 2
vpos = clamp(0, ev.x() - self.margin, vw)
vpos = clamp(0, ev.pos().x() - self.margin, vw)
lpos = int(vpos * self.maximum() / vw)

self.setSliderDown(True)
self.setSliderPosition(lpos)

def mouseReleaseEvent(self, ev):
vw = self.width() - self.margin * 2
vpos = clamp(0, ev.x() - self.margin, vw)
vpos = clamp(0, ev.pos().x() - self.margin, vw)
lpos = int(vpos * self.maximum() / vw)

self.setSliderPosition(lpos)
Expand Down
2 changes: 1 addition & 1 deletion lch-color-chooser/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
PyQt5
PyQt6
colormath
10 changes: 5 additions & 5 deletions qgifview/qgifview
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

import sys

from PyQt5.QtCore import Qt
from PyQt5.QtGui import QMovie
from PyQt5.QtWidgets import QApplication, QLabel
from PyQt6.QtCore import Qt
from PyQt6.QtGui import QMovie
from PyQt6.QtWidgets import QApplication, QLabel


app = QApplication(sys.argv)
Expand All @@ -25,7 +25,7 @@ if not movie.isValid():

class MyLabel(QLabel):
def keyPressEvent(self, ev):
if ev.key() == Qt.Key_Escape:
if ev.key() == Qt.Key.Key_Escape:
self.close()


Expand All @@ -37,4 +37,4 @@ label.show()

movie.finished.connect(movie.start) # loop

sys.exit(app.exec_())
sys.exit(app.exec())
2 changes: 1 addition & 1 deletion qgifview/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
PyQt5
PyQt6
49 changes: 28 additions & 21 deletions qr-shot/qrshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@
# SPDX-License-Identifier: WTFPL
# decoding is possible if 'zbar' module is installed, and 'qrencode' for encoding

from PyQt5.QtCore import pyqtSignal as Signal, pyqtSlot as Slot, Qt, QRect, QSize, QUrl
from PyQt5.QtGui import QPixmap, QCursor
from PyQt5.QtWidgets import QLabel, QDialog, QMainWindow, QApplication, QMessageBox, QTextEdit, QVBoxLayout, QFileDialog, QScrollArea, QDialogButtonBox, QLineEdit, QRubberBand, QFormLayout, qApp
from PyQt6.QtCore import pyqtSignal as Signal, pyqtSlot as Slot, Qt, QRect, QSize, QUrl
from PyQt6.QtGui import QPixmap, QCursor
from PyQt6.QtWidgets import QLabel, QDialog, QMainWindow, QApplication, QMessageBox, QTextEdit, QVBoxLayout, QFileDialog, QScrollArea, QDialogButtonBox, QLineEdit, QRubberBand, QFormLayout

import sys
import time
import tempfile

if sys.version_info.major > 2:
unicode = str

def tryImport(modulename):
try:
Expand Down Expand Up @@ -74,10 +72,10 @@ def __init__(self, mainwin):

self.setAcceptDrops(True)

self.marker = QRubberBand(QRubberBand.Rectangle, self)
self.marker = QRubberBand(QRubberBand.Shape.Rectangle, self)
self.markOrigin = self.markEnd = None

self.setContextMenuPolicy(Qt.ActionsContextMenu)
self.setContextMenuPolicy(Qt.ContextMenuPolicy.ActionsContextMenu)
self.addAction(mainwin.cropAction)
self.addAction(mainwin.saveAction)

Expand Down Expand Up @@ -108,7 +106,7 @@ def _makeRect(self, p1, p2):
return QRect().adjusted(x1, y1, x2, y2)

def mouseMoveEvent(self, ev):
if ev.buttons() != Qt.LeftButton:
if ev.buttons() != Qt.MouseButton.LeftButton:
return QLabel.mouseMoveEvent(self, ev)
self.markEnd = ev.pos()
diffpoint = self.markEnd - self.markOrigin
Expand All @@ -117,7 +115,7 @@ def mouseMoveEvent(self, ev):
#~ ev.accept()

def mousePressEvent(self, ev):
if ev.button() != Qt.LeftButton:
if ev.button() != Qt.MouseButton.LeftButton:
return QLabel.mousePressEvent(self, ev)
self.markOrigin = ev.pos()
self.marker.move(ev.pos())
Expand All @@ -127,12 +125,12 @@ def mousePressEvent(self, ev):

def dragEnterEvent(self, ev):
if ev.mimeData().hasUrls():
ev.setDropAction(Qt.CopyAction)
ev.setDropAction(Qt.DropAction.CopyAction)
ev.accept()

def dropEvent(self, ev):
if ev.mimeData().hasUrls():
ev.setDropAction(Qt.CopyAction)
ev.setDropAction(Qt.DropAction.CopyAction)
ev.accept()
self.fileDropped.emit(ev.mimeData().urls()[0])

Expand All @@ -149,7 +147,10 @@ def __init__(self, *args):

self.text = QLineEdit()

self.buttons = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
self.buttons = QDialogButtonBox(
QDialogButtonBox.StandardButton.Ok
| QDialogButtonBox.StandardButton.Cancel
)
self.buttons.accepted.connect(self.validateAndAccept)
self.buttons.rejected.connect(self.reject)

Expand All @@ -161,7 +162,7 @@ def __init__(self, *args):
@Slot()
def validateAndAccept(self):
if self.text.text():
self.value = {'text': unicode(self.text.text())}
self.value = {'text': self.text.text()}
self.accept()


Expand All @@ -174,7 +175,7 @@ def __init__(self, text, parent):
self.textDisplay = QTextEdit(text)
self.textDisplay.setReadOnly(True)

self.buttons = QDialogButtonBox(QDialogButtonBox.Ok)
self.buttons = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok)
self.buttons.accepted.connect(self.accept)

self.setLayout(QVBoxLayout())
Expand Down Expand Up @@ -205,11 +206,11 @@ def __init__(self):

self.scroller = QScrollArea()
self.scroller.setWidgetResizable(True)
self.scroller.setAlignment(Qt.AlignCenter)
self.scroller.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.setCentralWidget(self.scroller)

self.cropper = ImageCropperDropper(self)
self.cropper.setAlignment(Qt.AlignCenter)
self.cropper.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.scroller.setWidget(self.cropper)

self.status = self.statusBar()
Expand All @@ -232,7 +233,7 @@ def shootScreen(self):
#~ g = QRect(self.geometry())
self.hide()
time.sleep(1)
pix = qApp.primaryScreen().grabWindow(QApplication.desktop().winId())
pix = QApplication.instance().primaryScreen().grabWindow()
#~ pix = QPixmap.grabWindow(QApplication.desktop().winId())
self.show()
#~ self.setGeometry(g)
Expand Down Expand Up @@ -278,7 +279,7 @@ def decodeImage(self):
pix = self.loadImage()
if not pix or pix.isNull():
return
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
QApplication.setOverrideCursor(QCursor(Qt.CursorShape.WaitCursor))
text = decodeImage(pix)
QApplication.restoreOverrideCursor()
if not text:
Expand All @@ -290,13 +291,19 @@ def decodeImage(self):
def displayEncodeDialog(self):
if not hasattr(self, 'encodeDialog'):
self.encodeDialog = EncoderDialog(self)
ok = (self.encodeDialog.exec_() == QDialog.Accepted)
ok = (self.encodeDialog.exec() == QDialog.DialogCode.Accepted)
if not ok:
return
text = self.encodeDialog.value['text']
if len(text) > 1000:
if QMessageBox.question(self, 'Warning', 'The text entered is quite large, this could make the app crash. Continue anyway?', QMessageBox.Yes | QMessageBox.No) != QMessageBox.Yes:
if QMessageBox.question(
self, 'Warning', 'The text entered is quite large, this could make the app crash. Continue anyway?',
QMessageBox.StandardButton.Yes
| QMessageBox.StandardButton.No
) != QMessageBox.StandardButton.Yes:

return

pix = encodeText(text)

self.cropper.setStyleSheet('*{background: white;}')
Expand All @@ -311,4 +318,4 @@ def setPixmap(self, pix):
app = QApplication(sys.argv)
w = Window()
w.show()
sys.exit(app.exec_())
sys.exit(app.exec())
2 changes: 1 addition & 1 deletion qruler/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ Press arrow keys to move the ruler by 1 pixel in a direction.

![Screenshot](qruler.png)

QRuler needs on Python and PyQt5.
QRuler needs on Python and PyQt6.
QRuler is licensed under the [Do What the Fuck You Want to Public License](http://wtfpl.net)

Loading

0 comments on commit e1e6bd6

Please sign in to comment.