예제 #1
0
    def _schedule_refresh(self, change):
        """ Schedule an item refresh when the item dependencies change.

        """
        if change['type'] == 'update':
            if self._update_task is None:
                self._update_task = schedule(self._refresh)
예제 #2
0
    def _schedule_refresh(self, change):
        """ Schedule an item refresh when the item dependencies change.

        """
        if change['type'] == 'update':
            if self._update_task is None:
                self._update_task = schedule(self._refresh)
예제 #3
0
파일: processor.py 프로젝트: Qcircuits/ecpy
def schedule_and_block(func, args=(), kwargs={}, priority=100):
    """Schedule a function call on the main thread and wait for it to complete.

    """
    sheduled = schedule(func, args, kwargs, priority=100)
    while sheduled.pending():
        sleep(0.05)
예제 #4
0
파일: processor.py 프로젝트: Ecpy/ecpy
def schedule_and_block(func, args=(), kwargs={}, priority=100):
    """Schedule a function call on the main thread and wait for it to complete.

    """
    sheduled = schedule(func, args, kwargs, priority=100)
    while sheduled.pending():
        sleep(0.05)
예제 #5
0
    def request_redraw(self, clear: bool = False) -> None:
        """Request to redraw the canvas.

        If the canvas does not exist it is a no-op.

        """
        if not self._canvas or (
            self._redraw_task is not None and (not clear or self._redraw_and_clear)
        ):
            return

        task = self._redraw_task = schedule(self._redraw_handler, (clear,))
        self._redraw_and_clear = clear
        task.notify(self._cleanup_redraw_task)
예제 #6
0
    def _stop_monitors(self, measure):
        """Disconnect the monitors from the engine and stop them.

        The monitors windows is not hidden as the user may want to check it
        later.

        """
        def stop_monitors(engine, measure):
            if engine:
                engine.unobserve('news')
            for monitor in measure.monitors.values():
                monitor.stop()

        # Executed in the main thread to avoid GUI update issues.
        sheduled = schedule(stop_monitors, (self.engine, measure),
                            priority=100)
        while sheduled.pending():
            sleep(0.05)
예제 #7
0
    def _stop_monitors(self, measure):
        """Disconnect the monitors from the engine and stop them.

        The monitors windows is not hidden as the user may want to check it
        later.

        """
        def stop_monitors(engine, measure):
            if engine:
                engine.unobserve('news')
            for monitor in measure.monitors.values():
                monitor.stop()

        # Executed in the main thread to avoid GUI update issues.
        sheduled = schedule(stop_monitors, (self.engine, measure),
                            priority=100)
        while sheduled.pending():
            sleep(0.05)
예제 #8
0
    def _start_monitors(self, measure):
        """Start the monitors attached to a measure and display them.

        If no dedicated window exists one will be created. For monitors for
        which a dockitem already exists it is re-used.

        """
        def start_monitors(self, measure):

            workbench = self.plugin.workbench
            if not self.monitors_window:
                ui_plugin = workbench.get_plugin('enaml.workbench.ui')
                with enaml.imports():
                    from .workspace.monitors_window import MonitorsWindow
                self.monitors_window = MonitorsWindow(ui_plugin.window)

            self.monitors_window.measure = measure

            dock_area = self.monitors_window.dock_area
            anchor = ''
            for dock_item in dock_area.dock_items():
                if dock_item.name not in measure.monitors:
                    dock_item.destroy()
                elif not anchor:
                    anchor = dock_item.name

            # We show the window now because otherwise the layout ops are not
            # properly executed.
            if self.plugin.auto_show_monitors:
                self.monitors_window.show()

            ops = []
            for monitor in measure.monitors.values():
                decl = monitor.declaration
                dock_item = dock_area.find(decl.id)
                if dock_item is None:
                    try:
                        dock_item = decl.create_item(workbench, dock_area)
                    except Exception:
                        logger.error('Failed to create widget for monitor %s',
                                     decl.id)
                        logger.debug(format_exc())
                        continue

                    if dock_item is not None:
                        if dock_item.float_default:
                            ops.append(FloatItem(item=decl.id))
                        else:
                            ops.append(InsertTab(item=decl.id,
                                                 target=anchor))

                self.engine.observe('progress', monitor.process_news)
                if dock_item:
                    dock_item.monitor = monitor
                monitor.start()

            if ops:
                dock_area.update_layout(ops)

        # Executed in the main thread to avoid GUI update issues.
        sheduled = schedule(start_monitors, (self, measure), priority=100)
        while sheduled.pending():
            sleep(0.05)
예제 #9
0
 def _worker(self):
     while True:
         job = self._jobs_queue.get()
         result = job.run(self)
         schedule(job.finish, args=(self, result))
예제 #10
0
def safe_getattr(obj, name, default=None):
    if Application.instance() is None:
        return getattr(obj, name, default)
    return schedule(getattr, args=(obj, name, default))
예제 #11
0
    def _start_monitors(self, measure):
        """Start the monitors attached to a measure and display them.

        If no dedicated window exists one will be created. For monitors for
        which a dockitem already exists it is re-used.

        """
        def start_monitors(self, measure):

            workbench = self.plugin.workbench
            if not self.monitors_window:
                ui_plugin = workbench.get_plugin('enaml.workbench.ui')
                with enaml.imports():
                    from .workspace.monitors_window import MonitorsWindow
                self.monitors_window = MonitorsWindow(ui_plugin.window)

            self.monitors_window.measure = measure

            dock_area = self.monitors_window.dock_area
            anchor = ''
            for dock_item in dock_area.dock_items():
                if dock_item.name not in measure.monitors:
                    dock_item.destroy()
                elif not anchor:
                    anchor = dock_item.name

            # We show the window now because otherwise the layout ops are not
            # properly executed.
            if self.plugin.auto_show_monitors:
                self.monitors_window.show()

            ops = []
            for monitor in measure.monitors.values():
                decl = monitor.declaration
                dock_item = dock_area.find(decl.id)
                if dock_item is None:
                    try:
                        dock_item = decl.create_item(workbench, dock_area)
                    except Exception:
                        logger.error('Failed to create widget for monitor %s',
                                     decl.id)
                        logger.debug(format_exc())
                        continue

                    if dock_item is not None:
                        if dock_item.float_default:
                            ops.append(FloatItem(item=decl.id))
                        else:
                            ops.append(InsertTab(item=decl.id,
                                                 target=anchor))

                self.engine.observe('progress', monitor.process_news)
                if dock_item:
                    dock_item.monitor = monitor
                monitor.start()

            if ops:
                dock_area.update_layout(ops)

        # Executed in the main thread to avoid GUI update issues.
        sheduled = schedule(start_monitors, (self, measure), priority=100)
        while sheduled.pending():
            sleep(0.05)
예제 #12
0
 def _worker(self):
     while True:
         job = self._jobs_queue.get()
         result = job.run(self)
         schedule(job.finish, args=(self, result))