You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

157 lines
8.3 KiB

4 years ago
  1. # -*- coding: utf-8 -*-
  2. #
  3. # Copyright © 2014-2015 Colin Duquesnoy
  4. # Copyright © 2009- The Spyder Development Team
  5. #
  6. # Licensed under the terms of the MIT License
  7. # (see LICENSE.txt for details)
  8. """
  9. Provides QtGui classes and functions.
  10. .. warning:: Only PyQt4/PySide QtGui classes compatible with PyQt5.QtGui are
  11. exposed here. Therefore, you need to treat/use this package as if it were
  12. the ``PyQt5.QtGui`` module.
  13. """
  14. import warnings
  15. from . import PYQT5, PYQT4, PYSIDE, PYSIDE2, PythonQtError
  16. if PYQT5:
  17. from PyQt5.QtGui import *
  18. elif PYSIDE2:
  19. from PySide2.QtGui import *
  20. elif PYQT4:
  21. try:
  22. # Older versions of PyQt4 do not provide these
  23. from PyQt4.QtGui import (QGlyphRun, QMatrix2x2, QMatrix2x3,
  24. QMatrix2x4, QMatrix3x2, QMatrix3x3,
  25. QMatrix3x4, QMatrix4x2, QMatrix4x3,
  26. QMatrix4x4, QTouchEvent, QQuaternion,
  27. QRadialGradient, QRawFont, QStaticText,
  28. QVector2D, QVector3D, QVector4D,
  29. qFuzzyCompare)
  30. except ImportError:
  31. pass
  32. from PyQt4.Qt import QKeySequence, QTextCursor
  33. from PyQt4.QtGui import (QAbstractTextDocumentLayout, QActionEvent, QBitmap,
  34. QBrush, QClipboard, QCloseEvent, QColor,
  35. QConicalGradient, QContextMenuEvent, QCursor,
  36. QDoubleValidator, QDrag,
  37. QDragEnterEvent, QDragLeaveEvent, QDragMoveEvent,
  38. QDropEvent, QFileOpenEvent, QFocusEvent, QFont,
  39. QFontDatabase, QFontInfo, QFontMetrics,
  40. QFontMetricsF, QGradient, QHelpEvent,
  41. QHideEvent, QHoverEvent, QIcon, QIconDragEvent,
  42. QIconEngine, QImage, QImageIOHandler, QImageReader,
  43. QImageWriter, QInputEvent, QInputMethodEvent,
  44. QKeyEvent, QLinearGradient,
  45. QMouseEvent, QMoveEvent, QMovie,
  46. QPaintDevice, QPaintEngine, QPaintEngineState,
  47. QPaintEvent, QPainter, QPainterPath,
  48. QPainterPathStroker, QPalette, QPen, QPicture,
  49. QPictureIO, QPixmap, QPixmapCache, QPolygon,
  50. QPolygonF, QRegExpValidator, QRegion, QResizeEvent,
  51. QSessionManager, QShortcutEvent, QShowEvent,
  52. QStandardItem, QStandardItemModel,
  53. QStatusTipEvent, QSyntaxHighlighter, QTabletEvent,
  54. QTextBlock, QTextBlockFormat, QTextBlockGroup,
  55. QTextBlockUserData, QTextCharFormat,
  56. QTextDocument, QTextDocumentFragment,
  57. QTextDocumentWriter, QTextFormat, QTextFragment,
  58. QTextFrame, QTextFrameFormat, QTextImageFormat,
  59. QTextInlineObject, QTextItem, QTextLayout,
  60. QTextLength, QTextLine, QTextList, QTextListFormat,
  61. QTextObject, QTextObjectInterface, QTextOption,
  62. QTextTable, QTextTableCell, QTextTableCellFormat,
  63. QTextTableFormat, QTransform,
  64. QValidator, QWhatsThisClickedEvent, QWheelEvent,
  65. QWindowStateChangeEvent, qAlpha, qBlue,
  66. qGray, qGreen, qIsGray, qRed, qRgb,
  67. qRgba, QIntValidator)
  68. # QDesktopServices has has been split into (QDesktopServices and
  69. # QStandardPaths) in Qt5
  70. # It only exposes QDesktopServices that are still in pyqt5
  71. from PyQt4.QtGui import QDesktopServices as _QDesktopServices
  72. class QDesktopServices():
  73. openUrl = _QDesktopServices.openUrl
  74. setUrlHandler = _QDesktopServices.setUrlHandler
  75. unsetUrlHandler = _QDesktopServices.unsetUrlHandler
  76. def __getattr__(self, name):
  77. attr = getattr(_QDesktopServices, name)
  78. new_name = name
  79. if name == 'storageLocation':
  80. new_name = 'writableLocation'
  81. warnings.warn(("Warning QDesktopServices.{} is deprecated in Qt5"
  82. "we recommend you use QDesktopServices.{} instead").format(name, new_name),
  83. DeprecationWarning)
  84. return attr
  85. QDesktopServices = QDesktopServices()
  86. elif PYSIDE:
  87. from PySide.QtGui import (QAbstractTextDocumentLayout, QActionEvent, QBitmap,
  88. QBrush, QClipboard, QCloseEvent, QColor,
  89. QConicalGradient, QContextMenuEvent, QCursor,
  90. QDoubleValidator, QDrag,
  91. QDragEnterEvent, QDragLeaveEvent, QDragMoveEvent,
  92. QDropEvent, QFileOpenEvent, QFocusEvent, QFont,
  93. QFontDatabase, QFontInfo, QFontMetrics,
  94. QFontMetricsF, QGradient, QHelpEvent,
  95. QHideEvent, QHoverEvent, QIcon, QIconDragEvent,
  96. QIconEngine, QImage, QImageIOHandler, QImageReader,
  97. QImageWriter, QInputEvent, QInputMethodEvent,
  98. QKeyEvent, QKeySequence, QLinearGradient,
  99. QMatrix2x2, QMatrix2x3, QMatrix2x4, QMatrix3x2,
  100. QMatrix3x3, QMatrix3x4, QMatrix4x2, QMatrix4x3,
  101. QMatrix4x4, QMouseEvent, QMoveEvent, QMovie,
  102. QPaintDevice, QPaintEngine, QPaintEngineState,
  103. QPaintEvent, QPainter, QPainterPath,
  104. QPainterPathStroker, QPalette, QPen, QPicture,
  105. QPictureIO, QPixmap, QPixmapCache, QPolygon,
  106. QPolygonF, QQuaternion, QRadialGradient,
  107. QRegExpValidator, QRegion, QResizeEvent,
  108. QSessionManager, QShortcutEvent, QShowEvent,
  109. QStandardItem, QStandardItemModel,
  110. QStatusTipEvent, QSyntaxHighlighter, QTabletEvent,
  111. QTextBlock, QTextBlockFormat, QTextBlockGroup,
  112. QTextBlockUserData, QTextCharFormat, QTextCursor,
  113. QTextDocument, QTextDocumentFragment,
  114. QTextFormat, QTextFragment,
  115. QTextFrame, QTextFrameFormat, QTextImageFormat,
  116. QTextInlineObject, QTextItem, QTextLayout,
  117. QTextLength, QTextLine, QTextList, QTextListFormat,
  118. QTextObject, QTextObjectInterface, QTextOption,
  119. QTextTable, QTextTableCell, QTextTableCellFormat,
  120. QTextTableFormat, QTouchEvent, QTransform,
  121. QValidator, QVector2D, QVector3D, QVector4D,
  122. QWhatsThisClickedEvent, QWheelEvent,
  123. QWindowStateChangeEvent, qAlpha, qBlue,
  124. qGray, qGreen, qIsGray, qRed, qRgb, qRgba,
  125. QIntValidator)
  126. # QDesktopServices has has been split into (QDesktopServices and
  127. # QStandardPaths) in Qt5
  128. # It only exposes QDesktopServices that are still in pyqt5
  129. from PySide.QtGui import QDesktopServices as _QDesktopServices
  130. class QDesktopServices():
  131. openUrl = _QDesktopServices.openUrl
  132. setUrlHandler = _QDesktopServices.setUrlHandler
  133. unsetUrlHandler = _QDesktopServices.unsetUrlHandler
  134. def __getattr__(self, name):
  135. attr = getattr(_QDesktopServices, name)
  136. new_name = name
  137. if name == 'storageLocation':
  138. new_name = 'writableLocation'
  139. warnings.warn(("Warning QDesktopServices.{} is deprecated in Qt5"
  140. "we recommend you use QDesktopServices.{} instead").format(name, new_name),
  141. DeprecationWarning)
  142. return attr
  143. QDesktopServices = QDesktopServices()
  144. else:
  145. raise PythonQtError('No Qt bindings could be found')