RefactoringRope/IntroduceParameterDialog.py

changeset 10
0fdfae822ca7
child 20
83b71483e198
equal deleted inserted replaced
9:8cee612bcc28 10:0fdfae822ca7
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2011 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the Introduce Parameter dialog.
8 """
9
10 from PyQt4.QtCore import pyqtSlot
11 from PyQt4.QtGui import QDialogButtonBox, QAbstractButton
12
13 from Ui_IntroduceParameterDialog import Ui_IntroduceParameterDialog
14 from RefactoringDialogBase import RefactoringDialogBase
15
16 class IntroduceParameterDialog(RefactoringDialogBase,
17 Ui_IntroduceParameterDialog):
18 """
19 Class implementing the Introduce Parameter dialog.
20 """
21 def __init__(self, refactoring, title, introducer, parent=None):
22 """
23 Constructor
24
25 @param refactoring reference to the main refactoring object
26 (Refactoring)
27 @param title title of the dialog (string)
28 @param introducer reference to the factory introducer object
29 (rope.refactor.introduce_parameter.IntroduceParameter)
30 @param parent reference to the parent widget (QWidget)
31 """
32 RefactoringDialogBase.__init__(self, refactoring, title, parent)
33 self.setupUi(self)
34
35 self.__introducer = introducer
36
37 self.__okButton = self.buttonBox.button(QDialogButtonBox.Ok)
38 self.__okButton.setEnabled(False)
39 self.__previewButton = self.buttonBox.addButton(
40 self.trUtf8("Preview"), QDialogButtonBox.ActionRole)
41 self.__previewButton.setDefault(True)
42
43 self.nameEdit.setText("new_parameter")
44 self.nameEdit.selectAll()
45
46 @pyqtSlot(str)
47 def on_nameEdit_textChanged(self, text):
48 """
49 Private slot to react to changes of the name.
50
51 @param text text entered into the edit (string)
52 """
53 self.__okButton.setEnabled(text != "")
54
55 @pyqtSlot(QAbstractButton)
56 def on_buttonBox_clicked(self, button):
57 """
58 Private slot to act on the button pressed.
59
60 @param button reference to the button pressed (QAbstractButton)
61 """
62 if button == self.__previewButton:
63 self.previewChanges()
64 elif button == self.__okButton:
65 self.applyChanges()
66
67 def _calculateChanges(self, handle):
68 """
69 Protected method to calculate the changes.
70
71 @param handle reference to the task handle
72 (rope.base.taskhandle.TaskHandle)
73 @return reference to the Changes object (rope.base.change.ChangeSet)
74 """
75 try:
76 changes = self.__introducer.get_changes(self.nameEdit.text())
77 return changes
78 except Exception as err:
79 self._refactoring.handleRopeError(err, self._title, handle)
80 return None

eric ide

mercurial