From 56ebe60f8bd7d93f61e9acabd96b06149f316793 Mon Sep 17 00:00:00 2001 From: StSav012 Date: Fri, 29 Nov 2024 12:54:18 +0300 Subject: [PATCH 1/3] Make `QIcon.ThemeIcon` enum for Qt < 6.7 --- qtpy/QtGui.py | 159 +++++++++++++++++++++++++++++++++++++++ qtpy/tests/test_qtgui.py | 10 +++ 2 files changed, 169 insertions(+) diff --git a/qtpy/QtGui.py b/qtpy/QtGui.py index 3e8a4fb3..e4ccff5c 100644 --- a/qtpy/QtGui.py +++ b/qtpy/QtGui.py @@ -301,3 +301,162 @@ def setShortcuts(self, shortcuts): or QAction.setShortcuts is not _action_set_shortcuts ): QAction = _QAction + + +# Make `QIcon.ThemeIcon` enum for Qt < 6.7 +if PYQT5 or PYSIDE2 or parse(_qt_version) < parse("6.7"): + import enum as _enum + + class _ThemeIcon(_enum.StrEnum): + AddressBookNew = "address-book-new" + ApplicationExit = "application-exit" + AppointmentNew = "appointment-new" + CallStart = "call-start" + CallStop = "call-stop" + ContactNew = "contact-new" + DocumentNew = "document-new" + DocumentOpen = "document-open" + DocumentOpenRecent = "document-open-recent" + DocumentPageSetup = "document-page-setup" + DocumentPrint = "document-print" + DocumentPrintPreview = "document-print-preview" + DocumentProperties = "document-properties" + DocumentRevert = "document-revert" + DocumentSave = "document-save" + DocumentSaveAs = "document-save-as" + DocumentSend = "document-send" + EditClear = "edit-clear" + EditCopy = "edit-copy" + EditCut = "edit-cut" + EditDelete = "edit-delete" + EditFind = "edit-find" + EditPaste = "edit-paste" + EditRedo = "edit-redo" + EditSelectAll = "edit-select-all" + EditUndo = "edit-undo" + FolderNew = "folder-new" + FormatIndentLess = "format-indent-less" + FormatIndentMore = "format-indent-more" + FormatJustifyCenter = "format-justify-center" + FormatJustifyFill = "format-justify-fill" + FormatJustifyLeft = "format-justify-left" + FormatJustifyRight = "format-justify-right" + FormatTextDirectionLtr = "format-text-direction-ltr" + FormatTextDirectionRtl = "format-text-direction-rtl" + FormatTextBold = "format-text-bold" + FormatTextItalic = "format-text-italic" + FormatTextUnderline = "format-text-underline" + FormatTextStrikethrough = "format-text-strikethrough" + GoDown = "go-down" + GoHome = "go-home" + GoNext = "go-next" + GoPrevious = "go-previous" + GoUp = "go-up" + HelpAbout = "help-about" + HelpFaq = "help-faq" + InsertImage = "insert-image" + InsertLink = "insert-link" + InsertText = "insert-text" + ListAdd = "list-add" + ListRemove = "list-remove" + MailForward = "mail-forward" + MailMarkImportant = "mail-mark-important" + MailMarkRead = "mail-mark-read" + MailMarkUnread = "mail-mark-unread" + MailMessageNew = "mail-message-new" + MailReplyAll = "mail-reply-all" + MailReplySender = "mail-reply-sender" + MailSend = "mail-send" + MediaEject = "media-eject" + MediaPlaybackPause = "media-playback-pause" + MediaPlaybackStart = "media-playback-start" + MediaPlaybackStop = "media-playback-stop" + MediaRecord = "media-record" + MediaSeekBackward = "media-seek-backward" + MediaSeekForward = "media-seek-forward" + MediaSkipBackward = "media-skip-backward" + MediaSkipForward = "media-skip-forward" + ObjectRotateLeft = "object-rotate-left" + ObjectRotateRight = "object-rotate-right" + ProcessStop = "process-stop" + SystemLockScreen = "system-lock-screen" + SystemLogOut = "system-log-out" + SystemSearch = "system-search" + SystemReboot = "system-reboot" + SystemShutdown = "system-shutdown" + ToolsCheckSpelling = "tools-check-spelling" + ViewFullscreen = "view-fullscreen" + ViewRefresh = "view-refresh" + ViewRestore = "view-restore" + WindowClose = "window-close" + WindowNew = "window-new" + ZoomFitBest = "zoom-fit-best" + ZoomIn = "zoom-in" + ZoomOut = "zoom-out" + AudioCard = "audio-card" + AudioInputMicrophone = "audio-input-microphone" + Battery = "battery" + CameraPhoto = "camera-photo" + CameraVideo = "camera-video" + CameraWeb = "camera-web" + Computer = "computer" + DriveHarddisk = "drive-harddisk" + DriveOptical = "drive-optical" + InputGaming = "input-gaming" + InputKeyboard = "input-keyboard" + InputMouse = "input-mouse" + InputTablet = "input-tablet" + MediaFlash = "media-flash" + MediaOptical = "media-optical" + MediaTape = "media-tape" + MultimediaPlayer = "multimedia-player" + NetworkWired = "network-wired" + NetworkWireless = "network-wireless" + Phone = "phone" + Printer = "printer" + Scanner = "scanner" + VideoDisplay = "video-display" + AppointmentMissed = "appointment-missed" + AppointmentSoon = "appointment-soon" + AudioVolumeHigh = "audio-volume-high" + AudioVolumeLow = "audio-volume-low" + AudioVolumeMedium = "audio-volume-medium" + AudioVolumeMuted = "audio-volume-muted" + BatteryCaution = "battery-caution" + BatteryLow = "battery-low" + DialogError = "dialog-error" + DialogInformation = "dialog-information" + DialogPassword = "dialog-password" + DialogQuestion = "dialog-question" + DialogWarning = "dialog-warning" + FolderDragAccept = "folder-drag-accept" + FolderOpen = "folder-open" + FolderVisiting = "folder-visiting" + ImageLoading = "image-loading" + ImageMissing = "image-missing" + MailAttachment = "mail-attachment" + MailUnread = "mail-unread" + MailRead = "mail-read" + MailReplied = "mail-replied" + MediaPlaylistRepeat = "media-playlist-repeat" + MediaPlaylistShuffle = "media-playlist-shuffle" + NetworkOffline = "network-offline" + PrinterPrinting = "printer-printing" + SecurityHigh = "security-high" + SecurityLow = "security-low" + SoftwareUpdateAvailable = "software-update-available" + SoftwareUpdateUrgent = "software-update-urgent" + SyncError = "sync-error" + SyncSynchronizing = "sync-synchronizing" + UserAvailable = "user-available" + UserOffline = "user-offline" + WeatherClear = "weather-clear" + WeatherClearNight = "weather-clear-night" + WeatherFewClouds = "weather-few-clouds" + WeatherFewCloudsNight = "weather-few-clouds-night" + WeatherFog = "weather-fog" + WeatherShowers = "weather-showers" + WeatherSnow = "weather-snow" + WeatherStorm = "weather-storm" + + QIcon.ThemeIcon = _ThemeIcon diff --git a/qtpy/tests/test_qtgui.py b/qtpy/tests/test_qtgui.py index 23fc0158..51972943 100644 --- a/qtpy/tests/test_qtgui.py +++ b/qtpy/tests/test_qtgui.py @@ -236,3 +236,13 @@ def test_opengl_imports(): assert QtGui.QOpenGLVersionProfile is not None assert QtGui.QOpenGLVertexArrayObject is not None assert QtGui.QOpenGLWindow is not None + + +@pytest.mark.skipif( + PYQT5 and PYQT_VERSION.startswith("5.9"), + reason="A specific setup with at least sip 4.9.9 is needed for PyQt5 5.9.*" + "to work with scoped enum access", + ) +def test_theme_icon_enum(): + """Test `QIcon.ThemeIcon` presence and work.""" + QtGui.QIcon.fromTheme(QtGui.QIcon.ThemeIcon.AddressBookNew) From 3398e00379c530400d5ceea1b773439b6195c73c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 29 Nov 2024 10:31:02 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- qtpy/tests/test_qtgui.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qtpy/tests/test_qtgui.py b/qtpy/tests/test_qtgui.py index 51972943..938c40ff 100644 --- a/qtpy/tests/test_qtgui.py +++ b/qtpy/tests/test_qtgui.py @@ -241,8 +241,8 @@ def test_opengl_imports(): @pytest.mark.skipif( PYQT5 and PYQT_VERSION.startswith("5.9"), reason="A specific setup with at least sip 4.9.9 is needed for PyQt5 5.9.*" - "to work with scoped enum access", - ) + "to work with scoped enum access", +) def test_theme_icon_enum(): """Test `QIcon.ThemeIcon` presence and work.""" QtGui.QIcon.fromTheme(QtGui.QIcon.ThemeIcon.AddressBookNew) From 12d1f3149a9e5bad86fd394b19b8d742ed8dcb95 Mon Sep 17 00:00:00 2001 From: StSav012 Date: Fri, 29 Nov 2024 13:53:03 +0300 Subject: [PATCH 3/3] Make an `StrEnum` for Python < 3.11 --- qtpy/QtGui.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/qtpy/QtGui.py b/qtpy/QtGui.py index e4ccff5c..12d29d54 100644 --- a/qtpy/QtGui.py +++ b/qtpy/QtGui.py @@ -305,9 +305,16 @@ def setShortcuts(self, shortcuts): # Make `QIcon.ThemeIcon` enum for Qt < 6.7 if PYQT5 or PYSIDE2 or parse(_qt_version) < parse("6.7"): - import enum as _enum + # Make an `StrEnum` for Python < 3.11 + try: + from enum import StrEnum + except ImportError: + from enum import Enum + + class StrEnum(str, Enum): + pass - class _ThemeIcon(_enum.StrEnum): + class _ThemeIcon(StrEnum): AddressBookNew = "address-book-new" ApplicationExit = "application-exit" AppointmentNew = "appointment-new"