view.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. from PyQt5 import QtCore
  4. from PyQt5.QtCore import QUrl
  5. from PyQt5.QtGui import QFont, QSyntaxHighlighter
  6. from PyQt5.QtWidgets import QWidget, QLabel, QTabWidget, QHBoxLayout, QSplitter, QPlainTextEdit
  7. from PyQt5.QtWebKit import QWebSettings
  8. from PyQt5.QtWebKitWidgets import QWebView, QWebInspector
  9. class WebkitView(QWebView):
  10. def __init__(self, port):
  11. self.port = port
  12. self.view = QWebView.__init__(self)
  13. self.load(QUrl('http://localhost:'+str(self.port)))
  14. self.settings().setAttribute(QWebSettings.DeveloperExtrasEnabled, True)
  15. # self.settings().setAttribute(QWebSettings.PluginsEnabled, True)
  16. class WebkitInspector(QWebInspector):
  17. def __init__(self, webkitview):
  18. super(WebkitInspector, self).__init__()
  19. self.webkitview = webkitview
  20. self.setPage(self.webkitview.page())
  21. # TODO: webkitinspector is disappearing when chaging tabs
  22. class CodeEditor(QPlainTextEdit):
  23. def __init__(self):
  24. super(CodeEditor, self).__init__()
  25. font = QFont()
  26. font.setFamily('Courier')
  27. font.setFixedPitch(True)
  28. font.setPointSize(10)
  29. self.setFont(font)
  30. # self.highlighter = Highlighter(self.document())
  31. # https://pypi.python.org/pypi/QScintilla/2.9.2
  32. class ViewTab(QWidget):
  33. def __init__(self, core):
  34. super(ViewTab, self).__init__()
  35. # self.grid = QGridLayout()
  36. hbox = QHBoxLayout()
  37. hbox.setContentsMargins(0,0,0,0)
  38. self.setLayout(hbox)
  39. # webviewbox = QVBoxLayout()
  40. vsplitter = QSplitter(QtCore.Qt.Vertical)
  41. self.webkitview = WebkitView(core.server.port)
  42. vsplitter.addWidget(self.webkitview)
  43. self.webkitinspector = WebkitInspector(self.webkitview)
  44. vsplitter.addWidget(self.webkitinspector)
  45. hsplitter = QSplitter(QtCore.Qt.Horizontal)
  46. hsplitter.addWidget(vsplitter)
  47. self.codeeditor = CodeEditor()
  48. hsplitter.addWidget(self.codeeditor)
  49. hbox.addWidget(hsplitter)
  50. def onChanged(self, text):
  51. print("ViewTba Layout Changed")
  52. self.lbl.setText(text)
  53. self.lbl.adjustSize()