From a36708ef6334b053de105fa406458fefc862d899 Mon Sep 17 00:00:00 2001 From: Bob Schumaker Date: Fri, 29 Jul 2022 07:14:23 -0700 Subject: [PATCH 1/3] Add toPython conversion to QDate and QTime. --- qtpy/QtCore.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/qtpy/QtCore.py b/qtpy/QtCore.py index d892c07e..fa68d464 100644 --- a/qtpy/QtCore.py +++ b/qtpy/QtCore.py @@ -21,7 +21,9 @@ # For issue #153 and updated for issue #305 from PyQt5.QtCore import QDateTime + QDate.toPython = lambda self, *args, **kwargs: self.toPyDate(*args, **kwargs) QDateTime.toPython = lambda self, *args, **kwargs: self.toPyDateTime(*args, **kwargs) + QTime.toPython = lambda self, *args, **kwargs: self.toPyTime(*args, **kwargs) # Map missing methods on PyQt5 5.12 QTextStreamManipulator.exec_ = lambda self, *args, **kwargs: self.exec(*args, **kwargs) @@ -39,8 +41,10 @@ from PyQt6.QtCore import QT_VERSION_STR as __version__ # For issue #153 and updated for issue #305 - from PyQt6.QtCore import QDateTime + from PyQt6.QtCore import QDate, QDateTime, QTime + QDate.toPython = lambda self, *args, **kwargs: self.toPyDate(*args, **kwargs) QDateTime.toPython = lambda self, *args, **kwargs: self.toPyDateTime(*args, **kwargs) + QTime.toPython = lambda self, *args, **kwargs: self.toPyTime(*args, **kwargs) # For issue #311 # Seems like there is an error with sip. Without first From 503a07dbd85769c4703f51dab76a44f8407fadf9 Mon Sep 17 00:00:00 2001 From: Bob Schumaker <48453409+bob-schumaker@users.noreply.github.com> Date: Thu, 11 Aug 2022 18:15:59 -0700 Subject: [PATCH 2/3] Update qtpy/QtCore.py Missed a step that didn't get caught in testing for some reason. Co-authored-by: CAM Gerlach --- qtpy/QtCore.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qtpy/QtCore.py b/qtpy/QtCore.py index fa68d464..15ddc042 100644 --- a/qtpy/QtCore.py +++ b/qtpy/QtCore.py @@ -20,7 +20,7 @@ from PyQt5.QtCore import QT_VERSION_STR as __version__ # For issue #153 and updated for issue #305 - from PyQt5.QtCore import QDateTime + from PyQt5.QtCore import QDate, QDateTime, QTime QDate.toPython = lambda self, *args, **kwargs: self.toPyDate(*args, **kwargs) QDateTime.toPython = lambda self, *args, **kwargs: self.toPyDateTime(*args, **kwargs) QTime.toPython = lambda self, *args, **kwargs: self.toPyTime(*args, **kwargs) From f6164b1c9dcf09664c9f64a9a62c4cc97fdd5901 Mon Sep 17 00:00:00 2001 From: Bob Schumaker Date: Fri, 12 Aug 2022 11:08:47 -0700 Subject: [PATCH 3/3] Add tests for new functionality. --- qtpy/tests/test_qtcore.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/qtpy/tests/test_qtcore.py b/qtpy/tests/test_qtcore.py index 7ff60a01..6327ec92 100644 --- a/qtpy/tests/test_qtcore.py +++ b/qtpy/tests/test_qtcore.py @@ -1,6 +1,6 @@ """Test QtCore.""" -from datetime import datetime +from datetime import date, datetime, time import sys import pytest @@ -30,6 +30,22 @@ def test_qdatetime_toPython(): assert isinstance(py_date, datetime) +def test_qdate_toPython(): + """Test QDate.toPython""" + q_date = QtCore.QDate.currentDate() + assert QtCore.QDate.toPython is not None + py_date = q_date.toPython() + assert isinstance(py_date, date) + + +def test_qtime_toPython(): + """Test QTime.toPython""" + q_time = QtCore.QTime.currentTime() + assert QtCore.QTime.toPython is not None + py_time = q_time.toPython() + assert isinstance(py_time, time) + + @pytest.mark.skipif( sys.platform.startswith('linux') and not_using_conda(), reason="Fatal Python error: Aborted on Linux CI when not using conda")