# Path: spyder_notebook/utils/localization.py

# 
# Path: spyder_notebook/widgets/dom.py
# class DOMWidget(WebView):
#     """Widget to do DOM manipulations using Javascript."""
# 
#     def __init__(self, parent):
#         """Constructor."""
#         super().__init__(parent)
#         if WEBENGINE:
#             self.dom = self.page()
#         else:
#             self.dom = self.page().mainFrame()
# 
#     def evaluate(self, script):
#         """
#         Evaluate script in page frame.
# 
#         :param script: The script to evaluate.
#         """
#         if WEBENGINE:
#             return self.dom.runJavaScript("{}".format(script))
#         else:
#             return self.dom.evaluateJavaScript("{}".format(script))
# 
#     def mousedown(self, selector, btn=0):
#         """
#         Simulate a mousedown event on the targeted element.
# 
#         :param selector: A CSS3 selector to targeted element.
#         :param btn: The number of mouse button.
#             0 - left button,
#             1 - middle button,
#             2 - right button
#         """
#         return self.evaluate("""
#             (function () {{
#                 var element = document.querySelector({0});
#                 var evt = document.createEvent("MouseEvents");
#                 evt.initMouseEvent("mousedown", true, true, window,
#                                    1, 1, 1, 1, 1, false, false, false, false,
#                                    {1}, element);
#                 return element.dispatchEvent(evt);
#             }})();
#         """.format(repr(selector), repr(btn)))
# 
#     def set_input_value(self, selector, value):
#         """Set the value of the input matched by given selector."""
#         script = 'document.querySelector("%s").setAttribute("value", "%s")'
#         script = script % (selector, value)
#         self.evaluate(script)


import json
import os
import os.path as osp
import sys
import requests
        import webbrowser
from string import Template
from qtpy.QtCore import QUrl, Qt
from qtpy.QtGui import QFontMetrics, QFont
from qtpy.QtWebEngineWidgets import (QWebEnginePage, QWebEngineSettings,
                                     QWebEngineView, WEBENGINE)
from qtpy.QtWidgets import (QApplication, QMenu, QVBoxLayout, QWidget,
                            QMessageBox)
from notebook.utils import url_path_join, url_escape
from spyder.config.base import get_image_path, get_module_source_path
from spyder.utils.qthelpers import add_actions
from spyder.utils import sourcecode
from spyder.widgets.findreplace import FindReplace
from spyder_notebook.utils.localization import _
from spyder_notebook.widgets.dom import DOMWidget
    from spyder.utils.qthelpers import qapplication
    WebView which opens document in an external browser.

    This is a subclass of QWebEngineView, which as soon as the URL is set,
    opens the web page in an external browser and closes itself. It is used
    in NotebookWidget to open links.
    """

    def __init__(self, parent):
        """Construct object."""
        super().__init__(parent)
        self.urlChanged.connect(self.open_in_browser)

    def open_in_browser(self, url):
        """
        Open web page in external browser and close self.

        Parameters
        ----------
        url : QUrl
            URL of web page to open in browser
        """
        try:
            webbrowser.open(url.toString())
        except ValueError:
            # See: spyder-ide/spyder#9849
            pass
        self.stop()
        self.close()



# Path: spyder_notebook/utils/localization.py

# 
# Path: spyder_notebook/widgets/dom.py
# class DOMWidget(WebView):
#     """Widget to do DOM manipulations using Javascript."""
# 
#     def __init__(self, parent):
#         """Constructor."""
#         super().__init__(parent)
#         if WEBENGINE:
#             self.dom = self.page()
#         else:
#             self.dom = self.page().mainFrame()
# 
#     def evaluate(self, script):
#         """
#         Evaluate script in page frame.
# 
#         :param script: The script to evaluate.
#         """
#         if WEBENGINE:
#             return self.dom.runJavaScript("{}".format(script))
#         else:
#             return self.dom.evaluateJavaScript("{}".format(script))
# 
#     def mousedown(self, selector, btn=0):
#         """
#         Simulate a mousedown event on the targeted element.
# 
#         :param selector: A CSS3 selector to targeted element.
#         :param btn: The number of mouse button.
#             0 - left button,
#             1 - middle button,
#             2 - right button
#         """
#         return self.evaluate("""
#             (function () {{
#                 var element = document.querySelector({0});
#                 var evt = document.createEvent("MouseEvents");
#                 evt.initMouseEvent("mousedown", true, true, window,
#                                    1, 1, 1, 1, 1, false, false, false, false,
#                                    {1}, element);
#                 return element.dispatchEvent(evt);
#             }})();
#         """.format(repr(selector), repr(btn)))
# 
#     def set_input_value(self, selector, value):
#         """Set the value of the input matched by given selector."""
#         script = 'document.querySelector("%s").setAttribute("value", "%s")'
#         script = script % (selector, value)
#         self.evaluate(script)


# Path: spyder_notebook/widgets/client.py
import json
import os
import os.path as osp
import sys
import requests
        import webbrowser
from string import Template
from qtpy.QtCore import QUrl, Qt
from qtpy.QtGui import QFontMetrics, QFont
from qtpy.QtWebEngineWidgets import (QWebEnginePage, QWebEngineSettings,
                                     QWebEngineView, WEBENGINE)
from qtpy.QtWidgets import (QApplication, QMenu, QVBoxLayout, QWidget,
                            QMessageBox)
from notebook.utils import url_path_join, url_escape
from spyder.config.base import get_image_path, get_module_source_path
from spyder.utils.qthelpers import add_actions
from spyder.utils import sourcecode
from spyder.widgets.findreplace import FindReplace
from spyder_notebook.utils.localization import _
from spyder_notebook.widgets.dom import DOMWidget
    from spyder.utils.qthelpers import qapplication

    WebView which opens document in an external browser.

    This is a subclass of QWebEngineView, which as soon as the URL is set,
    opens the web page in an external browser and closes itself. It is used
    in NotebookWidget to open links.
    """

    def __init__(self, parent):
        """Construct object."""
        super().__init__(parent)
        self.urlChanged.connect(self.open_in_browser)

    def open_in_browser(self, url):
        """
        Open web page in external browser and close self.

        Parameters
        ----------
        url : QUrl
            URL of web page to open in browser
        """
        try:
            webbrowser.open(url.toString())
        except ValueError:
            # See: spyder-ide/spyder#9849
            pass
        self.stop()
        self.close()



class NotebookWidget(DOMWidget):