| Conditions | 7 | 
| Total Lines | 63 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | # -*- coding: utf-8 -*-  | 
            ||
| 91 | def __init__(self, parent=None, parameters_dict=None):  | 
            ||
| 92 | super().__init__(parent)  | 
            ||
| 93 | if parameters_dict is None:  | 
            ||
| 94 | self._parameters = OrderedDict()  | 
            ||
| 95 | else:  | 
            ||
| 96 | self._parameters = parameters_dict  | 
            ||
| 97 | |||
| 98 | self._width_hint = 90 * len(self._parameters)  | 
            ||
| 99 | self._ach_widgets = OrderedDict()  | 
            ||
| 100 | |||
| 101 | main_layout = QtGui.QHBoxLayout()  | 
            ||
| 102 | for param in self._parameters:  | 
            ||
| 103 | label = QtGui.QLabel(param)  | 
            ||
| 104 | label.setAlignment(QtCore.Qt.AlignCenter)  | 
            ||
| 105 | if self._parameters[param]['type'] == float:  | 
            ||
| 106 | widget = ScienDSpinBox()  | 
            ||
| 107 | widget.setMinimum(self._parameters[param]['min'])  | 
            ||
| 108 | widget.setMaximum(self._parameters[param]['max'])  | 
            ||
| 109 | widget.setDecimals(6, False)  | 
            ||
| 110 | widget.setValue(self._parameters[param]['init'])  | 
            ||
| 111 | widget.setSuffix(self._parameters[param]['unit'])  | 
            ||
| 112 | # Set size constraints  | 
            ||
| 113 | widget.setFixedWidth(90)  | 
            ||
| 114 | # Forward editingFinished signal of child widget  | 
            ||
| 115 | widget.editingFinished.connect(self.editingFinished)  | 
            ||
| 116 | elif self._parameters[param]['type'] == int:  | 
            ||
| 117 | widget = ScienSpinBox()  | 
            ||
| 118 | widget.setValue(self._parameters[param]['init'])  | 
            ||
| 119 | widget.setMinimum(self._parameters[param]['min'])  | 
            ||
| 120 | widget.setMaximum(self._parameters[param]['max'])  | 
            ||
| 121 | widget.setSuffix(self._parameters[param]['unit'])  | 
            ||
| 122 | # Set size constraints  | 
            ||
| 123 | widget.setFixedWidth(90)  | 
            ||
| 124 | # Forward editingFinished signal of child widget  | 
            ||
| 125 | widget.editingFinished.connect(self.editingFinished)  | 
            ||
| 126 | elif self._parameters[param]['type'] == str:  | 
            ||
| 127 | widget = QtGui.QLineEdit()  | 
            ||
| 128 | widget.setText(self._parameters[param]['init'])  | 
            ||
| 129 | # Set size constraints  | 
            ||
| 130 | widget.setFixedWidth(90)  | 
            ||
| 131 | # Forward editingFinished signal of child widget  | 
            ||
| 132 | widget.editingFinished.connect(self.editingFinished)  | 
            ||
| 133 | elif self._parameters[param]['type'] == bool:  | 
            ||
| 134 | widget = QtGui.QCheckBox()  | 
            ||
| 135 | widget.setChecked(self._parameters[param]['init'])  | 
            ||
| 136 | # Set size constraints  | 
            ||
| 137 | widget.setFixedWidth(90)  | 
            ||
| 138 | # Forward editingFinished signal of child widget  | 
            ||
| 139 | widget.stateChanged.connect(self.editingFinished)  | 
            ||
| 140 | |||
| 141 |             self._ach_widgets[param] = {'label': label, 'widget': widget} | 
            ||
| 142 | |||
| 143 | v_layout = QtGui.QVBoxLayout()  | 
            ||
| 144 | v_layout.addWidget(label)  | 
            ||
| 145 | v_layout.addWidget(widget)  | 
            ||
| 146 | v_layout.setAlignment(label, QtCore.Qt.AlignHCenter)  | 
            ||
| 147 | v_layout.setAlignment(widget, QtCore.Qt.AlignHCenter)  | 
            ||
| 148 | main_layout.addLayout(v_layout)  | 
            ||
| 149 | |||
| 150 | main_layout.addStretch(1)  | 
            ||
| 151 | main_layout.setSpacing(0)  | 
            ||
| 152 | main_layout.setContentsMargins(0, 0, 0, 0)  | 
            ||
| 153 | self.setLayout(main_layout)  | 
            ||
| 154 | |||
| 192 |