本文整理汇总了Python中pychron.core.ui.gui.invoke_in_main_thread函数的典型用法代码示例。如果您正苦于以下问题:Python invoke_in_main_thread函数的具体用法?Python invoke_in_main_thread怎么用?Python invoke_in_main_thread使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了invoke_in_main_thread函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _poll
def _poll(self, last_run_uuid):
self._polling = True
sub = self.subscriber
db_poll_interval = self._db_poll_interval
poll_interval = self._poll_interval
st = time.time()
while 1:
#only check subscription availability if one poll_interval has elapsed
#sinde the last subscription message was received
#check subscription availability
if time.time() - sub.last_message_time > poll_interval:
if sub.check_server_availability(timeout=0.5, verbose=True):
if not sub.is_listening():
self.info('Subscription server now available. starting to listen')
self.subscriber.listen()
else:
if sub.was_listening:
self.warning('Subscription server no longer available. stop listen')
self.subscriber.stop()
if self._wait(poll_interval):
if not sub.is_listening():
if time.time() - st > db_poll_interval:
st = time.time()
lr = self._get_last_run_uuid()
self.debug('current uuid {} <> {}'.format(last_run_uuid, lr))
if lr != last_run_uuid:
last_run_uuid = lr
invoke_in_main_thread(self.run_added_handler, lr)
else:
break
示例2: _peak_center
def _peak_center(self, setup_kw=None, peak_kw=None):
if setup_kw is None:
setup_kw = {}
if peak_kw is None:
peak_kw = {}
es = []
for e in self.editor_area.editors:
if isinstance(e, PeakCenterEditor):
try:
es.append(int(e.name.split(' ')[-1]))
except ValueError:
pass
i = max(es) + 1 if es else 1
ret = -1
ion = self.scan_manager.ion_optics_manager
self._peak_center_start_hook()
time.sleep(2)
name = 'Peak Center {:02d}'.format(i)
if ion.setup_peak_center(new=True, **setup_kw):
self._on_peak_center_start()
invoke_in_main_thread(self._open_editor, PeakCenterEditor(model=ion.peak_center, name=name))
ion.do_peak_center(**peak_kw)
ret = ion.peak_center_result
self._peak_center_stop_hook()
return ret
示例3: block
def block(self, n=3, tolerance=1, progress=None, homing=False):
"""
"""
fail_cnt = 0
pos_buffer = []
while not self.parent.simulation:
steps = self.load_data_position(set_pos=False)
if homing:
invoke_in_main_thread(self.trait_set, homing_position=steps)
if progress is not None:
progress.change_message('{} position = {}'.format(self.name, steps),
auto_increment=False)
if steps is None:
fail_cnt += 1
if fail_cnt > 5:
break
continue
pos_buffer.append(steps)
if len(pos_buffer) == n:
if abs(float(sum(pos_buffer)) / n - steps) < tolerance:
break
else:
pos_buffer.pop(0)
time.sleep(0.1)
if fail_cnt > 5:
self.warning('Problem Communicating')
示例4: _loop2
def _loop2(self, n, d):
invoke_in_main_thread(self._build_graph, n, d,)
for i in range(100):
if i % 10 == 0:
print '{} {}'.format(i, get_current_mem())
time.sleep(0.1)
示例5: _wait_for_home
def _wait_for_home(self, progress=None):
# wait until homing signal set
hbit = 5 if self.home_limit == 1 else 6
psteps = None
while 1:
steps = self.load_data_position(set_pos=False)
invoke_in_main_thread(self.trait_set, homing_position=steps)
status = self.read_defined_status()
if not self._test_status_byte(status, setbits=[7]):
break
if self._test_status_byte(status, setbits=[7, hbit]):
break
if steps == psteps:
step_count += 1
else:
step_count = 0
if step_count > 10:
break
psteps = steps
time.sleep(0.25)
self.debug('wait for home complete')
示例6: open_view
def open_view(self, obj, **kw):
def _open():
ui = obj.edit_traits(**kw)
self.add_window(ui)
from pychron.core.ui.gui import invoke_in_main_thread
invoke_in_main_thread(_open)
示例7: get_peak_center
def get_peak_center(self, ntries=2):
self._alive = True
self.canceled = False
center_dac = self.center_dac
self.info('starting peak center. center dac= {} step_width={}'.format(center_dac, self.step_width))
# self.graph = self._graph_factory()
width = self.step_width
smart_shift = False
center = None
self.debug('width = {}'.format(width))
for i in range(ntries):
if not self.isAlive():
break
self._reset_graph()
if i == 0:
self.graph.add_vertical_rule(self.center_dac, line_style='solid', color='black', line_width=1.5)
else:
self.graph.add_vertical_rule(center, line_style='solid', color='black', line_width=1.5)
start, end = self._get_scan_parameters(i, center, smart_shift)
center, smart_shift, success = self.iteration(start, end, width)
if success:
invoke_in_main_thread(self._post_execute)
return center
示例8: _set_motor
def _set_motor(self, pos, main=True):
if self._data_position != pos or not self._data_position:
self.info('setting motor in data space {:0.3f}'.format(float(pos)))
self._data_position = pos
lm = self.linear_mapper
steps = lm.map_steps(pos)
hv = 0
hysteresis = self.hysteresis_value
if hysteresis:
self.do_hysteresis = False
if hysteresis < 0:
use_hysteresis = self._motor_position > steps
else:
use_hysteresis = self._motor_position < steps
if use_hysteresis:
self.do_hysteresis = True
self.doing_hysteresis_correction = False
hv = hysteresis
self._set_motor_position(steps, hv)
def launch():
self.timer = self.timer_factory()
if main:
invoke_in_main_thread(launch)
else:
launch()
示例9: run_added_handler
def run_added_handler(self, last_run_uuid=None):
"""
add to sys mon series
if atype is blank, air, cocktail, background
add to atype series
else
if step heat
add to spectrum
else
add to ideogram
"""
def func():
#with self.db_lock:
self.info('refresh analyses. last UUID={}'.format(last_run_uuid))
proc = self.processor
db = proc.db
with db.session_ctx():
if last_run_uuid is None:
dbrun = db.get_last_analysis(spectrometer=self.conn_spec.system_name)
else:
dbrun = db.get_analysis_uuid(last_run_uuid)
#if last_run_uuid:
# dbrun = db.get_analysis_uuid(last_run_uuid)
if dbrun:
an = proc.make_analysis(dbrun)
self._refresh_sys_mon_series(an)
self._refresh_figures(an)
invoke_in_main_thread(func)
示例10: _run_added_handler
def _run_added_handler(self, last_run_uuid=None):
"""
add to sys mon series
if atype is blank, air, cocktail, background
add to atype series
else
if step heat
add to spectrum
else
add to ideogram
"""
def func(lr):
self._refresh_sys_mon_series()
self.info('refresh analyses. last UUID={}'.format(lr))
proc = self.processor
db = proc.db
with db.session_ctx():
if last_run_uuid is None:
dbrun = db.get_last_analysis(spectrometer=self.conn_spec.system_name)
else:
dbrun = db.get_analysis_uuid(last_run_uuid)
self.debug('run_added_handler dbrun={}'.format(dbrun))
if dbrun:
self.debug('run_added_handler identifier={}'.format(dbrun.labnumber.identifier))
an = proc.make_analysis(dbrun)
self._refresh_figures(an)
# self.rebuild()
self._lock.release()
invoke_in_main_thread(func, last_run_uuid)
示例11: stop
def stop(self):
self.debug('stop')
self.dump()
if self._lum_evt:
self._lum_evt.set()
if self._info:
invoke_in_main_thread(self._info.dispose, abort=True)
示例12: run_with_except_hook
def run_with_except_hook(*args, **kw):
try:
run_old(*args, **kw)
except (KeyboardInterrupt, SystemExit):
raise
except:
from pychron.core.ui.gui import invoke_in_main_thread
invoke_in_main_thread(sys.excepthook, *sys.exc_info())
示例13: _do_hop
def _do_hop(self):
"""
is it time for a magnet move
"""
# try:
cycle, dets, isos, defls, settle, count = self.hop_generator.next()
# except StopIteration:
# return
#update the iso/det in plotpanel
# self.plot_panel.set_detectors(isos, dets)
detector = dets[0]
isotope = isos[0]
# self.debug('c={} pc={} nc={}'.format(cycle, self.plot_panel.ncycles, self.ncycles))
if self.plot_panel.ncycles!=self.ncycles:
if cycle >= self.plot_panel.ncycles:
self.info('user termination. measurement iteration executed {}/{} cycles'.format(cycle, self.ncycles))
self.stop()
return
elif cycle>=self.ncycles:
return
if count == 0:
#set deflections
# only set deflections deflections were changed or need changing
deflect = len([d for d in defls if d is not None])
if deflect or self._was_deflected:
self._was_deflected = False
for det, defl in zip(dets, defls):
#use the measurement script to set the deflections
#this way defaults from the config can be used
if defl is None:
defl = ''
else:
self._was_deflected = True
self.measurement_script.set_deflection(det, defl)
self.parent.set_magnet_position(isotope, detector,
update_detectors=False, update_labels=False,
update_isotopes=True,
remove_non_active=False)
msg = 'delaying {} for detectors to settle after peak hop'.format(settle)
self.parent.wait(settle, msg)
self.debug(msg)
d = self.parent.get_detector(detector)
# self.debug('cycle {} count {} {}'.format(cycle, count, id(self)))
if self.plot_panel.is_baseline:
isotope = '{}bs'.format(isotope)
invoke_in_main_thread(self.plot_panel.trait_set,
current_cycle='{} cycle={} count={}'.format(isotope, cycle + 1, count + 1),
current_color=d.color)
return dets, isos
示例14: _show_pane
def _show_pane(self, p):
#if not self.suppress_pane_change:
def _show():
ctrl = p.control
if not p.visible:
ctrl.show()
ctrl.raise_()
invoke_in_main_thread(_show)
示例15: add_text
def add_text(self, txt, color, force=False, **kw):
'''
if txt,color same as previous txt,color than message only added if force=True
'''
# ms = self.messages[-self.max_messages:]
# ms.append((txt, color))
# self.message = (txt, color, force)
self.qmessage.put((txt, color, force))
invoke_in_main_thread(self.trait_set, refresh=True)