Commit f1722b64 authored by Carsten Richter's avatar Carsten Richter

Merge branch 'code-style' into 'master'

Code style update in merging

See merge request !93
parents 50060d23 686ca178
Pipeline #6709 passed with stages
in 4 minutes and 43 seconds
This diff is collapsed.
This diff is collapsed.
......@@ -38,6 +38,28 @@ _PHI_LOWER = u'\u03C6'
_ETA_LOWER = u'\u03B7'
class _DblValidator(Qt.QDoubleValidator):
"""QDoubleValidator accepting empty text"""
def validate(self, text, pos):
if len(text) == 0:
return Qt.QValidator.Acceptable, text, pos
return super(_DblValidator, self).validate(text, pos)
def _dblLineEditWidget(width, read_only):
"""Returns a LineEdit of given width
:param int width: Widget's width in pixels
:param bool read_only: Set read only or read/write widget
:rtype: StyledLineEdit
"""
wid = StyledLineEdit(nChar=width,
readOnly=read_only)
wid.setValidator(_DblValidator())
return wid
class AcqParamsWidget(Qt.QWidget):
def __init__(self,
......@@ -47,33 +69,14 @@ class AcqParamsWidget(Qt.QWidget):
layout = Qt.QGridLayout(self)
layout.setContentsMargins(0, 0, 0, 0)
self.__read_only = read_only
self.__beam_energy = None
self.__dir_beam_h = None
self.__dir_beam_v = None
self.__chpdeg_h = None
self.__chpdeg_v = None
class DblValidator(Qt.QDoubleValidator):
def validate(self, text, pos):
if len(text) == 0:
return Qt.QValidator.Acceptable, text, pos
return super(DblValidator, self).validate(text, pos)
def dblLineEditWidget(width):
wid = StyledLineEdit(nChar=width,
readOnly=read_only)
wid.setValidator(DblValidator())
return wid
# ===========
# beam energy
# ===========
row = 0
h_layout = Qt.QHBoxLayout()
self.__beam_nrg_edit = dblLineEditWidget(8)
self.__beam_nrg_edit = _dblLineEditWidget(8, read_only)
h_layout.addWidget(self.__beam_nrg_edit)
h_layout.addWidget(Qt.QLabel('<b>eV</b>'))
......@@ -96,10 +99,10 @@ class AcqParamsWidget(Qt.QWidget):
h_layout = Qt.QHBoxLayout()
layout.addLayout(h_layout, row, 1,
alignment=Qt.Qt.AlignLeft | Qt.Qt.AlignTop)
self.__dir_beam_v_edit = dblLineEditWidget(6)
self.__dir_beam_v_edit = _dblLineEditWidget(6, read_only)
h_layout.addWidget(Qt.QLabel('v='))
h_layout.addWidget(self.__dir_beam_v_edit)
self.__dir_beam_h_edit = dblLineEditWidget(6)
self.__dir_beam_h_edit = _dblLineEditWidget(6, read_only)
h_layout.addWidget(Qt.QLabel(' h='))
h_layout.addWidget(self.__dir_beam_h_edit)
h_layout.addWidget(Qt.QLabel('<b>px</b>'))
......@@ -121,10 +124,10 @@ class AcqParamsWidget(Qt.QWidget):
h_layout = Qt.QHBoxLayout()
layout.addLayout(h_layout, row, 1,
alignment=Qt.Qt.AlignLeft | Qt.Qt.AlignTop)
self.__chpdeg_v_edit = dblLineEditWidget(6)
self.__chpdeg_v_edit = _dblLineEditWidget(6, read_only)
h_layout.addWidget(Qt.QLabel('v='))
h_layout.addWidget(self.__chpdeg_v_edit)
self.__chpdeg_h_edit = dblLineEditWidget(6)
self.__chpdeg_h_edit = _dblLineEditWidget(6, read_only)
h_layout.addWidget(Qt.QLabel(' h='))
h_layout.addWidget(self.__chpdeg_h_edit)
h_layout.addWidget(Qt.QLabel('<b>px</b>'))
......@@ -161,7 +164,6 @@ class AcqParamsWidget(Qt.QWidget):
@beam_energy.setter
def beam_energy(self, beam_energy):
self.__beam_nrg_edit.setText(str(beam_energy))
self.__beam_energy = beam_energy
@property
def direct_beam_h(self):
......@@ -173,7 +175,6 @@ class AcqParamsWidget(Qt.QWidget):
@direct_beam_h.setter
def direct_beam_h(self, direct_beam_h):
self.__dir_beam_h_edit.setText(str(direct_beam_h))
self.__dir_beam_h = direct_beam_h
@property
def direct_beam_v(self):
......@@ -185,7 +186,6 @@ class AcqParamsWidget(Qt.QWidget):
@direct_beam_v.setter
def direct_beam_v(self, direct_beam_v):
self.__dir_beam_v_edit.setText(str(direct_beam_v))
self.__dir_beam_v = direct_beam_v
@property
def chperdeg_h(self):
......@@ -197,7 +197,6 @@ class AcqParamsWidget(Qt.QWidget):
@chperdeg_h.setter
def chperdeg_h(self, chperdeg_h):
self.__chpdeg_h_edit.setText(str(chperdeg_h))
self.__chpdeg_h = chperdeg_h
@property
def chperdeg_v(self):
......@@ -209,4 +208,3 @@ class AcqParamsWidget(Qt.QWidget):
@chperdeg_v.setter
def chperdeg_v(self, chperdeg_v):
self.__chpdeg_v_edit.setText(str(chperdeg_v))
self.__chpdeg_v = chperdeg_v
......@@ -116,7 +116,6 @@ class KmapMerger(object):
self.__output_dir = output_dir
self.__params = {'prefix': None,
'beam_energy': None,
'center_channel': None,
'chan_per_deg': None}
......@@ -153,11 +152,10 @@ class KmapMerger(object):
self.__set_status(self.READY)
def __set_status(self, status, msg=None):
"""
Sets the status of this instance.
"""Sets the status of this instance.
:param status:
:param msg:
:return:
"""
assert status in self.__STATUSES
self.__status = status
......@@ -167,15 +165,14 @@ class KmapMerger(object):
overwrite=False,
blocking=True,
callback=None):
"""
Starts the merge.
"""Starts the merge.
:param overwrite: if False raises an exception if some files already
exist.
exist.
:param blocking: if False, the merge will be done in a separate
thread and this method will return immediately.
:param callback: callback that will be called when the merging is done.
It overwrites the one passed the constructor.
:return:
It overwrites the one passed the constructor.
"""
self.__set_status(self.RUNNING)
......@@ -210,15 +207,11 @@ class KmapMerger(object):
if blocking:
self.__run_merge()
else:
thread = self.__thread = Thread(target=self.__run_merge)
thread.start()
self.__thread = Thread(target=self.__run_merge)
self.__thread.start()
def __run_merge(self):
"""
Runs the merge.
:return:
"""
"""Runs the merge."""
self.__set_status(self.RUNNING)
self.__master = None
......@@ -239,7 +232,7 @@ class KmapMerger(object):
try:
manager = Manager()
self.__term_evt = term_evt = manager.Event()
self.__term_evt = manager.Event()
self.__shared_progress = mp_sharedctypes.RawArray(ctypes.c_int32,
len(scans))
......@@ -260,7 +253,7 @@ class KmapMerger(object):
pool = Pool(self.n_proc,
initializer=_init_process,
initargs=(term_evt,
initargs=(self.__term_evt,
self.__shared_progress),
maxtasksperchild=2)
......@@ -268,10 +261,10 @@ class KmapMerger(object):
scan, finished, info = result_
_logger.info('{0} finished.'.format(scan))
if not finished:
term_evt.set()
self.__term_evt.set()
results = {}
self.__proc_indices = proc_indices = {}
self.__proc_indices = {}
for proc_idx, (scan_id, infos) in enumerate(scans.items()):
args = (scan_id,
proc_idx,
......@@ -287,11 +280,9 @@ class KmapMerger(object):
results[scan_id] = pool.apply_async(_add_edf_data,
args,
callback=callback)
proc_indices[scan_id] = proc_idx
self.__proc_indices[scan_id] = proc_idx
pool.close()
self.__proc_indices = proc_indices
pool.join()
proc_results = [result.get() for result in results.values()]
......@@ -332,10 +323,7 @@ class KmapMerger(object):
return self.__results
def wait(self):
"""
Waits until parsing is done, or returns if it is not running.
:return:
"""
"""Waits until parsing is done, or returns if it is not running."""
if self.__thread:
self.__thread.join()
......@@ -377,7 +365,6 @@ class KmapMerger(object):
self.__selected_ids |= scan_ids
def unselect(self, scan_ids):
if scan_ids is None:
return
......@@ -444,9 +431,7 @@ class KmapMerger(object):
return exist
def check_consistency(self):
"""
Checks if all selected scans have the same command.
"""
"""Checks if all selected scans have the same command."""
errors = []
scan_ids = self.selected_ids
n_scans = len(scan_ids)
......@@ -503,7 +488,7 @@ class KmapMerger(object):
if len(chan_per_deg) != 2:
raise ValueError('chan_per_deg must be a two elements array.')
self.__params['chan_per_deg'] = [float(chan_per_deg[0]),
float(chan_per_deg[1])]
float(chan_per_deg[1])]
center_chan = property(lambda self: self.__params['center_chan'])
......@@ -534,7 +519,6 @@ class KmapMerger(object):
raise ValueError('n_proc must be strictly positive')
self.__n_proc = n_proc
image_roi = property(lambda self: self.__image_roi)
""" Image ROI (origin_row, origin_column, height, width) to save.
......@@ -657,11 +641,10 @@ class KmapMerger(object):
# TODO : rework
if self.__shared_progress is not None:
progress = np.frombuffer(self.__shared_progress, dtype='int32')
proc_indices = self.__proc_indices
if proc_indices:
if self.__proc_indices:
merge_progress = dict([(scan_id, progress[proc_idx])
for scan_id, proc_idx in
proc_indices.items()])
self.__proc_indices.items()])
else:
merge_progress = dict([(scan_id, 0)
for scan_id in self.selected_ids])
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment