Browse Source

initial implementation of the swapping text block, using inbuilt markdown support

john melesky 6 months ago
parent
commit
3a8e8af89b
1 changed files with 108 additions and 0 deletions
  1. 108 0
      proto-magpy.py

+ 108 - 0
proto-magpy.py

@@ -0,0 +1,108 @@
+#!/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_view(event)
+
+
+class MagpyTextToggle(QStackedWidget):
+    def __init__(self, parent, doc=None):
+        QStackedWidget.__init__(self, parent)
+
+        self.editbox = MagpyPlainTextEdit(self)
+        self.displaybox = QTextEdit(self)
+        self.displaybox.setReadOnly(True)
+        self.addWidget(self.editbox)
+        self.addWidget(self.displaybox)
+
+        if doc:
+            self.doc = doc
+        else:
+            self.doc = QTextDocument(self)
+            self.doc.setDocumentLayout(QPlainTextDocumentLayout(self.doc))
+
+        self.editbox.setDocument(self.doc)
+
+        self.displaybox.mouseReleaseEvent=self.to_edit
+
+        self.to_view(None)
+
+
+
+    def to_edit(self, event):
+        print("to_edit!")
+        self.setCurrentIndex(0)
+
+    def to_view(self, event):
+        print("to_view!")
+        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.pagedown)
+
+    def pagedown(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()