RefactoringRope/MoveMethodDialog.py

Wed, 01 Jan 2014 14:47:56 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 01 Jan 2014 14:47:56 +0100
changeset 62
1077db8d0589
parent 55
d501156be247
child 74
0973b175e2ad
permissions
-rw-r--r--

Updated copyright for 2014.

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

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

"""
Module implementing the Move Method dialog.
"""

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

from Ui_MoveMethodDialog import Ui_MoveMethodDialog
from RefactoringDialogBase import RefactoringDialogBase


class MoveMethodDialog(RefactoringDialogBase, Ui_MoveMethodDialog):
    """
    Class implementing the Move Method dialog.
    """
    def __init__(self, refactoring, title, mover, parent=None):
        """
        Constructor
        
        @param refactoring reference to the main refactoring object
            (Refactoring)
        @param title title of the dialog (string)
        @param mover reference to the mover object
            (rope.refactor.move.MoveMethod)
        @param parent reference to the parent widget (QWidget)
        """
        RefactoringDialogBase.__init__(self, refactoring, title, parent)
        self.setupUi(self)
        
        self.__mover = mover
        
        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.methodEdit.setText(self.__mover.get_method_name())
        self.methodEdit.selectAll()
    
    @pyqtSlot(str)
    def on_attributeEdit_textChanged(self, text):
        """
        Private slot to react to changes of the attribute.
        
        @param text text entered into the edit (string)
        """
        self.__updateUI()
    
    @pyqtSlot(str)
    def on_methodEdit_textChanged(self, text):
        """
        Private slot to react to changes of the method.
        
        @param text text entered into the edit (string)
        """
        self.__updateUI()
    
    @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 __updateUI(self):
        """
        Private method to perform various UI updates.
        """
        self.__okButton.setEnabled(
            self.attributeEdit.text() != "" and
            self.methodEdit.text() != "")
    
    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:
            newName = self.methodEdit.text()
            if not newName:
                newName = None
            changes = self.__mover.get_changes(
                self.attributeEdit.text(), newName, task_handle=handle)
            return changes
        except Exception as err:
            self._refactoring.handleRopeError(err, self._title, handle)
            return None

eric ide

mercurial