Skip to content

Commit

Permalink
Upgrade PyQt5 to PyQt6
Browse files Browse the repository at this point in the history
  • Loading branch information
yakimka committed Sep 14, 2023
1 parent 5754cd8 commit dfa403e
Show file tree
Hide file tree
Showing 24 changed files with 504 additions and 435 deletions.
2 changes: 1 addition & 1 deletion CherryTomato/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Easy to use, flexible PyQt5 Pomodoro Technique timer."""
"""Easy to use, flexible PyQt6 Pomodoro Technique timer."""

import os

Expand Down
28 changes: 13 additions & 15 deletions CherryTomato/about_ui.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'CherryTomato/about_ui.ui'
#
# Created by: PyQt5 UI code generator 5.15.1
# Created by: PyQt6 UI code generator 6.5.2
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# WARNING: Any manual changes made to this file will be lost when pyuic6 is
# run again. Do not edit this file unless you know what you are doing.


from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt6 import QtCore, QtGui, QtWidgets


class Ui_About(object):
Expand All @@ -17,8 +15,8 @@ def setupUi(self, About):
About.resize(402, 222)
self.verticalLayout = QtWidgets.QVBoxLayout(About)
self.verticalLayout.setObjectName("verticalLayout")
self.labelTitle = QtWidgets.QLabel(About)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Minimum)
self.labelTitle = QtWidgets.QLabel(parent=About)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Preferred, QtWidgets.QSizePolicy.Policy.Minimum)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.labelTitle.sizePolicy().hasHeightForWidth())
Expand All @@ -29,29 +27,29 @@ def setupUi(self, About):
font.setWeight(75)
self.labelTitle.setFont(font)
self.labelTitle.setText("CherryTomato")
self.labelTitle.setAlignment(QtCore.Qt.AlignHCenter|QtCore.Qt.AlignTop)
self.labelTitle.setAlignment(QtCore.Qt.AlignmentFlag.AlignHCenter|QtCore.Qt.AlignmentFlag.AlignTop)
self.labelTitle.setObjectName("labelTitle")
self.verticalLayout.addWidget(self.labelTitle)
self.labelText = QtWidgets.QLabel(About)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.MinimumExpanding)
self.labelText = QtWidgets.QLabel(parent=About)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Preferred, QtWidgets.QSizePolicy.Policy.MinimumExpanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(1)
sizePolicy.setHeightForWidth(self.labelText.sizePolicy().hasHeightForWidth())
self.labelText.setSizePolicy(sizePolicy)
self.labelText.setTextFormat(QtCore.Qt.RichText)
self.labelText.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignTop)
self.labelText.setTextFormat(QtCore.Qt.TextFormat.RichText)
self.labelText.setAlignment(QtCore.Qt.AlignmentFlag.AlignLeading|QtCore.Qt.AlignmentFlag.AlignLeft|QtCore.Qt.AlignmentFlag.AlignTop)
self.labelText.setWordWrap(True)
self.labelText.setOpenExternalLinks(True)
self.labelText.setObjectName("labelText")
self.verticalLayout.addWidget(self.labelText)
self.labelCopyright = QtWidgets.QLabel(About)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Minimum)
self.labelCopyright = QtWidgets.QLabel(parent=About)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Preferred, QtWidgets.QSizePolicy.Policy.Minimum)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.labelCopyright.sizePolicy().hasHeightForWidth())
self.labelCopyright.setSizePolicy(sizePolicy)
self.labelCopyright.setText("Copyright © 2019-2020 yakimka")
self.labelCopyright.setAlignment(QtCore.Qt.AlignBottom|QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft)
self.labelCopyright.setAlignment(QtCore.Qt.AlignmentFlag.AlignBottom|QtCore.Qt.AlignmentFlag.AlignLeading|QtCore.Qt.AlignmentFlag.AlignLeft)
self.labelCopyright.setObjectName("labelCopyright")
self.verticalLayout.addWidget(self.labelCopyright)

Expand Down
8 changes: 4 additions & 4 deletions CherryTomato/about_window.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from PyQt5 import Qt
from PyQt5 import QtWidgets
from PyQt5.QtGui import QIcon
from PyQt6 import QtWidgets
from PyQt6.QtCore import Qt
from PyQt6.QtGui import QIcon

from CherryTomato import APP_ICON, __version__ as VERSION
from CherryTomato.about_ui import Ui_About
Expand All @@ -18,7 +18,7 @@ def __init__(self):
self.setWindowIcon(QIcon(APP_ICON))

def keyPressEvent(self, event):
if event.key() == Qt.Qt.Key_Escape:
if event.key() == Qt.Key.Key_Escape:
self.close()
else:
super().keyPressEvent(event)
11 changes: 5 additions & 6 deletions CherryTomato/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
import logging
import sys

from PyQt5 import Qt
from PyQt5.QtCore import QCoreApplication
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QSystemTrayIcon, QMenu, QAction
from PyQt6.QtCore import QCoreApplication
from PyQt6.QtGui import QIcon, QAction
from PyQt6.QtWidgets import QSystemTrayIcon, QMenu, QApplication

from CherryTomato import ORGANIZATION_NAME, APPLICATION_NAME, APP_ICON
from CherryTomato.main_window import CherryTomatoMainWindow
Expand Down Expand Up @@ -50,7 +49,7 @@ def main():
QCoreApplication.setOrganizationName(ORGANIZATION_NAME)
QCoreApplication.setApplicationName(APPLICATION_NAME)

app = Qt.QApplication(sys.argv)
app = QApplication(sys.argv)

# https://bugs.documentfoundation.org/show_bug.cgi?id=125934
app.setDesktopFileName('cherrytomato.desktop')
Expand All @@ -75,7 +74,7 @@ def main():

watch.show()

app.exec_()
app.exec()


if __name__ == '__main__':
Expand Down
30 changes: 14 additions & 16 deletions CherryTomato/main_ui.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'CherryTomato/main_ui.ui'
#
# Created by: PyQt5 UI code generator 5.15.1
# Created by: PyQt6 UI code generator 6.5.2
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# WARNING: Any manual changes made to this file will be lost when pyuic6 is
# run again. Do not edit this file unless you know what you are doing.


from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt6 import QtCore, QtGui, QtWidgets


class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget = QtWidgets.QWidget(parent=MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget)
self.verticalLayout.setContentsMargins(15, 15, 15, 60)
self.verticalLayout.setObjectName("verticalLayout")
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setContentsMargins(-1, -1, -1, 40)
self.horizontalLayout.setObjectName("horizontalLayout")
self.progress = QRoundProgressBar(self.centralwidget)
self.progress = QRoundProgressBar(parent=self.centralwidget)
self.progress.setMinimumSize(QtCore.QSize(200, 200))
self.progress.setObjectName("progress")
self.horizontalLayout.addWidget(self.progress)
self.verticalLayout.addLayout(self.horizontalLayout)
self.button = QRoundPushbutton(self.centralwidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
self.button = QRoundPushbutton(parent=self.centralwidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Fixed, QtWidgets.QSizePolicy.Policy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.button.sizePolicy().hasHeightForWidth())
Expand All @@ -44,21 +42,21 @@ def setupUi(self, MainWindow):
self.button.setText("")
self.button.setFlat(True)
self.button.setObjectName("button")
self.verticalLayout.addWidget(self.button, 0, QtCore.Qt.AlignHCenter)
self.verticalLayout.addWidget(self.button, 0, QtCore.Qt.AlignmentFlag.AlignHCenter)
MainWindow.setCentralWidget(self.centralwidget)
self.menuBar = QtWidgets.QMenuBar(MainWindow)
self.menuBar = QtWidgets.QMenuBar(parent=MainWindow)
self.menuBar.setGeometry(QtCore.QRect(0, 0, 800, 30))
self.menuBar.setObjectName("menuBar")
self.menuFile = QtWidgets.QMenu(self.menuBar)
self.menuFile = QtWidgets.QMenu(parent=self.menuBar)
self.menuFile.setObjectName("menuFile")
MainWindow.setMenuBar(self.menuBar)
self.actionAbout = QtWidgets.QAction(MainWindow)
self.actionAbout = QtGui.QAction(parent=MainWindow)
self.actionAbout.setObjectName("actionAbout")
self.actionSettings = QtWidgets.QAction(MainWindow)
self.actionSettings = QtGui.QAction(parent=MainWindow)
self.actionSettings.setObjectName("actionSettings")
self.actionReset = QtWidgets.QAction(MainWindow)
self.actionReset = QtGui.QAction(parent=MainWindow)
self.actionReset.setObjectName("actionReset")
self.actionQuit = QtWidgets.QAction(MainWindow)
self.actionQuit = QtGui.QAction(parent=MainWindow)
self.actionQuit.setObjectName("actionQuit")
self.menuFile.addAction(self.actionReset)
self.menuFile.addAction(self.actionSettings)
Expand Down
40 changes: 21 additions & 19 deletions CherryTomato/main_window.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import os
from functools import lru_cache

from PyQt5 import Qt, QtCore
from PyQt5.QtCore import QCoreApplication
from PyQt5.QtGui import QBrush, QColor, QPalette, QIcon, QKeySequence
from PyQt5.QtMultimedia import QSound
from PyQt6 import QtCore
from PyQt6.QtCore import QCoreApplication, Qt, pyqtSlot
from PyQt6.QtGui import QBrush, QColor, QPalette, QIcon, QKeySequence
from PyQt6.QtMultimedia import QSoundEffect
from PyQt6.QtWidgets import QMainWindow

from CherryTomato import about_window, APP_ICON, MEDIA_DIR, settings_window
from CherryTomato.main_ui import Ui_MainWindow
from CherryTomato.timer_proxy import AbstractTimerProxy
from CherryTomato.utils import classLogger


class CherryTomatoMainWindow(Qt.QMainWindow, Ui_MainWindow):
class CherryTomatoMainWindow(QMainWindow, Ui_MainWindow):
def __init__(self, timerProxy: AbstractTimerProxy, settings, parent=None):
super().__init__(parent=parent)
self.logger = classLogger(__name__, self.__class__.__name__)
Expand Down Expand Up @@ -87,7 +87,7 @@ def getWindowCenterPoint(self, window):

return centerX, centerY

@Qt.pyqtSlot(name='display')
@pyqtSlot(name='display')
def display(self):
self.progress.useSystemFont = self.settings.useSystemFont
self.progress.setFormat(self.timerProxy.getUpperText())
Expand All @@ -105,33 +105,35 @@ def changeButtonState(self):
@lru_cache(maxsize=1)
def setColor(self, base: tuple, highlight: tuple):
base_brush = QBrush(QColor(*base))
base_brush.setStyle(QtCore.Qt.SolidPattern)
base_brush.setStyle(Qt.BrushStyle.SolidPattern)
highlight_brush = QBrush(QColor(*highlight))
highlight_brush.setStyle(QtCore.Qt.SolidPattern)
highlight_brush.setStyle(Qt.BrushStyle.SolidPattern)

palette = QPalette()
palette.setBrush(QPalette.Active, QPalette.Base, base_brush)
palette.setBrush(QPalette.Inactive, QPalette.Base, base_brush)
palette.setBrush(QPalette.Active, QPalette.Highlight, highlight_brush)
palette.setBrush(QPalette.Inactive, QPalette.Highlight, highlight_brush)
palette.setBrush(QPalette.Text, highlight_brush)
palette.setBrush(QPalette.ColorGroup.Active, QPalette.ColorRole.Base, base_brush)
palette.setBrush(QPalette.ColorGroup.Inactive, QPalette.ColorRole.Base, base_brush)
palette.setBrush(QPalette.ColorGroup.Active, QPalette.ColorRole.Highlight, highlight_brush)
palette.setBrush(QPalette.ColorGroup.Inactive, QPalette.ColorRole.Highlight, highlight_brush)
palette.setBrush(QPalette.ColorRole.Text, highlight_brush)

self.progress.setPalette(palette)
self.button.setColor(highlight)

@Qt.pyqtSlot(name='setFocusOnWindow')
@pyqtSlot(name='setFocusOnWindow')
def setFocusOnWindow(self):
self.show()
self.activateWindow()
self.raise_()

@Qt.pyqtSlot(name='setFocusOnWindowAndPlayNotification')
@pyqtSlot(name='setFocusOnWindowAndPlayNotification')
def setFocusOnWindowAndPlayNotification(self):
if self.settings.interrupt:
self.setFocusOnWindow()
if self.windowState() == QtCore.Qt.WindowMinimized:
if self.windowState() == QtCore.Qt.WindowState.WindowMinimized:
# Window is minimised. Restore it.
self.setWindowState(QtCore.Qt.WindowNoState)
self.setWindowState(QtCore.Qt.WindowState.WindowNoState)

if self.settings.notification:
QSound.play(os.path.join(MEDIA_DIR, 'sound.wav'))
sound_effect = QSoundEffect()
sound_effect.setSource(QtCore.QUrl.fromLocalFile(os.path.join(MEDIA_DIR, 'sound.wav')))
sound_effect.play()
2 changes: 1 addition & 1 deletion CherryTomato/settings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from PyQt5.QtCore import QSettings, QSize, QPoint
from PyQt6.QtCore import QSettings, QSize, QPoint

STATE_TOMATO = 'stateTomato'
STATE_BREAK = 'stateBreak'
Expand Down
Loading

0 comments on commit dfa403e

Please sign in to comment.