RefactoringRope/PreviewDialogBase.py

Tue, 28 Mar 2017 19:36:35 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 28 Mar 2017 19:36:35 +0200
changeset 151
5260100b6700
parent 147
3f8a995f6e49
child 203
c38750e1bafd
permissions
-rw-r--r--

Fixed some code style issues.

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

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

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

from __future__ import unicode_literals

from PyQt5.QtCore import Qt
from PyQt5.QtGui import QBrush, QColor, QTextCursor
from PyQt5.QtWidgets import QDialog

from Ui_PreviewDialog import Ui_PreviewDialog

import Globals


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 (QWidget)
        """
        QDialog.__init__(self, parent)
        self.setAttribute(Qt.WA_DeleteOnClose)
        self.setupUi(self)
        
        if Globals.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(QColor(190, 237, 190)))
        self.formats['+'] = charFormat
        charFormat = self.previewEdit.currentCharFormat()
        charFormat.setBackground(QBrush(QColor(237, 190, 190)))
        self.formats['-'] = charFormat
        charFormat = self.previewEdit.currentCharFormat()
        charFormat.setBackground(QBrush(QColor(190, 190, 237)))
        self.formats['@'] = charFormat
        charFormat = self.previewEdit.currentCharFormat()
        charFormat.setBackground(QBrush(QColor(124, 124, 124)))
        self.formats['?'] = charFormat
        charFormat = self.previewEdit.currentCharFormat()
        charFormat.setBackground(QBrush(QColor(190, 190, 190)))
        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 (string)
        @param charFormat text format to be used (QTextCharFormat)
        """
        tc = self.previewEdit.textCursor()
        tc.movePosition(QTextCursor.End)
        self.previewEdit.setTextCursor(tc)
        self.previewEdit.setCurrentCharFormat(charFormat)
        self.previewEdit.insertPlainText(txt)

eric ide

mercurial