Skip to content

Commit

Permalink
fix Python API compatibility (qgis#58860)
Browse files Browse the repository at this point in the history
* fix Python API compatibility

* Update qgis.h
  • Loading branch information
3nids authored Sep 25, 2024
1 parent 6d4e343 commit eafa4b4
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 14 deletions.
23 changes: 17 additions & 6 deletions python/PyQt6/core/auto_additions/qgis.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,12 +727,23 @@
Qgis.VectorLayerTypeFlags = lambda flags=0: Qgis.VectorLayerTypeFlag(flags)
Qgis.VectorLayerTypeFlags.baseClass = Qgis
VectorLayerTypeFlags = Qgis # dirty hack since SIP seems to introduce the flags in module
# monkey patching scoped based enum
Qgis.PythonEmbeddedMode.Never.__doc__ = "Python embedded never run"
Qgis.PythonEmbeddedMode.Ask.__doc__ = "User is prompt before running"
Qgis.PythonEmbeddedMode.SessionOnly.__doc__ = "Only during this session"
Qgis.PythonEmbeddedMode.Always.__doc__ = "Python embedded is always run"
Qgis.PythonEmbeddedMode.NotForThisSession.__doc__ = "Python embedded will not be run for this session"
Qgis.PythonMacroMode = Qgis.PythonEmbeddedMode
# monkey patching scoped based enum
Qgis.Never = Qgis.PythonEmbeddedMode.Never
Qgis.Never.is_monkey_patched = True
Qgis.Never.__doc__ = "Python embedded never run"
Qgis.Ask = Qgis.PythonEmbeddedMode.Ask
Qgis.Ask.is_monkey_patched = True
Qgis.Ask.__doc__ = "User is prompt before running"
Qgis.SessionOnly = Qgis.PythonEmbeddedMode.SessionOnly
Qgis.SessionOnly.is_monkey_patched = True
Qgis.SessionOnly.__doc__ = "Only during this session"
Qgis.Always = Qgis.PythonEmbeddedMode.Always
Qgis.Always.is_monkey_patched = True
Qgis.Always.__doc__ = "Python embedded is always run"
Qgis.NotForThisSession = Qgis.PythonEmbeddedMode.NotForThisSession
Qgis.NotForThisSession.is_monkey_patched = True
Qgis.NotForThisSession.__doc__ = "Python embedded will not be run for this session"
Qgis.PythonEmbeddedMode.__doc__ = """Authorisation to run Python Embedded in projects

.. versionadded:: 3.40
Expand Down
2 changes: 2 additions & 0 deletions python/core/__init__.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ QgsProviderMetadata = PyProviderMetadata

# monkey patch deprecated enum values to maintain API
# TODO - remove for QGIS 4.0
Qgis.PythonMacroMode = Qgis.PythonEmbeddedMode

QgsMarkerLineSymbolLayer.Interval = Qgis.MarkerLinePlacement.Interval
QgsMarkerLineSymbolLayer.Vertex = Qgis.MarkerLinePlacement.Vertex
QgsMarkerLineSymbolLayer.LastVertex = Qgis.MarkerLinePlacement.LastVertex
Expand Down
23 changes: 17 additions & 6 deletions python/core/auto_additions/qgis.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,12 +718,23 @@
Qgis.VectorLayerTypeFlag.baseClass = Qgis
Qgis.VectorLayerTypeFlags.baseClass = Qgis
VectorLayerTypeFlags = Qgis # dirty hack since SIP seems to introduce the flags in module
# monkey patching scoped based enum
Qgis.PythonEmbeddedMode.Never.__doc__ = "Python embedded never run"
Qgis.PythonEmbeddedMode.Ask.__doc__ = "User is prompt before running"
Qgis.PythonEmbeddedMode.SessionOnly.__doc__ = "Only during this session"
Qgis.PythonEmbeddedMode.Always.__doc__ = "Python embedded is always run"
Qgis.PythonEmbeddedMode.NotForThisSession.__doc__ = "Python embedded will not be run for this session"
Qgis.PythonMacroMode = Qgis.PythonEmbeddedMode
# monkey patching scoped based enum
Qgis.Never = Qgis.PythonEmbeddedMode.Never
Qgis.Never.is_monkey_patched = True
Qgis.Never.__doc__ = "Python embedded never run"
Qgis.Ask = Qgis.PythonEmbeddedMode.Ask
Qgis.Ask.is_monkey_patched = True
Qgis.Ask.__doc__ = "User is prompt before running"
Qgis.SessionOnly = Qgis.PythonEmbeddedMode.SessionOnly
Qgis.SessionOnly.is_monkey_patched = True
Qgis.SessionOnly.__doc__ = "Only during this session"
Qgis.Always = Qgis.PythonEmbeddedMode.Always
Qgis.Always.is_monkey_patched = True
Qgis.Always.__doc__ = "Python embedded is always run"
Qgis.NotForThisSession = Qgis.PythonEmbeddedMode.NotForThisSession
Qgis.NotForThisSession.is_monkey_patched = True
Qgis.NotForThisSession.__doc__ = "Python embedded will not be run for this session"
Qgis.PythonEmbeddedMode.__doc__ = """Authorisation to run Python Embedded in projects

.. versionadded:: 3.40
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgis.h
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,8 @@ class CORE_EXPORT Qgis
* Authorisation to run Python Embedded in projects
* \since QGIS 3.40
*/
enum class PythonEmbeddedMode : int
{
enum class PythonEmbeddedMode SIP_MONKEYPATCH_SCOPEENUM_UNNEST( Qgis, PythonMacroMode ) : int
{
Never = 0, //!< Python embedded never run
Ask = 1, //!< User is prompt before running
SessionOnly = 2, //!< Only during this session
Expand Down

0 comments on commit eafa4b4

Please sign in to comment.