RefactoringRope/MoveMethodDialog.py

changeset 7
5ecf9ef23d39
child 20
83b71483e198
equal deleted inserted replaced
6:07dabc6bb157 7:5ecf9ef23d39
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2011 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the Move Method dialog.
8 """
9
10 from PyQt4.QtCore import pyqtSlot
11 from PyQt4.QtGui import QDialogButtonBox, QAbstractButton
12
13 from Ui_MoveMethodDialog import Ui_MoveMethodDialog
14 from RefactoringDialogBase import RefactoringDialogBase
15
16 class MoveMethodDialog(RefactoringDialogBase, Ui_MoveMethodDialog):
17 """
18 Class implementing the Move Method dialog.
19 """
20 def __init__(self, refactoring, title, mover, parent=None):
21 """
22 Constructor
23
24 @param refactoring reference to the main refactoring object
25 (Refactoring)
26 @param title title of the dialog (string)
27 @param mover reference to the mover object
28 (rope.refactor.move.MoveMethod)
29 @param parent reference to the parent widget (QWidget)
30 """
31 RefactoringDialogBase.__init__(self, refactoring, title, parent)
32 self.setupUi(self)
33
34 self.__mover = mover
35
36 self.__okButton = self.buttonBox.button(QDialogButtonBox.Ok)
37 self.__okButton.setEnabled(False)
38 self.__previewButton = self.buttonBox.addButton(
39 self.trUtf8("Preview"), QDialogButtonBox.ActionRole)
40 self.__previewButton.setDefault(True)
41
42 self.methodEdit.setText(self.__mover.get_method_name())
43 self.methodEdit.selectAll()
44
45 @pyqtSlot(str)
46 def on_attributeEdit_textChanged(self, text):
47 """
48 Private slot to react to changes of the attribute.
49
50 @param text text entered into the edit (string)
51 """
52 self.__updateUI()
53
54 @pyqtSlot(str)
55 def on_methodEdit_textChanged(self, text):
56 """
57 Private slot to react to changes of the attribute.
58
59 @param text text entered into the edit (string)
60 """
61 self.__updateUI()
62
63 @pyqtSlot(QAbstractButton)
64 def on_buttonBox_clicked(self, button):
65 """
66 Private slot to act on the button pressed.
67
68 @param button reference to the button pressed (QAbstractButton)
69 """
70 if button == self.__previewButton:
71 self.previewChanges()
72 elif button == self.__okButton:
73 self.applyChanges()
74
75 def __updateUI(self):
76 """
77 Private method to perform various UI updates.
78 """
79 self.__okButton.setEnabled(
80 self.attributeEdit.text() != "" and \
81 self.methodEdit.text() != "")
82
83 def _calculateChanges(self, handle):
84 """
85 Protected method to calculate the changes.
86
87 @param handle reference to the task handle
88 (rope.base.taskhandle.TaskHandle)
89 @return reference to the Changes object (rope.base.change.ChangeSet)
90 """
91 try:
92 newName = self.methodEdit.text()
93 if not newName:
94 newName = None
95 changes = self.__mover.get_changes(self.attributeEdit.text(),
96 newName, task_handle=handle)
97 return changes
98 except Exception as err:
99 self._refactoring.handleRopeError(err, self._title, handle)
100 return None

eric ide

mercurial