Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Make QIcon.ThemeIcon enum for Qt < 6.7 #503

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
166 changes: 166 additions & 0 deletions qtpy/QtGui.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,169 @@ 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"):
# 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(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
10 changes: 10 additions & 0 deletions qtpy/tests/test_qtgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Loading