RefactoringRope/GetterSetterDialog.py

branch
eric7
changeset 389
4f53795beff0
parent 374
958f34e97952
child 409
65153bf17e8d
equal deleted inserted replaced
388:cb044ec27c24 389:4f53795beff0
16 16
17 class GetterSetterDialog(RefactoringDialogBase, Ui_GetterSetterDialog): 17 class GetterSetterDialog(RefactoringDialogBase, Ui_GetterSetterDialog):
18 """ 18 """
19 Class implementing the encapsulate attribute dialog. 19 Class implementing the encapsulate attribute dialog.
20 """ 20 """
21
21 def __init__(self, refactoring, title, filename, offset, parent=None): 22 def __init__(self, refactoring, title, filename, offset, parent=None):
22 """ 23 """
23 Constructor 24 Constructor
24 25
25 @param refactoring reference to the main refactoring object 26 @param refactoring reference to the main refactoring object
26 @type RefactoringServer 27 @type RefactoringServer
27 @param title title of the dialog 28 @param title title of the dialog
28 @type str 29 @type str
29 @param filename file name to be worked on 30 @param filename file name to be worked on
33 @param parent reference to the parent widget 34 @param parent reference to the parent widget
34 @type QWidget 35 @type QWidget
35 """ 36 """
36 RefactoringDialogBase.__init__(self, refactoring, title, parent) 37 RefactoringDialogBase.__init__(self, refactoring, title, parent)
37 self.setupUi(self) 38 self.setupUi(self)
38 39
39 self._changeGroupName = "GetterSetter" 40 self._changeGroupName = "GetterSetter"
40 41
41 self.__filename = filename 42 self.__filename = filename
42 self.__offset = offset 43 self.__offset = offset
43 44
44 self.__okButton = self.buttonBox.button( 45 self.__okButton = self.buttonBox.button(QDialogButtonBox.StandardButton.Ok)
45 QDialogButtonBox.StandardButton.Ok)
46 self.__okButton.setEnabled(False) 46 self.__okButton.setEnabled(False)
47 self.__previewButton = self.buttonBox.addButton( 47 self.__previewButton = self.buttonBox.addButton(
48 self.tr("Preview"), QDialogButtonBox.ButtonRole.ActionRole) 48 self.tr("Preview"), QDialogButtonBox.ButtonRole.ActionRole
49 )
49 self.__previewButton.setDefault(True) 50 self.__previewButton.setDefault(True)
50 self.__previewButton.setEnabled(False) 51 self.__previewButton.setEnabled(False)
51 52
52 self.__fieldName = "" 53 self.__fieldName = ""
53 54
54 self._refactoring.sendJson("RequestFieldName", { 55 self._refactoring.sendJson(
55 "ChangeGroup": self._changeGroupName, 56 "RequestFieldName",
56 "Title": self._title, 57 {
57 "FileName": self.__filename, 58 "ChangeGroup": self._changeGroupName,
58 "Offset": self.__offset, 59 "Title": self._title,
59 }) 60 "FileName": self.__filename,
60 61 "Offset": self.__offset,
62 },
63 )
64
61 def __processFieldName(self, data): 65 def __processFieldName(self, data):
62 """ 66 """
63 Private method to process the field name data sent by the refactoring 67 Private method to process the field name data sent by the refactoring
64 client in order to polish the dialog. 68 client in order to polish the dialog.
65 69
66 @param data dictionary containing the inline type data 70 @param data dictionary containing the inline type data
67 @type dict 71 @type dict
68 """ 72 """
69 self.__fieldName = data["Name"] 73 self.__fieldName = data["Name"]
70 74
71 self.on_typeCheckBox_toggled(False) 75 self.on_typeCheckBox_toggled(False)
72 76
73 msh = self.minimumSizeHint() 77 msh = self.minimumSizeHint()
74 self.resize(max(self.width(), msh.width()), msh.height()) 78 self.resize(max(self.width(), msh.width()), msh.height())
75 79
76 def __updateUI(self): 80 def __updateUI(self):
77 """ 81 """
78 Private slot to update the UI. 82 Private slot to update the UI.
79 """ 83 """
80 enable = bool(self.getterEdit.text()) and bool(self.setterEdit.text()) 84 enable = bool(self.getterEdit.text()) and bool(self.setterEdit.text())
81 85
82 self.__okButton.setEnabled(enable) 86 self.__okButton.setEnabled(enable)
83 self.__previewButton.setEnabled(enable) 87 self.__previewButton.setEnabled(enable)
84 88
85 @pyqtSlot(str) 89 @pyqtSlot(str)
86 def on_getterEdit_textChanged(self, text): 90 def on_getterEdit_textChanged(self, text):
87 """ 91 """
88 Private slot to react to changes of the getter method. 92 Private slot to react to changes of the getter method.
89 93
90 @param text text entered into the edit 94 @param text text entered into the edit
91 @type str 95 @type str
92 """ 96 """
93 self.__updateUI() 97 self.__updateUI()
94 98
95 @pyqtSlot(str) 99 @pyqtSlot(str)
96 def on_setterEdit_textChanged(self, text): 100 def on_setterEdit_textChanged(self, text):
97 """ 101 """
98 Private slot to react to changes of the setter method. 102 Private slot to react to changes of the setter method.
99 103
100 @param text text entered into the edit 104 @param text text entered into the edit
101 @type str 105 @type str
102 """ 106 """
103 self.__updateUI() 107 self.__updateUI()
104 108
105 @pyqtSlot(bool) 109 @pyqtSlot(bool)
106 def on_typeCheckBox_toggled(self, checked): 110 def on_typeCheckBox_toggled(self, checked):
107 """ 111 """
108 Private slot to react to changes of the type checkbox. 112 Private slot to react to changes of the type checkbox.
109 113
110 @param checked state of the checkbox 114 @param checked state of the checkbox
111 @type bool 115 @type bool
112 """ 116 """
113 if checked: 117 if checked:
114 self.getterEdit.setText("get_{0}".format(self.__fieldName)) 118 self.getterEdit.setText("get_{0}".format(self.__fieldName))
115 self.setterEdit.setText("set_{0}".format(self.__fieldName)) 119 self.setterEdit.setText("set_{0}".format(self.__fieldName))
116 else: 120 else:
117 self.getterEdit.setText( 121 self.getterEdit.setText("get{0}".format(self.__fieldName.capitalize()))
118 "get{0}".format(self.__fieldName.capitalize())) 122 self.setterEdit.setText("set{0}".format(self.__fieldName.capitalize()))
119 self.setterEdit.setText( 123
120 "set{0}".format(self.__fieldName.capitalize()))
121
122 @pyqtSlot(QAbstractButton) 124 @pyqtSlot(QAbstractButton)
123 def on_buttonBox_clicked(self, button): 125 def on_buttonBox_clicked(self, button):
124 """ 126 """
125 Private slot to act on the button pressed. 127 Private slot to act on the button pressed.
126 128
127 @param button reference to the button pressed 129 @param button reference to the button pressed
128 @type QAbstractButton 130 @type QAbstractButton
129 """ 131 """
130 if button == self.__previewButton: 132 if button == self.__previewButton:
131 self.requestPreview() 133 self.requestPreview()
132 elif button == self.__okButton: 134 elif button == self.__okButton:
133 self.applyChanges() 135 self.applyChanges()
134 136
135 def _calculateChanges(self): 137 def _calculateChanges(self):
136 """ 138 """
137 Protected method to initiate the calculation of the changes. 139 Protected method to initiate the calculation of the changes.
138 """ 140 """
139 self._refactoring.sendJson("CalculateEncapsulateFieldChanges", { 141 self._refactoring.sendJson(
140 "ChangeGroup": self._changeGroupName, 142 "CalculateEncapsulateFieldChanges",
141 "Title": self._title, 143 {
142 "FileName": self.__filename, 144 "ChangeGroup": self._changeGroupName,
143 "Offset": self.__offset, 145 "Title": self._title,
144 "Getter": self.getterEdit.text(), 146 "FileName": self.__filename,
145 "Setter": self.setterEdit.text(), 147 "Offset": self.__offset,
146 }) 148 "Getter": self.getterEdit.text(),
147 149 "Setter": self.setterEdit.text(),
150 },
151 )
152
148 def processChangeData(self, data): 153 def processChangeData(self, data):
149 """ 154 """
150 Public method to process the change data sent by the refactoring 155 Public method to process the change data sent by the refactoring
151 client. 156 client.
152 157
153 @param data dictionary containing the change data 158 @param data dictionary containing the change data
154 @type dict 159 @type dict
155 """ 160 """
156 subcommand = data["Subcommand"] 161 subcommand = data["Subcommand"]
157 if subcommand == "FieldName": 162 if subcommand == "FieldName":

eric ide

mercurial