proto-magpy.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #!/usr/bin/env python3
  2. from PyQt6.QtCore import *
  3. from PyQt6.QtGui import *
  4. from PyQt6.QtWidgets import *
  5. import sys
  6. class MagpyPlainTextEdit(QPlainTextEdit):
  7. def focusOutEvent(self, event):
  8. super().focusOutEvent(event)
  9. if event.lostFocus():
  10. self.parentWidget().to_display(event)
  11. class MagpyTextToggle(QStackedWidget):
  12. def __init__(self, parent, doc=None):
  13. QStackedWidget.__init__(self, parent)
  14. self.editbox = MagpyPlainTextEdit(self)
  15. if doc:
  16. self.doc = doc
  17. else:
  18. self.doc = QTextDocument(self)
  19. self.doc.setDocumentLayout(QPlainTextDocumentLayout(self.doc))
  20. self.editbox.setDocument(self.doc)
  21. self.displaybox = QTextEdit(self)
  22. self.displaybox.setReadOnly(True)
  23. self.displaybox.mouseReleaseEvent=self.to_edit
  24. self.addWidget(self.editbox)
  25. self.addWidget(self.displaybox)
  26. self.to_display(None)
  27. def to_edit(self, event):
  28. self.setCurrentIndex(0)
  29. def to_display(self, event):
  30. self.setCurrentIndex(1)
  31. self.displaybox.setMarkdown(self.doc.toPlainText())
  32. class MagpyContainer(QWidget):
  33. def __init__(self, parent, doc=None):
  34. QWidget.__init__(self, parent)
  35. vlayout = QVBoxLayout(self)
  36. for i in range(8):
  37. vlayout.addWidget(MagpyTextToggle(self, doc))
  38. self.setLayout(vlayout)
  39. # scroll = QScrollArea(self)
  40. # scroll.setWidget(self)
  41. # scroll.setWidgetResizable(True)
  42. class ProtoMagpy(QMainWindow):
  43. def __init__(self, parent=None):
  44. QMainWindow.__init__(self, parent)
  45. self.filename = ''
  46. self.actions = {}
  47. self.initUI()
  48. self.initActions()
  49. def initActions(self):
  50. self.actions['quit'] = QAction('Quit', self)
  51. self.actions['quit'].setShortcut(QKeySequence('Ctrl+Q'))
  52. self.actions['quit'].triggered.connect(self.close)
  53. s = QShortcut(QKeySequence('Ctrl+T'), self)
  54. s.activated.connect(self.widgprint)
  55. def widgprint(self):
  56. print(QApplication.focusWidget())
  57. def initUI(self):
  58. top_level = MagpyContainer(self)
  59. self.setCentralWidget(top_level)
  60. self.statusbar = self.statusBar()
  61. self.setGeometry(100, 100, 1030, 800)
  62. self.setWindowTitle("Proto-Magpy")
  63. def main():
  64. app = QApplication(sys.argv)
  65. main = ProtoMagpy()
  66. main.show()
  67. sys.exit(app.exec())
  68. if __name__ == '__main__':
  69. main()