本文整理汇总了Python中pychron.core.ui.thread.Thread.start方法的典型用法代码示例。如果您正苦于以下问题:Python Thread.start方法的具体用法?Python Thread.start怎么用?Python Thread.start使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pychron.core.ui.thread.Thread
的用法示例。
在下文中一共展示了Thread.start方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _do_execute
# 需要导入模块: from pychron.core.ui.thread import Thread [as 别名]
# 或者: from pychron.core.ui.thread.Thread import start [as 别名]
def _do_execute(self):
mapper = self.mapper
mapper.laser_manager = self._laser_manager
editor = self.editor
padding = editor.padding
# if editor.discrete_scan:
# mapper.canvas = self.canvas
# self.component = self.canvas
# else:
c = mapper.make_component(padding)
self.component = c
bd = editor.beam_diameter
rp = editor.request_power
cx = editor.center_x
cy = editor.center_y
step_len = editor.step_length
t = Thread(target=mapper.do_power_mapping,
args=(bd, rp, cx, cy, padding, step_len))
t.start()
self._execute_thread = t
return True
示例2: _home_fired
# 需要导入模块: from pychron.core.ui.thread import Thread [as 别名]
# 或者: from pychron.core.ui.thread.Thread import start [as 别名]
def _home_fired(self):
"""
"""
t = Thread(name='stage.home', target=self._home)
t.start()
# need to store a reference to thread so it is not garbage collected
self.move_thread = t
示例3: _test1
# 需要导入模块: from pychron.core.ui.thread import Thread [as 别名]
# 或者: from pychron.core.ui.thread.Thread import start [as 别名]
def _test1(self):
self.test_image.setup_images(3,
# (475, 613)
(640, 480)
)
t = Thread(target=self._test)
t.start()
self._t = t
示例4: _test_fired
# 需要导入模块: from pychron.core.ui.thread import Thread [as 别名]
# 或者: from pychron.core.ui.thread.Thread import start [as 别名]
def _test_fired(self):
from pychron.globals import globalv
p = '/Users/ross/Sandbox/test_target.jpg'
# p = '/Users/ross/Sandbox/pos_err/pos_err_200_0-002.jpg'
p = '/Users/ross/Sandbox/poserror/pos_err_221_0-007.jpg'
# p = '/Users/ross/Sandbox/poserror/snapshot009.jpg'
# force video to reload test image
self.video.source_frame = None
globalv.video_test_path = p
im = self.setup_image()
# self._test2(im)
from pychron.core.ui.thread import Thread
t = Thread(target=self._test2, args=(im,))
t.start()
self._t = t
示例5: do_peak_center
# 需要导入模块: from pychron.core.ui.thread import Thread [as 别名]
# 或者: from pychron.core.ui.thread.Thread import start [as 别名]
def do_peak_center(self,
save=True,
confirm_save=False,
warn=False,
new_thread=True):
self.debug('doing pc')
self.canceled = False
self.alive = True
args = (save, confirm_save, warn)
if new_thread:
t = Thread(name='ion_optics.peak_center', target=self._peak_center,
args=args)
t.start()
self._thread = t
return t
else:
self._peak_center(*args)
示例6: execute
# 需要导入模块: from pychron.core.ui.thread import Thread [as 别名]
# 或者: from pychron.core.ui.thread.Thread import start [as 别名]
def execute(self):
self.canceled = False
t = Thread(target=self._execute)
t.start()
self._t = t
示例7: _back_button_fired
# 需要导入模块: from pychron.core.ui.thread import Thread [as 别名]
# 或者: from pychron.core.ui.thread.Thread import start [as 别名]
def _back_button_fired(self):
pos, kw = self.linear_move_history.pop(-1)
t = Thread(target=self.stage_controller.linear_move, args=pos, kwargs=kw)
t.start()
self.move_thread = t
示例8: StageManager
# 需要导入模块: from pychron.core.ui.thread import Thread [as 别名]
# 或者: from pychron.core.ui.thread.Thread import start [as 别名]
#.........这里部分代码省略.........
return self.stage_map._get_hole_by_position(x, y)
def _get_hole_by_name(self, key):
sm = self.stage_map
return sm.get_hole(key)
# ===============================================================================
# special move
# ===============================================================================
def _stop(self, ax_key=None, verbose=False):
self.stage_controller.stop(ax_key=ax_key, verbose=verbose)
if self.parent.pattern_executor:
self.parent.pattern_executor.stop()
# def _move(self, func, pos, name=None, *args, **kw):
# if pos is None:
# return
#
# if self.move_thread and self.move_thread.isRunning():
# self.stage_controller.stop()
# if name is None:
# name = func.func_name
#
# self.move_thread = Thread(name='stage.{}'.format(name),
# target=func, args=(pos,) + args, kwargs=kw)
# self.move_thread.start()
def _drill_point(self, pt):
zend = pt.zend
vel = pt.velocity
# assume already at zstart
st = time.time()
self.info('start drilling. move to {}. velocity={}'.format(zend, vel))
self.set_z(zend, velocity=vel, block=True)
et = time.time() - st
self.info('drilling complete. drilled for {}s'.format(et))
def _move_polygon(self, pts, velocity=5,
offset=50,
use_outline=True,
find_min=False,
scan_size=None,
use_move=True,
use_convex_hull=True,
motors=None,
verbose=True,
start_callback=None, end_callback=None):
"""
motors is a dict of motor_name:value pairs
"""
if pts is None:
return
if not isinstance(pts, list):
velocity = pts.velocity
use_convex_hull = pts.use_convex_hull
if scan_size is None:
scan_size = pts.scan_size
use_outline = pts.use_outline
offset = pts.offset
find_min = pts.find_min
pts = [dict(xy=(pi.x, pi.y), z=pi.z, ) for pi in pts.points]
# set motors
示例9: FusionsLaserManager
# 需要导入模块: from pychron.core.ui.thread import Thread [as 别名]
# 或者: from pychron.core.ui.thread.Thread import start [as 别名]
#.........这里部分代码省略.........
self.info('beam disabled by lens configuration {}'.format(self.lens_configuration))
return result
def set_zoom(self, z, **kw):
"""
"""
self.set_motor('zoom', z, **kw)
def set_motor_lock(self, name, value):
m = self.get_motor(name)
if m is not None:
m.locked = to_bool(value)
return True
def set_motor(self, *args, **kw):
self.motor_event = (args, kw)
return self.laser_controller.set_motor(*args, **kw)
def get_motor(self, name):
return next((mi for mi in self.laser_controller.motors if mi.name == name), None)
def do_autofocus(self, **kw):
if self.use_video:
am = self.stage_manager.autofocus_manager
am.passive_focus(block=True, **kw)
def take_snapshot(self, *args, **kw):
if self.use_video:
return self.stage_manager.snapshot(
auto=True,
inform=False,
*args, **kw)
def start_video_recording(self, name='video', *args, **kw):
if self.use_video:
self.stage_manager.start_recording(basename=name)
def stop_video_recording(self, *args, **kw):
if self.use_video:
self.stage_manager.stop_recording()
def degasser_factory(self):
from pychron.mv.degas.degasser import Degasser
dm = Degasser(
laser_manager=self,
video=self.stage_manager.video,
)
return dm
def do_machine_vision_degas(self, lumens, duration, new_thread=False):
if self.use_video:
dm = self.degasser_factory()
def func():
dm.degas(lumens, duration)
if new_thread:
self._degas_thread = Thread(target=func)
self._degas_thread.start()
else:
func()
def get_brightness(self):
if self.use_video:
return self.stage_manager.get_brightness()
示例10: NMGRLFurnaceManager
# 需要导入模块: from pychron.core.ui.thread import Thread [as 别名]
# 或者: from pychron.core.ui.thread.Thread import start [as 别名]
class NMGRLFurnaceManager(BaseFurnaceManager):
funnel = Instance(NMGRLFunnel)
loader_logic = Instance(LoaderLogic)
magnets = Instance(NMGRLMagnetDumper)
setpoint_readback_min = Float(0)
setpoint_readback_max = Float(1600.0)
graph = Instance(StreamGraph)
update_period = Int(2)
dumper_canvas = Instance(DumperCanvas)
_alive = False
_guide_overlay = None
_dumper_thread = None
mode = 'normal'
def activate(self):
# pref_id = 'pychron.furnace'
# bind_preference(self, 'update_period', '{}.update_period'.format(pref_id))
self._start_update()
def prepare_destroy(self):
self._stop_update()
self.loader_logic.manager = None
def dump_sample(self):
self.debug('dump sample')
if self._dumper_thread is None:
self._dumper_thread = Thread(name='DumpSample', target=self._dump_sample)
self._dumper_thread.start()
def is_dump_complete(self):
ret = self._dumper_thread is None
return ret
def actuate_magnets(self):
self.debug('actuate magnets')
if self.loader_logic.check('AM'):
self.magnet.open()
# wait for actuate magnets
pass
else:
self.warning('actuate magnets not enabled')
def lower_funnel(self):
self.debug('lower funnel')
if self.loader_logic.check('FD'):
self.funnel.set_value(self.funnel.down_position)
# todo: update canvas state
return True
else:
self.warning('lowering funnel not enabled')
def raise_funnel(self):
self.debug('raise funnel')
if self.loader_logic.check('FU'):
self.funnel.set_value(self.funnel.up_position)
# todo: update canvas state
return True
else:
self.warning('raising funnel not enabled')
def set_setpoint(self, v):
if self.controller:
# print self.controller, self.controller._cdevice
self.controller.set_setpoint(v)
if not self._guide_overlay:
self._guide_overlay = self.graph.add_horizontal_rule(v)
self._guide_overlay.visible = bool(v)
self._guide_overlay.value = v
# ymi, yma = self.graph.get_y_limits()
d = self.graph.get_data(axis=1)
self.graph.set_y_limits(min_=0, max_=max(d.max(), v * 1.1))
self.graph.redraw()
def read_setpoint(self, update=False):
v = 0
if self.controller:
force = update and not self.controller.is_scanning()
v = self.controller.read_setpoint(force=force)
try:
self.setpoint_readback = v
return v
except TraitError:
pass
# canvas
def set_software_lock(self, name, lock):
if self.switch_manager is not None:
if lock:
#.........这里部分代码省略.........
示例11: PatternExecutor
# 需要导入模块: from pychron.core.ui.thread import Thread [as 别名]
# 或者: from pychron.core.ui.thread.Thread import start [as 别名]
class PatternExecutor(Patternable):
"""
a pattern is only good for one execution.
self.pattern needs to be reset after stop or finish using load_pattern(name_or_pickle)
"""
controller = Any
laser_manager = Any
show_patterning = Bool(False)
_alive = Bool(False)
def __init__(self, *args, **kw):
super(PatternExecutor, self).__init__(*args, **kw)
self._next_point = None
self.pattern = None
self._xy_thread = None
self._power_thread = None
self._z_thread = None
def start(self, show=False):
self._alive = True
if show:
self.show_pattern()
if self.pattern:
self.pattern.clear_graph()
def finish(self):
self._alive = False
self.close_pattern()
self.pattern = None
def set_stage_values(self, sm):
if self.pattern:
self.pattern.set_stage_values(sm)
def set_current_position(self, x, y, z):
if self.isPatterning():
graph = self.pattern.graph
graph.set_data([x], series=1, axis=0)
graph.set_data([y], series=1, axis=1)
graph.add_datum((x, y), series=2)
graph.redraw()
def load_pattern(self, name_or_pickle):
"""
look for name_or_pickle in local pattern dir
if not found try interpreting name_or_pickle is a pickled name_or_pickle
"""
if name_or_pickle is None:
path = self.open_file_dialog()
if path is None:
return
else:
path = self.is_local_pattern(name_or_pickle)
if path:
wfile = open(path, 'rb')
else:
# convert name_or_pickle into a file like obj
wfile = StringIO(name_or_pickle)
# self._load_pattern sets self.pattern
pattern = self._load_pattern(wfile, path)
self.on_trait_change(self.stop, 'canceled')
return pattern
def is_local_pattern(self, name):
def test_name(ni):
path = os.path.join(paths.pattern_dir, ni)
if os.path.isfile(path):
return path
for ni in (name, name + '.lp'):
p = test_name(ni)
if p:
return p
def stop(self):
self._alive = False
if self.controller:
self.info('User requested stop')
self.controller.stop()
if self.pattern is not None:
if self.controller:
self.controller.linear_move(self.pattern.cx, self.pattern.cy, source='pattern stop')
# self.pattern.close_ui()
self.info('Pattern {} stopped'.format(self.pattern_name))
# prevent future stops (AbortJogs from massspec) from executing
self.pattern = None
def isPatterning(self):
#.........这里部分代码省略.........
示例12: AutoFocusManager
# 需要导入模块: from pychron.core.ui.thread import Thread [as 别名]
# 或者: from pychron.core.ui.thread.Thread import start [as 别名]
class AutoFocusManager(Manager):
"""
currently uses passive focus techniques
see
http://en.wikipedia.org/wiki/Autofocus
"""
video = Any
laser_manager = Any
stage_controller = Any
canvas = Any
parameters = Instance(FocusParameters)
configure_button = Button('configure')
autofocus_button = Event
autofocus_label = Property(depends_on='autofocusing')
autofocusing = Bool
# threading event for cancel signal
_evt_autofocusing = None
image = Instance(Image, ())
graph = None
def dump_parameters(self):
p = os.path.join(paths.hidden_dir, 'autofocus_configure')
self.info('dumping parameters to {}'.format(p))
with open(p, 'wb') as f:
pickle.dump(self.parameters, f)
def load_parameter(self):
p = os.path.join(paths.hidden_dir, 'autofocus_configure')
if os.path.isfile(p):
with open(p, 'rb') as f:
try:
params = pickle.load(f)
self.info('loading parameters from {}'.format(p))
if not isinstance(params, FocusParameters):
self.info('out of date parameters file. using default')
params = FocusParameters()
return params
except Exception as e:
print('autofocus load parameter', e)
return FocusParameters()
else:
return FocusParameters()
def passive_focus(self, block=False, **kw):
self._evt_autofocusing = TEvent()
self._evt_autofocusing.clear()
# manager = self.laser_manager
oper = self.parameters.operator
self.info('passive focus. operator = {}'.format(oper))
g = self.graph
if not g:
g = Graph(plotcontainer_dict=dict(padding=10),
window_x=0.70,
window_y=20,
window_width=325,
window_height=325,
window_title='Autofocus'
)
self.graph = g
g.clear()
g.new_plot(padding=[40, 10, 10, 40],
xtitle='Z (mm)',
ytitle='Focus Measure ({})'.format(oper)
)
g.new_series()
g.new_series()
invoke_in_main_thread(self._open_graph)
target = self._passive_focus
self._passive_focus_thread = Thread(name='autofocus', target=target,
args=(self._evt_autofocusing,
),
kwargs=kw
)
self._passive_focus_thread.start()
if block:
# while 1:
# if not self._passive_focus_thread.isRunning():
# break
# time.sleep(0.25)
self._passive_focus_thread.join()
def _open_graph(self):
ui = self.graph.edit_traits()
self.add_window(ui)
#.........这里部分代码省略.........
示例13: BaseStageManager
# 需要导入模块: from pychron.core.ui.thread import Thread [as 别名]
# 或者: from pychron.core.ui.thread.Thread import start [as 别名]
#.........这里部分代码省略.........
if ca:
rot = ca.rotation
cpos = ca.center
scale = ca.scale
self.debug('Calibration parameters: '
'rot={:0.3f}, cpos={} scale={:0.3f}'.format(rot, cpos,
scale))
pos = smap.map_to_calibration(pos, cpos, rot,
scale=scale)
return pos
def update_axes(self):
"""
"""
self.info('querying axis positions')
self._update_axes()
# private
def _update_axes(self):
pass
def _move_to_hole(self, key, correct_position=True, **kw):
pass
def _stop(self):
pass
def _move(self, func, pos, name=None, *args, **kw):
if pos is None:
return
if self.move_thread and self.move_thread.isRunning():
self._stop()
if name is None:
name = func.__name__
self.move_thread = Thread(name='stage.{}'.format(name),
target=func, args=(pos,) + args, kwargs=kw)
self.move_thread.start()
def _canvas_factory(self):
raise NotImplementedError
def _stage_map_changed_hook(self):
pass
# handlers
def _calibrated_position_entry_changed(self, new):
self.debug('User entered calibrated position {}'.format(new))
self.goto_position(new)
def _stage_map_name_changed(self, new):
if new:
self.debug('setting stage map to {}'.format(new))
root = self.root
path = os.path.join(root, add_extension(new, '.txt'))
sm = self.stage_map_klass(file_path=path)
self.tray_calibration_manager.load_calibration(stage_map=new)
self.canvas.set_map(sm)
self.canvas.request_redraw()
self.stage_map = sm
self._stage_map_changed_hook()
# defaults
def _root_default(self):
return paths.map_dir
def _tray_calibration_manager_default(self):
t = TrayCalibrationManager(parent=self,
canvas=self.canvas)
return t
def _canvas_default(self):
return self._canvas_factory()
def _save_stage_map(self):
p = self.stage_map_path
self.info('saving stage_map {} to {}'.format(self.stage_map_name, p))
with open(p, 'wb') as f:
pickle.dump(self.stage_map_name, f)
def _load_previous_stage_map(self):
p = self.stage_map_path
if os.path.isfile(p):
self.info('loading previous stage map from {}'.format(p))
with open(p, 'rb') as f:
try:
sm = pickle.load(f)
if not sm.endswith('.center'):
return sm
except (pickle.PickleError, ValueError):
pass
示例14: Scanner
# 需要导入模块: from pychron.core.ui.thread import Thread [as 别名]
# 或者: from pychron.core.ui.thread.Thread import start [as 别名]
#.........这里部分代码省略.........
self.stop_event = True
self.info('scan stopped')
if self.manager:
self._stop_hook()
self.manager.disable_device()
def _stop_hook(self):
pass
def execute(self):
if self._scanning:
self.stop()
else:
self.data_manager.new_frame(directory=self._directory,
base_frame_name=self._base_frame_name)
# write metadata if available
self._write_metadata()
# make header row
header = ['t'] + \
self._make_func_names() + \
[n for n, _ in self.static_values]
self.data_manager.write_to_frame(header)
self._scanning = True
if self.manager:
if self.manager.enable_device():
self._scanning = True
return self._scanning
def do_scan(self):
self._starttime = time.time()
self._execute()
def _execute(self):
yd = self._read_control_path()
if yd is None:
sp = 1000
else:
sp = yd['period']
# starts automatically
self.debug('scan starting')
self._timer = Timer(sp, self._scan)
self.info('scan started')
# yd = self._read_control_path()
if yd is not None:
# start a control thread
self._control_thread = Thread(target=self._control,
args=(yd,)
)
self._control_thread.start()
self.info('control started')
# if self.manager:
# if self.manager.enable_device():
#
# # starts automatically
# self.debug('scan starting')
# self._timer = Timer(sp, self._scan)
#
示例15: _position_changed
# 需要导入模块: from pychron.core.ui.thread import Thread [as 别名]
# 或者: from pychron.core.ui.thread.Thread import start [as 别名]
def _position_changed(self):
if self.position is not None:
t = Thread(target=self._move_to_position, args=(self.position, self.use_autocenter))
t.start()
self._position_thread = t