• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python gui.invoke_in_main_thread函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:jirhiker,项目名称:pychron,代码行数:34,代码来源:system_monitor_editor.py


示例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
开发者ID:NMGRL,项目名称:pychron,代码行数:34,代码来源:spectrometer_task.py


示例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')
开发者ID:OSUPychron,项目名称:pychron,代码行数:33,代码来源:kerr_motor.py


示例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)
开发者ID:UManPychron,项目名称:pychron,代码行数:7,代码来源:graph_loop_test.py


示例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')
开发者ID:OSUPychron,项目名称:pychron,代码行数:26,代码来源:kerr_motor.py


示例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)
开发者ID:OSUPychron,项目名称:pychron,代码行数:7,代码来源:manager.py


示例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
开发者ID:kenlchen,项目名称:pychron,代码行数:32,代码来源:peak_center.py


示例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()
开发者ID:NMGRL,项目名称:pychron,代码行数:31,代码来源:kerr_motor.py


示例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)
开发者ID:jirhiker,项目名称:pychron,代码行数:30,代码来源:system_monitor_editor.py


示例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)
开发者ID:OSUPychron,项目名称:pychron,代码行数:34,代码来源:system_monitor_editor.py


示例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)
开发者ID:NMGRL,项目名称:pychron,代码行数:8,代码来源:degasser.py


示例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())
开发者ID:OSUPychron,项目名称:pychron,代码行数:8,代码来源:exception_helper.py


示例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
开发者ID:jirhiker,项目名称:pychron,代码行数:57,代码来源:peak_hop_collector.py


示例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)
开发者ID:jirhiker,项目名称:pychron,代码行数:9,代码来源:base_task.py


示例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)
开发者ID:jirhiker,项目名称:pychron,代码行数:9,代码来源:display.py


示例16: view_image

def view_image(im, auto_close=True):
    def _func():
        open_view(im)
        if auto_close:
            minutes = 2
            t = Timer(60 * minutes, im.close_ui)
            t.start()

    invoke_in_main_thread(_func)
开发者ID:kenlchen,项目名称:pychron,代码行数:9,代码来源:machine_vision_manager.py


示例17: _execute_lumen_degas

    def _execute_lumen_degas(self, controller, pattern):
        from pychron.core.pid import PID
        from pychron.core.ui.gui import invoke_in_main_thread
        from pychron.lasers.pattern.mv_viewer import MVViewer
        from pychron.graph.stream_graph import StreamStackedGraph
        from pychron.mv.mv_image import MVImage

        lm = self.laser_manager
        sm = lm.stage_manager

        g = StreamStackedGraph()

        img = MVImage()

        img.setup_images(2, sm.get_frame_size())

        mvviewer = MVViewer(graph=g, image=img)
        mvviewer.edit_traits()
        # g.edit_traits()

        g.new_plot(xtitle='Time', ytitle='Lumens')
        g.new_series()

        g.new_plot(xtitle='Time', ytitle='Error')
        g.new_series(plotid=1)

        g.new_plot(xtitle='Time', ytitle='Power')
        g.new_series(plotid=2)

        duration = pattern.duration
        lumens = pattern.lumens
        dt = pattern.period
        st = time.time()

        pid = PID()

        def update(c, e, o, cs, ss):
            g.record(c, plotid=0)
            g.record(e, plotid=1)
            g.record(o, plotid=2)

            img.set_image(cs, 0)
            img.set_image(ss, 1)

        while self._alive:

            if duration and time.time() - st > duration:
                break

            with PeriodCTX(dt):
                csrc, src, cl = sm.get_brightness()

                err = lumens - cl
                out = pid.get_value(err, dt)
                lm.set_laser_power(out)
                invoke_in_main_thread(update, (cl, err, out, csrc, src))
开发者ID:OSUPychron,项目名称:pychron,代码行数:56,代码来源:pattern_executor.py


