Get :debug-dump-page to work
This commit is contained in:
parent
0c1e266073
commit
3ee58fdea3
@ -1294,23 +1294,21 @@ class CommandDispatcher:
|
|||||||
dest: Where to write the file to.
|
dest: Where to write the file to.
|
||||||
plain: Write plain text instead of HTML.
|
plain: Write plain text instead of HTML.
|
||||||
"""
|
"""
|
||||||
web_view = self._current_widget()
|
tab = self._current_widget()
|
||||||
mainframe = web_view.page().mainFrame()
|
|
||||||
if plain:
|
|
||||||
data = mainframe.toPlainText()
|
|
||||||
else:
|
|
||||||
data = mainframe.toHtml()
|
|
||||||
|
|
||||||
dest = os.path.expanduser(dest)
|
dest = os.path.expanduser(dest)
|
||||||
|
|
||||||
|
def callback(data):
|
||||||
try:
|
try:
|
||||||
with open(dest, 'w', encoding='utf-8') as f:
|
with open(dest, 'w', encoding='utf-8') as f:
|
||||||
f.write(data)
|
f.write(data)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
raise cmdexc.CommandError('Could not write page: {}'.format(e))
|
message.error(self._win_id, 'Could not write page: {}'.format(e))
|
||||||
else:
|
else:
|
||||||
message.info(self._win_id, "Dumped page to {}.".format(dest))
|
message.info(self._win_id, "Dumped page to {}.".format(dest))
|
||||||
|
|
||||||
|
tab.dump_async(callback, plain=plain)
|
||||||
|
|
||||||
|
|
||||||
@cmdutils.register(instance='command-dispatcher', name='help',
|
@cmdutils.register(instance='command-dispatcher', name='help',
|
||||||
scope='window')
|
scope='window')
|
||||||
@cmdutils.argument('topic', completion=usertypes.Completion.helptopic)
|
@cmdutils.argument('topic', completion=usertypes.Completion.helptopic)
|
||||||
|
@ -150,6 +150,14 @@ class AbstractTab(QWidget):
|
|||||||
def openurl(self, url):
|
def openurl(self, url):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def dump_async(self, callback=None, *, plain=False):
|
||||||
|
"""Dump the current page to a file ascync.
|
||||||
|
|
||||||
|
The given callback will be called with the result when dumping is
|
||||||
|
complete.
|
||||||
|
"""
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
url = utils.elide(self.cur_url.toDisplayString(QUrl.EncodeUnicode),
|
url = utils.elide(self.cur_url.toDisplayString(QUrl.EncodeUnicode),
|
||||||
100)
|
100)
|
||||||
|
@ -83,6 +83,12 @@ class WebEngineViewTab(tab.AbstractTab):
|
|||||||
def scroll_pos(self):
|
def scroll_pos(self):
|
||||||
return (0, 0)
|
return (0, 0)
|
||||||
|
|
||||||
|
def dump_async(self, callback=None, *, plain=False):
|
||||||
|
if plain:
|
||||||
|
self._widget.page().toPlainText(callback)
|
||||||
|
else:
|
||||||
|
self._widget.page().toHtml(callback)
|
||||||
|
|
||||||
def _connect_signals(self):
|
def _connect_signals(self):
|
||||||
view = self._widget
|
view = self._widget
|
||||||
page = view.page()
|
page = view.page()
|
||||||
|
@ -89,6 +89,13 @@ class WebViewTab(tab.AbstractTab):
|
|||||||
def scroll_pos(self):
|
def scroll_pos(self):
|
||||||
return self._widget.scroll_pos
|
return self._widget.scroll_pos
|
||||||
|
|
||||||
|
def dump_async(self, callback=None, *, plain=False):
|
||||||
|
frame = self._widget.page().mainFrame()
|
||||||
|
if plain:
|
||||||
|
callback(frame.toPlainText())
|
||||||
|
else:
|
||||||
|
callback(frame.toHtml())
|
||||||
|
|
||||||
def _connect_signals(self):
|
def _connect_signals(self):
|
||||||
view = self._widget
|
view = self._widget
|
||||||
page = view.page()
|
page = view.page()
|
||||||
|
Loading…
Reference in New Issue
Block a user