Skip to content

Commit

Permalink
Python Console: Don't throw exception if compiled without 3D
Browse files Browse the repository at this point in the history
Fixes #49987
  • Loading branch information
kannes authored and nyalldawson committed Sep 3, 2022
1 parent dd4e7b4 commit ccb46e7
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions python/console/console_sci.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,37 @@

from .ui_console_history_dlg import Ui_HistoryDialogPythonConsole

_init_commands = ["import sys", "import os", "from pathlib import Path", "import re", "import math", "from qgis.core import *",
"from qgis.gui import *", "from qgis.analysis import *", "from qgis._3d import *",
"import processing", "import qgis.utils",
"from qgis.utils import iface", "from qgis.PyQt.QtCore import *", "from qgis.PyQt.QtGui import *",
"from qgis.PyQt.QtWidgets import *",
"from qgis.PyQt.QtNetwork import *", "from qgis.PyQt.QtXml import *"]
_historyFile = os.path.join(QgsApplication.qgisSettingsDirPath(), "console_history.txt")

_init_statements = [
# Python
"import sys",
"import os",
"from pathlib import Path",
"import re",
"import math",
# QGIS
"from qgis.core import *",
"from qgis.gui import *",
"from qgis.analysis import *",
## 3D might not be compiled in
"""
try:
from qgis._3d import *
except ModuleNotFoundError:
pass
""",
"import processing",
"import qgis.utils",
"from qgis.utils import iface",
# Qt
"from qgis.PyQt.QtCore import *",
"from qgis.PyQt.QtGui import *",
"from qgis.PyQt.QtWidgets import *",
"from qgis.PyQt.QtNetwork import *",
"from qgis.PyQt.QtXml import *",
]


class ShellScintilla(QgsCodeEditorPython, code.InteractiveInterpreter):

Expand All @@ -69,9 +92,9 @@ def __init__(self, parent=None):

self.displayPrompt(self.continuationLine)

for line in _init_commands:
for statement in _init_statements:
try:
self.runsource(line)
self.runsource(statement)
except ModuleNotFoundError:
pass

Expand Down

0 comments on commit ccb46e7

Please sign in to comment.