RefactoringRope/PreviewDialogBase.py

Wed, 23 Oct 2024 17:45:37 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 23 Oct 2024 17:45:37 +0200
branch
eric7
changeset 420
fa31c3a0df1d
parent 412
6fa5892b9097
child 426
7592a1c052e8
permissions
-rw-r--r--

Adjusted code for eric7 24.10 and newer.

# -*- coding: utf-8 -*-

# Copyright (c) 2010 - 2024 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing a dialog base class to preview changes.
"""

from PyQt6.QtCore import Qt
from PyQt6.QtGui import QBrush, QTextCursor
from PyQt6.QtWidgets import QDialog

from eric7 import Preferences

try:
    from eric7.SystemUtilities.OSUtilities import isWindowsPlatform
except ImportError:
    # backward compatibility for eric < 23.1
    from eric7.Globals import isWindowsPlatform

from .Ui_PreviewDialog import Ui_PreviewDialog


class PreviewDialogBase(QDialog, Ui_PreviewDialog):
    """
    Class implementing a dialog base class to preview changes.
    """

    def __init__(self, parent=None):
        """
        Constructor

        @param parent reference to the parent widget
        @type QWidget
        """
        QDialog.__init__(self, parent)
        self.setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose)
        self.setupUi(self)

        if isWindowsPlatform():
            self.previewEdit.setFontFamily("Lucida Console")
        else:
            self.previewEdit.setFontFamily("Monospace")

        self.formats = {}
        self.formats[" "] = self.previewEdit.currentCharFormat()

        charFormat = self.previewEdit.currentCharFormat()
        charFormat.setBackground(QBrush(Preferences.getDiffColour("AddedColor")))
        self.formats["+"] = charFormat

        charFormat = self.previewEdit.currentCharFormat()
        charFormat.setBackground(QBrush(Preferences.getDiffColour("RemovedColor")))
        self.formats["-"] = charFormat

        charFormat = self.previewEdit.currentCharFormat()
        charFormat.setBackground(QBrush(Preferences.getDiffColour("ReplacedColor")))
        self.formats["@"] = charFormat

        charFormat = self.previewEdit.currentCharFormat()
        charFormat.setBackground(QBrush(Preferences.getDiffColour("ContextColor")))
        self.formats["?"] = charFormat

        charFormat = self.previewEdit.currentCharFormat()
        charFormat.setBackground(QBrush(Preferences.getDiffColour("HeaderColor")))
        self.formats["="] = charFormat

    def _appendText(self, txt, charFormat):
        """
        Protected method to append text to the end of the contents pane.

        @param txt text to insert
        @type str
        @param charFormat text format to be used
        @type QTextCharFormat
        """
        tc = self.previewEdit.textCursor()
        tc.movePosition(QTextCursor.MoveOperation.End)
        self.previewEdit.setTextCursor(tc)
        self.previewEdit.setCurrentCharFormat(charFormat)
        self.previewEdit.insertPlainText(txt)

eric ide

mercurial