示例18: message

    def message(self, msg):
        from pychron.displays.gdisplays import gMessageDisplay

        if not gMessageDisplay.opened and not gMessageDisplay.was_closed:
            gMessageDisplay.opened = True
            invoke_in_main_thread(gMessageDisplay.edit_traits)

        gMessageDisplay.add_text(msg)

        self.info(msg)
开发者ID:jirhiker,项目名称:pychron,代码行数:10,代码来源:loggable.py


示例19: _test

    def _test(self):

        p = '/Users/ross/Pychrondata_demo/data/snapshots/scan6/007.jpg'
        g = Graph()
        g.new_plot()


        for scan_i, z, idxs in [
#                    1,
#                     2,
#                     3, 4, 5,
#                     (6, [20, 30, 40, 50, 60, 70, 80, 90, 100, ],
#                         [2, 3, 4, 5, 6, 7, 8, 9, 10]
#                      ),
                    (6, [10],
                        [1]
                     ),
#                     (6, [100, 90, 80, 70, 60, 50, 40, 30, 20],
#                         [11, 12, 13, 14, 15, 16, 17, 18, 19]
#                     )

                   ]:
            dxs = []
            zs = []
            root = '/Users/ross/Pychrondata_demo/data/snapshots/scan{}'.format(scan_i)
            for  zi, idx in zip(z, idxs):
                pn = os.path.join(root, '{:03n}.jpg'.format(idx))
                d = load_image(pn)

                dx = self._calculate_spacing(d)
                dxs.append(dx)

                zs.append(zi)

            g.new_series(zs, dxs, type='scatter')

            coeffs = polyfit(zs, dxs, 2)
            print 'parabolic intercept {}'.format(coeffs[-1])

            xs = linspace(0, max(zs))
            ys = polyval(coeffs, xs)
            g.new_series(xs, ys)

            fitfunc = lambda p, x: p[0] * exp(p[1] * x) + p[2]
            lr = LeastSquaresRegressor(fitfunc=fitfunc,
                                       initial_guess=[1, 0.1, 0],
                                       xs=zs,
                                       ys=dxs
                                       )
            xs = linspace(0, max(zs))
            ys = lr.predict(xs)
            print 'exponential intercept {}'.format(lr.predict(0))
            g.new_series(xs, ys)

        invoke_in_main_thread(g.edit_traits)
开发者ID:UManPychron,项目名称:pychron,代码行数:55,代码来源:zoom_calibration.py


示例20: _consume

    def _consume(self, timeout):
        bt = self._buftime
        if bt:
            bt = bt / 1000.

            def get_func():
                q = self._consumer_queue
                v = None
                while 1:
                    try:
                        v = q.get(timeout=bt)
                    except Empty:
                        break
                return v
        else:
            def get_func():
                try:
                    return self._consumer_queue.get(timeout=1)
                except Empty:
                    return

        cfunc = self._consume_func

        st = time.time()
        while self._should_consume:
            if timeout:
                if time.time() - st > timeout:
                    self._should_consume = False
                    self._consumer_queue = None
                    print 'consumer time out'
                    break

            try:
                v = get_func()
                if v:
                    if cfunc:
                        if self._main:
                            from pychron.core.ui.gui import invoke_in_main_thread

                            invoke_in_main_thread(cfunc, v)
                        else:
                            cfunc(v)
                    elif isinstance(v, tuple):
                        func, a = v
                        if self._main:
                            from pychron.core.ui.gui import invoke_in_main_thread

                            invoke_in_main_thread(func, a)
                        else:
                            func(a)
            except Exception, e:
                import traceback

                traceback.print_exc()
开发者ID:UManPychron,项目名称:pychron,代码行数:54,代码来源:consumer_mixin.py



注:本文中的pychron.core.ui.gui.invoke_in_main_thread函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python tabular_editor.myTabularEditor函数代码示例发布时间:2022-05-25
下一篇:
Python strtools.to_bool函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap