本文整理汇总了Python中PySide.QtWebKit.QWebView.deleteLater方法的典型用法代码示例。如果您正苦于以下问题:Python QWebView.deleteLater方法的具体用法?Python QWebView.deleteLater怎么用?Python QWebView.deleteLater使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtWebKit.QWebView
的用法示例。
在下文中一共展示了QWebView.deleteLater方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Browser
# 需要导入模块: from PySide.QtWebKit import QWebView [as 别名]
# 或者: from PySide.QtWebKit.QWebView import deleteLater [as 别名]
#.........这里部分代码省略.........
def _start_task(self):
self._is_task_finished = False
# abusing the ok param of loadFinished
timed_out = lambda: self._load_finished('timed_out')
self._timeout_timer = QTimer()
self._timeout_timer.timeout.connect(timed_out)
self._timeout_timer.start(self._timeout)
def _finish_task(self, result):
self._is_task_finished = True
self._timeout_timer.stop()
# calling the callback function which we passed upon instantiation to
# report the results there
self._result_callback(result)
def make(self, method, url, headers, raw_data=None):
request = self._prepare_request(url, headers)
operation = self._request_ops[method.lower()]
request_data = self._urlencode_request_data(raw_data or dict())
self._start_task()
self._web_view.load(request, operation, request_data)
def _find_element(self, selector):
main_frame = self._web_page.mainFrame()
element = main_frame.findFirstElement(selector)
if element.isNull():
raise ElementNotFound(selector)
return element
def fill_input(self, selector, value):
js_fill_input = """
this.setAttribute("value", "{0}");
this.value = "{0}";
""".format(value)
element = self._find_element(selector)
element.evaluateJavaScript(js_fill_input)
def click(self, selector):
element = self._find_element(selector)
offset = element.geometry()
js_click = """
function mouse_click(element) {{
var event = document.createEvent('MouseEvents');
var offsetX = {0} + 2; //add 2 pixels otherwise it would
var offsetY = {1} - 2; //seem like we clicked on the margin
event.initMouseEvent(
'click', //event type
true, //canBubble
true, //cancelable
document.defaultView, //view
1, //detail
(window.screenX + offsetX), //screenX - The coords within
(window.screenY + offsetY), //screenY - the entire page
offsetX, //clientX - The coords within
offsetY, //clientY - the viewport
false, //ctrlKey
false, //altKey
false, //shiftKey
false, //metaKey
0, //0=left, 1=middle, 2=right
element //relatedTarget
);
element.dispatchEvent(event); //Fire the event
}}
mouse_click(this);""".format(offset.left(), offset.top())
self._start_task()
element.evaluateJavaScript(js_click)
def _destroyed(self, component):
self._destroyed_status[component] = True
if all(self._destroyed_status.values()):
self._shutdown_callback()
def shutdown(self, callback):
self._shutdown_callback = callback
self._web_view.stop()
self._web_view.close()
# will immediately stop any running javascript code
self._web_view.settings().setAttribute(QWebSettings.JavascriptEnabled,
False)
# if any requests were started by javascript after loadFinished was
# emitted, and before we stopped javascript execution, cancel them
self._network_manager.abort_requests()
self._destroyed_status['web_page'] = False
self._web_page.destroyed.connect(lambda: self._destroyed('web_page'))
self._web_page.deleteLater()
self._destroyed_status['web_view'] = False
self._web_view.destroyed.connect(lambda: self._destroyed('web_view'))
self._web_view.deleteLater()
self._destroyed_status['network_manager'] = False
destroyer = lambda: self._destroyed('network_manager')
self._network_manager.destroyed.connect(destroyer)
self._network_manager.deleteLater()