RefactoringRope/ChangesPreviewDialog.py

Fri, 25 Oct 2013 19:33:36 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Fri, 25 Oct 2013 19:33:36 +0200
changeset 55
d501156be247
parent 43
39924831c795
child 62
1077db8d0589
permissions
-rw-r--r--

Fixed code style issues.

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

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

"""
Module implementing the Changes preview dialog.
"""

from PyQt4.QtCore import Qt, pyqtSlot
from PyQt4.QtGui import QDialogButtonBox, QListWidgetItem

from PreviewDialogBase import PreviewDialogBase


class ChangesPreviewDialog(PreviewDialogBase):
    """
    Class implementing the Changes preview dialog.
    """
    ChangeRole = Qt.UserRole
    
    def __init__(self, changes, parent):
        """
        Constructor
        
        @param changes reference to the Changes object
            (rope.base.change.ChangeSet)
        @param parent reference to the parent widget (QWidget)
        """
        PreviewDialogBase.__init__(self, parent)
        
        self.buttonBox.addButton(
            self.trUtf8("&Apply Changes"), QDialogButtonBox.AcceptRole)
        self.buttonBox.addButton(QDialogButtonBox.Cancel)
        
        self.description.setText(changes.description)
        for change in changes.changes:
            itm = QListWidgetItem(str(change), self.changesList)
            try:
                changeDescription = change.get_description()
            except AttributeError:
                changeDescription = self.trUtf8("No changes available.")
            itm.setData(ChangesPreviewDialog.ChangeRole,
                        changeDescription)
        if self.changesList.count():
            self.changesList.item(0).setSelected(True)
    
    @pyqtSlot(QListWidgetItem, QListWidgetItem)
    def on_changesList_currentItemChanged(self, current, previous):
        """
        Private slot called when a change is selected.
        
        @param current reference to the new current item (QListWidgetItem)
        @param previous reference to the old current item (QListWidgetItem)
        """
        if current is None:
            return
        
        self.previewEdit.clear()
        for line in current.data(ChangesPreviewDialog.ChangeRole)\
                .splitlines(True):
            try:
                format = self.formats[line[0]]
            except (IndexError, KeyError):
                format = self.formats[' ']
            self._appendText(line, format)

eric ide

mercurial