From anonymous, 2 Months ago, written in Python.
Embed
  1. import os.path
  2.  
  3. from PyQt5.QtCore import QUrl, Qt, QEvent, QObject
  4. from PyQt5.QtWidgets import QApplication
  5. from PyQt5.QtWebEngineWidgets import QWebEngineView
  6.  
  7.  
  8. class Filter(QObject):
  9.  
  10.     def eventFilter(self, obj, event):
  11.         if event.type() != QEvent.KeyPress:
  12.             return False
  13.  
  14.         if event.key() != Qt.Key_F5:
  15.             return False
  16.  
  17.         view.page().runJavaScript(
  18.             "Blockly.Python.workspaceToCode(Code.workspace);", run_code)
  19.         return True
  20.  
  21.  
  22. def run_code(src):
  23.     print(src.strip())
  24.     code = compile(src, '<string>', 'exec')
  25.     exec(code)
  26.  
  27.  
  28. app = QApplication([])
  29. filt = Filter()
  30. app.installEventFilter(filt)
  31.  
  32. view = QWebEngineView()
  33. view.load(QUrl.fromLocalFile(os.path.abspath('index.html')))
  34. view.show()
  35.  
  36. app.exec_()
  37.