本文整理汇总了Python中pychron.core.ui.thread.Thread类的典型用法代码示例。如果您正苦于以下问题:Python Thread类的具体用法?Python Thread怎么用?Python Thread使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Thread类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _do_execute
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
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
def _test1(self):
self.test_image.setup_images(3,
# (475, 613)
(640, 480)
)
t = Thread(target=self._test)
t.start()
self._t = t
示例4: execute
def execute(self, block=False, duration=None, thread_safe=True):
"""
if block is true wait for patterning to finish
before returning
"""
if not self.pattern:
return
self.start(show=self.show_patterning)
evt = None
# if current_thread().name != 'MainThread':
if thread_safe:
evt = Event()
invoke_in_main_thread(self._pre_execute, evt)
while not evt.is_set():
time.sleep(0.05)
else:
self._pre_execute(evt)
self.debug('execute xy pattern')
xyp = self.pattern.xy_pattern_enabled
if duration:
self.pattern.external_duration = float(duration)
if xyp:
self._xy_thread = Thread(target=self._execute_xy_pattern)
self._xy_thread.start()
pp = self.pattern.power_pattern
if pp:
self.debug('execute power pattern')
self._power_thread = Thread(target=self._execute_power_pattern)
self._power_thread.start()
zp = self.pattern.z_pattern
if zp:
self.debug('execute z pattern')
self._z_thread = Thread(target=self._execute_z_pattern)
self._z_thread.start()
if block:
if self._xy_thread:
self._xy_thread.join()
if self._z_thread:
self._z_thread.join()
if self._power_thread:
self._power_thread.join()
self.finish()
示例5: _test_fired
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
示例6: do_peak_center
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)
示例7: do_machine_vision_degas
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()
示例8: _move
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()
示例9: passive_focus
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()
示例10: _set_point
def _set_point(self, v):
if self.canvas.calibrate:
self.warning_dialog('Cannot move while calibrating')
return
if self.canvas.markup:
self.warning_dialog('Cannot move while adding/editing points')
return
if (self.move_thread is None or not self.move_thread.isRunning()) and v is not self._point:
pos = self.canvas.get_item('point', int(v) - 1)
if pos is not None:
self._point = v
self.move_thread = Thread(target=self._move_to_point, args=(pos,))
self.move_thread.start()
else:
err = 'Invalid point {}'.format(v)
self.warning(err)
return err
示例11: _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')
示例12: dump_sample
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()
示例13: StageManager
#.........这里部分代码省略.........
# if self.move_thread is not None:
# self.stage_controller.stop()
#
# # if self.move_thread is None:
#
# pos = self._stage_map.get_hole_pos(v)
# if pos is not None:
# self.visualizer.set_current_hole(v)
# # self._hole = v
# self.move_thread = Thread(name='stage.move_to_hole',
# target=self._move_to_hole, args=(v,))
# self.move_thread.start()
# else:
# err = 'Invalid hole {}'.format(v)
# self.warning(err)
# return err
# def _get_hole(self):
# return self._hole
def _set_point(self, v):
if self.canvas.calibrate:
self.warning_dialog('Cannot move while calibrating')
return
if self.canvas.markup:
self.warning_dialog('Cannot move while adding/editing points')
return
if (self.move_thread is None or not self.move_thread.isRunning()) and v is not self._point:
pos = self.canvas.get_item('point', int(v) - 1)
if pos is not None:
self._point = v
self.move_thread = Thread(target=self._move_to_point, args=(pos,))
self.move_thread.start()
else:
err = 'Invalid point {}'.format(v)
self.warning(err)
return err
def _get_point(self):
return self._point
# ===============================================================================
# handlers
# ===============================================================================
def _stop_button_fired(self):
self._stop()
def _ejoystick_fired(self):
self.joystick = not self.joystick
if self.joystick:
self.stage_controller.enable_joystick()
self.joystick_label = 'Disable Joystick'
self.joystick_timer = self.timer_factory(func=self._joystick_inprogress_update)
else:
if self.joystick_timer is not None:
self.joystick_timer.Stop()
self.stage_controller.disable_joystick()
self.joystick_label = 'Enable Joystick'
def _home_fired(self):
"""
"""
示例14: FusionsLaserManager
#.........这里部分代码省略.........
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()
else:
return super(FusionsLaserManager, self).get_brightness()
def is_degassing(self):
if self._degas_thread:
return self._degas_thread.isRunning()
# ===============================================================================
# pyscript interface
# ===============================================================================
def _move_to_position(self, position, autocenter):
if self.stage_manager is not None:
if isinstance(position, tuple):
if len(position) > 1:
x, y = position[:2]
self.stage_manager.linear_move(x, y)
if len(position) == 3:
self.stage_manager.set_z(position[2])
else:
self.stage_manager.move_to_hole(position)
return True
def set_stage_map(self, mapname):
示例15: NMGRLFurnaceManager
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:
#.........这里部分代码省略.........