|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2011 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the Inline dialog. |
|
8 """ |
|
9 |
|
10 from PyQt4.QtCore import pyqtSlot |
|
11 from PyQt4.QtGui import QDialogButtonBox, QAbstractButton |
|
12 |
|
13 from Ui_UseFunctionDialog import Ui_UseFunctionDialog |
|
14 from RefactoringDialogBase import RefactoringDialogBase |
|
15 |
|
16 |
|
17 class UseFunctionDialog(RefactoringDialogBase, Ui_UseFunctionDialog): |
|
18 """ |
|
19 Class implementing the Inline dialog. |
|
20 """ |
|
21 def __init__(self, refactoring, title, user, 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 user reference to the usefunction object |
|
29 (rope.refactor.usefunction.UseFunction) |
|
30 @param parent reference to the parent widget (QWidget) |
|
31 """ |
|
32 RefactoringDialogBase.__init__(self, refactoring, title, parent) |
|
33 self.setupUi(self) |
|
34 |
|
35 self.__user = user |
|
36 |
|
37 self.description.setText( |
|
38 self.trUtf8("Using Function <b>{0}</b>.")\ |
|
39 .format(self.__user.get_function_name())) |
|
40 |
|
41 self.__okButton = self.buttonBox.button(QDialogButtonBox.Ok) |
|
42 self.__previewButton = self.buttonBox.addButton( |
|
43 self.trUtf8("Preview"), QDialogButtonBox.ActionRole) |
|
44 self.__previewButton.setDefault(True) |
|
45 |
|
46 @pyqtSlot(QAbstractButton) |
|
47 def on_buttonBox_clicked(self, button): |
|
48 """ |
|
49 Private slot to act on the button pressed. |
|
50 |
|
51 @param button reference to the button pressed (QAbstractButton) |
|
52 """ |
|
53 if button == self.__previewButton: |
|
54 self.previewChanges() |
|
55 elif button == self.__okButton: |
|
56 self.applyChanges() |
|
57 |
|
58 def _calculateChanges(self, handle): |
|
59 """ |
|
60 Protected method to calculate the changes. |
|
61 |
|
62 @param handle reference to the task handle |
|
63 (rope.base.taskhandle.TaskHandle) |
|
64 @return reference to the Changes object (rope.base.change.ChangeSet) |
|
65 """ |
|
66 try: |
|
67 changes = self.__user.get_changes(task_handle=handle) |
|
68 return changes |
|
69 except Exception as err: |
|
70 self._refactoring.handleRopeError(err, self._title, handle) |
|
71 return None |