From 32ee71b019b74ab9d59ba0a23c02d3a8f25f4609 Mon Sep 17 00:00:00 2001 From: Mark Harfouche Date: Tue, 25 Jun 2024 20:36:28 -0400 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Carlos Cordoba --- spyder/plugins/help/widgets.py | 11 +++++++---- spyder/plugins/ipythonconsole/widgets/main_widget.py | 10 ++++++---- spyder/plugins/onlinehelp/widgets.py | 12 ++++++++---- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/spyder/plugins/help/widgets.py b/spyder/plugins/help/widgets.py index dfe4d48ef23..7a164907029 100644 --- a/spyder/plugins/help/widgets.py +++ b/spyder/plugins/help/widgets.py @@ -17,10 +17,6 @@ from qtpy import PYQT5, PYQT6 from qtpy.QtCore import Qt, QUrl, Signal, Slot, QPoint from qtpy.QtGui import QColor -try: - from qtpy.QtWebEngineWidgets import WEBENGINE -except ImportError: - WEBENGINE = False from qtpy.QtWidgets import (QActionGroup, QLabel, QLineEdit, QMessageBox, QSizePolicy, QStackedWidget, QVBoxLayout, QWidget) @@ -44,6 +40,12 @@ from spyder.widgets.findreplace import FindReplace from spyder.widgets.simplecodeeditor import SimpleCodeEditor +# In case WebEngine is not available (e.g. in Conda-forge) +try: + from qtpy.QtWebEngineWidgets import WEBENGINE +except ImportError: + WEBENGINE = False + # --- Constants # ---------------------------------------------------------------------------- @@ -159,6 +161,7 @@ def __init__(self, parent): else: QWidget.__init__(self, parent) SpyderWidgetMixin.__init__(self, class_parent=parent) + from qtpy.QtWebEngineWidgets import QWebEnginePage from spyder.widgets.browser import FrameWebView diff --git a/spyder/plugins/ipythonconsole/widgets/main_widget.py b/spyder/plugins/ipythonconsole/widgets/main_widget.py index a8fd49c7df9..091a119d77e 100644 --- a/spyder/plugins/ipythonconsole/widgets/main_widget.py +++ b/spyder/plugins/ipythonconsole/widgets/main_widget.py @@ -25,10 +25,6 @@ from qtpy.QtCore import Signal, Slot from qtpy.QtGui import QColor, QKeySequence from qtpy.QtPrintSupport import QPrintDialog, QPrinter -try: - from qtpy.QtWebEngineWidgets import WEBENGINE -except ImportError: - WEBENGINE = False from qtpy.QtWidgets import ( QApplication, QHBoxLayout, QLabel, QMessageBox, QVBoxLayout, QWidget) from traitlets.config.loader import Config, load_pyconfig_files @@ -65,6 +61,12 @@ from spyder.widgets.tabs import Tabs from spyder.widgets.printer import SpyderPrinter +# In case WebEngine is not available (e.g. in Conda-forge) +try: + from qtpy.QtWebEngineWidgets import WEBENGINE +except ImportError: + WEBENGINE = False + # Logging logger = logging.getLogger(__name__) diff --git a/spyder/plugins/onlinehelp/widgets.py b/spyder/plugins/onlinehelp/widgets.py index beb039e2d86..9fa56999bd8 100644 --- a/spyder/plugins/onlinehelp/widgets.py +++ b/spyder/plugins/onlinehelp/widgets.py @@ -17,10 +17,6 @@ # Third party imports from qtpy.QtCore import Qt, QThread, QUrl, Signal, Slot from qtpy.QtGui import QCursor -try: - from qtpy.QtWebEngineWidgets import WEBENGINE -except ImportError: - WEBENGINE = False from qtpy.QtWidgets import QApplication, QLabel, QVBoxLayout # Local imports @@ -30,6 +26,12 @@ from spyder.widgets.comboboxes import UrlComboBox from spyder.widgets.findreplace import FindReplace +# In case WebEngine is not available (e.g. in Conda-forge) +try: + from qtpy.QtWebEngineWidgets import WEBENGINE +except ImportError: + WEBENGINE = False + # --- Constants # ---------------------------------------------------------------------------- @@ -248,6 +250,7 @@ def setup(self): def update_actions(self): from spyder.widgets.browser import WebViewActions + stop_action = self.get_action(WebViewActions.Stop) refresh_action = self.get_action(WebViewActions.Refresh) @@ -277,6 +280,7 @@ def _continue_initialization(self): def _handle_url_combo_activation(self): """Load URL from combo box first item.""" from spyder.widgets.browser import WebViewActions + if not self._is_running: text = str(self.url_combo.currentText()) self.go_to(self.text_to_url(text))