Conditions | 1 |
Total Lines | 92 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 -*- |
||
73 | def on_activate(self, e=None): |
||
74 | """ Definition and initialisation of the GUI. |
||
75 | |||
76 | @param object e: Fysom.event object from Fysom class. |
||
77 | An object created by the state machine module Fysom, |
||
78 | which is connected to a specific event (have a look in |
||
79 | the Base Class). This object contains the passed event, |
||
80 | the state before the event happened and the destination |
||
81 | of the state which should be reached after the event |
||
82 | had happened. |
||
83 | """ |
||
84 | |||
85 | self._counter_logic = self.gatedcounterlogic1() |
||
86 | self._trace_analysis = self.traceanalysislogic1() |
||
87 | |||
88 | self._mw = GatedCounterMainWindow() |
||
89 | self._mw.centralwidget.hide() |
||
90 | self._mw.setDockNestingEnabled(True) |
||
91 | self.set_default_view_main_window() |
||
92 | |||
93 | self._gp = self._mw.gated_count_trace_PlotWidget |
||
94 | self._gp.setLabel('left', 'Counts', units='counts/s') |
||
95 | self._gp.setLabel('bottom', 'Number of Gates', units='#') |
||
96 | |||
97 | # Create an empty plot curve to be filled later, set its pen |
||
98 | self._trace1 = self._gp.plot() |
||
99 | self._trace1.setPen(palette.c1) |
||
100 | |||
101 | self._hp = self._mw.histogram_PlotWidget |
||
102 | self._hp.setLabel('left', 'Occurrences', units='#') |
||
103 | self._hp.setLabel('bottom', 'Counts', units='counts/s') |
||
104 | |||
105 | self._histoplot1 = pg.PlotCurveItem() |
||
106 | self._histoplot1.setPen(palette.c1) |
||
107 | self._hp.addItem(self._histoplot1) |
||
108 | |||
109 | |||
110 | # Configure the fit of the data in the main pulse analysis display: |
||
111 | self._fit_image = pg.PlotCurveItem() |
||
112 | self._hp.addItem(self._fit_image) |
||
113 | |||
114 | # setting the x axis length correctly |
||
115 | self._gp.setXRange(0, self._counter_logic.get_count_length()) |
||
116 | self._mw.hist_bins_SpinBox.setRange(1, self._counter_logic.get_count_length()) |
||
117 | |||
118 | # set up the slider with the values of the logic: |
||
119 | self._mw.hist_bins_Slider.setRange(1,self._counter_logic.get_count_length()) |
||
120 | self._mw.hist_bins_Slider.setSingleStep(1) |
||
121 | |||
122 | # set the counting mode in the logic: |
||
123 | self._counter_logic.set_counting_mode('FINITE_GATED') |
||
124 | |||
125 | # Setting default parameters |
||
126 | self._mw.count_length_SpinBox.setValue(self._counter_logic.get_count_length()) |
||
127 | self._mw.count_per_readout_SpinBox.setValue(self._counter_logic.get_counting_samples()) |
||
128 | |||
129 | # Connecting user interactions |
||
130 | # set at first the action buttons in the tab |
||
131 | self._mw.start_counter_Action.triggered.connect(self.start_clicked) |
||
132 | self._mw.stop_counter_Action.triggered.connect(self.stop_clicked) |
||
133 | self._mw.save_measurement_Action.triggered.connect(self.save_clicked) |
||
134 | self._mw.actionRestore_Default.triggered.connect(self.set_default_view_main_window) |
||
135 | |||
136 | # that is also the default value of the histogram method in logic |
||
137 | # important: the set of a value should not trigger a redrawn of the |
||
138 | # current empty histogram, which is at the start of the program. |
||
139 | self._mw.hist_bins_SpinBox.setValue(50) |
||
140 | # connect now a reaction on a change of the various input widgets: |
||
141 | self._mw.count_length_SpinBox.editingFinished.connect(self.count_length_changed) |
||
142 | self._mw.count_per_readout_SpinBox.editingFinished.connect(self.count_per_readout_changed) |
||
143 | self._mw.hist_bins_Slider.valueChanged.connect(self.num_bins_changed) |
||
144 | self._mw.hist_bins_SpinBox.valueChanged.connect(self.num_bins_changed) |
||
145 | self._trace_analysis.sigHistogramUpdated.connect(self.update_histogram) |
||
146 | |||
147 | |||
148 | # starting the physical measurement: |
||
149 | self.sigStartGatedCounter.connect(self._counter_logic.startCount) |
||
150 | self.sigStopGatedCounter.connect(self._counter_logic.stopCount) |
||
151 | |||
152 | # connect to signals in the logic: |
||
153 | self._counter_logic.sigCounterUpdated.connect(self.update_trace) |
||
154 | self._counter_logic.sigGatedCounterFinished.connect(self.reset_toolbar_display) |
||
155 | |||
156 | # configuration of the combo widget |
||
157 | fit_functions = self._trace_analysis.get_fit_functions() |
||
158 | self._mw.fit_methods_ComboBox.addItems(fit_functions) |
||
159 | |||
160 | # Push buttons |
||
161 | self._mw.fit_PushButton.clicked.connect(self.fit_clicked) |
||
162 | |||
163 | # Connect analysis result update |
||
164 | self._trace_analysis.sigAnalysisResultsUpdated.connect(self.update_analysis_results) |
||
165 | |||
304 |