RefactoringRope/PreviewDialogBase.py

Tue, 13 Aug 2013 21:13:02 +0200

author
T.Rzepka <Tobias.Rzepka@gmail.com>
date
Tue, 13 Aug 2013 21:13:02 +0200
branch
Py2 comp.
changeset 50
a29c3d2e6dc0
parent 43
39924831c795
child 63
c02061242598
permissions
-rw-r--r--

rope for Python2 projects enabled, if running on Python2

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

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

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

from __future__ import unicode_literals    # __IGNORE_WARNING__

from PyQt4.QtCore import Qt
from PyQt4.QtGui import QDialog, QBrush, QColor, QTextCursor

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()
        format = self.previewEdit.currentCharFormat()
        format.setBackground(QBrush(QColor(190, 237, 190)))
        self.formats['+'] = format
        format = self.previewEdit.currentCharFormat()
        format.setBackground(QBrush(QColor(237, 190, 190)))
        self.formats['-'] = format
        format = self.previewEdit.currentCharFormat()
        format.setBackground(QBrush(QColor(190, 190, 237)))
        self.formats['@'] = format
        format = self.previewEdit.currentCharFormat()
        format.setBackground(QBrush(QColor(124, 124, 124)))
        self.formats['?'] = format
        format = self.previewEdit.currentCharFormat()
        format.setBackground(QBrush(QColor(190, 190, 190)))
        self.formats['='] = format
    
    def _appendText(self, txt, format):
        """
        Restricted method to append text to the end of the contents pane.
        
        @param txt text to insert (string)
        @param format text format to be used (QTextCharFormat)
        """
        tc = self.previewEdit.textCursor()
        tc.movePosition(QTextCursor.End)
        self.previewEdit.setTextCursor(tc)
        self.previewEdit.setCurrentCharFormat(format)
        self.previewEdit.insertPlainText(txt)

eric ide

mercurial