RefactoringRope/MethodToMethodObjectDialog.py

Wed, 01 Jan 2014 14:49:26 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 01 Jan 2014 14:49:26 +0100
branch
Py2 comp.
changeset 63
c02061242598
parent 50
a29c3d2e6dc0
child 76
936b2a98fe4e
permissions
-rw-r--r--

Updated copyright for 2014.

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

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

"""
Module implementing the Method To Method object dialog.
"""

from __future__ import unicode_literals    # __IGNORE_WARNING__

from PyQt4.QtCore import pyqtSlot
from PyQt4.QtGui import QDialogButtonBox, QAbstractButton

from Ui_MethodToMethodObjectDialog import Ui_MethodToMethodObjectDialog
from RefactoringDialogBase import RefactoringDialogBase


class MethodToMethodObjectDialog(RefactoringDialogBase,
                                 Ui_MethodToMethodObjectDialog):
    """
    Class implementing the Method To Method object dialog.
    """
    def __init__(self, refactoring, title, converter, parent=None):
        """
        Constructor
         
        @param refactoring reference to the main refactoring object
            (Refactoring)
        @param title title of the dialog (string)
        @param converter reference to the converter object
            (rope.refactor.method_object.MethodObject)
        @param parent reference to the parent widget (QWidget)
        """
        RefactoringDialogBase.__init__(self, refactoring, title, parent)
        self.setupUi(self)
        
        self.__converter = converter
        
        self.__okButton = self.buttonBox.button(QDialogButtonBox.Ok)
        self.__okButton.setEnabled(False)
        self.__previewButton = self.buttonBox.addButton(
            self.trUtf8("Preview"), QDialogButtonBox.ActionRole)
        self.__previewButton.setDefault(True)
        
        self.nameEdit.setText("_MethodObject")
        self.nameEdit.selectAll()
    
    @pyqtSlot(str)
    def on_nameEdit_textChanged(self, text):
        """
        Private slot to react to changes of the name.
        
        @param text text entered into the edit (string)
        """
        self.__okButton.setEnabled(text != "")
    
    @pyqtSlot(QAbstractButton)
    def on_buttonBox_clicked(self, button):
        """
        Private slot to act on the button pressed.
        
        @param button reference to the button pressed (QAbstractButton)
        """
        if button == self.__previewButton:
            self.previewChanges()
        elif button == self.__okButton:
            self.applyChanges()
    
    def _calculateChanges(self, handle):
        """
        Protected method to calculate the changes.
        
        @param handle reference to the task handle
            (rope.base.taskhandle.TaskHandle)
        @return reference to the Changes object (rope.base.change.ChangeSet)
        """
        try:
            changes = self.__converter.get_changes(self.nameEdit.text())
            return changes
        except Exception as err:
            self._refactoring.handleRopeError(err, self._title, handle)
            return None

eric ide

mercurial