RefactoringRope/IntroduceFactoryDialog.py

Fri, 01 Jan 2016 12:19:02 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Fri, 01 Jan 2016 12:19:02 +0100
changeset 144
bfc6a3b38330
parent 94
03d6a17c66ac
child 147
3f8a995f6e49
permissions
-rw-r--r--

Updated copyright for 2016.

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

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

"""
Module implementing the Introduce Factory dialog.
"""

from __future__ import unicode_literals

from PyQt5.QtCore import pyqtSlot
from PyQt5.QtWidgets import QDialogButtonBox, QAbstractButton

from Ui_IntroduceFactoryDialog import Ui_IntroduceFactoryDialog
from RefactoringDialogBase import RefactoringDialogBase


class IntroduceFactoryDialog(RefactoringDialogBase, Ui_IntroduceFactoryDialog):
    """
    Class implementing the Introduce Factory dialog.
    """
    def __init__(self, refactoring, title, introducer, parent=None):
        """
        Constructor
         
        @param refactoring reference to the main refactoring object
            (Refactoring)
        @param title title of the dialog (string)
        @param introducer reference to the factory introducer object
            (rope.refactor.introduce_factory.IntroduceFactoryRefactoring)
        @param parent reference to the parent widget (QWidget)
        """
        RefactoringDialogBase.__init__(self, refactoring, title, parent)
        self.setupUi(self)
        
        self.__introducer = introducer
        
        self.__okButton = self.buttonBox.button(QDialogButtonBox.Ok)
        self.__okButton.setEnabled(False)
        self.__previewButton = self.buttonBox.addButton(
            self.tr("Preview"), QDialogButtonBox.ActionRole)
        self.__previewButton.setDefault(True)
        
        self.nameEdit.setText("create")
        self.nameEdit.selectAll()
        
        msh = self.minimumSizeHint()
        self.resize(max(self.width(), msh.width()), msh.height())
    
    @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.__introducer.get_changes(
                self.nameEdit.text(),
                global_factory=self.globalButton.isChecked(),
                task_handle=handle)
            return changes
        except Exception as err:
            self._refactoring.handleRopeError(err, self._title, handle)
            return None

eric ide

mercurial