Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Remove deprecated QWebKit code #221

Merged
merged 2 commits into from
Jun 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 27 additions & 39 deletions spyder_terminal/tests/test_terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from qtpy.QtWebEngineWidgets import WEBENGINE
from qtpy.QtWidgets import QMainWindow


os.environ['SPYDER_DEV'] = 'True'

# Local imports
Expand Down Expand Up @@ -46,17 +45,14 @@

def check_pwd(termwidget):
"""Check if pwd command is executed."""
if WEBENGINE:
def callback(data):
global html
html = data
termwidget.body.runJavaScript(PREFIX + "getTerminalLines()", callback)
try:
return LOCATION in html
except NameError:
return False
else:
return LOCATION in termwidget.body.toHtml()
def callback(data):
global html
html = data
termwidget.body.runJavaScript(PREFIX + "getTerminalLines()", callback)
try:
return LOCATION in html
except NameError:
return False


def check_increase_font_size(term):
Expand Down Expand Up @@ -85,37 +81,29 @@ def callback(data):

def check_fonts(term, expected):
"""Check if terminal fonts were updated."""
if WEBENGINE:
def callback(data):
global term_fonts
term_fonts = data
term.body.runJavaScript(PREFIX + "getFonts()", callback)
try:
return term_fonts == expected
except NameError:
return False
else:
fonts = term.get_fonts()
fonts = fonts.replace("'", '"')
return fonts == expected
def callback(data):
global term_fonts
term_fonts = data
term.body.runJavaScript(PREFIX + "getFonts()", callback)
try:
return term_fonts == expected
except NameError:
return False


def check_hex_to_rgb(term):
"""Check if terminal is converting hexa colors to rgb correctly."""
if WEBENGINE:
def callback(data):
global hex_to_rgb
hex_to_rgb = data
expected = 'rgba(170, 171, 33, 0.2)'
color = '#aaab21'
term.body.runJavaScript(PREFIX + "hexToRGB('{}')".format(color),
callback)
try:
return hex_to_rgb == expected
except NameError:
return False
else:
return True
def callback(data):
global hex_to_rgb
hex_to_rgb = data
expected = 'rgba(170, 171, 33, 0.2)'
color = '#aaab21'
term.body.runJavaScript(PREFIX + "hexToRGB('{}')".format(color),
callback)
try:
return hex_to_rgb == expected
except NameError:
return False


def check_num_tabs(terminal, ref_value):
Expand Down
40 changes: 12 additions & 28 deletions spyder_terminal/widgets/terminalgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
from qtpy.QtCore import (Qt, QUrl, Slot, QEvent, QTimer, Signal,
QObject)
from qtpy.QtGui import QKeySequence
from qtpy.QtWebEngineWidgets import (QWebEnginePage, QWebEngineSettings,
WEBENGINE)
from qtpy.QtWebChannel import QWebChannel
from qtpy.QtWebEngineWidgets import QWebEnginePage, QWebEngineSettings
from qtpy.QtWidgets import QMenu, QFrame, QVBoxLayout, QWidget
from spyder.config.base import DEV, get_translation
from spyder.config.manager import CONF
Expand All @@ -27,8 +27,6 @@
from spyder_terminal.widgets.style.themes import ANSI_COLORS
from spyder_terminal.config import CONF_SECTION

if WEBENGINE:
from qtpy.QtWebChannel import QWebChannel

PREFIX = 'spyder_terminal.default.'

Expand Down Expand Up @@ -88,8 +86,6 @@ def __init__(self, parent, port, path='~', font=None, theme=None,
self.body = self.view.document

self.handler.sig_ready.connect(self.setup_term)
if not WEBENGINE:
QTimer.singleShot(250, self.__alive_loopback)

def setup_term(self):
"""Setup other terminal options after page has loaded."""
Expand Down Expand Up @@ -222,21 +218,18 @@ def __init__(self, parent, CONF, term_url='http://127.0.0.1:8070',
self.parent = parent
self.CONF = CONF
self.shortcuts = self.create_shortcuts()
if WEBENGINE:
self.channel = QWebChannel(self.page())
self.page().setWebChannel(self.channel)
self.channel.registerObject('handler', handler)
self.channel = QWebChannel(self.page())
self.page().setWebChannel(self.channel)
self.channel.registerObject('handler', handler)

self.term_url = QUrl(term_url)
self.load(self.term_url)

if WEBENGINE:
self.document = self.page()
try:
self.document.profile().clearHttpCache()
except AttributeError:
pass
else:
self.document = self.page().mainFrame()
self.document = self.page()
try:
self.document.profile().clearHttpCache()
except AttributeError:
pass

self.initial_y_pos = 0
self.setFocusPolicy(Qt.ClickFocus)
Expand Down Expand Up @@ -326,11 +319,6 @@ def contextMenuEvent(self, event):
actions = [self.pageAction(QWebEnginePage.SelectAll),
copy_action, paste_action, clear_action, None, zoom_in,
zoom_out]
if DEV and not WEBENGINE:
settings = self.page().settings()
settings.setAttribute(QWebEngineSettings.DeveloperExtrasEnabled,
True)
actions += [None, self.pageAction(QWebEnginePage.InspectElement)]
add_actions(menu, actions)
menu.popup(event.globalPos())
event.accept()
Expand All @@ -340,11 +328,7 @@ def eval_javascript(self, script):
Evaluate Javascript instructions inside DOM with the expected prefix.
"""
script = PREFIX + script
if WEBENGINE:
self.document.runJavaScript("{}".format(script),
self.return_js_value)
else:
self.document.evaluateJavaScript("{}".format(script))
self.document.runJavaScript("{}".format(script), self.return_js_value)

def return_js_value(self, value):
"""Return the value of the function evaluated in Javascript."""
Expand Down