def _update_temptint(self, args=None): if args is None: args = self._device.get_temperature_tint() if args: with no_update(self): self.trait_set(temperature=int(args[0]), tint=int(args[1]))
def _load_holder_positions(self, holes): self.irradiated_positions = [] if holes: with dirty_ctx(self): with no_update(self): self.irradiated_positions = [IrradiatedPosition(hole=int(c), pos=(x, y)) for x, y, r, c in holes]
def load(self, s): with no_update(self): try: s = self._extract_docstring(s) except SyntaxError: return if s: try: ctx = yaml.load(s) except yaml.ScannerError: return self.multicollect.load(ctx) self.baseline.load(ctx) self.peakcenter.load(ctx) # self.multicollect.detectors = self.detectors # self.multicollect.isotopes = self.isotopes # self.peakcenter.detectors = self.detectors # self.peakcenter.isotopes = self.isotopes self.equilibration.load(ctx) self.peakhop.load(ctx) self.default_fits = ctx.get('default_fits', '')
def _active_editor_changed(self, new): if new: self.last_activated = time.time() if self.controls_pane: tool = None # if hasattr(new, 'tool'): # tool = new.tool if hasattr(new, 'search_tool'): tool = new.search_tool self.controls_pane.tool = tool if isinstance(new, FigureEditor): self.plotter_options_pane.pom = new.plotter_options_manager if isinstance(new, SystemMonitorEditor): self.console_pane.name = '{} - Console'.format(new.name) self.console_pane.console_display = new.console_display self.connection_pane.conn_spec = new.conn_spec if self.unknowns_pane: if hasattr(new, 'analyses'): with no_update(self.unknowns_pane, fire_update_needed=False): self.unknowns_pane.trait_set(items=new.analyses)
def _move_selected(self, idx): with no_update(self): for si in self.selected: self.automated_runs.remove(si) for si in reversed(self.selected): self.automated_runs.insert(idx, si)
def dropEvent(self, e): if self.is_external(): data = PyMimeData.coerce(e.mimeData()).instance() if not hasattr(data, '__iter__'): return df = self.drop_factory if not df: df = lambda x: x row = self.rowAt(e.pos().y()) n = len(self._editor.value) if row == -1: row = n model = self._editor.model if self._dragging: rows = [ri for ri, _ in data] model.moveRows(rows, row) else: data = [di for _, di in data] with no_update(self._editor.object): for i, di in enumerate(reversed(data)): if isinstance(di, tuple): di = di[1] model.insertRow(row=row, obj=df(di)) for i, di in enumerate(reversed(df(data))): model.insertRow(row=row, obj=di) e.accept() self._dragging = None else: super(_TableView, self).dropEvent(e)
def dropEvent(self, e): if self.is_external(): data = PyMimeData.coerce(e.mimeData()).instance() if not hasattr(data, '__iter__'): return df = self.drop_factory if not df: df = lambda x: x row = self.rowAt(e.pos().y()) n = len(self._editor.value) if row == -1: row = n model = self._editor.model if self._dragging: rows = [ri for ri, _ in data] model.moveRows(rows, row) else: with no_update(self._editor.object): for i, di in enumerate(reversed(data)): if isinstance(di, tuple): di = di[1] model.insertRow(row=row, obj=df(di)) e.accept() self._dragging = None else: super(_TableView, self).dropEvent(e)
def load(self, s): with no_update(self): try: s = self._extract_docstring(s) except SyntaxError: return if s: try: ctx = yaml.load(s) except yaml.YAMLError: return self.multicollect.load(ctx) self.baseline.load(ctx) self.peakcenter.load(ctx) # self.multicollect.detectors = self.detectors # self.multicollect.isotopes = self.isotopes # self.peakcenter.detectors = self.detectors # self.peakcenter.isotopes = self.isotopes self.equilibration.load(ctx) self.peakhop.load(ctx) self.default_fits = ctx.get('default_fits', '') self._octx = ctx
def add_runs(self, runviews, freq=None): ''' runviews: list of runs freq: optional inter ''' if not runviews: return with no_update(self): aruns = self.automated_runs # self._suppress_aliquot_update = True if freq: cnt = 0 n = len(aruns) for i, ai in enumerate(aruns[::-1]): if cnt == freq: run = runviews[0].clone_traits() run.frequency_added = True aruns.insert(n - i, run) cnt = 0 if ai.analysis_type in ('unknown', 'air', 'cocktail'): cnt += 1 else: if self.selected: idx = aruns.index(self.selected[-1]) for ri in reversed(runviews): aruns.insert(idx + 1, ri) else: aruns.extend(runviews)
def _active_editor_changed(self, new): if new: self.last_activated = time.time() if self.controls_pane: tool = None # if hasattr(new, 'tool'): # tool = new.tool if hasattr(new, "search_tool"): tool = new.search_tool self.controls_pane.tool = tool if isinstance(new, FigureEditor): self.plotter_options_pane.pom = new.plotter_options_manager if isinstance(new, SystemMonitorEditor): self.console_pane.name = "{} - Console".format(new.name) self.console_pane.console_display = new.console_display self.connection_pane.conn_spec = new.conn_spec if self.unknowns_pane: if hasattr(new, "analyses"): with no_update(self.unknowns_pane, fire_update_needed=False): self.unknowns_pane.trait_set(items=new.analyses)
def _set_current_task(self): with no_update(self): if isinstance(self.active_editor, IdeogramEditor): self.browser_model.current_task_name = 'Ideogram' elif isinstance(self.active_editor, SpectrumEditor): self.browser_model.current_task_name = 'Spectrum' else: super(FigureTask, self)._set_current_task()
def move(self, step): if self.selected: with no_update(self): run = self.selected[0] idx = self.automated_runs.index(run) idx = max(min(0, idx + step), len(self.automated_runs) - 1) self._move_selected(idx + step)
def _key_press_hook(self, event): """ Reimplemented to support edit, insert, and delete by keyboard. reimplmented to support no_update context manager. """ editor = self._editor factory = editor.factory # Note that setting 'EditKeyPressed' as an edit trigger does not work on # most platforms, which is why we do this here. if (event.key() in (QtCore.Qt.Key_Enter, QtCore.Qt.Key_Return) and self.state() != QtGui.QAbstractItemView.EditingState and factory.editable and 'edit' in factory.operations): if factory.multi_select: rows = editor.multi_selected_rows row = rows[0] if len(rows) == 1 else -1 else: row = editor.selected_row if row != -1: event.accept() self.edit(editor.model.index(row, 0)) elif (event.key() in (QtCore.Qt.Key_Backspace, QtCore.Qt.Key_Delete) and factory.editable and 'delete' in factory.operations): event.accept() ''' sets _no_update and update_needed on the editor.object e.g editor.object== ExperimentQueue editor is editing ExperimentQueue.automated_runs ''' with no_update(editor.object): if factory.multi_select: for row in reversed(sorted(editor.multi_selected_rows)): editor.model.removeRow(row) elif editor.selected_row != -1: editor.model.removeRow(editor.selected_row) elif (event.key() == QtCore.Qt.Key_Insert and factory.editable and 'insert' in factory.operations): event.accept() if factory.multi_select: rows = sorted(editor.multi_selected_rows) row = rows[0] if len(rows) else -1 else: row = editor.selected_row if row == -1: row = editor.adapter.len(editor.object, editor.name) editor.model.insertRow(row) self.setCurrentIndex(editor.model.index(row, 0)) else: QtGui.QTableView.keyPressEvent(self, event)
def _make_positions(self, n, positions): with no_update(self): for pi in positions: hi = pi.position - 1 if hi < n: ir = self.irradiated_positions[hi] self._sync_position(pi, ir) else: self.debug('extra irradiation position for this tray {}'.format(hi))
def load(self, txt): self.initialized = False self.stats.delay_between_analyses = self.delay_between_analyses aruns = self._load_runs(txt) if aruns: with no_update(self): self.automated_runs = aruns self.initialized = True return True
def _load_holder_positions(self, holes): self.irradiated_positions = [] if holes: with dirty_ctx(self): with no_update(self): self.irradiated_positions = [ IrradiatedPosition(hole=int(c), pos=(x, y)) for x, y, r, c in holes ]
def move(self, step): if self.selected: with no_update(self): run = self.selected[0] idx = self.automated_runs.index(run) idx = max(min(0, idx+step), len(self.automated_runs)-1) self._move_selected(idx+step)
def _load_holder_positions(self, holder): self.irradiated_positions = [] geom = holder.geometry with dirty_ctx(self): if geom: with no_update(self): self.irradiated_positions = [IrradiatedPosition(hole=c + 1, pos=(x, y)) for c, (x, y, r) in iter_geom(geom)] elif holder.name: self._load_holder_positons_from_file(holder.name)
def _update_parameters(self): self._update_temptint() with no_update(self): d = {k: getattr(self._device, 'get_{}'.format(k))() for k in ('hue', 'saturation', 'brightness', 'contrast', 'gamma', 'auto_exposure', 'exposure_time')} try: self.trait_set(**d) except TraitError: pass
def _make_positions(self, n, positions): with no_update(self): for pi in positions: hi = pi.position - 1 if hi < n: ir = self.irradiated_positions[hi] self._sync_position(pi, ir) else: self.debug( 'extra irradiation position for this tray {}'.format( hi))
def _load_holder_positions(self, holder): self.irradiated_positions = [] geom = holder.geometry with dirty_ctx(self): if geom: with no_update(self): self.irradiated_positions = [ IrradiatedPosition(hole=c + 1, pos=(x, y)) for c, (x, y, r) in iter_geom(geom) ] elif holder.name: self._load_holder_positons_from_file(holder.name)
def _selected_changed(self, new): if new: teststr = new.teststr with no_update(self): for a in TAGS.split(','): try: setattr(self, a, getattr(new, a)) except AttributeError: continue self.function = '' self.secondary_value = 0 self.value = 0 self.modifier = '' for r, a in ((CP_REGEX, 'Current'), (STD_REGEX, 'StdDev'), (ACTIVE_REGEX, 'Inactive'), (BASELINECOR_REGEX, 'BaselineCorrected'), (BASELINE_REGEX, 'Baseline')): if r.search(teststr): setattr(self, 'modifier', a) break for r, a in ((MAX_REGEX, 'Max'), (MIN_REGEX, 'Min'), (AVG_REGEX, 'Average'), (SLOPE_REGEX, 'Slope')): if r.search(teststr): setattr(self, 'function', a) break else: if BETWEEN_REGEX.search(teststr): self.function = 'Between' self.comparator = '' args = ARGS_REGEX.findall(teststr)[0][1:-1].split(',') self.value = float(args[1].strip()) self.secondary_value = float(args[2].strip()) # extract comparator m = COMP_REGEX.findall(teststr) if m: m1 = m[0] self.comparator = c = m1 self.value = float(teststr.split(c)[-1]) # extract use invert if teststr.startswith('not '): self.use_invert = True self._selected_changed_hook()
def _selected_changed(self, new): if new: teststr = new.teststr with no_update(self): for a in TAGS.split(','): try: setattr(self, a, getattr(new, a)) except (AttributeError, TraitError): continue self.function = '' self.secondary_value = 0 self.value = 0 self.modifier = '' for r, a in ((CP_REGEX, 'Current'), (STD_REGEX, 'StdDev'), (ACTIVE_REGEX, 'Inactive'), (BASELINECOR_REGEX, 'BaselineCorrected'), (BASELINE_REGEX, 'Baseline')): if r.search(teststr): setattr(self, 'modifier', a) break for r, a in ((MAX_REGEX, 'Max'), (MIN_REGEX, 'Min'), (AVG_REGEX, 'Average'), (SLOPE_REGEX, 'Slope')): if r.search(teststr): setattr(self, 'function', a) break else: if BETWEEN_REGEX.search(teststr): self.function = 'Between' self.comparator = '' args = ARGS_REGEX.findall(teststr)[0][1:-1].split(',') self.value = float(args[1].strip()) self.secondary_value = float(args[2].strip()) # extract comparator m = COMP_REGEX.findall(teststr) if m: m1 = m[0] self.comparator = c = m1 self.value = float(teststr.split(c)[-1]) # extract use invert if teststr.startswith('not '): self.use_invert = True self._selected_changed_hook()
def _add(self, items): si = self.selectedIndexes() paste_func = self.paste_func if paste_func is None: paste_func = lambda x: x.clone_traits() if len(si): idx = si[-1].row() + 1 else: idx = len(self._editor.value) editor = self._editor with no_update(editor.object): for ci in reversed(items): editor.model.insertRow(idx, obj=paste_func(ci))
def _active_editor_changed(self, new): if new: if self.controls_pane: tool = None if hasattr(new, 'tool'): tool = new.tool elif isinstance(new, RecallEditor): tool = new.analysis_view.selection_tool self.controls_pane.tool = tool if self.unknowns_pane: if hasattr(new, 'analyses'): with no_update(self): self.unknowns_pane.trait_set(items=new.analyses)
def _add(self, items, insert_mode='after', idx=None): if idx is None: selection = self.selectedIndexes() if len(selection): offset = 1 if insert_mode == 'after' else 0 idx = selection[-1].row() + offset else: idx = len(self._editor.value) paste_func = self.paste_func if paste_func is None: paste_func = lambda x: x.clone_traits() editor = self._editor with no_update(editor.object): for ci in reversed(items): editor.model.insertRow(idx, obj=paste_func(ci))
def activated(self): model = self._get_browser_model() self.browser_model = model if not model.is_activated: self._setup_browser_model() with no_update(self): self.browser_model.current_task_name = self.default_task_name # self._top_level_filter = None self.activate_workspace() self.browser_model.activated() if to_bool(self.application.preferences.get('pychron.dvc.enabled')): self.dvc = self.application.get_service('pychron.dvc.dvc.DVC')
def load(self, txt): self.initialized = False self.stats.delay_between_analyses = self.delay_between_analyses self.stats.delay_before_analyses = self.delay_before_analyses line_gen = self._get_line_generator(txt) self._extract_meta(line_gen) aruns = self._load_runs(line_gen) if aruns is not None: # set frequency_added_counter if aruns: self._frequency_group_counter = max([ri.frequency_group for ri in aruns]) with no_update(self): self.automated_runs = aruns self.initialized = True self.debug('loading queue successful') return True
def load(self, txt): self.initialized = False self.stats.delay_between_analyses = self.delay_between_analyses self.stats.delay_before_analyses = self.delay_before_analyses line_gen = self._get_line_generator(txt) self._extract_meta(line_gen) aruns = self._load_runs(line_gen) if aruns is not None: # set frequency_added_counter if aruns: self._frequency_group_counter = max( [ri.frequency_group for ri in aruns]) with no_update(self): self.automated_runs = aruns self.initialized = True self.debug('loading queue successful') return True
def dropEvent(self, e): if self.is_external(): data = PyMimeData.coerce(e.mimeData()).instance() df = self.drop_factory if not df: df = lambda x: x row = self.rowAt(e.pos().y()) n = len(self._editor.value) if row == -1: row = n model = self._editor.model if self._dragging: rows = [ri for ri, _ in data] model.moveRows(rows, row) else: # self._editor._no_update = True # parent = QtCore.QModelIndex() # model.beginInsertRows(parent, row, row) # editor = self._editor # self._editor.object._no_update = True with no_update(self._editor.object): for i, (_, di) in enumerate(reversed(data)): # print 'insert' # obj = paste_func1(di) # editor.callx(editor.adapter.insert, editor.object, editor.name, row + i, obj) model.insertRow(row=row, obj=df(di)) # model.insertRow(row=row, obj=paste_func(data[0][1])) # self._editor.object._no_update = False # model.endInsertRows() # self._editor._no_update = False e.accept() self._dragging = None else: super(_myTableView, self).dropEvent(e)
def add_runs(self, runspecs, freq=None, freq_before=True, freq_after=False, is_run_block=False, is_repeat_block=False): """ runspecs: list of runs freq: optional inter freq_before_or_after: if true add before else add after """ if not runspecs: return [] with no_update(self): if freq: runs = self._add_frequency_runs(runspecs, freq, freq_before, freq_after, is_run_block, is_repeat_block) else: runs = self._add_runs(runspecs) return runs
def group_extractions2(self): """ group using ABC, ABC, ABC :return: """ sel = self.selected evs = sorted({s.extract_value for s in sel}) n = len(evs) with no_update(self): gs = [] for i, a in enumerate(self.automated_runs): if a.extract_value == evs[0]: gs.extend(self.automated_runs[i:i + n]) if gs: for gi in gs: self.automated_runs.remove(gi) for gi in reversed(gs): self.automated_runs.insert(0, gi)
def group_extractions2(self): """ group using ABC, ABC, ABC :return: """ sel = self.selected evs = sorted({s.extract_value for s in sel}) n = len(evs) with no_update(self): gs = [] for i, a in enumerate(self.automated_runs): if a.extract_value == evs[0]: gs.extend(self.automated_runs[i:i+n]) if gs: for gi in gs: self.automated_runs.remove(gi) for gi in reversed(gs): self.automated_runs.insert(0, gi)
def group_extractions(self): """ group using AAA, BBB, CCC :return: """ sel = self.selected evs = {s.extract_value for s in sel} with no_update(self): gs = [] for ev in sorted(evs): for a in self.automated_runs: if a.extract_value == ev: gs.append(a) if gs: for gi in gs: self.automated_runs.remove(gi) for gi in reversed(gs): self.automated_runs.insert(0, gi)
def _refresh_comp(self, name, new): if not self._no_update: with no_update(self): if name == 'function': self.modifier = '' elif name == 'modifier': self.function = '' attr = self.attr try: s = MOD_DICT[self.modifier] attr = s.format(attr) except KeyError: pass func = self.function.lower() if func == 'between': comp = 'between({},{},{})'.format(attr, self.value, self.secondary_value) else: try: s = FUNC_DICT[func] attr = s.format(attr) except KeyError: pass if self.comparator: comp = '{}{}{}'.format(attr, self.comparator, self.value) else: comp = '{}'.format(attr) if self.use_invert: comp = 'not {}'.format(comp) self.selected.teststr = comp
def reset(self): with no_update(self, fire_update_needed=False): self.high = int(self.duration) self.current_time = self.duration self._paused = False
def _update_color(self): self._update_temptint() with no_update(self): d = {k: getattr(self.camera, 'get_{}'.format(k))() for k in ('hue', 'saturation', 'brightness', 'contrast', 'gamma')} self.trait_set(**d)
def move_selected_last(self): with no_update(self): for si in self.selected: self.automated_runs.remove(si) self.automated_runs.extend(self.selected)
def handle_context_update(self): with no_update(self): docstr = self.context_editor.generate_docstr() self._set_docstr(docstr) self.dirty = True
def _set_current_task(self): with no_update(self): editor = self.active_editor if isinstance(editor, RecallEditor): self.browser_model.current_task_name = 'Recall'
def _copy_selected(self, idx): with no_update(self): for si in reversed(self.selected): self.automated_runs.insert(idx, si.tocopy())
def reset(self): with no_update(self, fire_update_needed=False): self.high = self.duration self.current_time = self.duration self._paused = False