コード例 #1
0
ファイル: client.py プロジェクト: SetSplin/DigitalLibrary
class Browser(QObject):
	# pylint: disable=too-many-public-methods

	__execute_script_called = Signal(str)

	def __init__(self):
		super().__init__()

		self.app = QApplication([])

		self.webview = QWebView()
		self.webview.setAttribute(Qt.WA_DeleteOnClose)
		self.webview.destroyed.connect(self.app.quit)

		self.__execute_script_called.connect(self.__execute_script)

	def __execute_script(self, javascript_code: str):
		assert current_thread_is_main()
		self.webview.page().mainFrame().evaluateJavaScript(javascript_code)

	def execute_script(self, javascript_code: str):
		if current_thread_is_main():
			self.__execute_script(javascript_code)
		else:
			self.__execute_script_called.emit(javascript_code)

	def run(self, url):
		assert current_thread_is_main()
		self.webview.showFullScreen()
		self.webview.load(url)
		self.app.exec_()