123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- #!/usr/bin/env python3
- from PyQt6.QtCore import *
- from PyQt6.QtGui import *
- from PyQt6.QtWidgets import *
- import sys
- class MagpyPlainTextEdit(QPlainTextEdit):
- def focusOutEvent(self, event):
- super().focusOutEvent(event)
- if event.lostFocus():
- self.parentWidget().to_display(event)
- class MagpyTextToggle(QStackedWidget):
- def __init__(self, parent, doc=None):
- QStackedWidget.__init__(self, parent)
- self.editbox = MagpyPlainTextEdit(self)
- if doc:
- self.doc = doc
- else:
- self.doc = QTextDocument(self)
- self.doc.setDocumentLayout(QPlainTextDocumentLayout(self.doc))
- self.editbox.setDocument(self.doc)
- self.displaybox = QTextEdit(self)
- self.displaybox.setReadOnly(True)
- self.displaybox.mouseReleaseEvent=self.to_edit
- self.addWidget(self.editbox)
- self.addWidget(self.displaybox)
- self.to_display(None)
- def to_edit(self, event):
- self.setCurrentIndex(0)
- def to_display(self, event):
- self.setCurrentIndex(1)
- self.displaybox.setMarkdown(self.doc.toPlainText())
- class MagpyContainer(QWidget):
- def __init__(self, parent, doc=None):
- QWidget.__init__(self, parent)
- vlayout = QVBoxLayout(self)
- for i in range(8):
- vlayout.addWidget(MagpyTextToggle(self, doc))
- self.setLayout(vlayout)
- # scroll = QScrollArea(self)
- # scroll.setWidget(self)
- # scroll.setWidgetResizable(True)
- class ProtoMagpy(QMainWindow):
- def __init__(self, parent=None):
- QMainWindow.__init__(self, parent)
- self.filename = ''
- self.actions = {}
- self.initUI()
- self.initActions()
- def initActions(self):
- self.actions['quit'] = QAction('Quit', self)
- self.actions['quit'].setShortcut(QKeySequence('Ctrl+Q'))
- self.actions['quit'].triggered.connect(self.close)
- s = QShortcut(QKeySequence('Ctrl+T'), self)
- s.activated.connect(self.widgprint)
- def widgprint(self):
- print(QApplication.focusWidget())
- def initUI(self):
- top_level = MagpyContainer(self)
- self.setCentralWidget(top_level)
- self.statusbar = self.statusBar()
- self.setGeometry(100, 100, 1030, 800)
- self.setWindowTitle("Proto-Magpy")
- def main():
- app = QApplication(sys.argv)
- main = ProtoMagpy()
- main.show()
- sys.exit(app.exec())
- if __name__ == '__main__':
- main()
|