aboutsummaryrefslogtreecommitdiffstats
path: root/examples/widgets
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2023-02-20 14:02:34 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2023-02-20 16:02:05 +0100
commitf06734a016b4c97719c8b2a5f638bb200651a792 (patch)
tree1e891eb1c4bd20926132ef7acdbbfd11edc40743 /examples/widgets
parent7e6236ec25f8739648e36cf82054c6b2cd4f714d (diff)
Remove the codeeditor example
Following qtbase/48a1a5564f89e1e8f0b6f4a28398e4ae0b3f751c. Task-number: PYSIDE-2206 Change-Id: I6aa4b84133bb3d1ebb030f5db098fe1f341b6029 Reviewed-by: Adrian Herrmann <adrian.herrmann@qt.io> Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'examples/widgets')
-rw-r--r--examples/widgets/codeeditor/codeeditor.py104
-rw-r--r--examples/widgets/codeeditor/codeeditor.pyproject3
-rw-r--r--examples/widgets/codeeditor/doc/codeeditor.pngbin7759 -> 0 bytes
-rw-r--r--examples/widgets/codeeditor/doc/codeeditor.rst9
-rw-r--r--examples/widgets/codeeditor/main.py15
5 files changed, 0 insertions, 131 deletions
diff --git a/examples/widgets/codeeditor/codeeditor.py b/examples/widgets/codeeditor/codeeditor.py
deleted file mode 100644
index 22f0b685b..000000000
--- a/examples/widgets/codeeditor/codeeditor.py
+++ /dev/null
@@ -1,104 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-from PySide6.QtCore import Slot, Qt, QRect, QSize
-from PySide6.QtGui import QColor, QPainter, QTextFormat
-from PySide6.QtWidgets import QPlainTextEdit, QWidget, QTextEdit
-
-
-class LineNumberArea(QWidget):
- def __init__(self, editor):
- QWidget.__init__(self, editor)
- self._code_editor = editor
-
- def sizeHint(self):
- return QSize(self._code_editor.line_number_area_width(), 0)
-
- def paintEvent(self, event):
- self._code_editor.lineNumberAreaPaintEvent(event)
-
-
-class CodeEditor(QPlainTextEdit):
- def __init__(self):
- super().__init__()
- self.line_number_area = LineNumberArea(self)
-
- self.blockCountChanged[int].connect(self.update_line_number_area_width)
- self.updateRequest[QRect, int].connect(self.update_line_number_area)
- self.cursorPositionChanged.connect(self.highlight_current_line)
-
- self.update_line_number_area_width(0)
- self.highlight_current_line()
-
- def line_number_area_width(self):
- digits = 1
- max_num = max(1, self.blockCount())
- while max_num >= 10:
- max_num *= 0.1
- digits += 1
-
- space = 3 + self.fontMetrics().horizontalAdvance('9') * digits
- return space
-
- def resizeEvent(self, e):
- super().resizeEvent(e)
- cr = self.contentsRect()
- width = self.line_number_area_width()
- rect = QRect(cr.left(), cr.top(), width, cr.height())
- self.line_number_area.setGeometry(rect)
-
- def lineNumberAreaPaintEvent(self, event):
- with QPainter(self.line_number_area) as painter:
- painter.fillRect(event.rect(), Qt.lightGray)
- block = self.firstVisibleBlock()
- block_number = block.blockNumber()
- offset = self.contentOffset()
- top = self.blockBoundingGeometry(block).translated(offset).top()
- bottom = top + self.blockBoundingRect(block).height()
-
- while block.isValid() and top <= event.rect().bottom():
- if block.isVisible() and bottom >= event.rect().top():
- number = str(block_number + 1)
- painter.setPen(Qt.black)
- width = self.line_number_area.width()
- height = self.fontMetrics().height()
- painter.drawText(0, top, width, height, Qt.AlignRight, number)
-
- block = block.next()
- top = bottom
- bottom = top + self.blockBoundingRect(block).height()
- block_number += 1
-
- @Slot(int)
- def update_line_number_area_width(self, newBlockCount):
- self.setViewportMargins(self.line_number_area_width(), 0, 0, 0)
-
- @Slot(QRect, int)
- def update_line_number_area(self, rect, dy):
- if dy:
- self.line_number_area.scroll(0, dy)
- else:
- width = self.line_number_area.width()
- self.line_number_area.update(0, rect.y(), width, rect.height())
-
- if rect.contains(self.viewport().rect()):
- self.update_line_number_area_width(0)
-
- @Slot()
- def highlight_current_line(self):
- extra_selections = []
-
- if not self.isReadOnly():
- selection = QTextEdit.ExtraSelection()
-
- line_color = QColor(Qt.yellow).lighter(160)
- selection.format.setBackground(line_color)
-
- selection.format.setProperty(QTextFormat.FullWidthSelection, True)
-
- selection.cursor = self.textCursor()
- selection.cursor.clearSelection()
-
- extra_selections.append(selection)
-
- self.setExtraSelections(extra_selections)
diff --git a/examples/widgets/codeeditor/codeeditor.pyproject b/examples/widgets/codeeditor/codeeditor.pyproject
deleted file mode 100644
index f51cfc6d2..000000000
--- a/examples/widgets/codeeditor/codeeditor.pyproject
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "files": ["codeeditor.py", "main.py"]
-}
diff --git a/examples/widgets/codeeditor/doc/codeeditor.png b/examples/widgets/codeeditor/doc/codeeditor.png
deleted file mode 100644
index e3def6b04..000000000
--- a/examples/widgets/codeeditor/doc/codeeditor.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/codeeditor/doc/codeeditor.rst b/examples/widgets/codeeditor/doc/codeeditor.rst
deleted file mode 100644
index 16345eaa3..000000000
--- a/examples/widgets/codeeditor/doc/codeeditor.rst
+++ /dev/null
@@ -1,9 +0,0 @@
-Code Editor Example
-===================
-
-The Code Editor example shows how to create a simple editor that has line
-numbers and that highlights the current line.
-
-.. image:: painter.png
- :width: 400
- :alt: Code Editor Screenshot
diff --git a/examples/widgets/codeeditor/main.py b/examples/widgets/codeeditor/main.py
deleted file mode 100644
index cffcca02c..000000000
--- a/examples/widgets/codeeditor/main.py
+++ /dev/null
@@ -1,15 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-import sys
-from PySide6.QtWidgets import QApplication
-from codeeditor import CodeEditor
-
-"""PySide6 port of the widgets/codeeditor example from Qt5"""
-
-if __name__ == "__main__":
- app = QApplication([])
- editor = CodeEditor()
- editor.setWindowTitle("Code Editor Example")
- editor.show()
- sys.exit(app.exec())