Sun, 06 Jul 2014 14:23:25 +0200
Ported to PyQt5 and eric6.
8
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1 | # -*- coding: utf-8 -*- |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
2 | |
63
c02061242598
Updated copyright for 2014.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
50
diff
changeset
|
3 | # Copyright (c) 2010 - 2014 Detlev Offenbach <detlev@die-offenbachs.de> |
8
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
4 | # |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
5 | |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
6 | """ |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
7 | Module implementing the Inline dialog. |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
8 | """ |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
9 | |
76 | 10 | from __future__ import unicode_literals |
50
a29c3d2e6dc0
rope for Python2 projects enabled, if running on Python2
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
43
diff
changeset
|
11 | |
87
1fbf5fdbe721
Ported to PyQt5 and eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
76
diff
changeset
|
12 | from PyQt5.QtCore import pyqtSlot |
1fbf5fdbe721
Ported to PyQt5 and eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
76
diff
changeset
|
13 | from PyQt5.QtWidgets import QDialogButtonBox, QAbstractButton |
8
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
14 | |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
15 | from Ui_UseFunctionDialog import Ui_UseFunctionDialog |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
16 | from RefactoringDialogBase import RefactoringDialogBase |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
17 | |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
18 | |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
19 | class UseFunctionDialog(RefactoringDialogBase, Ui_UseFunctionDialog): |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
20 | """ |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
21 | Class implementing the Inline dialog. |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
22 | """ |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
23 | def __init__(self, refactoring, title, user, parent=None): |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
24 | """ |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
25 | Constructor |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
26 | |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
27 | @param refactoring reference to the main refactoring object |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
28 | (Refactoring) |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
29 | @param title title of the dialog (string) |
20
83b71483e198
Made the code PEP-8 compliant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8
diff
changeset
|
30 | @param user reference to the usefunction object |
8
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
31 | (rope.refactor.usefunction.UseFunction) |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
32 | @param parent reference to the parent widget (QWidget) |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
33 | """ |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
34 | RefactoringDialogBase.__init__(self, refactoring, title, parent) |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
35 | self.setupUi(self) |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
36 | |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
37 | self.__user = user |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
38 | |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
39 | self.description.setText( |
87
1fbf5fdbe721
Ported to PyQt5 and eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
76
diff
changeset
|
40 | self.tr("Using Function <b>{0}</b>.") |
8
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
41 | .format(self.__user.get_function_name())) |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
42 | |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
43 | self.__okButton = self.buttonBox.button(QDialogButtonBox.Ok) |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
44 | self.__previewButton = self.buttonBox.addButton( |
87
1fbf5fdbe721
Ported to PyQt5 and eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
76
diff
changeset
|
45 | self.tr("Preview"), QDialogButtonBox.ActionRole) |
8
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
46 | self.__previewButton.setDefault(True) |
74
0973b175e2ad
Fixed a window sizing issue.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
62
diff
changeset
|
47 | |
0973b175e2ad
Fixed a window sizing issue.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
62
diff
changeset
|
48 | msh = self.minimumSizeHint() |
0973b175e2ad
Fixed a window sizing issue.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
62
diff
changeset
|
49 | self.resize(max(self.width(), msh.width()), msh.height()) |
8
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
50 | |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
51 | @pyqtSlot(QAbstractButton) |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
52 | def on_buttonBox_clicked(self, button): |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
53 | """ |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
54 | Private slot to act on the button pressed. |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
55 | |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
56 | @param button reference to the button pressed (QAbstractButton) |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
57 | """ |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
58 | if button == self.__previewButton: |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
59 | self.previewChanges() |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
60 | elif button == self.__okButton: |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
61 | self.applyChanges() |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
62 | |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
63 | def _calculateChanges(self, handle): |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
64 | """ |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
65 | Protected method to calculate the changes. |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
66 | |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
67 | @param handle reference to the task handle |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
68 | (rope.base.taskhandle.TaskHandle) |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
69 | @return reference to the Changes object (rope.base.change.ChangeSet) |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
70 | """ |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
71 | try: |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
72 | changes = self.__user.get_changes(task_handle=handle) |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
73 | return changes |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
74 | except Exception as err: |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
75 | self._refactoring.handleRopeError(err, self._title, handle) |
fc14525f0501
Added the 'use function' refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
76 | return None |