RefactoringRope/IntroduceFactoryDialog.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 Factory dialog.
8 """
9
10 from PyQt4.QtCore import pyqtSlot
11 from PyQt4.QtGui import QDialogButtonBox, QAbstractButton
12
13 from Ui_IntroduceFactoryDialog import Ui_IntroduceFactoryDialog
14 from RefactoringDialogBase import RefactoringDialogBase
15
16 class IntroduceFactoryDialog(RefactoringDialogBase, Ui_IntroduceFactoryDialog):
17 """
18 Class implementing the Introduce Factory dialog.
19 """
20 def __init__(self, refactoring, title, introducer, 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 introducer reference to the factory introducer object
28 (rope.refactor.introduce_factory.IntroduceFactoryRefactoring)
29 @param parent reference to the parent widget (QWidget)
30 """
31 RefactoringDialogBase.__init__(self, refactoring, title, parent)
32 self.setupUi(self)
33
34 self.__introducer = introducer
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.nameEdit.setText("create")
43 self.nameEdit.selectAll()
44
45 @pyqtSlot(str)
46 def on_nameEdit_textChanged(self, text):
47 """
48 Private slot to react to changes of the name.
49
50 @param text text entered into the edit (string)
51 """
52 self.__okButton.setEnabled(text != "")
53
54 @pyqtSlot(QAbstractButton)
55 def on_buttonBox_clicked(self, button):
56 """
57 Private slot to act on the button pressed.
58
59 @param button reference to the button pressed (QAbstractButton)
60 """
61 if button == self.__previewButton:
62 self.previewChanges()
63 elif button == self.__okButton:
64 self.applyChanges()
65
66 def _calculateChanges(self, handle):
67 """
68 Protected method to calculate the changes.
69
70 @param handle reference to the task handle
71 (rope.base.taskhandle.TaskHandle)
72 @return reference to the Changes object (rope.base.change.ChangeSet)
73 """
74 try:
75 changes = self.__introducer.get_changes(self.nameEdit.text(),
76 global_factory=self.globalButton.isChecked(),
77 task_handle=handle)
78 return changes
79 except Exception as err:
80 self._refactoring.handleRopeError(err, self._title, handle)
81 return None

eric ide

mercurial